Extend Javadoc Task : 自定义任务 « 蚂蚁编译 « Java

En
Java
1. 图形用户界面
2. 三维图形动画
3. 高级图形
4. 蚂蚁编译
5. Apache类库
6. 统计图
7. 
8. 集合数据结构
9. 数据类型
10. 数据库JDBC
11. 设计模式
12. 开发相关类
13. EJB3
14. 电子邮件
15. 事件
16. 文件输入输出
17. 游戏
18. 泛型
19. GWT
20. Hibernate
21. 本地化
22. J2EE平台
23. 基于J2ME
24. JDK-6
25. JNDI的LDAP
26. JPA
27. JSP技术
28. JSTL
29. 语言基础知识
30. 网络协议
31. PDF格式RTF格式
32. 映射
33. 常规表达式
34. 脚本
35. 安全
36. Servlets
37. Spring
38. Swing组件
39. 图形用户界面
40. SWT-JFace-Eclipse
41. 线程
42. 应用程序
43. Velocity
44. Web服务SOA
45. 可扩展标记语言
Java 教程
Java » 蚂蚁编译 » 自定义任务屏幕截图 
Extend Javadoc Task


/*
 *  Extends org.apache.tools.ant.taskdefs.Javadoc
 *  and uses org.apache.tools.ant.taskdefs.UpToDate,
 *  which are Copyright 2000-2005 The Apache Software Foundation.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

package org.mwrm.ant.tasks;

import java.io.File;

import java.util.Enumeration;
import java.util.StringTokenizer;
import java.util.Vector;

import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;

import org.apache.tools.ant.taskdefs.Javadoc;
import org.apache.tools.ant.taskdefs.UpToDate;

import org.apache.tools.ant.types.FileSet;

/**
 * <p>The <code>ExtendJavadocTask</code> class
 * extends the {@link org.apache.tools.ant.taskdefs.Javadoc Javadoc} task.
 * It checks whether a set of source files are newer than a set of target files
 * and if so, it generates Javadocs.</p>
 *
 */

public class ExtendJavadocTask extends Javadoc {

    /** The attribute of the task element. */
    private File target;

    /** A set of file sets,
     * each of which is provided by a nested file set. */
    private Vector targetFileSets  = new Vector();

    /** The internal uptodate task. */
    private UpToDate utd;

    /**
     * <p>Creates a new instance of an internal
     * <code>&lt;uptodate&gt;</code> task
     * and adds it to the current project.</p>
     @see UpToDate org.apache.tools.ant.taskdefs.UpToDate
     */
    public final void init() {
        // We need an instance of the <uptodate> task
        utd = new UpToDate();
        // We need to add the task to this project
        utd.setProject(this.getProject());
    }

    /**
     * <p>Checks if Javadocs should be created
     * and then calls <code>super.execute()</code> if so.</p>
     * <p>This method does usage checks on the task's attributes
     * and its nested elements.
     * It will throw a <code>BuildException</code> if there is a violation.</p>
     */
    public final void execute() {
        // This is the usage information

        // We can't have a target attribute
        // and nested targetfiles elements
        if (target != null && targetFileSets.size() 0) {
            String msg = "You can't specify a targetfile attribute "
                "and <targetfiles> elements.";
            throw new BuildException(msg);
        }
        // We have to specify either a target attribute
        // or at least one nested targetfiles elements
        if (target == null && targetFileSets.size() == 0) {
            String msg = "You must specify either a targetfile attribute "
                "or at least one <targetfiles> element.";
            throw new BuildException(msg);
        }

        // If this is false, the files aren't up to date
        // and we have to run the javadocs
        boolean eval = false;

        // If we've got to this point, we know the usage must be correct.
        // Let's check whether a single target attribute has been used.

        if (target != null) {
            // Get the results of the check
            eval = getResult(target);
        else {
            // If a target attribute wasn't specified,
            // at least one nested targetfiles element was.

            // We first get all the file sets represented by the nested elements
            Enumeration e = targetFileSets.elements();

            // And then iterate over them
            while (e.hasMoreElements()) {

                // The next element is a file set, so we get its files
                // in a semi-colon-separated list
                String files = e.nextElement().toString();

                // Next, we split the list into its file names
                StringTokenizer st = new StringTokenizer(files, ";");

                // And iterate over them to test each one
                while (st.hasMoreTokens()) {
                    // We create a file
                    //from the current file name in the iteration
                    File tempTarget = new File(st.nextToken());

                    // Get the results of the check
                    eval = getResult(tempTarget);

                    // One false result is enough to fail the whole file set
                    if (!eval) {
                        break;
                    }
                }
                // One false result is enough to fail the whole file set
                if (!eval) {
                    break;
                }
            }
        }

        // If the test failed, we want to generate Javadocs
        if (!eval) {
            super.execute();
        else {
            log("Skipping Javadoc creation. The files are up to date.",
                Project.MSG_INFO);
        }
    }

    /** <p>Checks whether the files are up to date.</p>
     @param file The file to evaluate
     @return boolean The result
     */
    private boolean getResult(final File file) {
        // Set the target property in the <uptodate> task
        utd.setTargetFile(file);
        // Evaluate the files
        return utd.eval();
    }

    /**
     * <p>The setter method for the <code>target</code> attribute.</p>
     @param targetFile A file to check against
     */
    public final void setTarget(final File targetFile) {
        this.target = targetFile;
    }

    /**
     * <p>The setter method for the file set
     * contained in the nested <code>&lt;srcfiles&gt;</code> element.</p>
     @param fileset A file set of source files
     */
    public final void addSrcfiles(final FileSet fileset) {
        utd.addSrcfiles(fileset);
    }

    /**
     * <p>The setter method for the file sets
     * contained in nested <code>&lt;targetfiles&gt;</code> elements.</p>
     @param fileset A file set of target files
     */
    public final void addTargetfiles(final FileSet fileset) {
        targetFileSets.add(fileset);
    }
}


           
       
AntWriteOurOwnTask.zip( 157 k)
Related examples in the same category
1. 创建您自己的Ant任务
2. 第三方任务
3. Ant Write Our Own Task
4. 生命周期任务
5. How to use a Class argument in a custom class attribute
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.