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;
021
022import org.kuali.common.util.CollectionUtils;
023import org.kuali.common.util.execute.Executable;
024import org.springframework.beans.factory.annotation.Autowired;
025import org.springframework.context.annotation.Bean;
026import org.springframework.context.annotation.Configuration;
027import org.springframework.core.env.Environment;
028
029/**
030 * @deprecated
031 */
032@Deprecated
033@Configuration
034public class MetaInfSqlSetupConfig {
035
036        @Autowired
037        Environment env;
038
039        @Bean
040        public Executable metaInfExecutable() {
041                List<org.kuali.common.util.metainf.MetaInfContext> contexts = new ArrayList<org.kuali.common.util.metainf.MetaInfContext>();
042                contexts.add(getMetaInfContext("sql.metainf.output.schema", "sql.metainf.include.schema"));
043                contexts.add(getMetaInfContext("sql.metainf.output.data", "sql.metainf.include.data"));
044                contexts.add(getMetaInfContext("sql.metainf.output.constraints", "sql.metainf.include.constraints"));
045                contexts.add(getMetaInfContext("sql.metainf.output.other", "sql.metainf.include.other"));
046
047                org.kuali.common.util.execute.MetaInfExecutable mie = new org.kuali.common.util.execute.MetaInfExecutable();
048                mie.setSkip(SpringUtils.getBoolean(env, "sql.metainf.sql.skip", false));
049                mie.setContexts(contexts);
050                return mie;
051
052        }
053
054        protected org.kuali.common.util.metainf.MetaInfContext getMetaInfContext(String outputFileKey, String includesKey) {
055                String csv = SpringUtils.getProperty(env, includesKey);
056                List<String> includes = CollectionUtils.getTrimmedListFromCSV(csv);
057                File outputFile = new File(SpringUtils.getProperty(env, outputFileKey));
058                File baseDir = new File(SpringUtils.getProperty(env, "project.build.outputDirectory"));
059
060                org.kuali.common.util.metainf.MetaInfContext context = new org.kuali.common.util.metainf.MetaInfContext();
061                context.setBaseDir(baseDir);
062                context.setOutputFile(outputFile);
063                context.setIncludes(includes);
064                return context;
065        }
066}