001/** 002 * Copyright 2010-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.common.util.spring; 017 018import java.io.File; 019import java.util.ArrayList; 020import java.util.List; 021import java.util.Properties; 022 023import org.kuali.common.util.execute.Executable; 024import org.kuali.common.util.execute.ExecutablesExecutable; 025import org.kuali.common.util.execute.StorePropertiesExecutable; 026import org.kuali.common.util.execute.StoreRicePropertiesExecutable; 027import org.kuali.common.util.property.Constants; 028import org.springframework.beans.factory.annotation.Autowired; 029import org.springframework.beans.factory.annotation.Value; 030import org.springframework.context.annotation.Bean; 031import org.springframework.context.annotation.Configuration; 032import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; 033import org.springframework.core.env.ConfigurableEnvironment; 034import org.springframework.util.Assert; 035 036/** 037 * @deprecated 038 */ 039@Deprecated 040@Configuration 041public class MetaInfProjectPropertiesSetupConfig { 042 043 @Autowired 044 ConfigurableEnvironment env; 045 046 @Bean 047 public static PropertySourcesPlaceholderConfigurer pspc() { 048 return new PropertySourcesPlaceholderConfigurer(); 049 } 050 051 @Value(Constants.PROJECT_PROPERTIES_OUTPUTFILE) 052 File outputFile; 053 054 @Value(Constants.RICE_PROJECT_PROPERTIES_OUTPUTFILE) 055 File riceOutputFile; 056 057 @Bean 058 public Properties springProperties() { 059 return PropertySourceUtils.getAllEnumerableProperties(env); 060 } 061 062 @Bean 063 public Executable storePropertiesExecutablesExectuable() { 064 065 // Extract property values from the environment 066 String encoding = SpringUtils.getProperty(env, "project.encoding"); 067 068 // Encoding must be provided 069 Assert.hasText(encoding); 070 071 // Setup includes / excludes 072 List<String> includes = SpringUtils.getNoneSensitiveListFromCSV(env, "project.metainf.includes"); 073 List<String> excludes = SpringUtils.getNoneSensitiveListFromCSV(env, "project.metainf.excludes"); 074 075 // Get the list of all properties spring knows about 076 Properties properties = springProperties(); 077 078 // Setup the regular properties file executable 079 StorePropertiesExecutable spe = new StorePropertiesExecutable(); 080 spe.setSkip(SpringUtils.getBoolean(env, "project.metainf.skip", false)); 081 spe.setSkipIfExists(SpringUtils.getBoolean(env, "project.metainf.skipIfExists", true)); 082 spe.setSkipIfEqual(SpringUtils.getBoolean(env, "project.metainf.skipIfEqual", true)); 083 spe.setEncoding(encoding); 084 spe.setOutputFile(outputFile); 085 spe.setProperties(properties); 086 spe.setIncludes(includes); 087 spe.setExcludes(excludes); 088 089 // Setup the Rice style properties file executable 090 StoreRicePropertiesExecutable srpe = new StoreRicePropertiesExecutable(); 091 spe.setSkip(SpringUtils.getBoolean(env, "project.metainf.skip", false)); 092 spe.setSkipIfExists(SpringUtils.getBoolean(env, "project.metainf.skipIfExists", true)); 093 spe.setSkipIfEqual(SpringUtils.getBoolean(env, "project.metainf.skipIfEqual", true)); 094 srpe.setEncoding(encoding); 095 srpe.setOutputFile(riceOutputFile); 096 srpe.setProperties(properties); 097 srpe.setIncludes(includes); 098 srpe.setExcludes(excludes); 099 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}