📄 javadoc.java
字号:
writeExternalArgs(toExecute); } File tmpList = null; PrintWriter srcListWriter = null; try { /** * Write sourcefiles and package names to a temporary file * if requested. */ if (useExternalFile) { tmpList = FILE_UTILS.createTempFile("javadoc", "", null, true, true); toExecute.createArgument() .setValue("@" + tmpList.getAbsolutePath()); srcListWriter = new PrintWriter( new FileWriter(tmpList.getAbsolutePath(), true)); } doSourceAndPackageNames( toExecute, packagesToDoc, sourceFilesToDoc, useExternalFile, tmpList, srcListWriter); } catch (IOException e) { tmpList.delete(); throw new BuildException("Error creating temporary file", e, getLocation()); } finally { if (srcListWriter != null) { srcListWriter.close(); } } if (packageList != null) { toExecute.createArgument().setValue("@" + packageList); } log(toExecute.describeCommand(), Project.MSG_VERBOSE); log("Javadoc execution", Project.MSG_INFO); JavadocOutputStream out = new JavadocOutputStream(Project.MSG_INFO); JavadocOutputStream err = new JavadocOutputStream(Project.MSG_WARN); Execute exe = new Execute(new PumpStreamHandler(out, err)); exe.setAntRun(getProject()); /* * No reason to change the working directory as all filenames and * path components have been resolved already. * * Avoid problems with command line length in some environments. */ exe.setWorkingDirectory(null); try { exe.setCommandline(toExecute.getCommandline()); int ret = exe.execute(); if (ret != 0 && failOnError) { throw new BuildException("Javadoc returned " + ret, getLocation()); } } catch (IOException e) { throw new BuildException("Javadoc failed: " + e, e, getLocation()); } finally { if (tmpList != null) { tmpList.delete(); tmpList = null; } out.logFlush(); err.logFlush(); try { out.close(); err.close(); } catch (IOException e) { // ignore } } } private void checkTaskName() { if ("javadoc2".equals(getTaskType())) { log("Warning: the task name <javadoc2> is deprecated." + " Use <javadoc> instead.", Project.MSG_WARN); } } private void checkPackageAndSourcePath() { if (packageList != null && sourcePath == null) { String msg = "sourcePath attribute must be set when " + "specifying packagelist."; throw new BuildException(msg); } } private void checkPackages(Vector packagesToDoc, Path sourceDirs) { if (packagesToDoc.size() != 0 && sourceDirs.size() == 0) { String msg = "sourcePath attribute must be set when " + "specifying package names."; throw new BuildException(msg); } } private void checkPackagesToDoc( Vector packagesToDoc, Vector sourceFilesToDoc) { if (packageList == null && packagesToDoc.size() == 0 && sourceFilesToDoc.size() == 0) { throw new BuildException("No source files and no packages have " + "been specified."); } } private void doSourcePath(Commandline toExecute, Path sourceDirs) { if (sourceDirs.size() > 0) { toExecute.createArgument().setValue("-sourcepath"); toExecute.createArgument().setPath(sourceDirs); } } private void generalJavadocArguments(Commandline toExecute) { if (doctitle != null) { toExecute.createArgument().setValue("-doctitle"); toExecute.createArgument().setValue(expand(doctitle.getText())); } if (header != null) { toExecute.createArgument().setValue("-header"); toExecute.createArgument().setValue(expand(header.getText())); } if (footer != null) { toExecute.createArgument().setValue("-footer"); toExecute.createArgument().setValue(expand(footer.getText())); } if (bottom != null) { toExecute.createArgument().setValue("-bottom"); toExecute.createArgument().setValue(expand(bottom.getText())); } if (classpath == null) { classpath = (new Path(getProject())).concatSystemClasspath("last"); } else { classpath = classpath.concatSystemClasspath("ignore"); } if (classpath.size() > 0) { toExecute.createArgument().setValue("-classpath"); toExecute.createArgument().setPath(classpath); } if (version && doclet == null) { toExecute.createArgument().setValue("-version"); } if (author && doclet == null) { toExecute.createArgument().setValue("-author"); } if (doclet == null && destDir == null) { throw new BuildException("destdir attribute must be set!"); } } private void doDoclet(Commandline toExecute) { if (doclet != null) { if (doclet.getName() == null) { throw new BuildException("The doclet name must be " + "specified.", getLocation()); } else { toExecute.createArgument().setValue("-doclet"); toExecute.createArgument().setValue(doclet.getName()); if (doclet.getPath() != null) { Path docletPath = doclet.getPath().concatSystemClasspath("ignore"); if (docletPath.size() != 0) { toExecute.createArgument().setValue("-docletpath"); toExecute.createArgument().setPath(docletPath); } } for (Enumeration e = doclet.getParams(); e.hasMoreElements();) { DocletParam param = (DocletParam) e.nextElement(); if (param.getName() == null) { throw new BuildException("Doclet parameters must " + "have a name"); } toExecute.createArgument().setValue(param.getName()); if (param.getValue() != null) { toExecute.createArgument() .setValue(param.getValue()); } } } } } private void writeExternalArgs(Commandline toExecute) { // If using an external file, write the command line options to it File optionsTmpFile = null; PrintWriter optionsListWriter = null; try { optionsTmpFile = FILE_UTILS.createTempFile( "javadocOptions", "", null, true, true); String[] listOpt = toExecute.getArguments(); toExecute.clearArgs(); toExecute.createArgument().setValue( "@" + optionsTmpFile.getAbsolutePath()); optionsListWriter = new PrintWriter( new FileWriter(optionsTmpFile.getAbsolutePath(), true)); for (int i = 0; i < listOpt.length; i++) { String string = listOpt[i]; if (string.startsWith("-J-")) { toExecute.createArgument().setValue(string); } else { if (string.startsWith("-")) { optionsListWriter.print(string); optionsListWriter.print(" "); } else { optionsListWriter.println(quoteString(string)); } } } optionsListWriter.close(); } catch (IOException ex) { if (optionsTmpFile != null) { optionsTmpFile.delete(); } throw new BuildException( "Error creating or writing temporary file for javadoc options", ex, getLocation()); } finally { FILE_UTILS.close(optionsListWriter); } } private void doBootPath(Commandline toExecute) { Path bcp = new Path(getProject()); if (bootclasspath != null) { bcp.append(bootclasspath); } bcp = bcp.concatSystemBootClasspath("ignore"); if (bcp.size() > 0) { toExecute.createArgument().setValue("-bootclasspath"); toExecute.createArgument().setPath(bcp); } } private void doLinks(Commandline toExecute) { if (links.size() != 0) { for (Enumeration e = links.elements(); e.hasMoreElements();) { LinkArgument la = (LinkArgument) e.nextElement(); if (la.getHref() == null || la.getHref().length() == 0) { log("No href was given for the link - skipping", Project.MSG_VERBOSE); continue; } String link = null; if (la.shouldResolveLink()) { File hrefAsFile = getProject().resolveFile(la.getHref()); if (hrefAsFile.exists()) { try { link = FILE_UTILS.getFileURL(hrefAsFile) .toExternalForm(); } catch (MalformedURLException ex) { // should be impossible log("Warning: link location was invalid " + hrefAsFile, Project.MSG_WARN); } } } if (link == null) { // is the href a valid URL try { URL base = new URL("file://."); new URL(base, la.getHref()); link = la.getHref(); } catch (MalformedURLException mue) { // ok - just skip log("Link href \"" + la.getHref() + "\" is not a valid url - skipping link", Project.MSG_WARN); continue; } } if (la.isLinkOffline()) { File packageListLocation = la.getPackagelistLoc(); if (packageListLocation == null) { throw new BuildException("The package list" + " location for link " + la.getHref() + " must be provided " + "because the link is " + "offline"); } File packageListFile = new File(packageListLocation, "package-list"); if (packageListFile.exists()) { try { String packageListURL = FILE_UTILS.getFileURL(packageListLocation) .toExternalForm(); toExecute.createArgument() .setValue("-linkoffline"); toExecute.createArgument() .setValue(link); toExecute.createArgument() .setValue(packageListURL); } catch (MalformedURLException ex) { log("Warning: Package list location was " + "invalid " + packageListLocation, Project.MSG_WARN); } } else { log("Warning: No package list was found at " + packageListLocation, Project.MSG_VERBOSE); } } else { toExecute.createArgument().setValue("-link"); toExecute.createArgument().setValue(link); } } } } private void doGroup(Commandline toExecute) { // add the single group arguments // Javadoc 1.2 rules: // Multiple -group args allowed. // Each arg includes 3 strings: -group [name] [packagelist]. // Elements in [packagelist] are colon-delimited. // An element in [packagelist] may end with the * wildcard. // Ant javadoc task rules for group attribute: // Args are comma-delimited. // Each arg is 2 space-delimited strings. // E.g., group="XSLT_Packages org.apache.xalan.xslt*, // XPath_Packages org.apache.xalan.xpath*" if (group != null) { StringTokenizer tok = new StringTokenizer(group, ",", false); while (tok.hasMoreTokens()) { String grp = tok.nextToken().trim(); int space = grp.indexOf(" "); if (space > 0) { String name = grp.substring(0, space); String pkgList = grp.substring(space + 1); toExecute.createArgument().setValue("-group"); toExecute.createArgument().setValue(name); toExecute.createArgument().setValue(pkgList); } } } } // add the group arguments private void doGroups(Commandline toExecute) { if (groups.size() != 0) { for (Enumeration e = groups.elements(); e.hasMoreElements();) { GroupArgument ga = (GroupArgument) e.nextElement(); String title = ga.getTitle(); String packages = ga.getPackages(); if (title == null || packages == null) { throw new BuildException("The title and packages must " + "be specified for group " + "elements."); } toExecute.createArgument().setValue("-group"); toExecute.createArgument().setValue(expand(title)); toExecute.createArgument().setValue(packages); } } } // Do java1.4 arguments private void doJava14(Commandline toExecute) { for (Enumeration e = tags.elements(); e.hasMoreElements();) { Object element = e.nextElement(); if (element instanceof TagArgument) { TagArgument ta = (TagArgument) element; File tagDir = ta.getDir(getProject()); if (tagDir == null) { // The tag element is not used as a fileset, // but specifies the tag directly. toExecute.createArgument().setValue ("-tag"); toExecute.createArgument() .setValue (ta.getParameter()); } else { // The tag element is used as a // fileset. Parse all the files and create // -tag arguments. DirectoryScanner tagDefScanner = ta.getDirectoryScanner(getProject()); String[] files = tagDefScanner.getIncludedFiles(); for (int i = 0; i < files.length; i++) { File tagDefFile = new File(tagDir, files[i]); try { BufferedReader in = new BufferedReader( new FileReader(tagDefFile) ); String line = null; while ((line = in.readLine()) != null) { toExecute.createArgument() .setValue("-tag"); toExecute.createArgument() .setValue(line); } in.close(); } catch (IOException ioe) { throw new BuildException( "Couldn't read " + " tag file from " + tagDefFile.getAbsolutePath(), ioe); } } } } else { ExtensionInfo tagletInfo = (Extensi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -