View Javadoc
1   /**
2    * Copyright 2010-2014 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.util.config.spring;
17  
18  import java.util.Properties;
19  
20  import org.kuali.common.util.maven.MavenConstants;
21  import org.kuali.common.util.maven.MavenUtils;
22  import org.kuali.common.util.maven.spring.AutowiredMavenProperties;
23  import org.kuali.common.util.maven.spring.NoAutowiredMavenProperties;
24  import org.kuali.common.util.project.ProjectService;
25  import org.kuali.common.util.project.model.Project;
26  import org.kuali.common.util.project.spring.ProjectServiceConfig;
27  import org.springframework.beans.factory.annotation.Autowired;
28  import org.springframework.beans.factory.annotation.Qualifier;
29  import org.springframework.context.annotation.Bean;
30  import org.springframework.context.annotation.Configuration;
31  import org.springframework.context.annotation.Import;
32  import org.springframework.util.Assert;
33  
34  /**
35   * You can use this configuration transparently between the Maven CLI and a normal runtime by injecting <code>projectId</code> into your context.
36   * 
37   * When running from the Maven CLI, <code>projectId</code> is ignored because project properties are pre-injected into the context by spring-maven-plugin.
38   * 
39   * When running in a normal runtime, <code>projectId</code> is used to load a <code>project.properties</code> file.
40   * 
41   * Project Id's are in this format:
42   * 
43   * <pre>
44   *   org.kuali.common:kuali-util
45   * </pre>
46   * 
47   * @deprecated
48   */
49  @Configuration
50  @Deprecated
51  public class ProjectPropertySourceConfig extends BasicPropertySourceConfig {
52  
53  	private static final String PROJECT_BEAN_NAME = "project.immutable";
54  	public static final String PROJECT_ID_BEAN_NAME = "project.id";
55  
56  	@Autowired
57  	@Qualifier(PROJECT_BEAN_NAME)
58  	Project project;
59  
60  	@Override
61  	protected Properties getOverrides() {
62  		return project.getProperties();
63  	}
64  
65  	/**
66  	 * @deprecated
67  	 */
68  	@Deprecated
69  	@Configuration
70  	@NoAutowiredMavenProperties
71  	@Import({ ProjectServiceConfig.class })
72  	static class RuntimeProjectConfig {
73  
74  		// Use of this configuration at runtime requires "projectId" wired into the context
75  		// Format for "projectId" is [groupId:artifactId], eg "org.kuali.common:kuali-util"
76  		@Autowired
77  		@Qualifier(PROJECT_ID_BEAN_NAME)
78  		String projectId;
79  
80  		@Autowired
81  		ProjectServiceConfig projectServiceConfig;
82  
83  		@Bean(name = PROJECT_BEAN_NAME)
84  		public Project runtimeProjectConfigProject() {
85  
86  			// Make sure projectId got wired in correctly
87  			Assert.hasText(projectId, "projectId is blank");
88  
89  			// Get a reference to the project service
90  			ProjectService service = projectServiceConfig.projectService();
91  
92  			// Use the service to convert the projectId into a Project
93  			return service.getProject("", "");
94  		}
95  	}
96  
97  	/**
98  	 * @deprecated
99  	 */
100 	@Deprecated
101 	@Configuration
102 	@AutowiredMavenProperties
103 	@Import({ ProjectServiceConfig.class })
104 	static class BuildProjectConfig {
105 
106 		// Spring Maven Plugin wires this in for us
107 		@Autowired
108 		@Qualifier(MavenConstants.PROPERTIES_BEAN_NAME)
109 		Properties mavenProperties;
110 
111 		@Autowired
112 		ProjectServiceConfig projectServiceConfig;
113 
114 		@Bean(name = PROJECT_BEAN_NAME)
115 		public Project buildProjectConfigProject() {
116 			// Make sure the maven properties got wired in correctly
117 			Assert.notNull(mavenProperties, "mavenProperties are null");
118 
119 			// Get a reference to the project service
120 			ProjectService service = projectServiceConfig.projectService();
121 
122 			// Enhance the default set of Maven properties
123 			MavenUtils.augmentProjectProperties(service, mavenProperties);
124 
125 			// Use the service to convert the properties into a Project
126 			return service.getProject(mavenProperties);
127 		}
128 	}
129 
130 }