View Javadoc

1   package org.kuali.common.util.spring;
2   
3   import java.io.File;
4   import java.util.List;
5   import java.util.Properties;
6   
7   import org.kuali.common.util.CollectionUtils;
8   import org.kuali.common.util.execute.Executable;
9   import org.kuali.common.util.execute.StorePropertiesExecutable;
10  import org.kuali.common.util.property.Constants;
11  import org.springframework.beans.factory.annotation.Autowired;
12  import org.springframework.beans.factory.annotation.Value;
13  import org.springframework.context.annotation.Bean;
14  import org.springframework.context.annotation.Configuration;
15  import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
16  import org.springframework.core.env.ConfigurableEnvironment;
17  import org.springframework.util.Assert;
18  
19  @Configuration
20  public class MetaInfProjectPropertiesConfig {
21  
22  	@Autowired
23  	ConfigurableEnvironment env;
24  
25  	@Bean
26  	public static PropertySourcesPlaceholderConfigurer pspc() {
27  		return new PropertySourcesPlaceholderConfigurer();
28  	}
29  
30  	@Value(Constants.PROJECT_PROPERTIES_OUTPUTFILE)
31  	File outputFile;
32  
33  	@Bean
34  	public Properties springProperties() {
35  		return SpringUtils.getAllEnumerableProperties(env);
36  	}
37  
38  	@Bean(initMethod = "execute")
39  	public Executable storePropertiesExecutable() {
40  
41  		// Extract property values from the environment
42  		String encoding = SpringUtils.getProperty(env, "project.encoding");
43  		String includesCSV = SpringUtils.getProperty(env, "project.metainf.includes");
44  		String excludesCSV = SpringUtils.getProperty(env, "project.metainf.excludes");
45  
46  		// Make sure we are configured right
47  		Assert.hasText(encoding);
48  		Assert.hasText(includesCSV);
49  		Assert.hasText(excludesCSV);
50  
51  		// Convert the lists to CSV
52  		List<String> includes = CollectionUtils.getTrimmedListFromCSV(includesCSV);
53  		List<String> excludes = CollectionUtils.getTrimmedListFromCSV(excludesCSV);
54  
55  		// Get the list of all properties spring knows about
56  		Properties properties = springProperties();
57  
58  		// Setup the executable
59  		StorePropertiesExecutable spe = new StorePropertiesExecutable();
60  		spe.setEncoding(encoding);
61  		spe.setOutputFile(outputFile);
62  		spe.setProperties(properties);
63  		spe.setIncludes(includes);
64  		spe.setExcludes(excludes);
65  		return spe;
66  	}
67  
68  }