1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.deploy.spring;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.kuali.common.deploy.env.model.DeployEnvironment;
22 import org.kuali.common.deploy.env.spring.DefaultDeployEnvironmentConfig;
23 import org.kuali.common.deploy.env.spring.DeployEnvironmentConfig;
24 import org.kuali.common.deploy.project.DeployProjectConstants;
25 import org.kuali.common.jdbc.project.spring.JdbcProjectConfig;
26 import org.kuali.common.jdbc.project.spring.JdbcPropertyLocationsConfig;
27 import org.kuali.common.util.Assert;
28 import org.kuali.common.util.Mode;
29 import org.kuali.common.util.project.ProjectService;
30 import org.kuali.common.util.project.ProjectUtils;
31 import org.kuali.common.util.project.model.Project;
32 import org.kuali.common.util.project.model.ProjectIdentifier;
33 import org.kuali.common.util.project.spring.AutowiredProjectConfig;
34 import org.kuali.common.util.project.spring.ProjectServiceConfig;
35 import org.kuali.common.util.properties.Location;
36 import org.kuali.common.util.properties.PropertiesLocationService;
37 import org.kuali.common.util.properties.PropertiesService;
38 import org.kuali.common.util.properties.spring.DefaultPropertiesServiceConfig;
39 import org.kuali.common.util.properties.spring.PropertiesLocationServiceConfig;
40 import org.kuali.common.util.property.PropertyFormat;
41 import org.kuali.common.util.spring.PropertySourceUtils;
42 import org.kuali.common.util.spring.service.PropertySourceConfig;
43 import org.kuali.rice.deploy.RiceDeployProjectConstants;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.context.annotation.Bean;
46 import org.springframework.context.annotation.Configuration;
47 import org.springframework.context.annotation.Import;
48 import org.springframework.core.env.PropertySource;
49
50 @Configuration
51 @Import({ JdbcProjectConfig.class, JdbcPropertyLocationsConfig.class, DefaultPropertiesServiceConfig.class, PropertiesLocationServiceConfig.class, AutowiredProjectConfig.class,
52 DefaultDeployEnvironmentConfig.class, ProjectServiceConfig.class })
53 public class DeployPSC implements PropertySourceConfig {
54
55 private static final ProjectIdentifier DEPLOY = DeployProjectConstants.ID;
56
57 @Autowired
58 JdbcPropertyLocationsConfig jdbc;
59
60 @Autowired
61 PropertiesService service;
62
63 @Autowired
64 PropertiesLocationService locationService;
65
66 @Autowired
67 Project project;
68
69 @Autowired
70 ProjectService projectService;
71
72 @Autowired
73 DeployEnvironmentConfig deployEnvConfig;
74
75 @Override
76 @Bean
77 public PropertySource<?> propertySource() {
78
79 DeployEnvironment deployEnv = deployEnvConfig.deployEnvironment();
80
81
82 List<Location> jdbcLocations = jdbc.jdbcPropertyLocations();
83
84
85 Location branchLoc = getOptionalLocation(RiceDeployProjectConstants.ID, "deploy.properties");
86
87
88 String groupCode = project.getProperties().getProperty("project.groupId.code");
89 Assert.noBlanks(groupCode);
90
91
92 Location appLoc = getOptionalLocation(DEPLOY, groupCode + "/" + project.getArtifactId() + ".properties");
93
94
95 Location envLoc = getOptionalLocation(DEPLOY, groupCode + "/" + deployEnv.getName() + ".properties");
96
97
98 List<Location> locations = new ArrayList<Location>();
99 locations.addAll(jdbcLocations);
100 locations.addAll(getKualiDeployLocs());
101 locations.add(branchLoc);
102 locations.add(appLoc);
103 locations.add(envLoc);
104 return PropertySourceUtils.getPropertySource(service, locations);
105 }
106
107 protected Location getOptionalLocation(ProjectIdentifier pid, String filename) {
108 String value = ProjectUtils.getClasspathPrefix(pid) + "/" + filename;
109 Project project = projectService.getProject(pid);
110 String encoding = ProjectUtils.getEncoding(project);
111 return new Location(value, encoding, Mode.INFORM, PropertyFormat.NORMAL, true);
112
113 }
114
115 protected List<Location> getKualiDeployLocs() {
116 List<Location> locs = new ArrayList<Location>();
117 locs.add(getKualiDeployLoc("common.properties"));
118 locs.add(getKualiDeployLoc("appdynamics.properties"));
119 locs.add(getKualiDeployLoc("aws.properties"));
120 locs.add(getKualiDeployLoc("tomcat.properties"));
121 locs.add(getKualiDeployLoc("db.properties"));
122 locs.add(getKualiDeployLoc("rice/common.properties"));
123 locs.add(getKualiDeployLoc("rice/db.properties"));
124 locs.add(getKualiDeployLoc("rice/aws.properties"));
125 locs.add(getKualiDeployLoc("rice/appdynamics.properties"));
126 return locs;
127 }
128
129 protected Location getKualiDeployLoc(String filename) {
130 return locationService.getLocation(DEPLOY, filename);
131 }
132
133 }