1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.spring.car;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.Properties;
21
22 import org.kuali.common.util.LocationUtils;
23 import org.kuali.common.util.PropertyUtils;
24 import org.kuali.common.util.Str;
25 import org.kuali.common.util.property.Constants;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.context.annotation.Bean;
28 import org.springframework.context.annotation.Configuration;
29 import org.springframework.core.env.Environment;
30 import org.springframework.core.env.PropertiesPropertySource;
31 import org.springframework.util.PropertyPlaceholderHelper;
32
33 @Configuration
34 public class CarPropertySourcesConfig {
35
36 PropertyPlaceholderHelper pph = Constants.DEFAULT_PROPERTY_PLACEHOLDER_HELPER;
37
38 @Autowired
39 Environment env;
40
41 @Bean
42 public String projectPropertiesLocation() {
43 String groupId = "org.kuali.common";
44 String artifactId = "kuali-car";
45
46 Properties properties = new Properties();
47 properties.setProperty("project.groupId.path", Str.getPath(groupId));
48 properties.setProperty("project.artifactId", artifactId);
49
50 return pph.replacePlaceholders(Constants.PROJECT_PROPERTIES_LOCATION, properties);
51 }
52
53 @Bean()
54 public PropertiesPropertySource pps() {
55
56 String ppenc = env.getProperty("project.properties.encoding", "UTF-8");
57 String pploc = projectPropertiesLocation();
58 Properties projectProperties = PropertyUtils.load(pploc, ppenc);
59 String encoding = projectProperties.getProperty("project.encoding");
60 Properties global = PropertyUtils.getGlobalProperties();
61 Properties source = new Properties();
62 source.putAll(global);
63 List<String> locations = new ArrayList<String>();
64 locations.add("classpath:car.properties");
65 locations.add("classpath:${car.make}.properties");
66
67 for (String location : locations) {
68 String resolvedLocation = pph.replacePlaceholders(location, source);
69 boolean exists = LocationUtils.exists(resolvedLocation);
70 if (exists) {
71 source.putAll(PropertyUtils.load(resolvedLocation, encoding));
72 source.putAll(global);
73 }
74 }
75 String name = "springProperties";
76 return new PropertiesPropertySource(name, source);
77 }
78
79 }