1 package org
.argeo
.slc
.ant
;
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
;
11 import org
.argeo
.slc
.core
.structure
.StructurePath
;
12 import org
.argeo
.slc
.core
.structure
.StructureRegistry
;
14 /** Utilities to manipulate the structure registry in SLC Ant. */
15 public class AntRegistryUtil
{
16 private static Log log
= LogFactory
.getLog(AntRegistryUtil
.class);
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());
26 ProjectHelper helper
= new SlcProjectHelper();
27 p
.addReference("ant.projectHelper", helper
);
28 helper
.parse(p
, antFile
);
30 StructureRegistry registry
= (StructureRegistry
) p
31 .getReference(SlcProjectHelper
.REF_STRUCTURE_REGISTRY
);
32 registry
.setMode(StructureRegistry
.READ
);
34 p
.executeTarget(p
.getDefaultTarget());
38 /** Executes only the active paths of the Ant file. */
39 public static void runActive(File antFile
, List
<StructurePath
> activePaths
) {
40 if (log
.isDebugEnabled())
41 log
.debug("Runs the " + activePaths
.size()
42 + " provided active paths of Ant file " + antFile
);
43 Project p
= new Project();
44 p
.setUserProperty("ant.file", antFile
.getAbsolutePath());
45 p
.setBaseDir(antFile
.getParentFile());
47 ProjectHelper helper
= new SlcProjectHelper();
48 p
.addReference("ant.projectHelper", helper
);
49 helper
.parse(p
, antFile
);
51 StructureRegistry registry
= (StructureRegistry
) p
52 .getReference(SlcProjectHelper
.REF_STRUCTURE_REGISTRY
);
53 registry
.setMode(StructureRegistry
.ACTIVE
);
54 registry
.setActivePaths(activePaths
);
55 p
.executeTarget(p
.getDefaultTarget());
58 /** Executes all paths of the default target of the Ant file. */
59 public static void runAll(File antFile
) {
60 if (log
.isDebugEnabled())
61 log
.debug("Runs all paths of Ant file " + antFile
);
62 Project p
= new Project();
63 p
.setUserProperty("ant.file", antFile
.getAbsolutePath());
64 p
.setBaseDir(antFile
.getParentFile());
66 ProjectHelper helper
= new SlcProjectHelper();
67 p
.addReference("ant.projectHelper", helper
);
68 helper
.parse(p
, antFile
);
69 p
.executeTarget(p
.getDefaultTarget());