View Javadoc
1   /**
2    * Copyright 2010-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.deploy;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  import java.util.Properties;
21  
22  import org.kuali.common.deploy.spring.DeployConfig;
23  import org.kuali.common.deploy.spring.DeployPropertiesConfig;
24  import org.kuali.common.impex.spring.GeneratorPropertiesConfig;
25  import org.kuali.common.jdbc.spring.JdbcPropertiesConfig;
26  import org.kuali.common.util.CollectionUtils;
27  import org.kuali.common.util.Project;
28  import org.kuali.common.util.execute.Executable;
29  import org.kuali.common.util.property.ProjectProperties;
30  import org.kuali.common.util.property.PropertiesContext;
31  import org.kuali.common.util.property.processor.ProjectProcessor;
32  import org.kuali.common.util.spring.SpringUtils;
33  import org.springframework.beans.factory.annotation.Autowired;
34  import org.springframework.context.annotation.Bean;
35  import org.springframework.context.annotation.Configuration;
36  import org.springframework.context.annotation.Import;
37  import org.springframework.core.env.Environment;
38  import org.springframework.core.env.PropertySource;
39  
40  @Configuration
41  @Import({ JdbcPropertiesConfig.class, GeneratorPropertiesConfig.class, DeployPropertiesConfig.class })
42  public class KSDeployConfig {
43  
44  	@Autowired
45  	protected Environment env;
46  
47  	@Autowired
48  	protected JdbcPropertiesConfig jdbcProperties;
49  
50  	@Autowired
51  	protected GeneratorPropertiesConfig generatorProperties;
52  
53  	@Autowired
54  	protected DeployPropertiesConfig deployProperties;
55  
56  	public List<ProjectProperties> getProjectPropertiesList() {
57  		List<ProjectProperties> pps = new ArrayList<ProjectProperties>();
58  		pps.add(mavenProperties());
59  		pps.add(jdbcProperties.jdbcProjectProperties());
60  		pps.add(generatorProperties.generatorProjectProperties());
61  		pps.add(deployProperties.deployProjectProperties());
62  		return pps;
63  	}
64  
65  	@Bean
66  	public ProjectProperties mavenProperties() {
67  		Properties p = new Properties();
68  		p.setProperty("project.orgId", "org.kuali");
69  		p.setProperty("project.orgId.code", "kuali");
70  		p.setProperty("project.orgId.path", "org/kuali");
71  		p.setProperty("project.groupId", "org.kuali.student.web");
72  		p.setProperty("project.artifactId", "ks-with-rice-bundled");
73  		p.setProperty("project.version", "2.0.0-SNAPSHOT");
74  
75  		ProjectProcessor processor = new ProjectProcessor();
76  		processor.process(p);
77  
78  		Project project = new Project();
79  		project.setGroupId(p.getProperty("project.groupId"));
80  		project.setArtifactId(p.getProperty("project.artifactId"));
81  		project.setVersion(p.getProperty("project.version"));
82  		project.setEncoding("UTF-8");
83  
84  		PropertiesContext pc = new PropertiesContext();
85  		pc.setEncoding(project.getEncoding());
86  		pc.setProperties(p);
87  
88  		ProjectProperties pp = new ProjectProperties();
89  		pp.setProject(project);
90  		pp.setPropertiesContext(pc);
91  		return pp;
92  	}
93  
94  	@Bean
95  	public PropertySource<?> springPropertySource() {
96  		// Combine project properties into a list where the "last one in wins"
97  		List<ProjectProperties> pps = getProjectPropertiesList();
98  
99  		// Get a PropertySource object backed by the properties loaded from the list
100 		return SpringUtils.getPropertySource("springPropertySource", pps);
101 	}
102 
103 	@Bean(initMethod = "execute")
104 	public Executable springExecutable() {
105 		// Setup a flag for skipping the deploy completely
106 		boolean skip = SpringUtils.getBoolean(env, "kdo.deploy.skip", false);
107 		// Get an executable, backed by the correct set of properties, loading the correct config
108 		return SpringUtils.getSpringExecutable(env, skip, springPropertySource(), CollectionUtils.asList(DeployConfig.class));
109 	}
110 
111 }