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.util.spring;
17  
18  import java.io.File;
19  import java.util.ArrayList;
20  import java.util.List;
21  import java.util.Properties;
22  
23  import org.kuali.common.util.execute.Executable;
24  import org.kuali.common.util.execute.ExecutablesExecutable;
25  import org.kuali.common.util.execute.StorePropertiesExecutable;
26  import org.kuali.common.util.execute.StoreRicePropertiesExecutable;
27  import org.kuali.common.util.property.Constants;
28  import org.springframework.beans.factory.annotation.Autowired;
29  import org.springframework.beans.factory.annotation.Value;
30  import org.springframework.context.annotation.Bean;
31  import org.springframework.context.annotation.Configuration;
32  import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
33  import org.springframework.core.env.ConfigurableEnvironment;
34  import org.springframework.util.Assert;
35  
36  /**
37   * Create project.properties and embed it inside META-INF for jar's/war's
38   */
39  @Configuration
40  public class MetaInfProjectPropertiesSetupConfig {
41  
42  	@Autowired
43  	ConfigurableEnvironment env;
44  
45  	@Bean
46  	public static PropertySourcesPlaceholderConfigurer pspc() {
47  		return new PropertySourcesPlaceholderConfigurer();
48  	}
49  
50  	@Value(Constants.PROJECT_PROPERTIES_OUTPUTFILE)
51  	File outputFile;
52  
53  	@Value(Constants.RICE_PROJECT_PROPERTIES_OUTPUTFILE)
54  	File riceOutputFile;
55  
56  	@Bean
57  	public Properties springProperties() {
58  		return SpringUtils.getAllEnumerableProperties(env);
59  	}
60  
61  	@Bean
62  	public Executable storePropertiesExecutablesExectuable() {
63  
64  		// Extract property values from the environment
65  		String encoding = SpringUtils.getProperty(env, "project.encoding");
66  
67  		// Encoding must be provided
68  		Assert.hasText(encoding);
69  
70  		// Setup includes / excludes
71  		List<String> includes = SpringUtils.getNoneSensitiveListFromCSV(env, "project.metainf.includes");
72  		List<String> excludes = SpringUtils.getNoneSensitiveListFromCSV(env, "project.metainf.excludes");
73  
74  		// Get the list of all properties spring knows about
75  		Properties properties = springProperties();
76  
77  		// Setup the regular properties file executable
78  		StorePropertiesExecutable spe = new StorePropertiesExecutable();
79  		spe.setSkip(SpringUtils.getBoolean(env, "project.metainf.skip", false));
80  		spe.setEncoding(encoding);
81  		spe.setOutputFile(outputFile);
82  		spe.setProperties(properties);
83  		spe.setIncludes(includes);
84  		spe.setExcludes(excludes);
85  
86  		// Setup the Rice style properties file executable
87  		StoreRicePropertiesExecutable srpe = new StoreRicePropertiesExecutable();
88  		srpe.setSkip(SpringUtils.getBoolean(env, "project.metainf.rice.skip", false));
89  		srpe.setEncoding(encoding);
90  		srpe.setOutputFile(riceOutputFile);
91  		srpe.setProperties(properties);
92  		srpe.setIncludes(includes);
93  		srpe.setExcludes(excludes);
94  
95  		// Create an executables list
96  		List<Executable> executables = new ArrayList<Executable>();
97  		executables.add(spe);
98  		executables.add(srpe);
99  
100 		// Return an executable that executes the list
101 		return new ExecutablesExecutable(executables);
102 	}
103 
104 }