1 package org
.argeo
.slc
.ant
.structure
;
4 import java
.util
.Vector
;
6 import org
.apache
.tools
.ant
.BuildException
;
7 import org
.apache
.tools
.ant
.Target
;
9 import org
.argeo
.slc
.ant
.SlcProjectHelper
;
10 import org
.argeo
.slc
.ant
.spring
.AbstractSpringTask
;
11 import org
.argeo
.slc
.core
.structure
.StructurePath
;
12 import org
.argeo
.slc
.core
.structure
.StructureRegistry
;
13 import org
.argeo
.slc
.core
.structure
.tree
.DefaultTreeSAware
;
14 import org
.argeo
.slc
.core
.structure
.tree
.TreeSAware
;
15 import org
.argeo
.slc
.core
.structure
.tree
.TreeSElement
;
16 import org
.argeo
.slc
.core
.structure
.tree
.TreeSPath
;
18 /** Ant task that can be registered within a structure. */
19 public abstract class SAwareTask
extends AbstractSpringTask
{
20 protected final TreeSAware sAware
= new DefaultTreeSAware();
21 protected final List
<SAwareArg
> sAwareArgs
= new Vector
<SAwareArg
>();
24 public void init() throws BuildException
{
25 StructureRegistry registry
= getRegistry();
26 Target target
= getOwningTarget();
27 TreeSElement projectElement
= (TreeSElement
) registry
28 .getElement(SlcProjectHelper
.getProjectPath(getProject()));
29 TreeSElement targetElement
= (TreeSElement
) registry
30 .getElement(createTargetPath(target
));
32 if (targetElement
== null) {
33 // create target element
34 targetElement
= projectElement
.createChild(target
.getName(), target
35 .getDescription() != null ? target
.getDescription()
37 registry
.register(targetElement
);
40 TreeSElement taskElement
= targetElement
.createChild(getTaskName()
41 + targetElement
.getChildren().size(),
42 getDescription() != null ?
getDescription() : "<no task desc>");
43 sAware
.setElement(taskElement
);
48 * Called by Ant at runtime. Decides whether to call the actions depending
49 * of the mode of the underlying structure registry.
51 * @see #executeActions
52 * @see StructureRegistry
54 public final void execute() throws BuildException
{
55 for(SAwareArg arg
: sAwareArgs
){
59 getRegistry().register(sAware
);
61 String mode
= getRegistry().getMode();
62 if (mode
.equals(StructureRegistry
.ALL
)) {
64 } else if (mode
.equals(StructureRegistry
.ACTIVE
)) {
65 List
<StructurePath
> activePaths
= getRegistry().getActivePaths();
67 StructurePath targetPath
= createTargetPath(getOwningTarget());
68 if(activePaths
.contains(targetPath
)){
69 if (activePaths
.contains(sAware
.getElement().getPath())) {
77 /** Actions to be executed by the implementor. */
78 protected abstract void executeActions(String mode
);
80 /** Gets the underlying structure registry. */
81 protected StructureRegistry
getRegistry() {
82 return (StructureRegistry
) getProject().getReference(
83 SlcProjectHelper
.REF_STRUCTURE_REGISTRY
);
86 /** Creates the path for a given Ant target. */
87 protected static StructurePath
createTargetPath(Target target
) {
88 TreeSPath projectPath
= SlcProjectHelper
.getProjectPath(target
90 return TreeSPath
.createChild(projectPath
, target
.getName());