1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.spring;
17
18 import java.io.File;
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.kuali.common.util.CollectionUtils;
23 import org.kuali.common.util.metainf.MetaInfContext;
24 import org.kuali.common.util.execute.Executable;
25 import org.kuali.common.util.execute.MetaInfExecutable;
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 MetaInfSqlSetupConfig {
33
34 @Autowired
35 Environment env;
36
37 @Bean
38 public Executable metaInfExecutable() {
39 List<MetaInfContext> contexts = new ArrayList<MetaInfContext>();
40 contexts.add(getMetaInfContext("sql.metainf.output.schema", "sql.metainf.include.schema"));
41 contexts.add(getMetaInfContext("sql.metainf.output.data", "sql.metainf.include.data"));
42 contexts.add(getMetaInfContext("sql.metainf.output.constraints", "sql.metainf.include.constraints"));
43 contexts.add(getMetaInfContext("sql.metainf.output.other", "sql.metainf.include.other"));
44
45 MetaInfExecutable mie = new MetaInfExecutable();
46 mie.setSkip(SpringUtils.getBoolean(env, "sql.metainf.sql.skip", false));
47 mie.setContexts(contexts);
48 return mie;
49
50 }
51
52 protected MetaInfContext getMetaInfContext(String outputFileKey, String includesKey) {
53 String csv = SpringUtils.getProperty(env, includesKey);
54 List<String> includes = CollectionUtils.getTrimmedListFromCSV(csv);
55 File outputFile = new File(SpringUtils.getProperty(env, outputFileKey));
56 File baseDir = new File(SpringUtils.getProperty(env, "project.build.outputDirectory"));
57
58 MetaInfContext context = new MetaInfContext();
59 context.setBaseDir(baseDir);
60 context.setOutputFile(outputFile);
61 context.setIncludes(includes);
62 return context;
63 }
64 }