Update of /cvsroot/xdoclet/xdoclet/modules/apache/src/xdoclet/modules/apache/ant
In directory sc8-pr-cvs1:/tmp/cvs-serv31236

Modified Files:
        TaskTagsHandler.java 
Added Files:
        AntDocletTask.java AntSubTask.java 
        TaskDefPropertiesSubTask.java TaskDescriptorSubTask.java 
Removed Files:
        TaskSubTask.java 
Log Message:
Refactoring a little: making separate subtasks for descriptor and properties file

--- NEW FILE: AntDocletTask.java ---
/*
 * Copyright (c) 2001, 2002 The XDoclet team
 * All rights reserved.
 */
package xdoclet.modules.apache.ant;

import org.apache.tools.ant.BuildException;

import xdoclet.DocletTask;

/**
 * @created       January 5, 2003
 * @ant.element   name="antdoclet" display-name="AntDoclet Task"
 */
public class AntDocletTask extends DocletTask
{
    protected void validateOptions() throws BuildException
    {
        super.validateOptions();
        checkClass("org.apache.tools.ant.IntrospectionHelper");
    }
}

--- NEW FILE: AntSubTask.java ---
/*
 * Copyright (c) 2001, 2002 The XDoclet team
 * All rights reserved.
 */
package xdoclet.modules.apache.ant;

import java.util.Collection;
import java.util.Iterator;
import xjavadoc.XClass;
import xjavadoc.XJavaDoc;
import xjavadoc.XMethod;

import xdoclet.TemplateSubTask;
import xdoclet.XDocletException;
import xdoclet.util.TypeConversionUtil;

/**
 * @created   January 5, 2003
 */
public abstract class AntSubTask extends TemplateSubTask
{

    /**
     * Checks many factors to determine if the class is indeed an Ant task or not.
     *
     * @param clazz
     * @return
     * @exception XDocletException
     * @todo                        perhaps make deprecation switch configurable
     */
    public final static boolean isAntTask(XClass clazz) throws XDocletException
    {
        if (clazz.isAbstract()) {
            return false;
        }

        // no inner classes (for now - but is this possible? desired?)
        if (clazz.isInner()) {
            return false;
        }

        String ignoreValue = clazz.getDoc().getTagAttributeValue("ant.task", "ignore");
        boolean ignore = TypeConversionUtil.stringToBoolean(ignoreValue, false);

        if (ignore) {
            return false;
        }

        /*
         * Tag[] tags = clazz.tags();
         * for (int i = 0; i < tags.length; i++) {
         * if ("@deprecated".equals(tags[i].name())) {
         * return false;
         * }
         * }
         */
        if (hasExecuteMethod(clazz)) {
            return true;
        }

        return false;
    }

    /**
     * Check for class implementing an execute() method. Recursive calls are made to 
superclasses.
     *
     * @param clazz
     * @return
     */
    private static boolean hasExecuteMethod(XClass clazz)
    {
        if (clazz == null) {
            return false;
        }

        // It ain't a task if we've climbed back to Task itself.
        // Also ignore other special Ant classes
        if ("org.apache.tools.ant.Task".equals(clazz.getQualifiedName()) ||
            "org.apache.tools.ant.Target".equals(clazz.getQualifiedName()) ||
            "org.apache.tools.ant.TaskAdapter".equals(clazz.getQualifiedName()) ||
            "org.apache.tools.ant.UnknownElement".equals(clazz.getQualifiedName())) {
            return false;
        }

        // need to check that only runtime exceptions are thrown?
        Collection methods = clazz.getMethods();
        Iterator iter = methods.iterator();

        while (iter.hasNext()) {
            XMethod method = (XMethod) iter.next();

            if ("execute".equals(method.getName())) {
                if (method.getParameters().size() == 0) {
                    if (method.getReturnType().getName().equals("void")) {
                        return true;
                    }
                }
            }
        }

        return hasExecuteMethod(clazz.getSuperclass());
    }

