X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fant%2Fstructure%2FSAwareTask.java;h=3f4d35864abd8017f3ac0629caff3ec8fd9ae99c;hb=2f6d4fafcbd3fb0560c178356b91ddc9833d325d;hp=3defcd73f756de28d1af8ff7fc5bc337c4e023a1;hpb=6e6998e19852f8209f955c0d2c773feca161d4d0;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc/src/main/java/org/argeo/slc/ant/structure/SAwareTask.java b/org.argeo.slc/src/main/java/org/argeo/slc/ant/structure/SAwareTask.java index 3defcd73f..3f4d35864 100644 --- a/org.argeo.slc/src/main/java/org/argeo/slc/ant/structure/SAwareTask.java +++ b/org.argeo.slc/src/main/java/org/argeo/slc/ant/structure/SAwareTask.java @@ -7,40 +7,43 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Target; import org.argeo.slc.ant.SlcProjectHelper; +import org.argeo.slc.ant.spring.AbstractSpringArg; import org.argeo.slc.ant.spring.AbstractSpringTask; +import org.argeo.slc.core.structure.SimpleSElement; +import org.argeo.slc.core.structure.StructureAware; +import org.argeo.slc.core.structure.StructureElement; import org.argeo.slc.core.structure.StructurePath; import org.argeo.slc.core.structure.StructureRegistry; -import org.argeo.slc.core.structure.tree.DefaultTreeSAware; -import org.argeo.slc.core.structure.tree.TreeSAware; -import org.argeo.slc.core.structure.tree.TreeSElement; import org.argeo.slc.core.structure.tree.TreeSPath; /** Ant task that can be registered within a structure. */ -public abstract class SAwareTask extends AbstractSpringTask { - protected final TreeSAware sAware = new DefaultTreeSAware(); - protected final List sAwareArgs = new Vector(); +public abstract class SAwareTask extends AbstractSpringTask implements + StructureElement { + private TreeSPath path; + private final List sAwareArgs = new Vector(); @Override public void init() throws BuildException { StructureRegistry registry = getRegistry(); Target target = getOwningTarget(); - TreeSElement projectElement = (TreeSElement) registry - .getElement(SlcProjectHelper.getProjectPath(getProject())); - TreeSElement targetElement = (TreeSElement) registry + + TreeSPath targetPath = createTargetPath(target); + SimpleSElement targetElement = (SimpleSElement) registry .getElement(createTargetPath(target)); if (targetElement == null) { - // create target element - targetElement = projectElement.createChild(target.getName(), target - .getDescription() != null ? target.getDescription() - : ""); - registry.register(targetElement); + targetElement = new SimpleSElement(target.getDescription(), + ""); + registry.register(targetPath, targetElement); } + } - TreeSElement taskElement = targetElement.createChild(getTaskName() - + targetElement.getChildren().size(), - getDescription() != null ? getDescription() : ""); - sAware.setElement(taskElement); + /** + * Includes this arg in the checks for propagation of sstructure related + * information. + */ + protected void addSAwareArg(AbstractSpringArg arg) { + sAwareArgs.add(arg); } @Override @@ -52,24 +55,35 @@ public abstract class SAwareTask extends AbstractSpringTask { * @see StructureRegistry */ public final void execute() throws BuildException { - for(SAwareArg arg : sAwareArgs){ - arg.init(sAware); + // register the task in the structure + TreeSPath targetPath = createTargetPath(getOwningTarget()); + TreeSPath taskPath = targetPath.createChild(getTaskName() + + targetPath.listChildren(getRegistry()).size()); + getRegistry().register(taskPath, this); + path = taskPath; + + // notify registered args + for (AbstractSpringArg arg : sAwareArgs) { + Object obj = arg.getBeanInstance(); + + if (obj instanceof StructureAware) { + StructureAware sAwareT = (StructureAware) obj; + sAwareT.notifyCurrentPath(getRegistry(), taskPath); + } } - - getRegistry().register(sAware); - + + // execute depending on the registry mode String mode = getRegistry().getMode(); if (mode.equals(StructureRegistry.ALL)) { executeActions(mode); } else if (mode.equals(StructureRegistry.ACTIVE)) { List activePaths = getRegistry().getActivePaths(); - - StructurePath targetPath = createTargetPath(getOwningTarget()); - if(activePaths.contains(targetPath)){ - if (activePaths.contains(sAware.getElement().getPath())) { + + if (activePaths.contains(targetPath)) { + if (activePaths.contains(taskPath)) { executeActions(mode); } - } + } } } @@ -84,9 +98,25 @@ public abstract class SAwareTask extends AbstractSpringTask { } /** Creates the path for a given Ant target. */ - protected static StructurePath createTargetPath(Target target) { + protected static TreeSPath createTargetPath(Target target) { TreeSPath projectPath = SlcProjectHelper.getProjectPath(target .getProject()); - return TreeSPath.createChild(projectPath, target.getName()); + return projectPath.createChild(target.getName()); } + + /** Gets the path under which this task is registered. */ + public TreeSPath getPath() { + return path; + } + + @Override + public String getDescription() { + String description = super.getDescription(); + if (description == null) { + return ""; + } else { + return description; + } + } + }