src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java

Thu, 15 Nov 2012 19:54:20 -0800

author
jjg
date
Thu, 15 Nov 2012 19:54:20 -0800
changeset 1412
400a4e8accd3
parent 1410
bfec2a1cc869
child 1413
bdcef2ef52d2
permissions
-rw-r--r--

8002079: update DocFile to use a JavaFileManager
Reviewed-by: darcy

     1 /*
     2  * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.doclets.formats.html;
    28 import java.net.*;
    29 import java.util.*;
    31 import javax.tools.JavaFileManager;
    33 import com.sun.javadoc.*;
    34 import com.sun.tools.doclets.internal.toolkit.*;
    35 import com.sun.tools.doclets.internal.toolkit.util.*;
    36 import com.sun.tools.javac.file.JavacFileManager;
    37 import com.sun.tools.javac.util.Context;
    39 /**
    40  * Configure the output based on the command line options.
    41  * <p>
    42  * Also determine the length of the command line option. For example,
    43  * for a option "-header" there will be a string argument associated, then the
    44  * the length of option "-header" is two. But for option "-nohelp" no argument
    45  * is needed so it's length is 1.
    46  * </p>
    47  * <p>
    48  * Also do the error checking on the options used. For example it is illegal to
    49  * use "-helpfile" option when already "-nohelp" option is used.
    50  * </p>
    51  *
    52  *  <p><b>This is NOT part of any supported API.
    53  *  If you write code that depends on this, you do so at your own risk.
    54  *  This code and its internal interfaces are subject to change or
    55  *  deletion without notice.</b>
    56  *
    57  * @author Robert Field.
    58  * @author Atul Dambalkar.
    59  * @author Jamie Ho
    60  * @author Bhavesh Patel (Modified)
    61  */
    62 public class ConfigurationImpl extends Configuration {
    64     /**
    65      * The build date.  Note: For now, we will use
    66      * a version number instead of a date.
    67      */
    68     public static final String BUILD_DATE = System.getProperty("java.version");
    70     /**
    71      * Argument for command line option "-header".
    72      */
    73     public String header = "";
    75     /**
    76      * Argument for command line option "-packagesheader".
    77      */
    78     public String packagesheader = "";
    80     /**
    81      * Argument for command line option "-footer".
    82      */
    83     public String footer = "";
    85     /**
    86      * Argument for command line option "-doctitle".
    87      */
    88     public String doctitle = "";
    90     /**
    91      * Argument for command line option "-windowtitle".
    92      */
    93     public String windowtitle = "";
    95     /**
    96      * Argument for command line option "-top".
    97      */
    98     public String top = "";
   100     /**
   101      * Argument for command line option "-bottom".
   102      */
   103     public String bottom = "";
   105     /**
   106      * Argument for command line option "-helpfile".
   107      */
   108     public String helpfile = "";
   110     /**
   111      * Argument for command line option "-stylesheetfile".
   112      */
   113     public String stylesheetfile = "";
   115     /**
   116      * Argument for command line option "-Xdocrootparent".
   117      */
   118     public String docrootparent = "";
   120     /**
   121      * True if command line option "-nohelp" is used. Default value is false.
   122      */
   123     public boolean nohelp = false;
   125     /**
   126      * True if command line option "-splitindex" is used. Default value is
   127      * false.
   128      */
   129     public boolean splitindex = false;
   131     /**
   132      * False if command line option "-noindex" is used. Default value is true.
   133      */
   134     public boolean createindex = true;
   136     /**
   137      * True if command line option "-use" is used. Default value is false.
   138      */
   139     public boolean classuse = false;
   141     /**
   142      * False if command line option "-notree" is used. Default value is true.
   143      */
   144     public boolean createtree = true;
   146     /**
   147      * True if command line option "-nodeprecated" is used. Default value is
   148      * false.
   149      */
   150     public boolean nodeprecatedlist = false;
   152     /**
   153      * True if command line option "-nonavbar" is used. Default value is false.
   154      */
   155     public boolean nonavbar = false;
   157     /**
   158      * True if command line option "-nooverview" is used. Default value is
   159      * false
   160      */
   161     private boolean nooverview = false;
   163     /**
   164      * True if command line option "-overview" is used. Default value is false.
   165      */
   166     public boolean overview = false;
   168     /**
   169      * This is true if option "-overview" is used or option "-overview" is not
   170      * used and number of packages is more than one.
   171      */
   172     public boolean createoverview = false;
   174     /**
   175      * Unique Resource Handler for this package.
   176      */
   177     public final MessageRetriever standardmessage;
   179     /**
   180      * First file to appear in the right-hand frame in the generated
   181      * documentation.
   182      */
   183     public DocPath topFile = DocPath.empty;
   185     /**
   186      * The classdoc for the class file getting generated.
   187      */
   188     public ClassDoc currentcd = null;  // Set this classdoc in the ClassWriter.
   190     /**
   191      * Constructor. Initializes resource for the
   192      * {@link com.sun.tools.doclets.internal.toolkit.util.MessageRetriever MessageRetriever}.
   193      */
   194     public ConfigurationImpl() {
   195         standardmessage = new MessageRetriever(this,
   196             "com.sun.tools.doclets.formats.html.resources.standard");
   197     }
   199     /**
   200      * Return the build date for the doclet.
   201      */
   202     @Override
   203     public String getDocletSpecificBuildDate() {
   204         return BUILD_DATE;
   205     }
   207     /**
   208      * Depending upon the command line options provided by the user, set
   209      * configure the output generation environment.
   210      *
   211      * @param options The array of option names and values.
   212      */
   213     @Override
   214     public void setSpecificDocletOptions(String[][] options) {
   215         for (int oi = 0; oi < options.length; ++oi) {
   216             String[] os = options[oi];
   217             String opt = os[0].toLowerCase();
   218             if (opt.equals("-footer")) {
   219                 footer = os[1];
   220             } else if (opt.equals("-header")) {
   221                 header = os[1];
   222             } else if (opt.equals("-packagesheader")) {
   223                 packagesheader = os[1];
   224             } else if (opt.equals("-doctitle")) {
   225                 doctitle = os[1];
   226             } else if (opt.equals("-windowtitle")) {
   227                 windowtitle = os[1];
   228             } else if (opt.equals("-top")) {
   229                 top = os[1];
   230             } else if (opt.equals("-bottom")) {
   231                 bottom = os[1];
   232             } else if (opt.equals("-helpfile")) {
   233                 helpfile = os[1];
   234             } else if (opt.equals("-stylesheetfile")) {
   235                 stylesheetfile = os[1];
   236             } else if (opt.equals("-charset")) {
   237                 charset = os[1];
   238             } else if (opt.equals("-xdocrootparent")) {
   239                 docrootparent = os[1];
   240             } else if (opt.equals("-nohelp")) {
   241                 nohelp = true;
   242             } else if (opt.equals("-splitindex")) {
   243                 splitindex = true;
   244             } else if (opt.equals("-noindex")) {
   245                 createindex = false;
   246             } else if (opt.equals("-use")) {
   247                 classuse = true;
   248             } else if (opt.equals("-notree")) {
   249                 createtree = false;
   250             } else if (opt.equals("-nodeprecatedlist")) {
   251                 nodeprecatedlist = true;
   252             } else if (opt.equals("-nonavbar")) {
   253                 nonavbar = true;
   254             } else if (opt.equals("-nooverview")) {
   255                 nooverview = true;
   256             } else if (opt.equals("-overview")) {
   257                 overview = true;
   258             }
   259         }
   260         if (root.specifiedClasses().length > 0) {
   261             Map<String,PackageDoc> map = new HashMap<String,PackageDoc>();
   262             PackageDoc pd;
   263             ClassDoc[] classes = root.classes();
   264             for (int i = 0; i < classes.length; i++) {
   265                 pd = classes[i].containingPackage();
   266                 if(! map.containsKey(pd.name())) {
   267                     map.put(pd.name(), pd);
   268                 }
   269             }
   270         }
   271         setCreateOverview();
   272         setTopFile(root);
   273     }
   275     /**
   276      * Returns the "length" of a given option. If an option takes no
   277      * arguments, its length is one. If it takes one argument, it's
   278      * length is two, and so on. This method is called by JavaDoc to
   279      * parse the options it does not recognize. It then calls
   280      * {@link #validOptions(String[][], DocErrorReporter)} to
   281      * validate them.
   282      * <b>Note:</b><br>
   283      * The options arrive as case-sensitive strings. For options that
   284      * are not case-sensitive, use toLowerCase() on the option string
   285      * before comparing it.
   286      * </blockquote>
   287      *
   288      * @return number of arguments + 1 for a option. Zero return means
   289      * option not known.  Negative value means error occurred.
   290      */
   291     public int optionLength(String option) {
   292         int result = -1;
   293         if ((result = super.optionLength(option)) > 0) {
   294             return result;
   295         }
   296         // otherwise look for the options we have added
   297         option = option.toLowerCase();
   298         if (option.equals("-nodeprecatedlist") ||
   299             option.equals("-noindex") ||
   300             option.equals("-notree") ||
   301             option.equals("-nohelp") ||
   302             option.equals("-splitindex") ||
   303             option.equals("-serialwarn") ||
   304             option.equals("-use") ||
   305             option.equals("-nonavbar") ||
   306             option.equals("-nooverview")) {
   307             return 1;
   308         } else if (option.equals("-help")) {
   309             System.out.println(getText("doclet.usage"));
   310             return 1;
   311         } else if (option.equals("-footer") ||
   312                    option.equals("-header") ||
   313                    option.equals("-packagesheader") ||
   314                    option.equals("-doctitle") ||
   315                    option.equals("-windowtitle") ||
   316                    option.equals("-top") ||
   317                    option.equals("-bottom") ||
   318                    option.equals("-helpfile") ||
   319                    option.equals("-stylesheetfile") ||
   320                    option.equals("-charset") ||
   321                    option.equals("-overview") ||
   322                    option.equals("-xdocrootparent")) {
   323             return 2;
   324         } else {
   325             return 0;
   326         }
   327     }
   329     /**
   330      * {@inheritDoc}
   331      */
   332     @Override
   333     public boolean validOptions(String options[][],
   334             DocErrorReporter reporter) {
   335         boolean helpfile = false;
   336         boolean nohelp = false;
   337         boolean overview = false;
   338         boolean nooverview = false;
   339         boolean splitindex = false;
   340         boolean noindex = false;
   341         // check shared options
   342         if (!generalValidOptions(options, reporter)) {
   343             return false;
   344         }
   345         // otherwise look at our options
   346         for (int oi = 0; oi < options.length; ++oi) {
   347             String[] os = options[oi];
   348             String opt = os[0].toLowerCase();
   349             if (opt.equals("-helpfile")) {
   350                 if (nohelp == true) {
   351                     reporter.printError(getText("doclet.Option_conflict",
   352                         "-helpfile", "-nohelp"));
   353                     return false;
   354                 }
   355                 if (helpfile == true) {
   356                     reporter.printError(getText("doclet.Option_reuse",
   357                         "-helpfile"));
   358                     return false;
   359                 }
   360                 DocFile help = DocFile.createFileForInput(this, os[1]);
   361                 if (!help.exists()) {
   362                     reporter.printError(getText("doclet.File_not_found", os[1]));
   363                     return false;
   364                 }
   365                 helpfile = true;
   366             } else  if (opt.equals("-nohelp")) {
   367                 if (helpfile == true) {
   368                     reporter.printError(getText("doclet.Option_conflict",
   369                         "-nohelp", "-helpfile"));
   370                     return false;
   371                 }
   372                 nohelp = true;
   373             } else if (opt.equals("-xdocrootparent")) {
   374                 try {
   375                     new URL(os[1]);
   376                 } catch (MalformedURLException e) {
   377                     reporter.printError(getText("doclet.MalformedURL", os[1]));
   378                     return false;
   379                 }
   380             } else if (opt.equals("-overview")) {
   381                 if (nooverview == true) {
   382                     reporter.printError(getText("doclet.Option_conflict",
   383                         "-overview", "-nooverview"));
   384                     return false;
   385                 }
   386                 if (overview == true) {
   387                     reporter.printError(getText("doclet.Option_reuse",
   388                         "-overview"));
   389                     return false;
   390                 }
   391                 overview = true;
   392             } else  if (opt.equals("-nooverview")) {
   393                 if (overview == true) {
   394                     reporter.printError(getText("doclet.Option_conflict",
   395                         "-nooverview", "-overview"));
   396                     return false;
   397                 }
   398                 nooverview = true;
   399             } else if (opt.equals("-splitindex")) {
   400                 if (noindex == true) {
   401                     reporter.printError(getText("doclet.Option_conflict",
   402                         "-splitindex", "-noindex"));
   403                     return false;
   404                 }
   405                 splitindex = true;
   406             } else if (opt.equals("-noindex")) {
   407                 if (splitindex == true) {
   408                     reporter.printError(getText("doclet.Option_conflict",
   409                         "-noindex", "-splitindex"));
   410                     return false;
   411                 }
   412                 noindex = true;
   413             }
   414         }
   415         return true;
   416     }
   418     /**
   419      * {@inheritDoc}
   420      */
   421     @Override
   422     public MessageRetriever getDocletSpecificMsg() {
   423         return standardmessage;
   424     }
   426     /**
   427      * Decide the page which will appear first in the right-hand frame. It will
   428      * be "overview-summary.html" if "-overview" option is used or no
   429      * "-overview" but the number of packages is more than one. It will be
   430      * "package-summary.html" of the respective package if there is only one
   431      * package to document. It will be a class page(first in the sorted order),
   432      * if only classes are provided on the command line.
   433      *
   434      * @param root Root of the program structure.
   435      */
   436     protected void setTopFile(RootDoc root) {
   437         if (!checkForDeprecation(root)) {
   438             return;
   439         }
   440         if (createoverview) {
   441             topFile = DocPaths.OVERVIEW_SUMMARY;
   442         } else {
   443             if (packages.length == 1 && packages[0].name().equals("")) {
   444                 if (root.classes().length > 0) {
   445                     ClassDoc[] classarr = root.classes();
   446                     Arrays.sort(classarr);
   447                     ClassDoc cd = getValidClass(classarr);
   448                     topFile = DocPath.forClass(cd);
   449                 }
   450             } else {
   451                 topFile = DocPath.forPackage(packages[0]).resolve(DocPaths.PACKAGE_SUMMARY);
   452             }
   453         }
   454     }
   456     protected ClassDoc getValidClass(ClassDoc[] classarr) {
   457         if (!nodeprecated) {
   458             return classarr[0];
   459         }
   460         for (int i = 0; i < classarr.length; i++) {
   461             if (classarr[i].tags("deprecated").length == 0) {
   462                 return classarr[i];
   463             }
   464         }
   465         return null;
   466     }
   468     protected boolean checkForDeprecation(RootDoc root) {
   469         ClassDoc[] classarr = root.classes();
   470         for (int i = 0; i < classarr.length; i++) {
   471             if (isGeneratedDoc(classarr[i])) {
   472                 return true;
   473             }
   474         }
   475         return false;
   476     }
   478     /**
   479      * Generate "overview.html" page if option "-overview" is used or number of
   480      * packages is more than one. Sets {@link #createoverview} field to true.
   481      */
   482     protected void setCreateOverview() {
   483         if ((overview || packages.length > 1) && !nooverview) {
   484             createoverview = true;
   485         }
   486     }
   488     /**
   489      * {@inheritDoc}
   490      */
   491     @Override
   492     public WriterFactory getWriterFactory() {
   493         return new WriterFactoryImpl(this);
   494     }
   496     /**
   497      * {@inheritDoc}
   498      */
   499     @Override
   500     public Comparator<ProgramElementDoc> getMemberComparator() {
   501         return null;
   502     }
   504     /**
   505      * {@inheritDoc}
   506      */
   507     @Override
   508     public Locale getLocale() {
   509         if (root instanceof com.sun.tools.javadoc.RootDocImpl)
   510             return ((com.sun.tools.javadoc.RootDocImpl)root).getLocale();
   511         else
   512             return Locale.getDefault();
   513     }
   515     /**
   516      * {@inheritDoc}
   517      */
   518     @Override
   519     public JavaFileManager getFileManager() {
   520         if (root instanceof com.sun.tools.javadoc.RootDocImpl)
   521             return ((com.sun.tools.javadoc.RootDocImpl)root).getFileManager();
   522         else
   523             return new JavacFileManager(new Context(), false, null);
   524     }
   525 }

mercurial