001 /**
002 * Copyright 2010-2013 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 */
016 package org.kuali.common.util.spring;
017
018 import java.io.File;
019 import java.io.IOException;
020 import java.util.ArrayList;
021 import java.util.List;
022
023 import org.kuali.common.util.CollectionUtils;
024 import org.kuali.common.util.MetaInfContext;
025 import org.kuali.common.util.MetaInfUtils;
026 import org.springframework.beans.factory.annotation.Autowired;
027 import org.springframework.context.annotation.Bean;
028 import org.springframework.context.annotation.Configuration;
029 import org.springframework.core.env.Environment;
030
031 @Configuration
032 public class MetaInfSqlConfig {
033
034 @Autowired
035 Environment env;
036
037 @Bean
038 public Object scanAndCreateFiles() {
039 List<MetaInfContext> contexts = new ArrayList<MetaInfContext>();
040 contexts.add(getMetaInfContext("metainf.output.schema", "metainf.include.schema"));
041 contexts.add(getMetaInfContext("metainf.output.data", "metainf.include.data"));
042 contexts.add(getMetaInfContext("metainf.output.constraints", "metainf.include.constraints"));
043 contexts.add(getMetaInfContext("metainf.output.other", "metainf.include.other"));
044
045 try {
046 MetaInfUtils.scanAndCreateFiles(contexts);
047 return null;
048 } catch (IOException e) {
049 throw new IllegalStateException(e);
050 }
051 }
052
053 protected MetaInfContext getMetaInfContext(String outputFileKey, String includesKey) {
054 String csv = SpringUtils.getProperty(env, includesKey);
055 List<String> includes = CollectionUtils.getTrimmedListFromCSV(csv);
056 File outputFile = new File(SpringUtils.getProperty(env, outputFileKey));
057 File baseDir = new File(SpringUtils.getProperty(env, "project.build.outputDirectory"));
058
059 MetaInfContext context = new MetaInfContext();
060 context.setBaseDir(baseDir);
061 context.setOutputFile(outputFile);
062 context.setIncludes(includes);
063 return context;
064 }
065 }