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  
22  import org.kuali.common.util.CollectionUtils;
23  import org.kuali.common.util.metainf.MetaInfContext;
24  import org.kuali.common.util.execute.Executable;
25  import org.kuali.common.util.execute.MetaInfExecutable;
26  import org.springframework.beans.factory.annotation.Autowired;
27  import org.springframework.context.annotation.Bean;
28  import org.springframework.context.annotation.Configuration;
29  import org.springframework.core.env.Environment;
30  
31  @Configuration
32  public class MetaInfSqlSetupConfig {
33  
34  	@Autowired
35  	Environment env;
36  
37  	@Bean
38  	public Executable metaInfExecutable() {
39  		List<MetaInfContext> contexts = new ArrayList<MetaInfContext>();
40  		contexts.add(getMetaInfContext("sql.metainf.output.schema", "sql.metainf.include.schema"));
41  		contexts.add(getMetaInfContext("sql.metainf.output.data", "sql.metainf.include.data"));
42  		contexts.add(getMetaInfContext("sql.metainf.output.constraints", "sql.metainf.include.constraints"));
43  		contexts.add(getMetaInfContext("sql.metainf.output.other", "sql.metainf.include.other"));
44  
45  		MetaInfExecutable mie = new MetaInfExecutable();
46  		mie.setSkip(SpringUtils.getBoolean(env, "sql.metainf.sql.skip", false));
47  		mie.setContexts(contexts);
48  		return mie;
49  
50  	}
51  
52  	protected MetaInfContext getMetaInfContext(String outputFileKey, String includesKey) {
53  		String csv = SpringUtils.getProperty(env, includesKey);
54  		List<String> includes = CollectionUtils.getTrimmedListFromCSV(csv);
55  		File outputFile = new File(SpringUtils.getProperty(env, outputFileKey));
56  		File baseDir = new File(SpringUtils.getProperty(env, "project.build.outputDirectory"));
57  
58  		MetaInfContext context = new MetaInfContext();
59  		context.setBaseDir(baseDir);
60  		context.setOutputFile(outputFile);
61  		context.setIncludes(includes);
62  		return context;
63  	}
64  }