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.Arrays;
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 MetaInfMpxConfig {
035
036        private static final String DEFAULT_INCLUDE_PATTERN = "**/*.mpx";
037        private static final String DEFAULT_OUTPUT_FILE = "${project.build.outputDirectory}/META-INF/${project.groupId.base.path}/${project.artifactId}/data.resources";
038        private static final String INCLUDES_KEY = "impex.metainf.includes";
039        private static final String OUTPUT_FILE_KEY = "impex.metainf.includes";
040        private static final String BUILD_OUTPUT_DIR_KEY = "project.build.outputDirectory";
041
042        @Autowired
043        Environment env;
044
045        @Bean
046        public Executable mpxMetaInfExecutable() {
047
048                // Extract the CSV include patterns and convert to a list
049                String csv = SpringUtils.getProperty(env, INCLUDES_KEY, DEFAULT_INCLUDE_PATTERN);
050                List<String> includes = CollectionUtils.getTrimmedListFromCSV(csv);
051
052                // This is the base directory to scan
053                File buildOutputDir = new File(SpringUtils.getProperty(env, BUILD_OUTPUT_DIR_KEY));
054
055                // Output file contains one line of text for each file that gets located
056                // Each line is an entry similar to this "classpath:<groupId>/<artifactId>/<tablename>.mpx"
057                File outputFile = new File(SpringUtils.getProperty(env, OUTPUT_FILE_KEY, DEFAULT_OUTPUT_FILE));
058
059                // Setup the context
060                org.kuali.common.util.metainf.MetaInfContext context = new org.kuali.common.util.metainf.MetaInfContext();
061                context.setBaseDir(buildOutputDir);
062                context.setOutputFile(outputFile);
063                context.setIncludes(includes);
064
065                // Setup and return an executable
066                org.kuali.common.util.execute.MetaInfExecutable exec = new org.kuali.common.util.execute.MetaInfExecutable();
067                exec.setContexts(Arrays.asList(context));
068                return exec;
069        }
070
071}