]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc/src/main/java/org/argeo/slc/ant/AntRegistryUtil.java
c495b9253616202f293c84b869130482e69679e4
[gpl/argeo-slc.git] / org.argeo.slc / src / main / java / org / argeo / slc / ant / AntRegistryUtil.java
1 package org.argeo.slc.ant;
2
3 import java.io.File;
4 import java.util.List;
5 import java.util.Vector;
6
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9 import org.apache.tools.ant.Project;
10 import org.apache.tools.ant.ProjectHelper;
11
12 import org.argeo.slc.core.structure.StructureElement;
13 import org.argeo.slc.core.structure.StructurePath;
14 import org.argeo.slc.core.structure.StructureRegistry;
15
16 public class AntRegistryUtil {
17 private static Log log = LogFactory.getLog(AntRegistryUtil.class);
18
19 public static StructureRegistry readRegistry(File antFile) {
20
21 Project p = new Project();
22 p.setUserProperty("ant.file", antFile.getAbsolutePath());
23 p.init();
24 ProjectHelper helper = new SlcProjectHelper();
25 p.addReference("ant.projectHelper", helper);
26 helper.parse(p, antFile);
27
28 StructureRegistry registry = (StructureRegistry) p
29 .getReference(SlcProjectHelper.REF_STRUCTURE_REGISTRY);
30 registry.setMode(StructureRegistry.READ);
31
32 p.executeTarget(p.getDefaultTarget());
33 return registry;
34 }
35
36 public static void runActive(File antFile, List<StructurePath> activePaths) {
37
38 Project p = new Project();
39 p.setUserProperty("ant.file", antFile.getAbsolutePath());
40 p.init();
41 ProjectHelper helper = new SlcProjectHelper();
42 p.addReference("ant.projectHelper", helper);
43 helper.parse(p, antFile);
44
45 StructureRegistry registry = (StructureRegistry) p
46 .getReference(SlcProjectHelper.REF_STRUCTURE_REGISTRY);
47 registry.setMode(StructureRegistry.ACTIVE);
48 registry.setActivePaths(activePaths);
49 p.executeTarget(p.getDefaultTarget());
50 }
51
52 public static void main(String[] args) {
53 File antFile = new File(
54 "C:/dev/workspaces/default/org.argeo.slc/src/test/ant/build.xml");
55 System
56 .setProperty(SlcProjectHelper.PROP_APPLICATION_CONTEXT,
57 "C:/dev/workspaces/default/org.argeo.slc/src/test/ant/applicationContext.xml");
58 StructureRegistry registry = AntRegistryUtil.readRegistry(antFile);
59
60 StringBuffer buf = new StringBuffer("");
61
62 int count = 0;
63 List<StructurePath> activePaths = new Vector<StructurePath>();
64 for (StructureElement element : registry.listElements()) {
65 buf.append(element.getPath());
66 if (count != 0 && count % 2 == 0) {
67 // skip
68 } else {
69 activePaths.add(element.getPath());
70 buf.append(" <");
71 }
72 buf.append('\n');
73 count++;
74 }
75 log.info(buf);
76
77 runActive(antFile, activePaths);
78
79 }
80
81 }