duke@1: /* jjg@1490: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.internal.toolkit; duke@1: jjg@1357: import java.io.*; jjg@1357: import java.util.*; jjg@1357: jjg@1357: import com.sun.javadoc.*; bpatel@1568: import com.sun.tools.javac.sym.Profiles; bpatel@1568: import com.sun.tools.javac.jvm.Profile; jjg@1357: import com.sun.tools.doclets.internal.toolkit.builders.BuilderFactory; duke@1: import com.sun.tools.doclets.internal.toolkit.taglets.*; duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; jjg@1412: import javax.tools.JavaFileManager; duke@1: duke@1: /** duke@1: * Configure the output based on the options. Doclets should sub-class duke@1: * Configuration, to configure and add their own options. This class contains duke@1: * all user options which are supported by the 1.1 doclet and the standard duke@1: * doclet. duke@1: * jjg@1359: *

This is NOT part of any supported API. jjg@1359: * If you write code that depends on this, you do so at your own risk. jjg@1359: * This code and its internal interfaces are subject to change or jjg@1359: * deletion without notice. duke@1: * duke@1: * @author Robert Field. duke@1: * @author Atul Dambalkar. duke@1: * @author Jamie Ho duke@1: */ duke@1: public abstract class Configuration { duke@1: duke@1: /** duke@1: * The factory for builders. duke@1: */ duke@1: protected BuilderFactory builderFactory; duke@1: duke@1: /** duke@1: * The taglet manager. duke@1: */ duke@1: public TagletManager tagletManager; duke@1: duke@1: /** duke@1: * The path to the builder XML input file. duke@1: */ duke@1: public String builderXMLPath; duke@1: duke@1: /** duke@1: * The default path to the builder XML. duke@1: */ duke@1: private static final String DEFAULT_BUILDER_XML = "resources/doclet.xml"; duke@1: duke@1: /** duke@1: * The path to Taglets duke@1: */ duke@1: public String tagletpath = ""; duke@1: duke@1: /** duke@1: * This is true if option "-serialwarn" is used. Defualt value is false to jjg@1413: * suppress excessive warnings about serial tag. duke@1: */ duke@1: public boolean serialwarn = false; duke@1: duke@1: /** duke@1: * The specified amount of space between tab stops. duke@1: */ jjg@1410: public int sourcetab; jjg@1410: jjg@1410: public String tabSpaces; duke@1: duke@1: /** duke@1: * True if we should generate browsable sources. duke@1: */ duke@1: public boolean linksource = false; duke@1: duke@1: /** duke@1: * True if command line option "-nosince" is used. Default value is duke@1: * false. duke@1: */ duke@1: public boolean nosince = false; duke@1: duke@1: /** duke@1: * True if we should recursively copy the doc-file subdirectories duke@1: */ duke@1: public boolean copydocfilesubdirs = false; duke@1: duke@1: /** duke@1: * The META charset tag used for cross-platform viewing. duke@1: */ duke@1: public String charset = ""; duke@1: duke@1: /** duke@1: * True if user wants to add member names as meta keywords. duke@1: * Set to false because meta keywords are ignored in general duke@1: * by most Internet search engines. duke@1: */ duke@1: public boolean keywords = false; duke@1: duke@1: /** jjg@140: * The meta tag keywords instance. duke@1: */ jjg@140: public final MetaKeywords metakeywords = new MetaKeywords(this); duke@1: duke@1: /** duke@1: * The list of doc-file subdirectories to exclude duke@1: */ jjg@74: protected Set excludedDocFileDirs; duke@1: duke@1: /** duke@1: * The list of qualifiers to exclude duke@1: */ jjg@74: protected Set excludedQualifiers; duke@1: duke@1: /** duke@1: * The Root of the generated Program Structure from the Doclet API. duke@1: */ duke@1: public RootDoc root; duke@1: duke@1: /** duke@1: * Destination directory name, in which doclet will generate the entire duke@1: * documentation. Default is current directory. duke@1: */ duke@1: public String destDirName = ""; duke@1: duke@1: /** duke@1: * Destination directory name, in which doclet will copy the doc-files to. duke@1: */ duke@1: public String docFileDestDirName = ""; duke@1: duke@1: /** duke@1: * Encoding for this document. Default is default encoding for this duke@1: * platform. duke@1: */ duke@1: public String docencoding = null; duke@1: duke@1: /** duke@1: * True if user wants to suppress descriptions and tags. duke@1: */ duke@1: public boolean nocomment = false; duke@1: duke@1: /** duke@1: * Encoding for this document. Default is default encoding for this duke@1: * platform. duke@1: */ duke@1: public String encoding = null; duke@1: duke@1: /** duke@1: * Generate author specific information for all the classes if @author duke@1: * tag is used in the doc comment and if -author option is used. duke@1: * showauthor is set to true if -author option is used. duke@1: * Default is don't show author information. duke@1: */ duke@1: public boolean showauthor = false; duke@1: duke@1: /** jjg@1606: * Generate documentation for JavaFX getters and setters automatically jjg@1606: * by copying it from the appropriate property definition. jjg@1606: */ jjg@1606: public boolean javafx = false; jjg@1606: jjg@1606: /** duke@1: * Generate version specific information for the all the classes duke@1: * if @version tag is used in the doc comment and if -version option is duke@1: * used. showversion is set to true if -version option is duke@1: * used.Default is don't show version information. duke@1: */ duke@1: public boolean showversion = false; duke@1: duke@1: /** duke@1: * Sourcepath from where to read the source files. Default is classpath. duke@1: * duke@1: */ duke@1: public String sourcepath = ""; duke@1: duke@1: /** bpatel@1568: * Argument for command line option "-Xprofilespath". bpatel@1568: */ bpatel@1568: public String profilespath = ""; bpatel@1568: bpatel@1568: /** bpatel@1568: * Generate profiles documentation if profilespath is set and valid profiles bpatel@1568: * are present. bpatel@1568: */ bpatel@1568: public boolean showProfiles = false; bpatel@1568: bpatel@1568: /** duke@1: * Don't generate deprecated API information at all, if -nodeprecated duke@1: * option is used. nodepracted is set to true if duke@1: * -nodeprecated option is used. Default is generate deprected API duke@1: * information. duke@1: */ duke@1: public boolean nodeprecated = false; duke@1: duke@1: /** duke@1: * The catalog of classes specified on the command-line duke@1: */ duke@1: public ClassDocCatalog classDocCatalog; duke@1: duke@1: /** duke@1: * Message Retriever for the doclet, to retrieve message from the resource duke@1: * file for this Configuration, which is common for 1.1 and standard duke@1: * doclets. duke@1: * duke@1: * TODO: Make this private!!! duke@1: */ duke@1: public MessageRetriever message = null; duke@1: duke@1: /** duke@1: * True if user wants to suppress time stamp in output. duke@1: * Default is false. duke@1: */ duke@1: public boolean notimestamp= false; duke@1: duke@1: /** jjg@140: * The package grouping instance. duke@1: */ jjg@140: public final Group group = new Group(this); duke@1: duke@1: /** jjg@140: * The tracker of external package links. duke@1: */ duke@1: public final Extern extern = new Extern(this); duke@1: duke@1: /** duke@1: * Return the build date for the doclet. duke@1: */ duke@1: public abstract String getDocletSpecificBuildDate(); duke@1: duke@1: /** duke@1: * This method should be defined in all those doclets(configurations), duke@1: * which want to derive themselves from this Configuration. This method duke@1: * can be used to set its own command line options. duke@1: * duke@1: * @param options The array of option names and values. duke@1: * @throws DocletAbortException duke@1: */ duke@1: public abstract void setSpecificDocletOptions(String[][] options); duke@1: duke@1: /** duke@1: * Return the doclet specific {@link MessageRetriever} duke@1: * @return the doclet specific MessageRetriever. duke@1: */ duke@1: public abstract MessageRetriever getDocletSpecificMsg(); duke@1: duke@1: /** bpatel@1568: * A profiles object used to access profiles across various pages. bpatel@1568: */ bpatel@1568: public Profiles profiles; bpatel@1568: bpatel@1568: /** bpatel@1568: * An map of the profiles to packages. bpatel@1568: */ bpatel@1568: public Map profilePackages; bpatel@1568: bpatel@1568: /** duke@1: * An array of the packages specified on the command-line merged duke@1: * with the array of packages that contain the classes specified on the duke@1: * command-line. The array is sorted. duke@1: */ duke@1: public PackageDoc[] packages; duke@1: duke@1: /** duke@1: * Constructor. Constructs the message retriever with resource file. duke@1: */ duke@1: public Configuration() { duke@1: message = duke@1: new MessageRetriever(this, duke@1: "com.sun.tools.doclets.internal.toolkit.resources.doclets"); jjg@74: excludedDocFileDirs = new HashSet(); jjg@74: excludedQualifiers = new HashSet(); jjg@1410: setTabWidth(DocletConstants.DEFAULT_TAB_STOP_LENGTH); duke@1: } duke@1: duke@1: /** duke@1: * Return the builder factory for this doclet. duke@1: * duke@1: * @return the builder factory for this doclet. duke@1: */ duke@1: public BuilderFactory getBuilderFactory() { duke@1: if (builderFactory == null) { duke@1: builderFactory = new BuilderFactory(this); duke@1: } duke@1: return builderFactory; duke@1: } duke@1: duke@1: /** duke@1: * This method should be defined in all those doclets duke@1: * which want to inherit from this Configuration. This method duke@1: * should return the number of arguments to the command line duke@1: * option (including the option name). For example, duke@1: * -notimestamp is a single-argument option, so this method would duke@1: * return 1. duke@1: * duke@1: * @param option Command line option under consideration. duke@1: * @return number of arguments to option (including the duke@1: * option name). Zero return means option not known. duke@1: * Negative value means error occurred. duke@1: */ duke@1: public int optionLength(String option) { duke@1: option = option.toLowerCase(); duke@1: if (option.equals("-author") || duke@1: option.equals("-docfilessubdirs") || jjg@1606: option.equals("-javafx") || duke@1: option.equals("-keywords") || duke@1: option.equals("-linksource") || duke@1: option.equals("-nocomment") || duke@1: option.equals("-nodeprecated") || duke@1: option.equals("-nosince") || duke@1: option.equals("-notimestamp") || duke@1: option.equals("-quiet") || duke@1: option.equals("-xnodate") || duke@1: option.equals("-version")) { duke@1: return 1; duke@1: } else if (option.equals("-d") || duke@1: option.equals("-docencoding") || duke@1: option.equals("-encoding") || duke@1: option.equals("-excludedocfilessubdir") || duke@1: option.equals("-link") || duke@1: option.equals("-sourcetab") || duke@1: option.equals("-noqualifier") || duke@1: option.equals("-output") || duke@1: option.equals("-sourcepath") || duke@1: option.equals("-tag") || duke@1: option.equals("-taglet") || bpatel@1568: option.equals("-tagletpath") || bpatel@1568: option.equals("-xprofilespath")) { duke@1: return 2; duke@1: } else if (option.equals("-group") || duke@1: option.equals("-linkoffline")) { duke@1: return 3; duke@1: } else { duke@1: return -1; // indicate we don't know about it duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Perform error checking on the given options. duke@1: * duke@1: * @param options the given options to check. duke@1: * @param reporter the reporter used to report errors. duke@1: */ duke@1: public abstract boolean validOptions(String options[][], duke@1: DocErrorReporter reporter); duke@1: bpatel@1568: private void initProfiles() throws IOException { bpatel@1568: profiles = Profiles.read(new File(profilespath)); bpatel@1568: // Generate profiles documentation only is profilespath is set and if bpatel@1568: // profiles is not null and profiles count is 1 or more. bpatel@1568: showProfiles = (!profilespath.isEmpty() && profiles != null && bpatel@1568: profiles.getProfileCount() > 0); bpatel@1568: } bpatel@1568: bpatel@1568: private void initProfilePackages() throws IOException { bpatel@1568: profilePackages = new HashMap(); bpatel@1568: ArrayList results; bpatel@1568: Map packageIndex = new HashMap(); bpatel@1568: for (int i = 0; i < packages.length; i++) { bpatel@1568: PackageDoc pkg = packages[i]; bpatel@1568: packageIndex.put(pkg.name(), pkg); bpatel@1568: } bpatel@1568: for (int i = 1; i < profiles.getProfileCount(); i++) { bpatel@1568: Set profPkgs = profiles.getPackages(i); bpatel@1568: results = new ArrayList(); bpatel@1568: for (String packageName : profPkgs) { bpatel@1568: packageName = packageName.replace("/", "."); bpatel@1568: PackageDoc profPkg = packageIndex.get(packageName); bpatel@1568: if (profPkg != null) { bpatel@1568: results.add(profPkg); bpatel@1568: } bpatel@1568: } bpatel@1568: Collections.sort(results); bpatel@1568: PackageDoc[] profilePkgs = results.toArray(new PackageDoc[]{}); bpatel@1568: profilePackages.put(Profile.lookup(i).name, profilePkgs); bpatel@1568: } bpatel@1568: } bpatel@1568: duke@1: private void initPackageArray() { jjg@74: Set set = new HashSet(Arrays.asList(root.specifiedPackages())); duke@1: ClassDoc[] classes = root.specifiedClasses(); duke@1: for (int i = 0; i < classes.length; i++) { duke@1: set.add(classes[i].containingPackage()); duke@1: } jjg@74: ArrayList results = new ArrayList(set); duke@1: Collections.sort(results); jjg@74: packages = results.toArray(new PackageDoc[] {}); duke@1: } duke@1: duke@1: /** duke@1: * Set the command line options supported by this configuration. duke@1: * duke@1: * @param options the two dimensional array of options. duke@1: */ duke@1: public void setOptions(String[][] options) { jjg@74: LinkedHashSet customTagStrs = new LinkedHashSet(); duke@1: for (int oi = 0; oi < options.length; ++oi) { duke@1: String[] os = options[oi]; duke@1: String opt = os[0].toLowerCase(); duke@1: if (opt.equals("-d")) { duke@1: destDirName = addTrailingFileSep(os[1]); duke@1: docFileDestDirName = destDirName; bpatel@1324: } else if (opt.equals("-docfilessubdirs")) { duke@1: copydocfilesubdirs = true; bpatel@1324: } else if (opt.equals("-docencoding")) { duke@1: docencoding = os[1]; bpatel@1324: } else if (opt.equals("-encoding")) { duke@1: encoding = os[1]; bpatel@1324: } else if (opt.equals("-author")) { duke@1: showauthor = true; jjg@1606: } else if (opt.equals("-javafx")) { jjg@1606: javafx = true; bpatel@1324: } else if (opt.equals("-nosince")) { bpatel@1324: nosince = true; bpatel@1324: } else if (opt.equals("-version")) { duke@1: showversion = true; bpatel@1324: } else if (opt.equals("-nodeprecated")) { duke@1: nodeprecated = true; bpatel@1324: } else if (opt.equals("-sourcepath")) { duke@1: sourcepath = os[1]; duke@1: } else if (opt.equals("-classpath") && duke@1: sourcepath.length() == 0) { duke@1: sourcepath = os[1]; duke@1: } else if (opt.equals("-excludedocfilessubdir")) { duke@1: addToSet(excludedDocFileDirs, os[1]); duke@1: } else if (opt.equals("-noqualifier")) { duke@1: addToSet(excludedQualifiers, os[1]); duke@1: } else if (opt.equals("-linksource")) { duke@1: linksource = true; duke@1: } else if (opt.equals("-sourcetab")) { duke@1: linksource = true; duke@1: try { jjg@1410: setTabWidth(Integer.parseInt(os[1])); duke@1: } catch (NumberFormatException e) { duke@1: //Set to -1 so that warning will be printed duke@1: //to indicate what is valid argument. duke@1: sourcetab = -1; duke@1: } duke@1: if (sourcetab <= 0) { duke@1: message.warning("doclet.sourcetab_warning"); jjg@1410: setTabWidth(DocletConstants.DEFAULT_TAB_STOP_LENGTH); duke@1: } bpatel@1324: } else if (opt.equals("-notimestamp")) { duke@1: notimestamp = true; bpatel@1324: } else if (opt.equals("-nocomment")) { duke@1: nocomment = true; duke@1: } else if (opt.equals("-tag") || opt.equals("-taglet")) { duke@1: customTagStrs.add(os); duke@1: } else if (opt.equals("-tagletpath")) { duke@1: tagletpath = os[1]; bpatel@1568: } else if (opt.equals("-xprofilespath")) { bpatel@1568: profilespath = os[1]; bpatel@1324: } else if (opt.equals("-keywords")) { duke@1: keywords = true; bpatel@1324: } else if (opt.equals("-serialwarn")) { duke@1: serialwarn = true; duke@1: } else if (opt.equals("-group")) { duke@1: group.checkPackageGroups(os[1], os[2]); duke@1: } else if (opt.equals("-link")) { duke@1: String url = os[1]; jjg@1376: extern.link(url, url, root, false); duke@1: } else if (opt.equals("-linkoffline")) { duke@1: String url = os[1]; duke@1: String pkglisturl = os[2]; jjg@1376: extern.link(url, pkglisturl, root, true); duke@1: } duke@1: } duke@1: if (sourcepath.length() == 0) { duke@1: sourcepath = System.getProperty("env.class.path") == null ? "" : duke@1: System.getProperty("env.class.path"); duke@1: } duke@1: if (docencoding == null) { duke@1: docencoding = encoding; duke@1: } duke@1: bpatel@995: classDocCatalog = new ClassDocCatalog(root.specifiedClasses(), this); duke@1: initTagletManager(customTagStrs); duke@1: } duke@1: duke@1: /** duke@1: * Set the command line options supported by this configuration. duke@1: * duke@1: * @throws DocletAbortException duke@1: */ duke@1: public void setOptions() { duke@1: initPackageArray(); duke@1: setOptions(root.options()); bpatel@1568: if (!profilespath.isEmpty()) { bpatel@1568: try { bpatel@1568: initProfiles(); bpatel@1568: initProfilePackages(); bpatel@1568: } catch (Exception e) { bpatel@1568: throw new DocletAbortException(); bpatel@1568: } bpatel@1568: } duke@1: setSpecificDocletOptions(root.options()); duke@1: } duke@1: duke@1: duke@1: /** duke@1: * Initialize the taglet manager. The strings to initialize the simple custom tags should duke@1: * be in the following format: "[tag name]:[location str]:[heading]". jjg@1413: * @param customTagStrs the set two dimensional arrays of strings. These arrays contain duke@1: * either -tag or -taglet arguments. duke@1: */ mcimadamore@184: private void initTagletManager(Set customTagStrs) { duke@1: tagletManager = tagletManager == null ? jjg@1606: new TagletManager(nosince, showversion, showauthor, javafx, message) : duke@1: tagletManager; duke@1: String[] args; mcimadamore@184: for (Iterator it = customTagStrs.iterator(); it.hasNext(); ) { mcimadamore@184: args = it.next(); duke@1: if (args[0].equals("-taglet")) { jjg@1413: tagletManager.addCustomTag(args[1], getFileManager(), tagletpath); duke@1: continue; duke@1: } jjg@1383: String[] tokens = tokenize(args[1], jjg@1413: TagletManager.SIMPLE_TAGLET_OPT_SEPARATOR, 3); duke@1: if (tokens.length == 1) { duke@1: String tagName = args[1]; duke@1: if (tagletManager.isKnownCustomTag(tagName)) { duke@1: //reorder a standard tag duke@1: tagletManager.addNewSimpleCustomTag(tagName, null, ""); duke@1: } else { duke@1: //Create a simple tag with the heading that has the same name as the tag. jjg@1362: StringBuilder heading = new StringBuilder(tagName + ":"); duke@1: heading.setCharAt(0, Character.toUpperCase(tagName.charAt(0))); duke@1: tagletManager.addNewSimpleCustomTag(tagName, heading.toString(), "a"); duke@1: } duke@1: } else if (tokens.length == 2) { duke@1: //Add simple taglet without heading, probably to excluding it in the output. duke@1: tagletManager.addNewSimpleCustomTag(tokens[0], tokens[1], ""); duke@1: } else if (tokens.length >= 3) { duke@1: tagletManager.addNewSimpleCustomTag(tokens[0], tokens[2], tokens[1]); duke@1: } else { duke@1: message.error("doclet.Error_invalid_custom_tag_argument", args[1]); duke@1: } duke@1: } duke@1: } duke@1: jjg@1383: /** jjg@1383: * Given a string, return an array of tokens. The separator can be escaped jjg@1383: * with the '\' character. The '\' character may also be escaped by the jjg@1383: * '\' character. jjg@1383: * jjg@1383: * @param s the string to tokenize. jjg@1383: * @param separator the separator char. jjg@1383: * @param maxTokens the maximum number of tokens returned. If the jjg@1383: * max is reached, the remaining part of s is appended jjg@1383: * to the end of the last token. jjg@1383: * jjg@1383: * @return an array of tokens. jjg@1383: */ jjg@1383: private String[] tokenize(String s, char separator, int maxTokens) { jjg@1383: List tokens = new ArrayList(); jjg@1383: StringBuilder token = new StringBuilder (); jjg@1383: boolean prevIsEscapeChar = false; jjg@1383: for (int i = 0; i < s.length(); i += Character.charCount(i)) { jjg@1383: int currentChar = s.codePointAt(i); jjg@1383: if (prevIsEscapeChar) { jjg@1383: // Case 1: escaped character jjg@1383: token.appendCodePoint(currentChar); jjg@1383: prevIsEscapeChar = false; jjg@1383: } else if (currentChar == separator && tokens.size() < maxTokens-1) { jjg@1383: // Case 2: separator jjg@1383: tokens.add(token.toString()); jjg@1383: token = new StringBuilder(); jjg@1383: } else if (currentChar == '\\') { jjg@1383: // Case 3: escape character jjg@1383: prevIsEscapeChar = true; jjg@1383: } else { jjg@1383: // Case 4: regular character jjg@1383: token.appendCodePoint(currentChar); jjg@1383: } jjg@1383: } jjg@1383: if (token.length() > 0) { jjg@1383: tokens.add(token.toString()); jjg@1383: } jjg@1383: return tokens.toArray(new String[] {}); jjg@1383: } jjg@1383: jjg@74: private void addToSet(Set s, String str){ duke@1: StringTokenizer st = new StringTokenizer(str, ":"); duke@1: String current; duke@1: while(st.hasMoreTokens()){ duke@1: current = st.nextToken(); duke@1: s.add(current); duke@1: } duke@1: } duke@1: duke@1: /** bpatel@1351: * Add a trailing file separator, if not found. Remove superfluous bpatel@1351: * file separators if any. Preserve the front double file separator for bpatel@1351: * UNC paths. duke@1: * duke@1: * @param path Path under consideration. duke@1: * @return String Properly constructed path string. duke@1: */ bpatel@1351: public static String addTrailingFileSep(String path) { duke@1: String fs = System.getProperty("file.separator"); duke@1: String dblfs = fs + fs; duke@1: int indexDblfs; bpatel@1351: while ((indexDblfs = path.indexOf(dblfs, 1)) >= 0) { duke@1: path = path.substring(0, indexDblfs) + duke@1: path.substring(indexDblfs + fs.length()); duke@1: } duke@1: if (!path.endsWith(fs)) duke@1: path += fs; duke@1: return path; duke@1: } duke@1: duke@1: /** duke@1: * This checks for the validity of the options used by the user. duke@1: * This works exactly like duke@1: * {@link com.sun.javadoc.Doclet#validOptions(String[][], duke@1: * DocErrorReporter)}. This will validate the options which are shared duke@1: * by our doclets. For example, this method will flag an error using duke@1: * the DocErrorReporter if user has used "-nohelp" and "-helpfile" option duke@1: * together. duke@1: * duke@1: * @param options options used on the command line. duke@1: * @param reporter used to report errors. duke@1: * @return true if all the options are valid. duke@1: */ duke@1: public boolean generalValidOptions(String options[][], duke@1: DocErrorReporter reporter) { duke@1: boolean docencodingfound = false; duke@1: String encoding = ""; duke@1: for (int oi = 0; oi < options.length; oi++) { duke@1: String[] os = options[oi]; duke@1: String opt = os[0].toLowerCase(); duke@1: if (opt.equals("-d")) { duke@1: String destdirname = addTrailingFileSep(os[1]); jjg@1383: DocFile destDir = DocFile.createFileForDirectory(this, destdirname); duke@1: if (!destDir.exists()) { duke@1: //Create the output directory (in case it doesn't exist yet) duke@1: reporter.printNotice(getText("doclet.dest_dir_create", duke@1: destdirname)); jjg@1383: destDir.mkdirs(); duke@1: } else if (!destDir.isDirectory()) { duke@1: reporter.printError(getText( duke@1: "doclet.destination_directory_not_directory_0", duke@1: destDir.getPath())); duke@1: return false; duke@1: } else if (!destDir.canWrite()) { duke@1: reporter.printError(getText( duke@1: "doclet.destination_directory_not_writable_0", duke@1: destDir.getPath())); duke@1: return false; duke@1: } duke@1: } else if (opt.equals("-docencoding")) { duke@1: docencodingfound = true; duke@1: if (!checkOutputFileEncoding(os[1], reporter)) { duke@1: return false; duke@1: } duke@1: } else if (opt.equals("-encoding")) { duke@1: encoding = os[1]; duke@1: } duke@1: } duke@1: if (!docencodingfound && encoding.length() > 0) { duke@1: if (!checkOutputFileEncoding(encoding, reporter)) { duke@1: return false; duke@1: } duke@1: } duke@1: return true; duke@1: } duke@1: duke@1: /** duke@1: * Check the validity of the given Source or Output File encoding on this duke@1: * platform. duke@1: * duke@1: * @param docencoding output file encoding. duke@1: * @param reporter used to report errors. duke@1: */ duke@1: private boolean checkOutputFileEncoding(String docencoding, duke@1: DocErrorReporter reporter) { duke@1: OutputStream ost= new ByteArrayOutputStream(); duke@1: OutputStreamWriter osw = null; duke@1: try { duke@1: osw = new OutputStreamWriter(ost, docencoding); duke@1: } catch (UnsupportedEncodingException exc) { duke@1: reporter.printError(getText("doclet.Encoding_not_supported", duke@1: docencoding)); duke@1: return false; duke@1: } finally { duke@1: try { duke@1: if (osw != null) { duke@1: osw.close(); duke@1: } duke@1: } catch (IOException exc) { duke@1: } duke@1: } duke@1: return true; duke@1: } duke@1: duke@1: /** duke@1: * Return true if the given doc-file subdirectory should be excluded and duke@1: * false otherwise. duke@1: * @param docfilesubdir the doc-files subdirectory to check. duke@1: */ duke@1: public boolean shouldExcludeDocFileDir(String docfilesubdir){ duke@1: if (excludedDocFileDirs.contains(docfilesubdir)) { duke@1: return true; duke@1: } else { duke@1: return false; duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Return true if the given qualifier should be excluded and false otherwise. duke@1: * @param qualifier the qualifier to check. duke@1: */ duke@1: public boolean shouldExcludeQualifier(String qualifier){ duke@1: if (excludedQualifiers.contains("all") || duke@1: excludedQualifiers.contains(qualifier) || duke@1: excludedQualifiers.contains(qualifier + ".*")) { duke@1: return true; duke@1: } else { duke@1: int index = -1; duke@1: while ((index = qualifier.indexOf(".", index + 1)) != -1) { duke@1: if (excludedQualifiers.contains(qualifier.substring(0, index + 1) + "*")) { duke@1: return true; duke@1: } duke@1: } duke@1: return false; duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Return the qualified name of the ClassDoc if it's qualifier is not excluded. Otherwise, duke@1: * return the unqualified ClassDoc name. duke@1: * @param cd the ClassDoc to check. duke@1: */ duke@1: public String getClassName(ClassDoc cd) { duke@1: PackageDoc pd = cd.containingPackage(); duke@1: if (pd != null && shouldExcludeQualifier(cd.containingPackage().name())) { duke@1: return cd.name(); duke@1: } else { duke@1: return cd.qualifiedName(); duke@1: } duke@1: } duke@1: duke@1: public String getText(String key) { duke@1: try { duke@1: //Check the doclet specific properties file. duke@1: return getDocletSpecificMsg().getText(key); duke@1: } catch (Exception e) { duke@1: //Check the shared properties file. duke@1: return message.getText(key); duke@1: } duke@1: } duke@1: duke@1: public String getText(String key, String a1) { duke@1: try { duke@1: //Check the doclet specific properties file. duke@1: return getDocletSpecificMsg().getText(key, a1); duke@1: } catch (Exception e) { duke@1: //Check the shared properties file. duke@1: return message.getText(key, a1); duke@1: } duke@1: } duke@1: duke@1: public String getText(String key, String a1, String a2) { duke@1: try { duke@1: //Check the doclet specific properties file. duke@1: return getDocletSpecificMsg().getText(key, a1, a2); duke@1: } catch (Exception e) { duke@1: //Check the shared properties file. duke@1: return message.getText(key, a1, a2); duke@1: } duke@1: } duke@1: duke@1: public String getText(String key, String a1, String a2, String a3) { duke@1: try { duke@1: //Check the doclet specific properties file. duke@1: return getDocletSpecificMsg().getText(key, a1, a2, a3); duke@1: } catch (Exception e) { duke@1: //Check the shared properties file. duke@1: return message.getText(key, a1, a2, a3); duke@1: } duke@1: } duke@1: duke@1: /** bpatel@995: * Return true if the ClassDoc element is getting documented, depending upon bpatel@995: * -nodeprecated option and the deprecation information. Return true if bpatel@995: * -nodeprecated is not used. Return false if -nodeprecated is used and if bpatel@995: * either ClassDoc element is deprecated or the containing package is deprecated. bpatel@995: * bpatel@995: * @param cd the ClassDoc for which the page generation is checked duke@1: */ bpatel@995: public boolean isGeneratedDoc(ClassDoc cd) { duke@1: if (!nodeprecated) { duke@1: return true; duke@1: } bpatel@995: return !(Util.isDeprecated(cd) || Util.isDeprecated(cd.containingPackage())); duke@1: } duke@1: duke@1: /** duke@1: * Return the doclet specific instance of a writer factory. duke@1: * @return the {@link WriterFactory} for the doclet. duke@1: */ duke@1: public abstract WriterFactory getWriterFactory(); duke@1: duke@1: /** duke@1: * Return the input stream to the builder XML. duke@1: * duke@1: * @return the input steam to the builder XML. duke@1: * @throws FileNotFoundException when the given XML file cannot be found. duke@1: */ jjg@1412: public InputStream getBuilderXML() throws IOException { duke@1: return builderXMLPath == null ? duke@1: Configuration.class.getResourceAsStream(DEFAULT_BUILDER_XML) : jjg@1383: DocFile.createFileForInput(this, builderXMLPath).openInputStream(); duke@1: } duke@1: duke@1: /** bpatel@191: * Return the Locale for this document. bpatel@191: */ bpatel@191: public abstract Locale getLocale(); bpatel@191: bpatel@191: /** jjg@1412: * Return the current file manager. jjg@1412: */ jjg@1412: public abstract JavaFileManager getFileManager(); jjg@1412: jjg@1412: /** duke@1: * Return the comparator that will be used to sort member documentation. duke@1: * To no do any sorting, return null. duke@1: * duke@1: * @return the {@link java.util.Comparator} used to sort members. duke@1: */ jjg@74: public abstract Comparator getMemberComparator(); jjg@1410: jjg@1410: private void setTabWidth(int n) { jjg@1410: sourcetab = n; jjg@1410: tabSpaces = String.format("%" + n + "s", ""); jjg@1410: } jjg@1490: jjg@1490: public abstract boolean showMessage(SourcePosition pos, String key); duke@1: }