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.io.IOException;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.kuali.common.util.CollectionUtils;
24 import org.kuali.common.util.MetaInfContext;
25 import org.kuali.common.util.MetaInfUtils;
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 MetaInfSqlConfig {
33
34 @Autowired
35 Environment env;
36
37 @Bean
38 public Object scanAndCreateFiles() {
39 List<MetaInfContext> contexts = new ArrayList<MetaInfContext>();
40 contexts.add(getMetaInfContext("metainf.output.schema", "metainf.include.schema"));
41 contexts.add(getMetaInfContext("metainf.output.data", "metainf.include.data"));
42 contexts.add(getMetaInfContext("metainf.output.constraints", "metainf.include.constraints"));
43 contexts.add(getMetaInfContext("metainf.output.other", "metainf.include.other"));
44
45 try {
46 MetaInfUtils.scanAndCreateFiles(contexts);
47 return null;
48 } catch (IOException e) {
49 throw new IllegalStateException(e);
50 }
51 }
52
53 protected MetaInfContext getMetaInfContext(String outputFileKey, String includesKey) {
54 String csv = SpringUtils.getProperty(env, includesKey);
55 List<String> includes = CollectionUtils.getTrimmedListFromCSV(csv);
56 File outputFile = new File(SpringUtils.getProperty(env, outputFileKey));
57 File baseDir = new File(SpringUtils.getProperty(env, "project.build.outputDirectory"));
58
59 MetaInfContext context = new MetaInfContext();
60 context.setBaseDir(baseDir);
61 context.setOutputFile(outputFile);
62 context.setIncludes(includes);
63 return context;
64 }
65 }