Thu, 24 May 2018 18:02:46 +0800
Merge
aoqi@0 | 1 | /* |
aefimov@3315 | 2 | * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.tools.doclets.formats.html; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.net.*; |
aoqi@0 | 29 | import java.util.*; |
aoqi@0 | 30 | |
aoqi@0 | 31 | import javax.tools.JavaFileManager; |
aoqi@0 | 32 | |
aoqi@0 | 33 | import com.sun.javadoc.*; |
aoqi@0 | 34 | import com.sun.tools.doclets.formats.html.markup.ContentBuilder; |
aoqi@0 | 35 | import com.sun.tools.doclets.internal.toolkit.*; |
aoqi@0 | 36 | import com.sun.tools.doclets.internal.toolkit.util.*; |
aoqi@0 | 37 | import com.sun.tools.doclint.DocLint; |
aoqi@0 | 38 | import com.sun.tools.javac.file.JavacFileManager; |
aoqi@0 | 39 | import com.sun.tools.javac.util.Context; |
aoqi@0 | 40 | import com.sun.tools.javac.util.StringUtils; |
aefimov@3315 | 41 | import com.sun.tools.javadoc.JavaScriptScanner; |
aoqi@0 | 42 | import com.sun.tools.javadoc.RootDocImpl; |
aoqi@0 | 43 | |
aoqi@0 | 44 | /** |
aoqi@0 | 45 | * Configure the output based on the command line options. |
aoqi@0 | 46 | * <p> |
aoqi@0 | 47 | * Also determine the length of the command line option. For example, |
aoqi@0 | 48 | * for a option "-header" there will be a string argument associated, then the |
aoqi@0 | 49 | * the length of option "-header" is two. But for option "-nohelp" no argument |
aoqi@0 | 50 | * is needed so it's length is 1. |
aoqi@0 | 51 | * </p> |
aoqi@0 | 52 | * <p> |
aoqi@0 | 53 | * Also do the error checking on the options used. For example it is illegal to |
aoqi@0 | 54 | * use "-helpfile" option when already "-nohelp" option is used. |
aoqi@0 | 55 | * </p> |
aoqi@0 | 56 | * |
aoqi@0 | 57 | * <p><b>This is NOT part of any supported API. |
aoqi@0 | 58 | * If you write code that depends on this, you do so at your own risk. |
aoqi@0 | 59 | * This code and its internal interfaces are subject to change or |
aoqi@0 | 60 | * deletion without notice.</b> |
aoqi@0 | 61 | * |
aoqi@0 | 62 | * @author Robert Field. |
aoqi@0 | 63 | * @author Atul Dambalkar. |
aoqi@0 | 64 | * @author Jamie Ho |
aoqi@0 | 65 | * @author Bhavesh Patel (Modified) |
aoqi@0 | 66 | */ |
aoqi@0 | 67 | public class ConfigurationImpl extends Configuration { |
aoqi@0 | 68 | |
aoqi@0 | 69 | /** |
aoqi@0 | 70 | * The build date. Note: For now, we will use |
aoqi@0 | 71 | * a version number instead of a date. |
aoqi@0 | 72 | */ |
aoqi@0 | 73 | public static final String BUILD_DATE = System.getProperty("java.version"); |
aoqi@0 | 74 | |
aoqi@0 | 75 | /** |
aoqi@0 | 76 | * Argument for command line option "-header". |
aoqi@0 | 77 | */ |
aoqi@0 | 78 | public String header = ""; |
aoqi@0 | 79 | |
aoqi@0 | 80 | /** |
aoqi@0 | 81 | * Argument for command line option "-packagesheader". |
aoqi@0 | 82 | */ |
aoqi@0 | 83 | public String packagesheader = ""; |
aoqi@0 | 84 | |
aoqi@0 | 85 | /** |
aoqi@0 | 86 | * Argument for command line option "-footer". |
aoqi@0 | 87 | */ |
aoqi@0 | 88 | public String footer = ""; |
aoqi@0 | 89 | |
aoqi@0 | 90 | /** |
aoqi@0 | 91 | * Argument for command line option "-doctitle". |
aoqi@0 | 92 | */ |
aoqi@0 | 93 | public String doctitle = ""; |
aoqi@0 | 94 | |
aoqi@0 | 95 | /** |
aoqi@0 | 96 | * Argument for command line option "-windowtitle". |
aoqi@0 | 97 | */ |
aoqi@0 | 98 | public String windowtitle = ""; |
aoqi@0 | 99 | |
aoqi@0 | 100 | /** |
aoqi@0 | 101 | * Argument for command line option "-top". |
aoqi@0 | 102 | */ |
aoqi@0 | 103 | public String top = ""; |
aoqi@0 | 104 | |
aoqi@0 | 105 | /** |
aoqi@0 | 106 | * Argument for command line option "-bottom". |
aoqi@0 | 107 | */ |
aoqi@0 | 108 | public String bottom = ""; |
aoqi@0 | 109 | |
aoqi@0 | 110 | /** |
aoqi@0 | 111 | * Argument for command line option "-helpfile". |
aoqi@0 | 112 | */ |
aoqi@0 | 113 | public String helpfile = ""; |
aoqi@0 | 114 | |
aoqi@0 | 115 | /** |
aoqi@0 | 116 | * Argument for command line option "-stylesheetfile". |
aoqi@0 | 117 | */ |
aoqi@0 | 118 | public String stylesheetfile = ""; |
aoqi@0 | 119 | |
aoqi@0 | 120 | /** |
aoqi@0 | 121 | * Argument for command line option "-Xdocrootparent". |
aoqi@0 | 122 | */ |
aoqi@0 | 123 | public String docrootparent = ""; |
aoqi@0 | 124 | |
aoqi@0 | 125 | /** |
aoqi@0 | 126 | * True if command line option "-nohelp" is used. Default value is false. |
aoqi@0 | 127 | */ |
aoqi@0 | 128 | public boolean nohelp = false; |
aoqi@0 | 129 | |
aoqi@0 | 130 | /** |
aoqi@0 | 131 | * True if command line option "-splitindex" is used. Default value is |
aoqi@0 | 132 | * false. |
aoqi@0 | 133 | */ |
aoqi@0 | 134 | public boolean splitindex = false; |
aoqi@0 | 135 | |
aoqi@0 | 136 | /** |
aoqi@0 | 137 | * False if command line option "-noindex" is used. Default value is true. |
aoqi@0 | 138 | */ |
aoqi@0 | 139 | public boolean createindex = true; |
aoqi@0 | 140 | |
aoqi@0 | 141 | /** |
aoqi@0 | 142 | * True if command line option "-use" is used. Default value is false. |
aoqi@0 | 143 | */ |
aoqi@0 | 144 | public boolean classuse = false; |
aoqi@0 | 145 | |
aoqi@0 | 146 | /** |
aoqi@0 | 147 | * False if command line option "-notree" is used. Default value is true. |
aoqi@0 | 148 | */ |
aoqi@0 | 149 | public boolean createtree = true; |
aoqi@0 | 150 | |
aoqi@0 | 151 | /** |
aoqi@0 | 152 | * True if command line option "-nodeprecated" is used. Default value is |
aoqi@0 | 153 | * false. |
aoqi@0 | 154 | */ |
aoqi@0 | 155 | public boolean nodeprecatedlist = false; |
aoqi@0 | 156 | |
aoqi@0 | 157 | /** |
aoqi@0 | 158 | * True if command line option "-nonavbar" is used. Default value is false. |
aoqi@0 | 159 | */ |
aoqi@0 | 160 | public boolean nonavbar = false; |
aoqi@0 | 161 | |
aoqi@0 | 162 | /** |
aoqi@0 | 163 | * True if command line option "-nooverview" is used. Default value is |
aoqi@0 | 164 | * false |
aoqi@0 | 165 | */ |
aoqi@0 | 166 | private boolean nooverview = false; |
aoqi@0 | 167 | |
aoqi@0 | 168 | /** |
aoqi@0 | 169 | * True if command line option "-overview" is used. Default value is false. |
aoqi@0 | 170 | */ |
aoqi@0 | 171 | public boolean overview = false; |
aoqi@0 | 172 | |
aoqi@0 | 173 | /** |
aoqi@0 | 174 | * This is true if option "-overview" is used or option "-overview" is not |
aoqi@0 | 175 | * used and number of packages is more than one. |
aoqi@0 | 176 | */ |
aoqi@0 | 177 | public boolean createoverview = false; |
aoqi@0 | 178 | |
aoqi@0 | 179 | /** |
aoqi@0 | 180 | * Collected set of doclint options |
aoqi@0 | 181 | */ |
aoqi@0 | 182 | public Set<String> doclintOpts = new LinkedHashSet<String>(); |
aoqi@0 | 183 | |
aoqi@0 | 184 | /** |
aefimov@3315 | 185 | * Whether or not to check for JavaScript in doc comments. |
aefimov@3315 | 186 | */ |
aefimov@3315 | 187 | private boolean allowScriptInComments; |
aefimov@3315 | 188 | |
aefimov@3315 | 189 | /** |
aoqi@0 | 190 | * Unique Resource Handler for this package. |
aoqi@0 | 191 | */ |
aoqi@0 | 192 | public final MessageRetriever standardmessage; |
aoqi@0 | 193 | |
aoqi@0 | 194 | /** |
aoqi@0 | 195 | * First file to appear in the right-hand frame in the generated |
aoqi@0 | 196 | * documentation. |
aoqi@0 | 197 | */ |
aoqi@0 | 198 | public DocPath topFile = DocPath.empty; |
aoqi@0 | 199 | |
aoqi@0 | 200 | /** |
aoqi@0 | 201 | * The classdoc for the class file getting generated. |
aoqi@0 | 202 | */ |
aoqi@0 | 203 | public ClassDoc currentcd = null; // Set this classdoc in the ClassWriter. |
aoqi@0 | 204 | |
aoqi@0 | 205 | /** |
aoqi@0 | 206 | * Constructor. Initializes resource for the |
aoqi@0 | 207 | * {@link com.sun.tools.doclets.internal.toolkit.util.MessageRetriever MessageRetriever}. |
aoqi@0 | 208 | */ |
aoqi@0 | 209 | public ConfigurationImpl() { |
aoqi@0 | 210 | standardmessage = new MessageRetriever(this, |
aoqi@0 | 211 | "com.sun.tools.doclets.formats.html.resources.standard"); |
aoqi@0 | 212 | } |
aoqi@0 | 213 | |
aoqi@0 | 214 | private final String versionRBName = "com.sun.tools.javadoc.resources.version"; |
aoqi@0 | 215 | private ResourceBundle versionRB; |
aoqi@0 | 216 | |
aoqi@0 | 217 | /** |
aoqi@0 | 218 | * Return the build date for the doclet. |
aoqi@0 | 219 | */ |
aoqi@0 | 220 | @Override |
aoqi@0 | 221 | public String getDocletSpecificBuildDate() { |
aoqi@0 | 222 | if (versionRB == null) { |
aoqi@0 | 223 | try { |
aoqi@0 | 224 | versionRB = ResourceBundle.getBundle(versionRBName); |
aoqi@0 | 225 | } catch (MissingResourceException e) { |
aoqi@0 | 226 | return BUILD_DATE; |
aoqi@0 | 227 | } |
aoqi@0 | 228 | } |
aoqi@0 | 229 | |
aoqi@0 | 230 | try { |
aoqi@0 | 231 | return versionRB.getString("release"); |
aoqi@0 | 232 | } catch (MissingResourceException e) { |
aoqi@0 | 233 | return BUILD_DATE; |
aoqi@0 | 234 | } |
aoqi@0 | 235 | } |
aoqi@0 | 236 | |
aoqi@0 | 237 | /** |
aoqi@0 | 238 | * Depending upon the command line options provided by the user, set |
aoqi@0 | 239 | * configure the output generation environment. |
aoqi@0 | 240 | * |
aoqi@0 | 241 | * @param options The array of option names and values. |
aoqi@0 | 242 | */ |
aoqi@0 | 243 | @Override |
aoqi@0 | 244 | public void setSpecificDocletOptions(String[][] options) { |
aoqi@0 | 245 | for (int oi = 0; oi < options.length; ++oi) { |
aoqi@0 | 246 | String[] os = options[oi]; |
aoqi@0 | 247 | String opt = StringUtils.toLowerCase(os[0]); |
aoqi@0 | 248 | if (opt.equals("-footer")) { |
aoqi@0 | 249 | footer = os[1]; |
aoqi@0 | 250 | } else if (opt.equals("-header")) { |
aoqi@0 | 251 | header = os[1]; |
aoqi@0 | 252 | } else if (opt.equals("-packagesheader")) { |
aoqi@0 | 253 | packagesheader = os[1]; |
aoqi@0 | 254 | } else if (opt.equals("-doctitle")) { |
aoqi@0 | 255 | doctitle = os[1]; |
aoqi@0 | 256 | } else if (opt.equals("-windowtitle")) { |
aoqi@0 | 257 | windowtitle = os[1].replaceAll("\\<.*?>", ""); |
aoqi@0 | 258 | } else if (opt.equals("-top")) { |
aoqi@0 | 259 | top = os[1]; |
aoqi@0 | 260 | } else if (opt.equals("-bottom")) { |
aoqi@0 | 261 | bottom = os[1]; |
aoqi@0 | 262 | } else if (opt.equals("-helpfile")) { |
aoqi@0 | 263 | helpfile = os[1]; |
aoqi@0 | 264 | } else if (opt.equals("-stylesheetfile")) { |
aoqi@0 | 265 | stylesheetfile = os[1]; |
aoqi@0 | 266 | } else if (opt.equals("-charset")) { |
aoqi@0 | 267 | charset = os[1]; |
aoqi@0 | 268 | } else if (opt.equals("-xdocrootparent")) { |
aoqi@0 | 269 | docrootparent = os[1]; |
aoqi@0 | 270 | } else if (opt.equals("-nohelp")) { |
aoqi@0 | 271 | nohelp = true; |
aoqi@0 | 272 | } else if (opt.equals("-splitindex")) { |
aoqi@0 | 273 | splitindex = true; |
aoqi@0 | 274 | } else if (opt.equals("-noindex")) { |
aoqi@0 | 275 | createindex = false; |
aoqi@0 | 276 | } else if (opt.equals("-use")) { |
aoqi@0 | 277 | classuse = true; |
aoqi@0 | 278 | } else if (opt.equals("-notree")) { |
aoqi@0 | 279 | createtree = false; |
aoqi@0 | 280 | } else if (opt.equals("-nodeprecatedlist")) { |
aoqi@0 | 281 | nodeprecatedlist = true; |
aoqi@0 | 282 | } else if (opt.equals("-nonavbar")) { |
aoqi@0 | 283 | nonavbar = true; |
aoqi@0 | 284 | } else if (opt.equals("-nooverview")) { |
aoqi@0 | 285 | nooverview = true; |
aoqi@0 | 286 | } else if (opt.equals("-overview")) { |
aoqi@0 | 287 | overview = true; |
aoqi@0 | 288 | } else if (opt.equals("-xdoclint")) { |
aoqi@0 | 289 | doclintOpts.add(null); |
aoqi@0 | 290 | } else if (opt.startsWith("-xdoclint:")) { |
aoqi@0 | 291 | doclintOpts.add(opt.substring(opt.indexOf(":") + 1)); |
aefimov@3315 | 292 | } else if (opt.equals("--allow-script-in-comments")) { |
aefimov@3315 | 293 | allowScriptInComments = true; |
aoqi@0 | 294 | } |
aoqi@0 | 295 | } |
aefimov@3315 | 296 | |
aoqi@0 | 297 | if (root.specifiedClasses().length > 0) { |
aoqi@0 | 298 | Map<String,PackageDoc> map = new HashMap<String,PackageDoc>(); |
aoqi@0 | 299 | PackageDoc pd; |
aoqi@0 | 300 | ClassDoc[] classes = root.classes(); |
aoqi@0 | 301 | for (int i = 0; i < classes.length; i++) { |
aoqi@0 | 302 | pd = classes[i].containingPackage(); |
aoqi@0 | 303 | if(! map.containsKey(pd.name())) { |
aoqi@0 | 304 | map.put(pd.name(), pd); |
aoqi@0 | 305 | } |
aoqi@0 | 306 | } |
aoqi@0 | 307 | } |
aoqi@0 | 308 | setCreateOverview(); |
aoqi@0 | 309 | setTopFile(root); |
aoqi@0 | 310 | |
aoqi@0 | 311 | if (root instanceof RootDocImpl) { |
aoqi@0 | 312 | ((RootDocImpl) root).initDocLint(doclintOpts, tagletManager.getCustomTagNames()); |
aefimov@3315 | 313 | JavaScriptScanner jss = ((RootDocImpl) root).initJavaScriptScanner(isAllowScriptInComments()); |
aefimov@3315 | 314 | if (jss != null) { |
aefimov@3315 | 315 | // In a more object-oriented world, this would be done by methods on the Option objects. |
aefimov@3315 | 316 | // Note that -windowtitle silently removes any and all HTML elements, and so does not need |
aefimov@3315 | 317 | // to be handled here. |
aefimov@3315 | 318 | checkJavaScript(jss, "-header", header); |
aefimov@3315 | 319 | checkJavaScript(jss, "-footer", footer); |
aefimov@3315 | 320 | checkJavaScript(jss, "-top", top); |
aefimov@3315 | 321 | checkJavaScript(jss, "-bottom", bottom); |
aefimov@3315 | 322 | checkJavaScript(jss, "-doctitle", doctitle); |
aefimov@3315 | 323 | checkJavaScript(jss, "-packagesheader", packagesheader); |
aefimov@3315 | 324 | } |
aoqi@0 | 325 | } |
aoqi@0 | 326 | } |
aoqi@0 | 327 | |
aefimov@3315 | 328 | private void checkJavaScript(JavaScriptScanner jss, final String opt, String value) { |
aefimov@3315 | 329 | jss.parse(value, new JavaScriptScanner.Reporter() { |
aefimov@3315 | 330 | public void report() { |
aefimov@3315 | 331 | root.printError(getText("doclet.JavaScript_in_option", opt)); |
aefimov@3315 | 332 | throw new FatalError(); |
aefimov@3315 | 333 | } |
aefimov@3315 | 334 | }); |
aefimov@3315 | 335 | } |
aefimov@3315 | 336 | |
aoqi@0 | 337 | /** |
aoqi@0 | 338 | * Returns the "length" of a given option. If an option takes no |
aoqi@0 | 339 | * arguments, its length is one. If it takes one argument, it's |
aoqi@0 | 340 | * length is two, and so on. This method is called by JavaDoc to |
aoqi@0 | 341 | * parse the options it does not recognize. It then calls |
aoqi@0 | 342 | * {@link #validOptions(String[][], DocErrorReporter)} to |
aoqi@0 | 343 | * validate them. |
aoqi@0 | 344 | * <b>Note:</b><br> |
aoqi@0 | 345 | * The options arrive as case-sensitive strings. For options that |
aoqi@0 | 346 | * are not case-sensitive, use toLowerCase() on the option string |
aoqi@0 | 347 | * before comparing it. |
aoqi@0 | 348 | * </blockquote> |
aoqi@0 | 349 | * |
aoqi@0 | 350 | * @return number of arguments + 1 for a option. Zero return means |
aoqi@0 | 351 | * option not known. Negative value means error occurred. |
aoqi@0 | 352 | */ |
aoqi@0 | 353 | public int optionLength(String option) { |
aoqi@0 | 354 | int result = -1; |
aoqi@0 | 355 | if ((result = super.optionLength(option)) > 0) { |
aoqi@0 | 356 | return result; |
aoqi@0 | 357 | } |
aoqi@0 | 358 | // otherwise look for the options we have added |
aoqi@0 | 359 | option = StringUtils.toLowerCase(option); |
aoqi@0 | 360 | if (option.equals("-nodeprecatedlist") || |
aoqi@0 | 361 | option.equals("-noindex") || |
aoqi@0 | 362 | option.equals("-notree") || |
aoqi@0 | 363 | option.equals("-nohelp") || |
aoqi@0 | 364 | option.equals("-splitindex") || |
aoqi@0 | 365 | option.equals("-serialwarn") || |
aoqi@0 | 366 | option.equals("-use") || |
aoqi@0 | 367 | option.equals("-nonavbar") || |
aoqi@0 | 368 | option.equals("-nooverview") || |
aoqi@0 | 369 | option.equals("-xdoclint") || |
aefimov@3315 | 370 | option.startsWith("-xdoclint:") || |
aefimov@3315 | 371 | option.equals("--allow-script-in-comments")) { |
aoqi@0 | 372 | return 1; |
aoqi@0 | 373 | } else if (option.equals("-help")) { |
aoqi@0 | 374 | // Uugh: first, this should not be hidden inside optionLength, |
aoqi@0 | 375 | // and second, we should not be writing directly to stdout. |
aoqi@0 | 376 | // But we have no access to a DocErrorReporter, which would |
aoqi@0 | 377 | // allow use of reporter.printNotice |
aoqi@0 | 378 | System.out.println(getText("doclet.usage")); |
aoqi@0 | 379 | return 1; |
aoqi@0 | 380 | } else if (option.equals("-x")) { |
aoqi@0 | 381 | // Uugh: first, this should not be hidden inside optionLength, |
aoqi@0 | 382 | // and second, we should not be writing directly to stdout. |
aoqi@0 | 383 | // But we have no access to a DocErrorReporter, which would |
aoqi@0 | 384 | // allow use of reporter.printNotice |
aoqi@0 | 385 | System.out.println(getText("doclet.X.usage")); |
aoqi@0 | 386 | return 1; |
aoqi@0 | 387 | } else if (option.equals("-footer") || |
aoqi@0 | 388 | option.equals("-header") || |
aoqi@0 | 389 | option.equals("-packagesheader") || |
aoqi@0 | 390 | option.equals("-doctitle") || |
aoqi@0 | 391 | option.equals("-windowtitle") || |
aoqi@0 | 392 | option.equals("-top") || |
aoqi@0 | 393 | option.equals("-bottom") || |
aoqi@0 | 394 | option.equals("-helpfile") || |
aoqi@0 | 395 | option.equals("-stylesheetfile") || |
aoqi@0 | 396 | option.equals("-charset") || |
aoqi@0 | 397 | option.equals("-overview") || |
aoqi@0 | 398 | option.equals("-xdocrootparent")) { |
aoqi@0 | 399 | return 2; |
aoqi@0 | 400 | } else { |
aoqi@0 | 401 | return 0; |
aoqi@0 | 402 | } |
aoqi@0 | 403 | } |
aoqi@0 | 404 | |
aoqi@0 | 405 | /** |
aoqi@0 | 406 | * {@inheritDoc} |
aoqi@0 | 407 | */ |
aoqi@0 | 408 | @Override |
aoqi@0 | 409 | public boolean validOptions(String options[][], |
aoqi@0 | 410 | DocErrorReporter reporter) { |
aoqi@0 | 411 | boolean helpfile = false; |
aoqi@0 | 412 | boolean nohelp = false; |
aoqi@0 | 413 | boolean overview = false; |
aoqi@0 | 414 | boolean nooverview = false; |
aoqi@0 | 415 | boolean splitindex = false; |
aoqi@0 | 416 | boolean noindex = false; |
aoqi@0 | 417 | // check shared options |
aoqi@0 | 418 | if (!generalValidOptions(options, reporter)) { |
aoqi@0 | 419 | return false; |
aoqi@0 | 420 | } |
aoqi@0 | 421 | // otherwise look at our options |
aoqi@0 | 422 | for (int oi = 0; oi < options.length; ++oi) { |
aoqi@0 | 423 | String[] os = options[oi]; |
aoqi@0 | 424 | String opt = StringUtils.toLowerCase(os[0]); |
aoqi@0 | 425 | if (opt.equals("-helpfile")) { |
aoqi@0 | 426 | if (nohelp == true) { |
aoqi@0 | 427 | reporter.printError(getText("doclet.Option_conflict", |
aoqi@0 | 428 | "-helpfile", "-nohelp")); |
aoqi@0 | 429 | return false; |
aoqi@0 | 430 | } |
aoqi@0 | 431 | if (helpfile == true) { |
aoqi@0 | 432 | reporter.printError(getText("doclet.Option_reuse", |
aoqi@0 | 433 | "-helpfile")); |
aoqi@0 | 434 | return false; |
aoqi@0 | 435 | } |
aoqi@0 | 436 | DocFile help = DocFile.createFileForInput(this, os[1]); |
aoqi@0 | 437 | if (!help.exists()) { |
aoqi@0 | 438 | reporter.printError(getText("doclet.File_not_found", os[1])); |
aoqi@0 | 439 | return false; |
aoqi@0 | 440 | } |
aoqi@0 | 441 | helpfile = true; |
aoqi@0 | 442 | } else if (opt.equals("-nohelp")) { |
aoqi@0 | 443 | if (helpfile == true) { |
aoqi@0 | 444 | reporter.printError(getText("doclet.Option_conflict", |
aoqi@0 | 445 | "-nohelp", "-helpfile")); |
aoqi@0 | 446 | return false; |
aoqi@0 | 447 | } |
aoqi@0 | 448 | nohelp = true; |
aoqi@0 | 449 | } else if (opt.equals("-xdocrootparent")) { |
aoqi@0 | 450 | try { |
aoqi@0 | 451 | new URL(os[1]); |
aoqi@0 | 452 | } catch (MalformedURLException e) { |
aoqi@0 | 453 | reporter.printError(getText("doclet.MalformedURL", os[1])); |
aoqi@0 | 454 | return false; |
aoqi@0 | 455 | } |
aoqi@0 | 456 | } else if (opt.equals("-overview")) { |
aoqi@0 | 457 | if (nooverview == true) { |
aoqi@0 | 458 | reporter.printError(getText("doclet.Option_conflict", |
aoqi@0 | 459 | "-overview", "-nooverview")); |
aoqi@0 | 460 | return false; |
aoqi@0 | 461 | } |
aoqi@0 | 462 | if (overview == true) { |
aoqi@0 | 463 | reporter.printError(getText("doclet.Option_reuse", |
aoqi@0 | 464 | "-overview")); |
aoqi@0 | 465 | return false; |
aoqi@0 | 466 | } |
aoqi@0 | 467 | overview = true; |
aoqi@0 | 468 | } else if (opt.equals("-nooverview")) { |
aoqi@0 | 469 | if (overview == true) { |
aoqi@0 | 470 | reporter.printError(getText("doclet.Option_conflict", |
aoqi@0 | 471 | "-nooverview", "-overview")); |
aoqi@0 | 472 | return false; |
aoqi@0 | 473 | } |
aoqi@0 | 474 | nooverview = true; |
aoqi@0 | 475 | } else if (opt.equals("-splitindex")) { |
aoqi@0 | 476 | if (noindex == true) { |
aoqi@0 | 477 | reporter.printError(getText("doclet.Option_conflict", |
aoqi@0 | 478 | "-splitindex", "-noindex")); |
aoqi@0 | 479 | return false; |
aoqi@0 | 480 | } |
aoqi@0 | 481 | splitindex = true; |
aoqi@0 | 482 | } else if (opt.equals("-noindex")) { |
aoqi@0 | 483 | if (splitindex == true) { |
aoqi@0 | 484 | reporter.printError(getText("doclet.Option_conflict", |
aoqi@0 | 485 | "-noindex", "-splitindex")); |
aoqi@0 | 486 | return false; |
aoqi@0 | 487 | } |
aoqi@0 | 488 | noindex = true; |
aoqi@0 | 489 | } else if (opt.startsWith("-xdoclint:")) { |
aoqi@0 | 490 | if (opt.contains("/")) { |
aoqi@0 | 491 | reporter.printError(getText("doclet.Option_doclint_no_qualifiers")); |
aoqi@0 | 492 | return false; |
aoqi@0 | 493 | } |
aoqi@0 | 494 | if (!DocLint.isValidOption( |
aoqi@0 | 495 | opt.replace("-xdoclint:", DocLint.XMSGS_CUSTOM_PREFIX))) { |
aoqi@0 | 496 | reporter.printError(getText("doclet.Option_doclint_invalid_arg")); |
aoqi@0 | 497 | return false; |
aoqi@0 | 498 | } |
aoqi@0 | 499 | } |
aoqi@0 | 500 | } |
aoqi@0 | 501 | return true; |
aoqi@0 | 502 | } |
aoqi@0 | 503 | |
aoqi@0 | 504 | /** |
aoqi@0 | 505 | * {@inheritDoc} |
aoqi@0 | 506 | */ |
aoqi@0 | 507 | @Override |
aoqi@0 | 508 | public MessageRetriever getDocletSpecificMsg() { |
aoqi@0 | 509 | return standardmessage; |
aoqi@0 | 510 | } |
aoqi@0 | 511 | |
aoqi@0 | 512 | /** |
aoqi@0 | 513 | * Decide the page which will appear first in the right-hand frame. It will |
aoqi@0 | 514 | * be "overview-summary.html" if "-overview" option is used or no |
aoqi@0 | 515 | * "-overview" but the number of packages is more than one. It will be |
aoqi@0 | 516 | * "package-summary.html" of the respective package if there is only one |
aoqi@0 | 517 | * package to document. It will be a class page(first in the sorted order), |
aoqi@0 | 518 | * if only classes are provided on the command line. |
aoqi@0 | 519 | * |
aoqi@0 | 520 | * @param root Root of the program structure. |
aoqi@0 | 521 | */ |
aoqi@0 | 522 | protected void setTopFile(RootDoc root) { |
aoqi@0 | 523 | if (!checkForDeprecation(root)) { |
aoqi@0 | 524 | return; |
aoqi@0 | 525 | } |
aoqi@0 | 526 | if (createoverview) { |
aoqi@0 | 527 | topFile = DocPaths.OVERVIEW_SUMMARY; |
aoqi@0 | 528 | } else { |
aoqi@0 | 529 | if (packages.length == 1 && packages[0].name().equals("")) { |
aoqi@0 | 530 | if (root.classes().length > 0) { |
aoqi@0 | 531 | ClassDoc[] classarr = root.classes(); |
aoqi@0 | 532 | Arrays.sort(classarr); |
aoqi@0 | 533 | ClassDoc cd = getValidClass(classarr); |
aoqi@0 | 534 | topFile = DocPath.forClass(cd); |
aoqi@0 | 535 | } |
aoqi@0 | 536 | } else { |
aoqi@0 | 537 | topFile = DocPath.forPackage(packages[0]).resolve(DocPaths.PACKAGE_SUMMARY); |
aoqi@0 | 538 | } |
aoqi@0 | 539 | } |
aoqi@0 | 540 | } |
aoqi@0 | 541 | |
aoqi@0 | 542 | protected ClassDoc getValidClass(ClassDoc[] classarr) { |
aoqi@0 | 543 | if (!nodeprecated) { |
aoqi@0 | 544 | return classarr[0]; |
aoqi@0 | 545 | } |
aoqi@0 | 546 | for (int i = 0; i < classarr.length; i++) { |
aoqi@0 | 547 | if (classarr[i].tags("deprecated").length == 0) { |
aoqi@0 | 548 | return classarr[i]; |
aoqi@0 | 549 | } |
aoqi@0 | 550 | } |
aoqi@0 | 551 | return null; |
aoqi@0 | 552 | } |
aoqi@0 | 553 | |
aoqi@0 | 554 | protected boolean checkForDeprecation(RootDoc root) { |
aoqi@0 | 555 | ClassDoc[] classarr = root.classes(); |
aoqi@0 | 556 | for (int i = 0; i < classarr.length; i++) { |
aoqi@0 | 557 | if (isGeneratedDoc(classarr[i])) { |
aoqi@0 | 558 | return true; |
aoqi@0 | 559 | } |
aoqi@0 | 560 | } |
aoqi@0 | 561 | return false; |
aoqi@0 | 562 | } |
aoqi@0 | 563 | |
aoqi@0 | 564 | /** |
aoqi@0 | 565 | * Generate "overview.html" page if option "-overview" is used or number of |
aoqi@0 | 566 | * packages is more than one. Sets {@link #createoverview} field to true. |
aoqi@0 | 567 | */ |
aoqi@0 | 568 | protected void setCreateOverview() { |
aoqi@0 | 569 | if ((overview || packages.length > 1) && !nooverview) { |
aoqi@0 | 570 | createoverview = true; |
aoqi@0 | 571 | } |
aoqi@0 | 572 | } |
aoqi@0 | 573 | |
aoqi@0 | 574 | /** |
aoqi@0 | 575 | * {@inheritDoc} |
aoqi@0 | 576 | */ |
aoqi@0 | 577 | @Override |
aoqi@0 | 578 | public WriterFactory getWriterFactory() { |
aoqi@0 | 579 | return new WriterFactoryImpl(this); |
aoqi@0 | 580 | } |
aoqi@0 | 581 | |
aoqi@0 | 582 | /** |
aoqi@0 | 583 | * {@inheritDoc} |
aoqi@0 | 584 | */ |
aoqi@0 | 585 | @Override |
aoqi@0 | 586 | public Comparator<ProgramElementDoc> getMemberComparator() { |
aoqi@0 | 587 | return null; |
aoqi@0 | 588 | } |
aoqi@0 | 589 | |
aoqi@0 | 590 | /** |
aoqi@0 | 591 | * {@inheritDoc} |
aoqi@0 | 592 | */ |
aoqi@0 | 593 | @Override |
aoqi@0 | 594 | public Locale getLocale() { |
aoqi@0 | 595 | if (root instanceof RootDocImpl) |
aoqi@0 | 596 | return ((RootDocImpl)root).getLocale(); |
aoqi@0 | 597 | else |
aoqi@0 | 598 | return Locale.getDefault(); |
aoqi@0 | 599 | } |
aoqi@0 | 600 | |
aoqi@0 | 601 | /** |
aoqi@0 | 602 | * {@inheritDoc} |
aoqi@0 | 603 | */ |
aoqi@0 | 604 | @Override |
aoqi@0 | 605 | public JavaFileManager getFileManager() { |
aoqi@0 | 606 | if (fileManager == null) { |
aoqi@0 | 607 | if (root instanceof RootDocImpl) |
aoqi@0 | 608 | fileManager = ((RootDocImpl) root).getFileManager(); |
aoqi@0 | 609 | else |
aoqi@0 | 610 | fileManager = new JavacFileManager(new Context(), false, null); |
aoqi@0 | 611 | } |
aoqi@0 | 612 | return fileManager; |
aoqi@0 | 613 | } |
aoqi@0 | 614 | |
aoqi@0 | 615 | private JavaFileManager fileManager; |
aoqi@0 | 616 | |
aoqi@0 | 617 | @Override |
aoqi@0 | 618 | public boolean showMessage(SourcePosition pos, String key) { |
aoqi@0 | 619 | if (root instanceof RootDocImpl) { |
aoqi@0 | 620 | return pos == null || ((RootDocImpl) root).showTagMessages(); |
aoqi@0 | 621 | } |
aoqi@0 | 622 | return true; |
aoqi@0 | 623 | } |
aoqi@0 | 624 | |
aoqi@0 | 625 | @Override |
aoqi@0 | 626 | public Content newContent() { |
aoqi@0 | 627 | return new ContentBuilder(); |
aoqi@0 | 628 | } |
aefimov@3315 | 629 | |
aefimov@3315 | 630 | /** |
aefimov@3315 | 631 | * Returns whether or not to allow JavaScript in comments. |
aefimov@3315 | 632 | * Default is off; can be set true from a command line option. |
aefimov@3315 | 633 | * @return the allowScriptInComments |
aefimov@3315 | 634 | */ |
aefimov@3315 | 635 | public boolean isAllowScriptInComments() { |
aefimov@3315 | 636 | return allowScriptInComments; |
aefimov@3315 | 637 | } |
aoqi@0 | 638 | } |