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.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   * @deprecated
38   */
39  @Deprecated
40  @Configuration
41  public class MetaInfProjectPropertiesSetupConfig {
42  
43  	@Autowired
44  	ConfigurableEnvironment env;
45  
46  	@Bean
47  	public static PropertySourcesPlaceholderConfigurer pspc() {
48  		return new PropertySourcesPlaceholderConfigurer();
49  	}
50  
51  	@Value(Constants.PROJECT_PROPERTIES_OUTPUTFILE)
52  	File outputFile;
53  
54  	@Value(Constants.RICE_PROJECT_PROPERTIES_OUTPUTFILE)
55  	File riceOutputFile;
56  
57  	@Bean
58  	public Properties springProperties() {
59  		return PropertySourceUtils.getAllEnumerableProperties(env);
60  	}
61  
62  	@Bean
63  	public Executable storePropertiesExecutablesExectuable() {
64  
65  		// Extract property values from the environment
66  		String encoding = SpringUtils.getProperty(env, "project.encoding");
67  
68  		// Encoding must be provided
69  		Assert.hasText(encoding);
70  
71  		// Setup includes / excludes
72  		List<String> includes = SpringUtils.getNoneSensitiveListFromCSV(env, "project.metainf.includes");
73  		List<String> excludes = SpringUtils.getNoneSensitiveListFromCSV(env, "project.metainf.excludes");
74  
75  		// Get the list of all properties spring knows about
76  		Properties properties = springProperties();
77  
78  		// Setup the regular properties file executable
79  		StorePropertiesExecutable spe = new StorePropertiesExecutable();
80  		spe.setSkip(SpringUtils.getBoolean(env, "project.metainf.skip", false));
81  		spe.setSkipIfExists(SpringUtils.getBoolean(env, "project.metainf.skipIfExists", true));
82  		spe.setSkipIfEqual(SpringUtils.getBoolean(env, "project.metainf.skipIfEqual", true));
83  		spe.setEncoding(encoding);
84  		spe.setOutputFile(outputFile);
85  		spe.setProperties(properties);
86  		spe.setIncludes(includes);
87  		spe.setExcludes(excludes);
88  
89  		// Setup the Rice style properties file executable
90  		StoreRicePropertiesExecutable srpe = new StoreRicePropertiesExecutable();
91  		spe.setSkip(SpringUtils.getBoolean(env, "project.metainf.skip", false));
92  		spe.setSkipIfExists(SpringUtils.getBoolean(env, "project.metainf.skipIfExists", true));
93  		spe.setSkipIfEqual(SpringUtils.getBoolean(env, "project.metainf.skipIfEqual", true));
94  		srpe.setEncoding(encoding);
95  		srpe.setOutputFile(riceOutputFile);
96  		srpe.setProperties(properties);
97  		srpe.setIncludes(includes);
98  		srpe.setExcludes(excludes);
99  
100 		// Create an executables list
101 		List<Executable> executables = new ArrayList<Executable>();
102 		executables.add(spe);
103 		executables.add(srpe);
104 
105 		// Return an executable that executes the list
106 		return new ExecutablesExecutable(executables);
107 	}
108 
109 }