src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java

Wed, 11 Sep 2013 14:50:11 -0700

author
bpatel
date
Wed, 11 Sep 2013 14:50:11 -0700
changeset 2023
cf37c3775397
parent 1997
f050c714b556
child 2413
fe033d997ddf
permissions
-rw-r--r--

8015496: Information that package is deprecated is missing in profiles view
Reviewed-by: jjg

duke@1 1 /*
jjg@1490 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.doclets.internal.toolkit;
duke@1 27
jjg@1357 28 import java.io.*;
jjg@1357 29 import java.util.*;
jjg@1740 30 import java.util.regex.Matcher;
jjg@1740 31 import java.util.regex.Pattern;
jjg@1357 32
jjg@1357 33 import com.sun.javadoc.*;
bpatel@1568 34 import com.sun.tools.javac.sym.Profiles;
bpatel@1568 35 import com.sun.tools.javac.jvm.Profile;
jjg@1357 36 import com.sun.tools.doclets.internal.toolkit.builders.BuilderFactory;
duke@1 37 import com.sun.tools.doclets.internal.toolkit.taglets.*;
duke@1 38 import com.sun.tools.doclets.internal.toolkit.util.*;
jjg@1412 39 import javax.tools.JavaFileManager;
duke@1 40
duke@1 41 /**
duke@1 42 * Configure the output based on the options. Doclets should sub-class
duke@1 43 * Configuration, to configure and add their own options. This class contains
duke@1 44 * all user options which are supported by the 1.1 doclet and the standard
duke@1 45 * doclet.
duke@1 46 *
jjg@1359 47 * <p><b>This is NOT part of any supported API.
jjg@1359 48 * If you write code that depends on this, you do so at your own risk.
jjg@1359 49 * This code and its internal interfaces are subject to change or
jjg@1359 50 * deletion without notice.</b>
duke@1 51 *
duke@1 52 * @author Robert Field.
duke@1 53 * @author Atul Dambalkar.
duke@1 54 * @author Jamie Ho
duke@1 55 */
duke@1 56 public abstract class Configuration {
duke@1 57
duke@1 58 /**
jjg@1611 59 * Exception used to report a problem during setOptions.
jjg@1611 60 */
jjg@1648 61 public static class Fault extends Exception {
jjg@1611 62 private static final long serialVersionUID = 0;
jjg@1611 63
jjg@1611 64 Fault(String msg) {
jjg@1611 65 super(msg);
jjg@1611 66 }
jjg@1611 67
jjg@1611 68 Fault(String msg, Exception cause) {
jjg@1611 69 super(msg, cause);
jjg@1611 70 }
jjg@1611 71 }
jjg@1611 72
jjg@1611 73 /**
duke@1 74 * The factory for builders.
duke@1 75 */
duke@1 76 protected BuilderFactory builderFactory;
duke@1 77
duke@1 78 /**
duke@1 79 * The taglet manager.
duke@1 80 */
duke@1 81 public TagletManager tagletManager;
duke@1 82
duke@1 83 /**
duke@1 84 * The path to the builder XML input file.
duke@1 85 */
duke@1 86 public String builderXMLPath;
duke@1 87
duke@1 88 /**
duke@1 89 * The default path to the builder XML.
duke@1 90 */
duke@1 91 private static final String DEFAULT_BUILDER_XML = "resources/doclet.xml";
duke@1 92
duke@1 93 /**
duke@1 94 * The path to Taglets
duke@1 95 */
duke@1 96 public String tagletpath = "";
duke@1 97
duke@1 98 /**
duke@1 99 * This is true if option "-serialwarn" is used. Defualt value is false to
jjg@1413 100 * suppress excessive warnings about serial tag.
duke@1 101 */
duke@1 102 public boolean serialwarn = false;
duke@1 103
duke@1 104 /**
duke@1 105 * The specified amount of space between tab stops.
duke@1 106 */
jjg@1410 107 public int sourcetab;
jjg@1410 108
jjg@1410 109 public String tabSpaces;
duke@1 110
duke@1 111 /**
duke@1 112 * True if we should generate browsable sources.
duke@1 113 */
duke@1 114 public boolean linksource = false;
duke@1 115
duke@1 116 /**
duke@1 117 * True if command line option "-nosince" is used. Default value is
duke@1 118 * false.
duke@1 119 */
duke@1 120 public boolean nosince = false;
duke@1 121
duke@1 122 /**
duke@1 123 * True if we should recursively copy the doc-file subdirectories
duke@1 124 */
duke@1 125 public boolean copydocfilesubdirs = false;
duke@1 126
duke@1 127 /**
duke@1 128 * The META charset tag used for cross-platform viewing.
duke@1 129 */
duke@1 130 public String charset = "";
duke@1 131
duke@1 132 /**
duke@1 133 * True if user wants to add member names as meta keywords.
duke@1 134 * Set to false because meta keywords are ignored in general
duke@1 135 * by most Internet search engines.
duke@1 136 */
duke@1 137 public boolean keywords = false;
duke@1 138
duke@1 139 /**
jjg@140 140 * The meta tag keywords instance.
duke@1 141 */
jjg@140 142 public final MetaKeywords metakeywords = new MetaKeywords(this);
duke@1 143
duke@1 144 /**
duke@1 145 * The list of doc-file subdirectories to exclude
duke@1 146 */
jjg@74 147 protected Set<String> excludedDocFileDirs;
duke@1 148
duke@1 149 /**
duke@1 150 * The list of qualifiers to exclude
duke@1 151 */
jjg@74 152 protected Set<String> excludedQualifiers;
duke@1 153
duke@1 154 /**
duke@1 155 * The Root of the generated Program Structure from the Doclet API.
duke@1 156 */
duke@1 157 public RootDoc root;
duke@1 158
duke@1 159 /**
duke@1 160 * Destination directory name, in which doclet will generate the entire
duke@1 161 * documentation. Default is current directory.
duke@1 162 */
duke@1 163 public String destDirName = "";
duke@1 164
duke@1 165 /**
duke@1 166 * Destination directory name, in which doclet will copy the doc-files to.
duke@1 167 */
duke@1 168 public String docFileDestDirName = "";
duke@1 169
duke@1 170 /**
duke@1 171 * Encoding for this document. Default is default encoding for this
duke@1 172 * platform.
duke@1 173 */
duke@1 174 public String docencoding = null;
duke@1 175
duke@1 176 /**
duke@1 177 * True if user wants to suppress descriptions and tags.
duke@1 178 */
duke@1 179 public boolean nocomment = false;
duke@1 180
duke@1 181 /**
duke@1 182 * Encoding for this document. Default is default encoding for this
duke@1 183 * platform.
duke@1 184 */
duke@1 185 public String encoding = null;
duke@1 186
duke@1 187 /**
duke@1 188 * Generate author specific information for all the classes if @author
duke@1 189 * tag is used in the doc comment and if -author option is used.
duke@1 190 * <code>showauthor</code> is set to true if -author option is used.
duke@1 191 * Default is don't show author information.
duke@1 192 */
duke@1 193 public boolean showauthor = false;
duke@1 194
duke@1 195 /**
jjg@1606 196 * Generate documentation for JavaFX getters and setters automatically
jjg@1606 197 * by copying it from the appropriate property definition.
jjg@1606 198 */
jjg@1606 199 public boolean javafx = false;
jjg@1606 200
jjg@1606 201 /**
duke@1 202 * Generate version specific information for the all the classes
duke@1 203 * if @version tag is used in the doc comment and if -version option is
duke@1 204 * used. <code>showversion</code> is set to true if -version option is
duke@1 205 * used.Default is don't show version information.
duke@1 206 */
duke@1 207 public boolean showversion = false;
duke@1 208
duke@1 209 /**
duke@1 210 * Sourcepath from where to read the source files. Default is classpath.
duke@1 211 *
duke@1 212 */
duke@1 213 public String sourcepath = "";
duke@1 214
duke@1 215 /**
bpatel@1568 216 * Argument for command line option "-Xprofilespath".
bpatel@1568 217 */
bpatel@1568 218 public String profilespath = "";
bpatel@1568 219
bpatel@1568 220 /**
bpatel@1568 221 * Generate profiles documentation if profilespath is set and valid profiles
bpatel@1568 222 * are present.
bpatel@1568 223 */
bpatel@1568 224 public boolean showProfiles = false;
bpatel@1568 225
bpatel@1568 226 /**
duke@1 227 * Don't generate deprecated API information at all, if -nodeprecated
duke@1 228 * option is used. <code>nodepracted</code> is set to true if
duke@1 229 * -nodeprecated option is used. Default is generate deprected API
duke@1 230 * information.
duke@1 231 */
duke@1 232 public boolean nodeprecated = false;
duke@1 233
duke@1 234 /**
duke@1 235 * The catalog of classes specified on the command-line
duke@1 236 */
duke@1 237 public ClassDocCatalog classDocCatalog;
duke@1 238
duke@1 239 /**
duke@1 240 * Message Retriever for the doclet, to retrieve message from the resource
duke@1 241 * file for this Configuration, which is common for 1.1 and standard
duke@1 242 * doclets.
duke@1 243 *
duke@1 244 * TODO: Make this private!!!
duke@1 245 */
duke@1 246 public MessageRetriever message = null;
duke@1 247
duke@1 248 /**
duke@1 249 * True if user wants to suppress time stamp in output.
duke@1 250 * Default is false.
duke@1 251 */
duke@1 252 public boolean notimestamp= false;
duke@1 253
duke@1 254 /**
jjg@140 255 * The package grouping instance.
duke@1 256 */
jjg@140 257 public final Group group = new Group(this);
duke@1 258
duke@1 259 /**
jjg@140 260 * The tracker of external package links.
duke@1 261 */
duke@1 262 public final Extern extern = new Extern(this);
duke@1 263
duke@1 264 /**
duke@1 265 * Return the build date for the doclet.
duke@1 266 */
duke@1 267 public abstract String getDocletSpecificBuildDate();
duke@1 268
duke@1 269 /**
duke@1 270 * This method should be defined in all those doclets(configurations),
duke@1 271 * which want to derive themselves from this Configuration. This method
duke@1 272 * can be used to set its own command line options.
duke@1 273 *
duke@1 274 * @param options The array of option names and values.
duke@1 275 * @throws DocletAbortException
duke@1 276 */
jjg@1611 277 public abstract void setSpecificDocletOptions(String[][] options) throws Fault;
duke@1 278
duke@1 279 /**
duke@1 280 * Return the doclet specific {@link MessageRetriever}
duke@1 281 * @return the doclet specific MessageRetriever.
duke@1 282 */
duke@1 283 public abstract MessageRetriever getDocletSpecificMsg();
duke@1 284
duke@1 285 /**
bpatel@1568 286 * A profiles object used to access profiles across various pages.
bpatel@1568 287 */
bpatel@1568 288 public Profiles profiles;
bpatel@1568 289
bpatel@1568 290 /**
bpatel@1568 291 * An map of the profiles to packages.
bpatel@1568 292 */
bpatel@1568 293 public Map<String,PackageDoc[]> profilePackages;
bpatel@1568 294
bpatel@1568 295 /**
duke@1 296 * An array of the packages specified on the command-line merged
duke@1 297 * with the array of packages that contain the classes specified on the
duke@1 298 * command-line. The array is sorted.
duke@1 299 */
duke@1 300 public PackageDoc[] packages;
duke@1 301
duke@1 302 /**
duke@1 303 * Constructor. Constructs the message retriever with resource file.
duke@1 304 */
duke@1 305 public Configuration() {
duke@1 306 message =
duke@1 307 new MessageRetriever(this,
duke@1 308 "com.sun.tools.doclets.internal.toolkit.resources.doclets");
jjg@74 309 excludedDocFileDirs = new HashSet<String>();
jjg@74 310 excludedQualifiers = new HashSet<String>();
jjg@1410 311 setTabWidth(DocletConstants.DEFAULT_TAB_STOP_LENGTH);
duke@1 312 }
duke@1 313
duke@1 314 /**
duke@1 315 * Return the builder factory for this doclet.
duke@1 316 *
duke@1 317 * @return the builder factory for this doclet.
duke@1 318 */
duke@1 319 public BuilderFactory getBuilderFactory() {
duke@1 320 if (builderFactory == null) {
duke@1 321 builderFactory = new BuilderFactory(this);
duke@1 322 }
duke@1 323 return builderFactory;
duke@1 324 }
duke@1 325
duke@1 326 /**
duke@1 327 * This method should be defined in all those doclets
duke@1 328 * which want to inherit from this Configuration. This method
duke@1 329 * should return the number of arguments to the command line
duke@1 330 * option (including the option name). For example,
duke@1 331 * -notimestamp is a single-argument option, so this method would
duke@1 332 * return 1.
duke@1 333 *
duke@1 334 * @param option Command line option under consideration.
duke@1 335 * @return number of arguments to option (including the
duke@1 336 * option name). Zero return means option not known.
duke@1 337 * Negative value means error occurred.
duke@1 338 */
duke@1 339 public int optionLength(String option) {
duke@1 340 option = option.toLowerCase();
duke@1 341 if (option.equals("-author") ||
duke@1 342 option.equals("-docfilessubdirs") ||
jjg@1606 343 option.equals("-javafx") ||
duke@1 344 option.equals("-keywords") ||
duke@1 345 option.equals("-linksource") ||
duke@1 346 option.equals("-nocomment") ||
duke@1 347 option.equals("-nodeprecated") ||
duke@1 348 option.equals("-nosince") ||
duke@1 349 option.equals("-notimestamp") ||
duke@1 350 option.equals("-quiet") ||
duke@1 351 option.equals("-xnodate") ||
duke@1 352 option.equals("-version")) {
duke@1 353 return 1;
duke@1 354 } else if (option.equals("-d") ||
duke@1 355 option.equals("-docencoding") ||
duke@1 356 option.equals("-encoding") ||
duke@1 357 option.equals("-excludedocfilessubdir") ||
duke@1 358 option.equals("-link") ||
duke@1 359 option.equals("-sourcetab") ||
duke@1 360 option.equals("-noqualifier") ||
duke@1 361 option.equals("-output") ||
duke@1 362 option.equals("-sourcepath") ||
duke@1 363 option.equals("-tag") ||
duke@1 364 option.equals("-taglet") ||
bpatel@1568 365 option.equals("-tagletpath") ||
bpatel@1568 366 option.equals("-xprofilespath")) {
duke@1 367 return 2;
duke@1 368 } else if (option.equals("-group") ||
duke@1 369 option.equals("-linkoffline")) {
duke@1 370 return 3;
duke@1 371 } else {
duke@1 372 return -1; // indicate we don't know about it
duke@1 373 }
duke@1 374 }
duke@1 375
duke@1 376 /**
duke@1 377 * Perform error checking on the given options.
duke@1 378 *
duke@1 379 * @param options the given options to check.
duke@1 380 * @param reporter the reporter used to report errors.
duke@1 381 */
duke@1 382 public abstract boolean validOptions(String options[][],
duke@1 383 DocErrorReporter reporter);
duke@1 384
bpatel@1568 385 private void initProfiles() throws IOException {
jjg@1997 386 if (profilespath.isEmpty())
jjg@1997 387 return;
jjg@1997 388
bpatel@1568 389 profiles = Profiles.read(new File(profilespath));
bpatel@1568 390
jjg@1997 391 // Group the packages to be documented by the lowest profile (if any)
jjg@1997 392 // in which each appears
jjg@1997 393 Map<Profile, List<PackageDoc>> interimResults =
jjg@1997 394 new EnumMap<Profile, List<PackageDoc>>(Profile.class);
jjg@1997 395 for (Profile p: Profile.values())
jjg@1997 396 interimResults.put(p, new ArrayList<PackageDoc>());
jjg@1997 397
jjg@1997 398 for (PackageDoc pkg: packages) {
bpatel@2023 399 if (nodeprecated && Util.isDeprecated(pkg)) {
bpatel@2023 400 continue;
bpatel@2023 401 }
jjg@1997 402 // the getProfile method takes a type name, not a package name,
jjg@1997 403 // but isn't particularly fussy about the simple name -- so just use *
jjg@1997 404 int i = profiles.getProfile(pkg.name().replace(".", "/") + "/*");
jjg@1997 405 Profile p = Profile.lookup(i);
jjg@1997 406 if (p != null) {
jjg@1997 407 List<PackageDoc> pkgs = interimResults.get(p);
jjg@1997 408 pkgs.add(pkg);
jjg@1997 409 }
jjg@1997 410 }
jjg@1997 411
jjg@1997 412 // Build the profilePackages structure used by the doclet
bpatel@1568 413 profilePackages = new HashMap<String,PackageDoc[]>();
jjg@1997 414 List<PackageDoc> prev = Collections.<PackageDoc>emptyList();
bpatel@2023 415 int size;
jjg@1997 416 for (Map.Entry<Profile,List<PackageDoc>> e: interimResults.entrySet()) {
jjg@1997 417 Profile p = e.getKey();
jjg@1997 418 List<PackageDoc> pkgs = e.getValue();
jjg@1997 419 pkgs.addAll(prev); // each profile contains all lower profiles
jjg@1997 420 Collections.sort(pkgs);
bpatel@2023 421 size = pkgs.size();
bpatel@2023 422 // For a profile, if there are no packages to be documented, do not add
bpatel@2023 423 // it to profilePackages map.
bpatel@2023 424 if (size > 0)
bpatel@2023 425 profilePackages.put(p.name, pkgs.toArray(new PackageDoc[pkgs.size()]));
jjg@1997 426 prev = pkgs;
bpatel@1568 427 }
jjg@1997 428
jjg@1997 429 // Generate profiles documentation if any profile contains any
jjg@1997 430 // of the packages to be documented.
jjg@1997 431 showProfiles = !prev.isEmpty();
bpatel@1568 432 }
bpatel@1568 433
duke@1 434 private void initPackageArray() {
jjg@74 435 Set<PackageDoc> set = new HashSet<PackageDoc>(Arrays.asList(root.specifiedPackages()));
duke@1 436 ClassDoc[] classes = root.specifiedClasses();
duke@1 437 for (int i = 0; i < classes.length; i++) {
duke@1 438 set.add(classes[i].containingPackage());
duke@1 439 }
jjg@74 440 ArrayList<PackageDoc> results = new ArrayList<PackageDoc>(set);
duke@1 441 Collections.sort(results);
jjg@74 442 packages = results.toArray(new PackageDoc[] {});
duke@1 443 }
duke@1 444
duke@1 445 /**
duke@1 446 * Set the command line options supported by this configuration.
duke@1 447 *
duke@1 448 * @param options the two dimensional array of options.
duke@1 449 */
jjg@1611 450 public void setOptions(String[][] options) throws Fault {
jjg@74 451 LinkedHashSet<String[]> customTagStrs = new LinkedHashSet<String[]>();
jjg@1611 452
jjg@1611 453 // Some options, specifically -link and -linkoffline, require that
jjg@1611 454 // the output directory has already been created: so do that first.
duke@1 455 for (int oi = 0; oi < options.length; ++oi) {
duke@1 456 String[] os = options[oi];
duke@1 457 String opt = os[0].toLowerCase();
duke@1 458 if (opt.equals("-d")) {
duke@1 459 destDirName = addTrailingFileSep(os[1]);
duke@1 460 docFileDestDirName = destDirName;
jjg@1611 461 ensureOutputDirExists();
jjg@1611 462 break;
jjg@1611 463 }
jjg@1611 464 }
jjg@1611 465
jjg@1611 466 for (int oi = 0; oi < options.length; ++oi) {
jjg@1611 467 String[] os = options[oi];
jjg@1611 468 String opt = os[0].toLowerCase();
jjg@1611 469 if (opt.equals("-docfilessubdirs")) {
duke@1 470 copydocfilesubdirs = true;
bpatel@1324 471 } else if (opt.equals("-docencoding")) {
duke@1 472 docencoding = os[1];
bpatel@1324 473 } else if (opt.equals("-encoding")) {
duke@1 474 encoding = os[1];
bpatel@1324 475 } else if (opt.equals("-author")) {
duke@1 476 showauthor = true;
jjg@1606 477 } else if (opt.equals("-javafx")) {
jjg@1606 478 javafx = true;
bpatel@1324 479 } else if (opt.equals("-nosince")) {
bpatel@1324 480 nosince = true;
bpatel@1324 481 } else if (opt.equals("-version")) {
duke@1 482 showversion = true;
bpatel@1324 483 } else if (opt.equals("-nodeprecated")) {
duke@1 484 nodeprecated = true;
bpatel@1324 485 } else if (opt.equals("-sourcepath")) {
duke@1 486 sourcepath = os[1];
vromero@1885 487 } else if ((opt.equals("-classpath") || opt.equals("-cp")) &&
duke@1 488 sourcepath.length() == 0) {
duke@1 489 sourcepath = os[1];
duke@1 490 } else if (opt.equals("-excludedocfilessubdir")) {
duke@1 491 addToSet(excludedDocFileDirs, os[1]);
duke@1 492 } else if (opt.equals("-noqualifier")) {
duke@1 493 addToSet(excludedQualifiers, os[1]);
duke@1 494 } else if (opt.equals("-linksource")) {
duke@1 495 linksource = true;
duke@1 496 } else if (opt.equals("-sourcetab")) {
duke@1 497 linksource = true;
duke@1 498 try {
jjg@1410 499 setTabWidth(Integer.parseInt(os[1]));
duke@1 500 } catch (NumberFormatException e) {
duke@1 501 //Set to -1 so that warning will be printed
duke@1 502 //to indicate what is valid argument.
duke@1 503 sourcetab = -1;
duke@1 504 }
duke@1 505 if (sourcetab <= 0) {
duke@1 506 message.warning("doclet.sourcetab_warning");
jjg@1410 507 setTabWidth(DocletConstants.DEFAULT_TAB_STOP_LENGTH);
duke@1 508 }
bpatel@1324 509 } else if (opt.equals("-notimestamp")) {
duke@1 510 notimestamp = true;
bpatel@1324 511 } else if (opt.equals("-nocomment")) {
duke@1 512 nocomment = true;
duke@1 513 } else if (opt.equals("-tag") || opt.equals("-taglet")) {
duke@1 514 customTagStrs.add(os);
duke@1 515 } else if (opt.equals("-tagletpath")) {
duke@1 516 tagletpath = os[1];
bpatel@1568 517 } else if (opt.equals("-xprofilespath")) {
bpatel@1568 518 profilespath = os[1];
bpatel@1324 519 } else if (opt.equals("-keywords")) {
duke@1 520 keywords = true;
bpatel@1324 521 } else if (opt.equals("-serialwarn")) {
duke@1 522 serialwarn = true;
duke@1 523 } else if (opt.equals("-group")) {
duke@1 524 group.checkPackageGroups(os[1], os[2]);
duke@1 525 } else if (opt.equals("-link")) {
duke@1 526 String url = os[1];
jjg@1376 527 extern.link(url, url, root, false);
duke@1 528 } else if (opt.equals("-linkoffline")) {
duke@1 529 String url = os[1];
duke@1 530 String pkglisturl = os[2];
jjg@1376 531 extern.link(url, pkglisturl, root, true);
duke@1 532 }
duke@1 533 }
duke@1 534 if (sourcepath.length() == 0) {
duke@1 535 sourcepath = System.getProperty("env.class.path") == null ? "" :
duke@1 536 System.getProperty("env.class.path");
duke@1 537 }
duke@1 538 if (docencoding == null) {
duke@1 539 docencoding = encoding;
duke@1 540 }
duke@1 541
bpatel@995 542 classDocCatalog = new ClassDocCatalog(root.specifiedClasses(), this);
duke@1 543 initTagletManager(customTagStrs);
duke@1 544 }
duke@1 545
duke@1 546 /**
duke@1 547 * Set the command line options supported by this configuration.
duke@1 548 *
duke@1 549 * @throws DocletAbortException
duke@1 550 */
jjg@1611 551 public void setOptions() throws Fault {
duke@1 552 initPackageArray();
duke@1 553 setOptions(root.options());
jjg@1997 554 try {
jjg@1997 555 initProfiles();
jjg@1997 556 } catch (Exception e) {
jjg@1997 557 throw new DocletAbortException(e);
bpatel@1568 558 }
duke@1 559 setSpecificDocletOptions(root.options());
duke@1 560 }
duke@1 561
jjg@1611 562 private void ensureOutputDirExists() throws Fault {
jjg@1611 563 DocFile destDir = DocFile.createFileForDirectory(this, destDirName);
jjg@1611 564 if (!destDir.exists()) {
jjg@1611 565 //Create the output directory (in case it doesn't exist yet)
jjg@1611 566 root.printNotice(getText("doclet.dest_dir_create", destDirName));
jjg@1611 567 destDir.mkdirs();
jjg@1611 568 } else if (!destDir.isDirectory()) {
jjg@1611 569 throw new Fault(getText(
jjg@1611 570 "doclet.destination_directory_not_directory_0",
jjg@1611 571 destDir.getPath()));
jjg@1611 572 } else if (!destDir.canWrite()) {
jjg@1611 573 throw new Fault(getText(
jjg@1611 574 "doclet.destination_directory_not_writable_0",
jjg@1611 575 destDir.getPath()));
jjg@1611 576 }
jjg@1611 577 }
jjg@1611 578
duke@1 579
duke@1 580 /**
duke@1 581 * Initialize the taglet manager. The strings to initialize the simple custom tags should
duke@1 582 * be in the following format: "[tag name]:[location str]:[heading]".
jjg@1413 583 * @param customTagStrs the set two dimensional arrays of strings. These arrays contain
duke@1 584 * either -tag or -taglet arguments.
duke@1 585 */
mcimadamore@184 586 private void initTagletManager(Set<String[]> customTagStrs) {
duke@1 587 tagletManager = tagletManager == null ?
jjg@1606 588 new TagletManager(nosince, showversion, showauthor, javafx, message) :
duke@1 589 tagletManager;
duke@1 590 String[] args;
mcimadamore@184 591 for (Iterator<String[]> it = customTagStrs.iterator(); it.hasNext(); ) {
mcimadamore@184 592 args = it.next();
duke@1 593 if (args[0].equals("-taglet")) {
jjg@1413 594 tagletManager.addCustomTag(args[1], getFileManager(), tagletpath);
duke@1 595 continue;
duke@1 596 }
jjg@1383 597 String[] tokens = tokenize(args[1],
jjg@1413 598 TagletManager.SIMPLE_TAGLET_OPT_SEPARATOR, 3);
duke@1 599 if (tokens.length == 1) {
duke@1 600 String tagName = args[1];
duke@1 601 if (tagletManager.isKnownCustomTag(tagName)) {
duke@1 602 //reorder a standard tag
duke@1 603 tagletManager.addNewSimpleCustomTag(tagName, null, "");
duke@1 604 } else {
duke@1 605 //Create a simple tag with the heading that has the same name as the tag.
jjg@1362 606 StringBuilder heading = new StringBuilder(tagName + ":");
duke@1 607 heading.setCharAt(0, Character.toUpperCase(tagName.charAt(0)));
duke@1 608 tagletManager.addNewSimpleCustomTag(tagName, heading.toString(), "a");
duke@1 609 }
duke@1 610 } else if (tokens.length == 2) {
duke@1 611 //Add simple taglet without heading, probably to excluding it in the output.
duke@1 612 tagletManager.addNewSimpleCustomTag(tokens[0], tokens[1], "");
duke@1 613 } else if (tokens.length >= 3) {
duke@1 614 tagletManager.addNewSimpleCustomTag(tokens[0], tokens[2], tokens[1]);
duke@1 615 } else {
duke@1 616 message.error("doclet.Error_invalid_custom_tag_argument", args[1]);
duke@1 617 }
duke@1 618 }
duke@1 619 }
duke@1 620
jjg@1383 621 /**
jjg@1383 622 * Given a string, return an array of tokens. The separator can be escaped
jjg@1383 623 * with the '\' character. The '\' character may also be escaped by the
jjg@1383 624 * '\' character.
jjg@1383 625 *
jjg@1383 626 * @param s the string to tokenize.
jjg@1383 627 * @param separator the separator char.
jjg@1383 628 * @param maxTokens the maximum number of tokens returned. If the
jjg@1383 629 * max is reached, the remaining part of s is appended
jjg@1383 630 * to the end of the last token.
jjg@1383 631 *
jjg@1383 632 * @return an array of tokens.
jjg@1383 633 */
jjg@1383 634 private String[] tokenize(String s, char separator, int maxTokens) {
jjg@1383 635 List<String> tokens = new ArrayList<String>();
jjg@1383 636 StringBuilder token = new StringBuilder ();
jjg@1383 637 boolean prevIsEscapeChar = false;
jjg@1383 638 for (int i = 0; i < s.length(); i += Character.charCount(i)) {
jjg@1383 639 int currentChar = s.codePointAt(i);
jjg@1383 640 if (prevIsEscapeChar) {
jjg@1383 641 // Case 1: escaped character
jjg@1383 642 token.appendCodePoint(currentChar);
jjg@1383 643 prevIsEscapeChar = false;
jjg@1383 644 } else if (currentChar == separator && tokens.size() < maxTokens-1) {
jjg@1383 645 // Case 2: separator
jjg@1383 646 tokens.add(token.toString());
jjg@1383 647 token = new StringBuilder();
jjg@1383 648 } else if (currentChar == '\\') {
jjg@1383 649 // Case 3: escape character
jjg@1383 650 prevIsEscapeChar = true;
jjg@1383 651 } else {
jjg@1383 652 // Case 4: regular character
jjg@1383 653 token.appendCodePoint(currentChar);
jjg@1383 654 }
jjg@1383 655 }
jjg@1383 656 if (token.length() > 0) {
jjg@1383 657 tokens.add(token.toString());
jjg@1383 658 }
jjg@1383 659 return tokens.toArray(new String[] {});
jjg@1383 660 }
jjg@1383 661
jjg@74 662 private void addToSet(Set<String> s, String str){
duke@1 663 StringTokenizer st = new StringTokenizer(str, ":");
duke@1 664 String current;
duke@1 665 while(st.hasMoreTokens()){
duke@1 666 current = st.nextToken();
duke@1 667 s.add(current);
duke@1 668 }
duke@1 669 }
duke@1 670
duke@1 671 /**
bpatel@1351 672 * Add a trailing file separator, if not found. Remove superfluous
bpatel@1351 673 * file separators if any. Preserve the front double file separator for
bpatel@1351 674 * UNC paths.
duke@1 675 *
duke@1 676 * @param path Path under consideration.
duke@1 677 * @return String Properly constructed path string.
duke@1 678 */
bpatel@1351 679 public static String addTrailingFileSep(String path) {
duke@1 680 String fs = System.getProperty("file.separator");
duke@1 681 String dblfs = fs + fs;
duke@1 682 int indexDblfs;
bpatel@1351 683 while ((indexDblfs = path.indexOf(dblfs, 1)) >= 0) {
duke@1 684 path = path.substring(0, indexDblfs) +
duke@1 685 path.substring(indexDblfs + fs.length());
duke@1 686 }
duke@1 687 if (!path.endsWith(fs))
duke@1 688 path += fs;
duke@1 689 return path;
duke@1 690 }
duke@1 691
duke@1 692 /**
duke@1 693 * This checks for the validity of the options used by the user.
duke@1 694 * This works exactly like
duke@1 695 * {@link com.sun.javadoc.Doclet#validOptions(String[][],
duke@1 696 * DocErrorReporter)}. This will validate the options which are shared
duke@1 697 * by our doclets. For example, this method will flag an error using
duke@1 698 * the DocErrorReporter if user has used "-nohelp" and "-helpfile" option
duke@1 699 * together.
duke@1 700 *
duke@1 701 * @param options options used on the command line.
duke@1 702 * @param reporter used to report errors.
duke@1 703 * @return true if all the options are valid.
duke@1 704 */
duke@1 705 public boolean generalValidOptions(String options[][],
duke@1 706 DocErrorReporter reporter) {
duke@1 707 boolean docencodingfound = false;
duke@1 708 String encoding = "";
duke@1 709 for (int oi = 0; oi < options.length; oi++) {
duke@1 710 String[] os = options[oi];
duke@1 711 String opt = os[0].toLowerCase();
jjg@1611 712 if (opt.equals("-docencoding")) {
duke@1 713 docencodingfound = true;
duke@1 714 if (!checkOutputFileEncoding(os[1], reporter)) {
duke@1 715 return false;
duke@1 716 }
duke@1 717 } else if (opt.equals("-encoding")) {
duke@1 718 encoding = os[1];
duke@1 719 }
duke@1 720 }
duke@1 721 if (!docencodingfound && encoding.length() > 0) {
duke@1 722 if (!checkOutputFileEncoding(encoding, reporter)) {
duke@1 723 return false;
duke@1 724 }
duke@1 725 }
duke@1 726 return true;
duke@1 727 }
duke@1 728
duke@1 729 /**
bpatel@2023 730 * Check the validity of the given profile. Return false if there are no
bpatel@2023 731 * valid packages to be documented for the profile.
bpatel@2023 732 *
bpatel@2023 733 * @param profileName the profile that needs to be validated.
bpatel@2023 734 * @return true if the profile has valid packages to be documented.
bpatel@2023 735 */
bpatel@2023 736 public boolean shouldDocumentProfile(String profileName) {
bpatel@2023 737 return profilePackages.containsKey(profileName);
bpatel@2023 738 }
bpatel@2023 739
bpatel@2023 740 /**
duke@1 741 * Check the validity of the given Source or Output File encoding on this
duke@1 742 * platform.
duke@1 743 *
duke@1 744 * @param docencoding output file encoding.
duke@1 745 * @param reporter used to report errors.
duke@1 746 */
duke@1 747 private boolean checkOutputFileEncoding(String docencoding,
duke@1 748 DocErrorReporter reporter) {
duke@1 749 OutputStream ost= new ByteArrayOutputStream();
duke@1 750 OutputStreamWriter osw = null;
duke@1 751 try {
duke@1 752 osw = new OutputStreamWriter(ost, docencoding);
duke@1 753 } catch (UnsupportedEncodingException exc) {
duke@1 754 reporter.printError(getText("doclet.Encoding_not_supported",
duke@1 755 docencoding));
duke@1 756 return false;
duke@1 757 } finally {
duke@1 758 try {
duke@1 759 if (osw != null) {
duke@1 760 osw.close();
duke@1 761 }
duke@1 762 } catch (IOException exc) {
duke@1 763 }
duke@1 764 }
duke@1 765 return true;
duke@1 766 }
duke@1 767
duke@1 768 /**
duke@1 769 * Return true if the given doc-file subdirectory should be excluded and
duke@1 770 * false otherwise.
duke@1 771 * @param docfilesubdir the doc-files subdirectory to check.
duke@1 772 */
duke@1 773 public boolean shouldExcludeDocFileDir(String docfilesubdir){
duke@1 774 if (excludedDocFileDirs.contains(docfilesubdir)) {
duke@1 775 return true;
duke@1 776 } else {
duke@1 777 return false;
duke@1 778 }
duke@1 779 }
duke@1 780
duke@1 781 /**
duke@1 782 * Return true if the given qualifier should be excluded and false otherwise.
duke@1 783 * @param qualifier the qualifier to check.
duke@1 784 */
duke@1 785 public boolean shouldExcludeQualifier(String qualifier){
duke@1 786 if (excludedQualifiers.contains("all") ||
duke@1 787 excludedQualifiers.contains(qualifier) ||
duke@1 788 excludedQualifiers.contains(qualifier + ".*")) {
duke@1 789 return true;
duke@1 790 } else {
duke@1 791 int index = -1;
duke@1 792 while ((index = qualifier.indexOf(".", index + 1)) != -1) {
duke@1 793 if (excludedQualifiers.contains(qualifier.substring(0, index + 1) + "*")) {
duke@1 794 return true;
duke@1 795 }
duke@1 796 }
duke@1 797 return false;
duke@1 798 }
duke@1 799 }
duke@1 800
duke@1 801 /**
duke@1 802 * Return the qualified name of the <code>ClassDoc</code> if it's qualifier is not excluded. Otherwise,
duke@1 803 * return the unqualified <code>ClassDoc</code> name.
duke@1 804 * @param cd the <code>ClassDoc</code> to check.
duke@1 805 */
duke@1 806 public String getClassName(ClassDoc cd) {
duke@1 807 PackageDoc pd = cd.containingPackage();
duke@1 808 if (pd != null && shouldExcludeQualifier(cd.containingPackage().name())) {
duke@1 809 return cd.name();
duke@1 810 } else {
duke@1 811 return cd.qualifiedName();
duke@1 812 }
duke@1 813 }
duke@1 814
duke@1 815 public String getText(String key) {
duke@1 816 try {
duke@1 817 //Check the doclet specific properties file.
duke@1 818 return getDocletSpecificMsg().getText(key);
duke@1 819 } catch (Exception e) {
duke@1 820 //Check the shared properties file.
duke@1 821 return message.getText(key);
duke@1 822 }
duke@1 823 }
duke@1 824
duke@1 825 public String getText(String key, String a1) {
duke@1 826 try {
duke@1 827 //Check the doclet specific properties file.
duke@1 828 return getDocletSpecificMsg().getText(key, a1);
duke@1 829 } catch (Exception e) {
duke@1 830 //Check the shared properties file.
duke@1 831 return message.getText(key, a1);
duke@1 832 }
duke@1 833 }
duke@1 834
duke@1 835 public String getText(String key, String a1, String a2) {
duke@1 836 try {
duke@1 837 //Check the doclet specific properties file.
duke@1 838 return getDocletSpecificMsg().getText(key, a1, a2);
duke@1 839 } catch (Exception e) {
duke@1 840 //Check the shared properties file.
duke@1 841 return message.getText(key, a1, a2);
duke@1 842 }
duke@1 843 }
duke@1 844
duke@1 845 public String getText(String key, String a1, String a2, String a3) {
duke@1 846 try {
duke@1 847 //Check the doclet specific properties file.
duke@1 848 return getDocletSpecificMsg().getText(key, a1, a2, a3);
duke@1 849 } catch (Exception e) {
duke@1 850 //Check the shared properties file.
duke@1 851 return message.getText(key, a1, a2, a3);
duke@1 852 }
duke@1 853 }
duke@1 854
jjg@1747 855 public abstract Content newContent();
jjg@1740 856
jjg@1740 857 /**
jjg@1740 858 * Get the configuration string as a content.
jjg@1740 859 *
jjg@1740 860 * @param key the key to look for in the configuration file
jjg@1740 861 * @return a content tree for the text
jjg@1740 862 */
jjg@1740 863 public Content getResource(String key) {
jjg@1747 864 Content c = newContent();
jjg@1740 865 c.addContent(getText(key));
jjg@1740 866 return c;
jjg@1740 867 }
jjg@1740 868
jjg@1740 869 /**
jjg@1740 870 * Get the configuration string as a content.
jjg@1740 871 *
jjg@1740 872 * @param key the key to look for in the configuration file
jjg@1740 873 * @param o string or content argument added to configuration text
jjg@1740 874 * @return a content tree for the text
jjg@1740 875 */
jjg@1740 876 public Content getResource(String key, Object o) {
jjg@1740 877 return getResource(key, o, null, null);
jjg@1740 878 }
jjg@1740 879
jjg@1740 880 /**
jjg@1740 881 * Get the configuration string as a content.
jjg@1740 882 *
jjg@1740 883 * @param key the key to look for in the configuration file
jjg@1740 884 * @param o string or content argument added to configuration text
jjg@1740 885 * @return a content tree for the text
jjg@1740 886 */
jjg@1740 887 public Content getResource(String key, Object o1, Object o2) {
jjg@1740 888 return getResource(key, o1, o2, null);
jjg@1740 889 }
jjg@1740 890
jjg@1740 891 /**
jjg@1740 892 * Get the configuration string as a content.
jjg@1740 893 *
jjg@1740 894 * @param key the key to look for in the configuration file
jjg@1740 895 * @param o1 string or content argument added to configuration text
jjg@1740 896 * @param o2 string or content argument added to configuration text
jjg@1740 897 * @return a content tree for the text
jjg@1740 898 */
jjg@1740 899 public Content getResource(String key, Object o0, Object o1, Object o2) {
jjg@1747 900 Content c = newContent();
jjg@1740 901 Pattern p = Pattern.compile("\\{([012])\\}");
jjg@1740 902 String text = getText(key);
jjg@1740 903 Matcher m = p.matcher(text);
jjg@1740 904 int start = 0;
jjg@1740 905 while (m.find(start)) {
jjg@1740 906 c.addContent(text.substring(start, m.start()));
jjg@1740 907
jjg@1740 908 Object o = null;
jjg@1740 909 switch (m.group(1).charAt(0)) {
jjg@1740 910 case '0': o = o0; break;
jjg@1740 911 case '1': o = o1; break;
jjg@1740 912 case '2': o = o2; break;
jjg@1740 913 }
jjg@1740 914
jjg@1740 915 if (o == null) {
jjg@1740 916 c.addContent("{" + m.group(1) + "}");
jjg@1740 917 } else if (o instanceof String) {
jjg@1740 918 c.addContent((String) o);
jjg@1740 919 } else if (o instanceof Content) {
jjg@1740 920 c.addContent((Content) o);
jjg@1740 921 }
jjg@1740 922
jjg@1740 923 start = m.end();
jjg@1740 924 }
jjg@1740 925
jjg@1740 926 c.addContent(text.substring(start));
jjg@1740 927 return c;
jjg@1740 928 }
jjg@1740 929
jjg@1740 930
duke@1 931 /**
bpatel@995 932 * Return true if the ClassDoc element is getting documented, depending upon
bpatel@995 933 * -nodeprecated option and the deprecation information. Return true if
bpatel@995 934 * -nodeprecated is not used. Return false if -nodeprecated is used and if
bpatel@995 935 * either ClassDoc element is deprecated or the containing package is deprecated.
bpatel@995 936 *
bpatel@995 937 * @param cd the ClassDoc for which the page generation is checked
duke@1 938 */
bpatel@995 939 public boolean isGeneratedDoc(ClassDoc cd) {
duke@1 940 if (!nodeprecated) {
duke@1 941 return true;
duke@1 942 }
bpatel@995 943 return !(Util.isDeprecated(cd) || Util.isDeprecated(cd.containingPackage()));
duke@1 944 }
duke@1 945
duke@1 946 /**
duke@1 947 * Return the doclet specific instance of a writer factory.
duke@1 948 * @return the {@link WriterFactory} for the doclet.
duke@1 949 */
duke@1 950 public abstract WriterFactory getWriterFactory();
duke@1 951
duke@1 952 /**
duke@1 953 * Return the input stream to the builder XML.
duke@1 954 *
duke@1 955 * @return the input steam to the builder XML.
duke@1 956 * @throws FileNotFoundException when the given XML file cannot be found.
duke@1 957 */
jjg@1412 958 public InputStream getBuilderXML() throws IOException {
duke@1 959 return builderXMLPath == null ?
duke@1 960 Configuration.class.getResourceAsStream(DEFAULT_BUILDER_XML) :
jjg@1383 961 DocFile.createFileForInput(this, builderXMLPath).openInputStream();
duke@1 962 }
duke@1 963
duke@1 964 /**
bpatel@191 965 * Return the Locale for this document.
bpatel@191 966 */
bpatel@191 967 public abstract Locale getLocale();
bpatel@191 968
bpatel@191 969 /**
jjg@1412 970 * Return the current file manager.
jjg@1412 971 */
jjg@1412 972 public abstract JavaFileManager getFileManager();
jjg@1412 973
jjg@1412 974 /**
duke@1 975 * Return the comparator that will be used to sort member documentation.
duke@1 976 * To no do any sorting, return null.
duke@1 977 *
duke@1 978 * @return the {@link java.util.Comparator} used to sort members.
duke@1 979 */
jjg@74 980 public abstract Comparator<ProgramElementDoc> getMemberComparator();
jjg@1410 981
jjg@1410 982 private void setTabWidth(int n) {
jjg@1410 983 sourcetab = n;
jjg@1410 984 tabSpaces = String.format("%" + n + "s", "");
jjg@1410 985 }
jjg@1490 986
jjg@1490 987 public abstract boolean showMessage(SourcePosition pos, String key);
duke@1 988 }

mercurial