    protected void startProcess() throws XDocletException
    {
        Collection classes = XJavaDoc.getInstance().getSourceClasses(false, 
processInnerClasses());

        super.startProcess();
    }

    /**
     * Returns true if the class is an Ant task. This causes the task to be processed 
by the XDoclet template task.
     *
     * @param clazz
     * @return
     * @exception XDocletException
     */
    protected boolean matchesGenerationRules(XClass clazz) throws XDocletException
    {
        boolean match = isAntTask(clazz);

        return match;
    }
}

--- NEW FILE: TaskDefPropertiesSubTask.java ---
/*
 * Copyright (c) 2001, 2002 The XDoclet team
 * All rights reserved.
 */
package xdoclet.modules.apache.ant;

import xdoclet.TemplateSubTask;

/**
 * Generates Ant taskdef properties files, suitable for bulk defining tasks with Ant's 
&lt;taskdef&gt; task.
 *
 * @author        Erik Hatcher ([EMAIL PROTECTED])
 * @created       January 5, 2003
 * @ant.element   display-name="taskdefproperties" name="taskdefproperties"
 *      parent="xdoclet.modules.apache.ant.AntDocletTask"
 * @version       $Revision: 1.1 $
 */
public class TaskDefPropertiesSubTask extends AntSubTask
{
    protected static String DEFAULT_TEMPLATE_FILE = "resources/taskdef_properties.xdt";

    public TaskDefPropertiesSubTask()
    {
        setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE));
        setDestinationFile("taskdef.properties");
    }
}

--- NEW FILE: TaskDescriptorSubTask.java ---
/*
 * Copyright (c) 2001, 2002 The XDoclet team
 * All rights reserved.
 */
package xdoclet.modules.apache.ant;

import java.io.File;
import java.util.Collection;
import java.util.Iterator;

import xjavadoc.XClass;
import xjavadoc.XJavaDoc;
import xjavadoc.XMethod;

import xdoclet.TemplateSubTask;
import xdoclet.XDocletException;
import xdoclet.XDocletTagSupport;
import xdoclet.util.TypeConversionUtil;

/**
 * Generates Ant task descriptors.
 *
 * @author        Erik Hatcher ([EMAIL PROTECTED])
 * @created       January 1, 2003
 * @ant.element   display-name="taskdescriptor" name="taskdescriptor" 
parent="xdoclet.modules.apache.ant.AntDocletTask"
 * @version       $Revision: 1.1 $
 */
public class TaskDescriptorSubTask extends AntSubTask
{
    protected static String DEFAULT_TEMPLATE_FILE = "resources/task_xml.xdt";

    public TaskDescriptorSubTask()
    {
        setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE));
        setDestinationFile("{0}.xml");
    }

    /**
     * Custom file naming. Use the task name for the file name rather than the default 
class name.
     *
     * @param clazz
     * @return
     * @exception XDocletException
     */
    protected String getGeneratedFileName(XClass clazz) throws XDocletException
    {
        String dir = TaskTagsHandler.getCategoryName(clazz);
        String taskName = TaskTagsHandler.getTaskName(clazz);

        return new File(dir, taskName + ".xml").toString();
    }

}

Index: TaskTagsHandler.java
===================================================================
RCS file: 
/cvsroot/xdoclet/xdoclet/modules/apache/src/xdoclet/modules/apache/ant/TaskTagsHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** TaskTagsHandler.java        5 Jan 2003 03:52:14 -0000       1.1
--- TaskTagsHandler.java        5 Jan 2003 15:41:43 -0000       1.2
***************
*** 151,155 ****
              setCurrentClass(cur_class);
  
!             if (TaskSubTask.isAntTask(cur_class)) {
                  generate(template);
              }
--- 151,155 ----
              setCurrentClass(cur_class);
  
!             if (TaskDescriptorSubTask.isAntTask(cur_class)) {
                  generate(template);
              }

--- TaskSubTask.java DELETED ---



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to