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

Sun, 24 Feb 2013 11:36:58 -0800

author
jjg
date
Sun, 24 Feb 2013 11:36:58 -0800
changeset 1606
ccbe7ffdd867
parent 1570
f91144b7da75
child 1611
6f988040a1c8
permissions
-rw-r--r--

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

mercurial