git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271581 13f79535-47bb-0310-9956-ffa450edef68master
@@ -18,22 +18,19 @@ | |||
location="${template.dir}/task_xdoc.template"/> | |||
<path id="xdoclet.classpath"> | |||
<pathelement location="${log4j.jar}"/> | |||
<pathelement location="${xdoclet.jar}"/> | |||
<!-- javadoc is needed --> | |||
<pathelement path="${java.class.path}"/> | |||
<pathelement location="${build.dir}"/> | |||
</path> | |||
<taskdef name="document" | |||
classname="xdoclet.doc.DocumentDocletTask" | |||
classpathref="xdoclet.classpath"/> | |||
<target name="init"> | |||
<mkdir dir="${build.dir}" /> | |||
<mkdir dir="${gen.dir}" /> | |||
<!-- hack, this should be outside a target but ${build.dir} gets stripped ?? --> | |||
<path id="xdoclet.classpath"> | |||
<pathelement location="${log4j.jar}"/> | |||
<pathelement location="${xdoclet.jar}"/> | |||
<!-- javadoc is needed --> | |||
<pathelement path="${java.class.path}"/> | |||
<pathelement location="${build.dir}"/> | |||
</path> | |||
</target> | |||
@@ -49,6 +46,10 @@ | |||
<target name="gen" depends="compile"> | |||
<delete dir="${gen.dir}"/> | |||
<taskdef name="document" | |||
classname="xdoclet.doc.DocumentDocletTask" | |||
classpathref="xdoclet.classpath"/> | |||
<document sourcepath="${src.root}" | |||
destdir="${gen.dir}" | |||
classpathref="xdoclet.classpath"> | |||
@@ -56,7 +57,8 @@ | |||
<include name="*.java" unless="class.name"/> | |||
<include name="${class.name}.java" if="class.name"/> | |||
</fileset> | |||
<template templateFile="${defaults.properties.template}" | |||
<template subTaskClassName="org.apache.tools.ant.xdoclet.AntSubTask" | |||
templateFile="${defaults.properties.template}" | |||
destinationfile="defaults.properties"/> | |||
<!-- <template templateFile="${xdoc.template}" | |||
destinationfile="{0}.xml" extent="concrete-type"/> --> | |||
@@ -83,15 +83,31 @@ public class AntSubTask extends TemplateSubTask { | |||
* - and only throw BuildException if at all | |||
*/ | |||
protected boolean matchesGenerationRules(ClassDoc clazz) throws XDocletException { | |||
MethodDoc[] methods = clazz.methods(); | |||
if (clazz.isAbstract()) { | |||
return false; | |||
} | |||
return isAntTask(clazz);; | |||
} | |||
/** | |||
* @todo pull out to utility method | |||
* @todo add more logic (like execute method signature) | |||
*/ | |||
public static final boolean isAntTask(ClassDoc clazz) { | |||
if (clazz.isAbstract()) { | |||
return false; | |||
} | |||
// no inner classes (for now - but is this possible? desired?) | |||
if (clazz.containingClass() != null) { | |||
return false; | |||
} | |||
MethodDoc[] methods = clazz.methods(); | |||
for (int i = 0; i < methods.length; i++) { | |||
if ("execute".equals(methods[i].name())) { | |||
System.out.println("Task: " + clazz.name()); | |||
return true; | |||
} | |||
} | |||
@@ -104,12 +120,17 @@ public class AntSubTask extends TemplateSubTask { | |||
* default class name. | |||
*/ | |||
protected String getGeneratedFileName(ClassDoc clazz) throws XDocletException { | |||
PackageDoc pak = clazz.containingPackage(); | |||
String packageName = PackageTagsHandler.packageNameAsPathFor(pak); | |||
String taskName = AntTagsHandler.getTaskName(clazz); | |||
String filename = MessageFormat.format(getDestinationFile(), new Object[]{taskName}); | |||
String filename = getDestinationFile(); | |||
String dir = getDestDir().getAbsolutePath(); | |||
if (filename.indexOf("{0}") != -1) { | |||
PackageDoc pak = clazz.containingPackage(); | |||
dir = PackageTagsHandler.packageNameAsPathFor(pak); | |||
String taskName = AntTagsHandler.getTaskName(clazz); | |||
filename = MessageFormat.format(getDestinationFile(), new Object[]{taskName}); | |||
} | |||
return new File(packageName, filename).toString(); | |||
return new File(dir, filename).toString(); | |||
} | |||
} |
@@ -57,6 +57,7 @@ import com.sun.javadoc.ClassDoc; | |||
import com.sun.javadoc.MethodDoc; | |||
import xdoclet.XDocletException; | |||
import xdoclet.XDocletTagSupport; | |||
import xdoclet.tags.AbstractProgramElementTagsHandler; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
@@ -80,6 +81,24 @@ import java.util.Properties; | |||
*/ | |||
public class AntTagsHandler extends XDocletTagSupport { | |||
/** | |||
* @todo add check for execute method | |||
*/ | |||
public void forAllTasks(String template, Properties attributes) throws XDocletException { | |||
ClassDoc[] classes = AbstractProgramElementTagsHandler.getAllClasses(); | |||
ClassDoc cur_class = null; | |||
for (int i = 0; i < classes.length; i++) { | |||
cur_class = classes[i]; | |||
setCurrentClass(cur_class); | |||
if (AntSubTask.isAntTask(cur_class)) { | |||
generate(template); | |||
} | |||
} | |||
} | |||
/** | |||
* Iterates over all Ant attributes. | |||
* | |||
@@ -120,21 +139,22 @@ public class AntTagsHandler extends XDocletTagSupport { | |||
} | |||
} | |||
/** | |||
* Provides the element name for the current method | |||
*/ | |||
public String elementName() throws XDocletException { | |||
String methodName = getCurrentMethod().name(); | |||
System.out.println(">>>> " + methodName); | |||
String elementName = "<not a valid element>"; | |||
if (methodName.startsWith("addConfigured")) { | |||
elementName = methodName.substring(13,methodName.length()); | |||
} else if (methodName.startsWith("add")) { | |||
elementName = methodName.substring(3,methodName.length()); | |||
} else if (methodName.startsWith("create")) { | |||
elementName = methodName.substring(6,methodName.length()); | |||
elementName = methodName.substring(13, methodName.length()); | |||
} | |||
else if (methodName.startsWith("add")) { | |||
elementName = methodName.substring(3, methodName.length()); | |||
} | |||
else if (methodName.startsWith("create")) { | |||
elementName = methodName.substring(6, methodName.length()); | |||
} | |||
System.out.println(" = " + elementName); | |||
return elementName.toLowerCase(); | |||
} | |||
@@ -1,5 +1,4 @@ | |||
<XDtTagDef:tagDef namespace="Ant" handler="org.apache.tools.ant.xdoclet.AntTagsHandler"/> | |||
<!-- @todo: add forAllTasks --> | |||
<XDtClass:forAllClasses> | |||
<XDtAnt:forAllTasks> | |||
<XDtAnt:taskName/>=<XDtClass:fullClassName/> | |||
</XDtClass:forAllClasses> | |||
</XDtAnt:forAllTasks> |