001    package org.kuali.common.util.spring;
002    
003    import java.util.ArrayList;
004    import java.util.Arrays;
005    import java.util.List;
006    import java.util.Properties;
007    
008    import org.kuali.common.util.PropertyUtils;
009    import org.kuali.common.util.property.Constants;
010    import org.kuali.common.util.property.processor.ProjectProcessor;
011    import org.kuali.common.util.property.processor.PropertyProcessor;
012    import org.kuali.common.util.property.processor.VersionProcessor;
013    import org.springframework.beans.factory.annotation.Autowired;
014    import org.springframework.beans.factory.annotation.Qualifier;
015    import org.springframework.context.annotation.Bean;
016    import org.springframework.context.annotation.Configuration;
017    import org.springframework.core.env.PropertiesPropertySource;
018    
019    /**
020     * Augment the default set of properties that ship with Maven and register them as a Spring <code>PropertySource</code>.
021     * 
022     * spring-maven-plugin auto-registers any beans that implement <code>PropertySource</code> as a top level property source
023     */
024    @Configuration
025    public class ProjectPropertySourceConfig {
026    
027            /**
028             * spring-maven-plugin auto-wires Maven properties by default
029             */
030            @Autowired
031            @Qualifier(Constants.DEFAULT_MAVEN_PROPERTIES_BEAN_NAME)
032            Properties mavenProperties;
033    
034            @Bean
035            public PropertiesPropertySource projectPropertySource() {
036    
037                    // Setup some processors
038                    List<PropertyProcessor> processors = new ArrayList<PropertyProcessor>();
039    
040                    // Add some organization, group, and path properties
041                    processors.add(new ProjectProcessor());
042    
043                    // Tokenize the version number and add properties for each token (major/minor/incremental)
044                    // Also add a boolean property indicating if this is a SNAPSHOT build
045                    processors.add(new VersionProcessor(Arrays.asList("project.version"), true));
046    
047                    // Process default Maven properties and add in our custom properties
048                    PropertyUtils.process(mavenProperties, processors);
049    
050                    // Return the augmented set of Maven properties as a Spring PropertySource
051                    String name = Constants.DEFAULT_MAVEN_PROPERTIES_BEAN_NAME;
052                    return new PropertiesPropertySource(name, mavenProperties);
053            }
054    }