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.io.IOException;
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import org.kuali.common.util.CollectionUtils;
24  import org.kuali.common.util.MetaInfContext;
25  import org.kuali.common.util.MetaInfUtils;
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 MetaInfSqlConfig {
33  
34  	@Autowired
35  	Environment env;
36  
37  	@Bean
38  	public Object scanAndCreateFiles() {
39  		List<MetaInfContext> contexts = new ArrayList<MetaInfContext>();
40  		contexts.add(getMetaInfContext("metainf.output.schema", "metainf.include.schema"));
41  		contexts.add(getMetaInfContext("metainf.output.data", "metainf.include.data"));
42  		contexts.add(getMetaInfContext("metainf.output.constraints", "metainf.include.constraints"));
43  		contexts.add(getMetaInfContext("metainf.output.other", "metainf.include.other"));
44  
45  		try {
46  			MetaInfUtils.scanAndCreateFiles(contexts);
47  			return null;
48  		} catch (IOException e) {
49  			throw new IllegalStateException(e);
50  		}
51  	}
52  
53  	protected MetaInfContext getMetaInfContext(String outputFileKey, String includesKey) {
54  		String csv = SpringUtils.getProperty(env, includesKey);
55  		List<String> includes = CollectionUtils.getTrimmedListFromCSV(csv);
56  		File outputFile = new File(SpringUtils.getProperty(env, outputFileKey));
57  		File baseDir = new File(SpringUtils.getProperty(env, "project.build.outputDirectory"));
58  
59  		MetaInfContext context = new MetaInfContext();
60  		context.setBaseDir(baseDir);
61  		context.setOutputFile(outputFile);
62  		context.setIncludes(includes);
63  		return context;
64  	}
65  }