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.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.beans.factory.annotation.Value;
12 import org.springframework.context.annotation.Bean;
13 import org.springframework.context.annotation.Configuration;
14 import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
15 import org.springframework.core.env.ConfigurableEnvironment;
16 import org.springframework.util.Assert;
17
18 @Configuration
19 public class MetaInfProjectPropertiesConfig {
20
21 @Autowired
22 ConfigurableEnvironment env;
23
24 @Bean
25 public static PropertySourcesPlaceholderConfigurer pspc() {
26 return new PropertySourcesPlaceholderConfigurer();
27 }
28
29 @Value("${project.build.outputDirectory}/META-INF/${project.groupId.path}/${project.artifactId}.properties")
30 File outputFile;
31
32 @Bean
33 public Properties springProperties() {
34 return SpringUtils.getAllProperties(env);
35 }
36
37 @Bean(initMethod = "execute")
38 public Executable storePropertiesExecutable() {
39
40
41 String encoding = SpringUtils.getProperty(env, "project.encoding");
42 String includesCSV = SpringUtils.getProperty(env, "project.metainf.includes");
43 String excludesCSV = SpringUtils.getProperty(env, "project.metainf.excludes");
44
45
46 Assert.hasText(encoding);
47 Assert.hasText(includesCSV);
48 Assert.hasText(excludesCSV);
49
50
51 List<String> includes = CollectionUtils.getTrimmedListFromCSV(includesCSV);
52 List<String> excludes = CollectionUtils.getTrimmedListFromCSV(excludesCSV);
53
54
55 Properties properties = springProperties();
56
57
58 StorePropertiesExecutable spe = new StorePropertiesExecutable();
59 spe.setEncoding(encoding);
60 spe.setOutputFile(outputFile);
61 spe.setProperties(properties);
62 spe.setIncludes(includes);
63 spe.setExcludes(excludes);
64 return spe;
65 }
66
67 }