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

Mon, 25 Mar 2013 16:55:14 -0700

author
mfang
date
Mon, 25 Mar 2013 16:55:14 -0700
changeset 1658
fdf30b225e1c
parent 1611
6f988040a1c8
child 1648
a03c4a86ea2b
permissions
-rw-r--r--

8010521: jdk8 l10n resource file translation update 2
Reviewed-by: naoto, yhuang

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

mercurial