]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.core/src/main/java/org/argeo/slc/ant/AntRegistryUtil.java
Progress on Web reporting
[gpl/argeo-slc.git] / org.argeo.slc.core / 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
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8 import org.apache.tools.ant.Project;
9 import org.apache.tools.ant.ProjectHelper;
10
11 import org.argeo.slc.core.structure.StructurePath;
12 import org.argeo.slc.core.structure.StructureRegistry;
13
14 /** Utilities to manipulate the structure registry in SLC Ant. */
15 public class AntRegistryUtil {
16 private static Log log = LogFactory.getLog(AntRegistryUtil.class);
17
18 /** Reads a structure registry from an Ant file without executing it. */
19 public static StructureRegistry readRegistry(File antFile) {
20 if (log.isDebugEnabled())
21 log.debug("Reads registry for Ant file " + antFile);
22 Project p = new Project();
23 p.setUserProperty("ant.file", antFile.getAbsolutePath());
24 p.setBaseDir(antFile.getParentFile());
25 p.init();
26 ProjectHelper helper = new SlcProjectHelper();
27 p.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, helper);
28 helper.parse(p, antFile);
29
30 StructureRegistry registry = (StructureRegistry) p
31 .getReference(SlcProjectHelper.REF_STRUCTURE_REGISTRY);
32 registry.setMode(StructureRegistry.READ);
33
34 p.executeTarget(p.getDefaultTarget());
35 return registry;
36 }
37
38 /** Executes only the active paths of the Ant file. */
39 public static Project runActive(File antFile,
40 List<StructurePath> activePaths) {
41 if (log.isDebugEnabled())
42 log.debug("Runs the " + activePaths.size()
43 + " provided active paths of Ant file " + antFile);
44 Project p = new Project();
45 p.setUserProperty("ant.file", antFile.getAbsolutePath());
46 p.setBaseDir(antFile.getParentFile());
47 p.init();
48 ProjectHelper helper = new SlcProjectHelper();
49 p.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, helper);
50 helper.parse(p, antFile);
51
52 StructureRegistry registry = (StructureRegistry) p
53 .getReference(SlcProjectHelper.REF_STRUCTURE_REGISTRY);
54 registry.setMode(StructureRegistry.ACTIVE);
55 registry.setActivePaths(activePaths);
56 p.executeTarget(p.getDefaultTarget());
57 return p;
58 }
59
60 /** Executes all paths of the default target of the Ant file. */
61 public static Project runAll(File antFile) {
62 if (log.isDebugEnabled())
63 log.debug("Runs all paths of Ant file " + antFile);
64 Project p = new Project();
65 p.setUserProperty("ant.file", antFile.getAbsolutePath());
66 p.setBaseDir(antFile.getParentFile());
67 p.init();
68 ProjectHelper helper = new SlcProjectHelper();
69 p.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, helper);
70 helper.parse(p, antFile);
71 p.executeTarget(p.getDefaultTarget());
72 return p;
73 }
74 }