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

Tue, 01 Nov 2016 23:55:58 -0700

author
asaha
date
Tue, 01 Nov 2016 23:55:58 -0700
changeset 3339
8efc10efbfe1
parent 2413
fe033d997ddf
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8168993: JDK8u121 L10n resource file update
Reviewed-by: coffeys
Contributed-by: li.jiang@oracle.com

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

mercurial