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(ProjectHelper
.PROJECTHELPER_REFERENCE
, 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 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());
48 ProjectHelper helper
= new SlcProjectHelper();
49 p
.addReference(ProjectHelper
.PROJECTHELPER_REFERENCE
, helper
);
50 helper
.parse(p
, antFile
);
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());
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());
68 ProjectHelper helper
= new SlcProjectHelper();
69 p
.addReference(ProjectHelper
.PROJECTHELPER_REFERENCE
, helper
);
70 helper
.parse(p
, antFile
);
71 p
.executeTarget(p
.getDefaultTarget());