📄 javadoc.java
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.apache.tools.ant.taskdefs;import java.io.File;import java.io.FileWriter;import java.io.FilenameFilter;import java.io.IOException;import java.io.PrintWriter;import java.io.BufferedReader;import java.io.FileReader;import java.net.MalformedURLException;import java.net.URL;import java.util.ArrayList;import java.util.Enumeration;import java.util.Iterator;import java.util.Locale;import java.util.StringTokenizer;import java.util.Vector;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.DirectoryScanner;import org.apache.tools.ant.MagicNames;import org.apache.tools.ant.Project;import org.apache.tools.ant.ProjectComponent;import org.apache.tools.ant.Task;import org.apache.tools.ant.types.Commandline;import org.apache.tools.ant.types.DirSet;import org.apache.tools.ant.types.EnumeratedAttribute;import org.apache.tools.ant.types.FileSet;import org.apache.tools.ant.types.Path;import org.apache.tools.ant.types.PatternSet;import org.apache.tools.ant.types.Reference;import org.apache.tools.ant.types.ResourceCollection;import org.apache.tools.ant.types.resources.FileResource;import org.apache.tools.ant.util.FileUtils;import org.apache.tools.ant.util.JavaEnvUtils;/** * Generates Javadoc documentation for a collection * of source code. * * <p>Current known limitations are: * * <p><ul> * <li>patterns must be of the form "xxx.*", every other pattern doesn't * work. * <li>there is no control on arguments sanity since they are left * to the Javadoc implementation. * </ul> * * <p>If no <code>doclet</code> is set, then the <code>version</code> and * <code>author</code> are by default <code>"yes"</code>. * * <p>Note: This task is run on another VM because the Javadoc code calls * <code>System.exit()</code> which would break Ant functionality. * * @since Ant 1.1 * * @ant.task category="java" */public class Javadoc extends Task { // Whether *this VM* is 1.4+ (but also check executable != null). private static final boolean JAVADOC_4 = !JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2) && !JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3); private static final boolean JAVADOC_5 = JAVADOC_4 && !JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_4); /** * Inner class used to manage doclet parameters. */ public class DocletParam { /** The parameter name */ private String name; /** The parameter value */ private String value; /** * Set the name of the parameter. * * @param name the name of the doclet parameter */ public void setName(String name) { this.name = name; } /** * Get the parameter name. * * @return the parameter's name. */ public String getName() { return name; } /** * Set the parameter value. * * Note that only string values are supported. No resolution of file * paths is performed. * * @param value the parameter value. */ public void setValue(String value) { this.value = value; } /** * Get the parameter value. * * @return the parameter value. */ public String getValue() { return value; } } /** * A project aware class used for Javadoc extensions which take a name * and a path such as doclet and taglet arguments. * */ public static class ExtensionInfo extends ProjectComponent { /** The name of the extension */ private String name; /** The optional path to use to load the extension */ private Path path; /** * Set the name of the extension * * @param name the extension's name. */ public void setName(String name) { this.name = name; } /** * Get the name of the extension. * * @return the extension's name. */ public String getName() { return name; } /** * Set the path to use when loading the component. * * @param path a Path instance containing the classpath to use. */ public void setPath(Path path) { if (this.path == null) { this.path = path; } else { this.path.append(path); } } /** * Get the extension's path. * * @return the path to be used to load the extension. * May be <code>null</code> */ public Path getPath() { return path; } /** * Create an empty nested path to be configured by Ant with the * classpath for the extension. * * @return a new Path instance to be configured. */ public Path createPath() { if (path == null) { path = new Path(getProject()); } return path.createPath(); } /** * Adds a reference to a CLASSPATH defined elsewhere. * * @param r the reference containing the path. */ public void setPathRef(Reference r) { createPath().setRefid(r); } } /** * This class stores info about doclets. * */ public class DocletInfo extends ExtensionInfo { /** Collection of doclet parameters. */ private Vector params = new Vector(); /** * Create a doclet parameter to be configured by Ant. * * @return a new DocletParam instance to be configured. */ public DocletParam createParam() { DocletParam param = new DocletParam(); params.addElement(param); return param; } /** * Get the doclet's parameters. * * @return an Enumeration of DocletParam instances. */ public Enumeration getParams() { return params.elements(); } } /** * Used to track info about the packages to be javadoc'd */ public static class PackageName { /** The package name */ private String name; /** * Set the name of the package * * @param name the package name. */ public void setName(String name) { this.name = name.trim(); } /** * Get the package name. * * @return the package's name. */ public String getName() { return name; } /** * Return a string rep for this object. * @return the package name. */ public String toString() { return getName(); } } /** * This class is used to manage the source files to be processed. */ public static class SourceFile { /** The source file */ private File file; /** * Default constructor */ public SourceFile() { //empty } /** * Constructor specifying the source file directly * * @param file the source file */ public SourceFile(File file) { this.file = file; } /** * Set the source file. * * @param file the source file. */ public void setFile(File file) { this.file = file; } /** * Get the source file. * * @return the source file. */ public File getFile() { return file; } } /** * An HTML element in the Javadoc. * * This class is used for those Javadoc elements which contain HTML such as * footers, headers, etc. */ public static class Html { /** The text for the element */ private StringBuffer text = new StringBuffer(); /** * Add text to the element. * * @param t the text to be added. */ public void addText(String t) { text.append(t); } /** * Get the current text for the element. * * @return the current text. */ public String getText() { return text.substring(0); } } /** * EnumeratedAttribute implementation supporting the Javadoc scoping * values. */ public static class AccessType extends EnumeratedAttribute { /** * @return the allowed values for the access type. */ public String[] getValues() { // Protected first so if any GUI tool offers a default // based on enum #0, it will be right. return new String[] {"protected", "public", "package", "private"}; } } /** * Holds a collection of ResourceCollections. * * <p>A separate kind of container is needed since this task * contains special handling for FileSets that has to occur at * task runtime.</p> */ public class ResourceCollectionContainer { private ArrayList rcs = new ArrayList(); /** * Add a resource collection to the container. * @param rc the collection to add. */ public void add(ResourceCollection rc) { rcs.add(rc); } /** * Get an iterator on the collection. * @return an iterator. */ private Iterator iterator() { return rcs.iterator(); } } private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); /** The command line built to execute Javadoc. */ private Commandline cmd = new Commandline(); /** * Utility method to add an argument to the command line conditionally * based on the given flag. * * @param b the flag which controls if the argument is added. * @param arg the argument value. */ private void addArgIf(boolean b, String arg) { if (b) { cmd.createArgument().setValue(arg); } } /** * Utility method to add a Javadoc argument. * * @param key the argument name. * @param value the argument value. */ private void addArgIfNotEmpty(String key, String value) { if (value != null && value.length() != 0) { cmd.createArgument().setValue(key); cmd.createArgument().setValue(value); } else { log("Warning: Leaving out empty argument '" + key + "'", Project.MSG_WARN); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -