import org.apache.tools.ant.Target;\r
\r
import org.argeo.slc.ant.SlcProjectHelper;\r
+import org.argeo.slc.ant.spring.AbstractSpringArg;\r
import org.argeo.slc.ant.spring.AbstractSpringTask;\r
+import org.argeo.slc.core.structure.SimpleSElement;\r
+import org.argeo.slc.core.structure.StructureAware;\r
+import org.argeo.slc.core.structure.StructureElement;\r
import org.argeo.slc.core.structure.StructurePath;\r
import org.argeo.slc.core.structure.StructureRegistry;\r
-import org.argeo.slc.core.structure.tree.DefaultTreeSAware;\r
-import org.argeo.slc.core.structure.tree.TreeSAware;\r
-import org.argeo.slc.core.structure.tree.TreeSElement;\r
import org.argeo.slc.core.structure.tree.TreeSPath;\r
\r
/** Ant task that can be registered within a structure. */\r
-public abstract class SAwareTask extends AbstractSpringTask {\r
- protected final TreeSAware sAware = new DefaultTreeSAware();\r
- protected final List<SAwareArg> sAwareArgs = new Vector<SAwareArg>();\r
+public abstract class SAwareTask extends AbstractSpringTask implements\r
+ StructureElement {\r
+ private TreeSPath path;\r
+ private final List<AbstractSpringArg> sAwareArgs = new Vector<AbstractSpringArg>();\r
\r
@Override\r
public void init() throws BuildException {\r
StructureRegistry registry = getRegistry();\r
Target target = getOwningTarget();\r
- TreeSElement projectElement = (TreeSElement) registry\r
- .getElement(SlcProjectHelper.getProjectPath(getProject()));\r
- TreeSElement targetElement = (TreeSElement) registry\r
+\r
+ TreeSPath targetPath = createTargetPath(target);\r
+ SimpleSElement targetElement = (SimpleSElement) registry\r
.getElement(createTargetPath(target));\r
\r
if (targetElement == null) {\r
- // create target element\r
- targetElement = projectElement.createChild(target.getName(), target\r
- .getDescription() != null ? target.getDescription()\r
- : "<no target>");\r
- registry.register(targetElement);\r
+ targetElement = new SimpleSElement(target.getDescription(),\r
+ "<no target desc>");\r
+ registry.register(targetPath, targetElement);\r
}\r
+ }\r
\r
- TreeSElement taskElement = targetElement.createChild(getTaskName()\r
- + targetElement.getChildren().size(),\r
- getDescription() != null ? getDescription() : "<no task desc>");\r
- sAware.setElement(taskElement);\r
+ /**\r
+ * Includes this arg in the checks for propagation of sstructure related\r
+ * information.\r
+ */\r
+ protected void addSAwareArg(AbstractSpringArg arg) {\r
+ sAwareArgs.add(arg);\r
}\r
\r
@Override\r
* @see StructureRegistry\r
*/\r
public final void execute() throws BuildException {\r
- for(SAwareArg arg : sAwareArgs){\r
- arg.init(sAware);\r
+ // register the task in the structure\r
+ TreeSPath targetPath = createTargetPath(getOwningTarget());\r
+ TreeSPath taskPath = targetPath.createChild(getTaskName()\r
+ + targetPath.listChildren(getRegistry()).size());\r
+ getRegistry().register(taskPath, this);\r
+ path = taskPath;\r
+\r
+ // notify registered args\r
+ for (AbstractSpringArg arg : sAwareArgs) {\r
+ Object obj = arg.getBeanInstance();\r
+\r
+ if (obj instanceof StructureAware) {\r
+ StructureAware sAwareT = (StructureAware) obj;\r
+ sAwareT.notifyCurrentPath(getRegistry(), taskPath);\r
+ }\r
}\r
- \r
- getRegistry().register(sAware);\r
- \r
+\r
+ // execute depending on the registry mode\r
String mode = getRegistry().getMode();\r
if (mode.equals(StructureRegistry.ALL)) {\r
executeActions(mode);\r
} else if (mode.equals(StructureRegistry.ACTIVE)) {\r
List<StructurePath> activePaths = getRegistry().getActivePaths();\r
- \r
- StructurePath targetPath = createTargetPath(getOwningTarget());\r
- if(activePaths.contains(targetPath)){\r
- if (activePaths.contains(sAware.getElement().getPath())) {\r
+\r
+ if (activePaths.contains(targetPath)) {\r
+ if (activePaths.contains(taskPath)) {\r
executeActions(mode);\r
}\r
- } \r
+ }\r
}\r
\r
}\r
}\r
\r
/** Creates the path for a given Ant target. */\r
- protected static StructurePath createTargetPath(Target target) {\r
+ protected static TreeSPath createTargetPath(Target target) {\r
TreeSPath projectPath = SlcProjectHelper.getProjectPath(target\r
.getProject());\r
- return TreeSPath.createChild(projectPath, target.getName());\r
+ return projectPath.createChild(target.getName());\r
}\r
+\r
+ /** Gets the path under which this task is registered. */\r
+ public TreeSPath getPath() {\r
+ return path;\r
+ }\r
+\r
+ @Override\r
+ public String getDescription() {\r
+ String description = super.getDescription();\r
+ if (description == null) {\r
+ return "<no task def>";\r
+ } else {\r
+ return description;\r
+ }\r
+ }\r
+\r
}\r