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