Thu, 04 Jul 2013 10:35:33 +0100
8009924: some langtools tools do not accept -cp as an alias for -classpath
Reviewed-by: jjg
jjg@1411 | 1 | /* |
vromero@1885 | 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
jjg@1411 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@1411 | 4 | * |
jjg@1411 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@1411 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@1411 | 7 | * published by the Free Software Foundation. Oracle designates this |
jjg@1411 | 8 | * particular file as subject to the "Classpath" exception as provided |
jjg@1411 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
jjg@1411 | 10 | * |
jjg@1411 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@1411 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@1411 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@1411 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@1411 | 15 | * accompanied this code). |
jjg@1411 | 16 | * |
jjg@1411 | 17 | * You should have received a copy of the GNU General Public License version |
jjg@1411 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@1411 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@1411 | 20 | * |
jjg@1411 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jjg@1411 | 22 | * or visit www.oracle.com if you need additional information or have any |
jjg@1411 | 23 | * questions. |
jjg@1411 | 24 | */ |
jjg@1411 | 25 | |
jjg@1411 | 26 | package com.sun.tools.javadoc; |
jjg@1411 | 27 | |
jjg@1411 | 28 | import com.sun.tools.javac.code.Flags; |
jjg@1411 | 29 | import com.sun.tools.javac.util.ListBuffer; |
jjg@1411 | 30 | import com.sun.tools.javac.util.Options; |
jjg@1411 | 31 | import java.util.StringTokenizer; |
jjg@1411 | 32 | |
jjg@1411 | 33 | |
jjg@1411 | 34 | /** |
jjg@1411 | 35 | * javadoc tool options. |
jjg@1411 | 36 | * |
jjg@1411 | 37 | * <p><b>This is NOT part of any supported API. |
jjg@1411 | 38 | * If you write code that depends on this, you do so at your own risk. |
jjg@1411 | 39 | * This code and its internal interfaces are subject to change or |
jjg@1411 | 40 | * deletion without notice.</b> |
jjg@1411 | 41 | */ |
jjg@1411 | 42 | public enum ToolOption { |
jjg@1411 | 43 | // ----- options for underlying compiler ----- |
jjg@1411 | 44 | |
jjg@1411 | 45 | BOOTCLASSPATH("-bootclasspath", true) { |
jjg@1411 | 46 | @Override |
jjg@1411 | 47 | public void process(Helper helper, String arg) { |
jjg@1411 | 48 | helper.setCompilerOpt(opt, arg); |
jjg@1411 | 49 | } |
jjg@1411 | 50 | }, |
jjg@1411 | 51 | |
jjg@1411 | 52 | CLASSPATH("-classpath", true) { |
jjg@1411 | 53 | @Override |
jjg@1411 | 54 | public void process(Helper helper, String arg) { |
jjg@1411 | 55 | helper.setCompilerOpt(opt, arg); |
jjg@1411 | 56 | } |
jjg@1411 | 57 | }, |
jjg@1411 | 58 | |
vromero@1885 | 59 | CP("-cp", true) { |
vromero@1885 | 60 | @Override |
vromero@1885 | 61 | public void process(Helper helper, String arg) { |
vromero@1885 | 62 | helper.setCompilerOpt(opt, arg); |
vromero@1885 | 63 | } |
vromero@1885 | 64 | }, |
vromero@1885 | 65 | |
jjg@1411 | 66 | EXTDIRS("-extdirs", true) { |
jjg@1411 | 67 | @Override |
jjg@1411 | 68 | public void process(Helper helper, String arg) { |
jjg@1411 | 69 | helper.setCompilerOpt(opt, arg); |
jjg@1411 | 70 | } |
jjg@1411 | 71 | }, |
jjg@1411 | 72 | |
jjg@1411 | 73 | SOURCEPATH("-sourcepath", true) { |
jjg@1411 | 74 | @Override |
jjg@1411 | 75 | public void process(Helper helper, String arg) { |
jjg@1411 | 76 | helper.setCompilerOpt(opt, arg); |
jjg@1411 | 77 | } |
jjg@1411 | 78 | }, |
jjg@1411 | 79 | |
jjg@1411 | 80 | SYSCLASSPATH("-sysclasspath", true) { |
jjg@1411 | 81 | @Override |
jjg@1411 | 82 | public void process(Helper helper, String arg) { |
jjg@1411 | 83 | helper.setCompilerOpt("-bootclasspath", arg); |
jjg@1411 | 84 | } |
jjg@1411 | 85 | }, |
jjg@1411 | 86 | |
jjg@1411 | 87 | ENCODING("-encoding", true) { |
jjg@1411 | 88 | @Override |
jjg@1411 | 89 | public void process(Helper helper, String arg) { |
jjg@1411 | 90 | helper.encoding = arg; |
jjg@1411 | 91 | helper.setCompilerOpt(opt, arg); |
jjg@1411 | 92 | } |
jjg@1411 | 93 | }, |
jjg@1411 | 94 | |
jjg@1411 | 95 | SOURCE("-source", true) { |
jjg@1411 | 96 | @Override |
jjg@1411 | 97 | public void process(Helper helper, String arg) { |
jjg@1411 | 98 | helper.setCompilerOpt(opt, arg); |
jjg@1411 | 99 | } |
jjg@1411 | 100 | }, |
jjg@1411 | 101 | |
jjg@1411 | 102 | XMAXERRS("-Xmaxerrs", true) { |
jjg@1411 | 103 | @Override |
jjg@1411 | 104 | public void process(Helper helper, String arg) { |
jjg@1411 | 105 | helper.setCompilerOpt(opt, arg); |
jjg@1411 | 106 | } |
jjg@1411 | 107 | }, |
jjg@1411 | 108 | |
jjg@1411 | 109 | XMAXWARNS("-Xmaxwarns", true) { |
jjg@1411 | 110 | @Override |
jjg@1411 | 111 | public void process(Helper helper, String arg) { |
jjg@1411 | 112 | helper.setCompilerOpt(opt, arg); |
jjg@1411 | 113 | } |
jjg@1411 | 114 | }, |
jjg@1411 | 115 | |
jjg@1411 | 116 | // ----- doclet options ----- |
jjg@1411 | 117 | |
jjg@1411 | 118 | DOCLET("-doclet", true), // handled in setDocletInvoker |
jjg@1411 | 119 | |
jjg@1411 | 120 | DOCLETPATH("-docletpath", true), // handled in setDocletInvoker |
jjg@1411 | 121 | |
jjg@1411 | 122 | // ----- selection options ----- |
jjg@1411 | 123 | |
jjg@1411 | 124 | SUBPACKAGES("-subpackages", true) { |
jjg@1411 | 125 | @Override |
jjg@1411 | 126 | public void process(Helper helper, String arg) { |
jjg@1411 | 127 | helper.addToList(helper.subPackages, arg); |
jjg@1411 | 128 | } |
jjg@1411 | 129 | }, |
jjg@1411 | 130 | |
jjg@1411 | 131 | EXCLUDE("-exclude", true) { |
jjg@1411 | 132 | @Override |
jjg@1411 | 133 | public void process(Helper helper, String arg) { |
jjg@1411 | 134 | helper.addToList(helper.excludedPackages, arg); |
jjg@1411 | 135 | } |
jjg@1411 | 136 | }, |
jjg@1411 | 137 | |
jjg@1411 | 138 | // ----- filtering options ----- |
jjg@1411 | 139 | |
jjg@1411 | 140 | PACKAGE("-package") { |
jjg@1411 | 141 | @Override |
jjg@1411 | 142 | public void process(Helper helper) { |
jjg@1411 | 143 | helper.setFilter( |
jjg@1411 | 144 | Flags.PUBLIC | Flags.PROTECTED | ModifierFilter.PACKAGE); |
jjg@1411 | 145 | } |
jjg@1411 | 146 | }, |
jjg@1411 | 147 | |
jjg@1411 | 148 | PRIVATE("-private") { |
jjg@1411 | 149 | @Override |
jjg@1411 | 150 | public void process(Helper helper) { |
jjg@1411 | 151 | helper.setFilter(ModifierFilter.ALL_ACCESS); |
jjg@1411 | 152 | } |
jjg@1411 | 153 | }, |
jjg@1411 | 154 | |
jjg@1411 | 155 | PROTECTED("-protected") { |
jjg@1411 | 156 | @Override |
jjg@1411 | 157 | public void process(Helper helper) { |
jjg@1411 | 158 | helper.setFilter(Flags.PUBLIC | Flags.PROTECTED); |
jjg@1411 | 159 | } |
jjg@1411 | 160 | }, |
jjg@1411 | 161 | |
jjg@1411 | 162 | PUBLIC("-public") { |
jjg@1411 | 163 | @Override |
jjg@1411 | 164 | public void process(Helper helper) { |
jjg@1411 | 165 | helper.setFilter(Flags.PUBLIC); |
jjg@1411 | 166 | } |
jjg@1411 | 167 | }, |
jjg@1411 | 168 | |
jjg@1411 | 169 | // ----- output control options ----- |
jjg@1411 | 170 | |
jjg@1411 | 171 | PROMPT("-prompt") { |
jjg@1411 | 172 | @Override |
jjg@1411 | 173 | public void process(Helper helper) { |
jjg@1411 | 174 | helper.compOpts.put("-prompt", "-prompt"); |
jjg@1411 | 175 | helper.promptOnError = true; |
jjg@1411 | 176 | } |
jjg@1411 | 177 | }, |
jjg@1411 | 178 | |
jjg@1411 | 179 | QUIET("-quiet") { |
jjg@1411 | 180 | @Override |
jjg@1411 | 181 | public void process(Helper helper) { |
jjg@1411 | 182 | helper.quiet = true; |
jjg@1411 | 183 | } |
jjg@1411 | 184 | }, |
jjg@1411 | 185 | |
jjg@1411 | 186 | VERBOSE("-verbose") { |
jjg@1411 | 187 | @Override |
jjg@1411 | 188 | public void process(Helper helper) { |
jjg@1411 | 189 | helper.compOpts.put("-verbose", ""); |
jjg@1411 | 190 | } |
jjg@1411 | 191 | }, |
jjg@1411 | 192 | |
jjg@1411 | 193 | XWERROR("-Xwerror") { |
jjg@1411 | 194 | @Override |
jjg@1411 | 195 | public void process(Helper helper) { |
jjg@1411 | 196 | helper.rejectWarnings = true; |
jjg@1411 | 197 | |
jjg@1411 | 198 | } |
jjg@1411 | 199 | }, |
jjg@1411 | 200 | |
jjg@1411 | 201 | // ----- other options ----- |
jjg@1411 | 202 | |
jjg@1411 | 203 | BREAKITERATOR("-breakiterator") { |
jjg@1411 | 204 | @Override |
jjg@1411 | 205 | public void process(Helper helper) { |
jjg@1411 | 206 | helper.breakiterator = true; |
jjg@1411 | 207 | } |
jjg@1411 | 208 | }, |
jjg@1411 | 209 | |
jjg@1411 | 210 | LOCALE("-locale", true) { |
jjg@1411 | 211 | @Override |
jjg@1411 | 212 | public void process(Helper helper, String arg) { |
jjg@1411 | 213 | helper.docLocale = arg; |
jjg@1411 | 214 | } |
jjg@1411 | 215 | }, |
jjg@1411 | 216 | |
jjg@1411 | 217 | OVERVIEW("-overview", true), |
jjg@1411 | 218 | |
jjg@1411 | 219 | XCLASSES("-Xclasses") { |
jjg@1411 | 220 | @Override |
jjg@1411 | 221 | public void process(Helper helper) { |
jjg@1411 | 222 | helper.docClasses = true; |
jjg@1411 | 223 | |
jjg@1411 | 224 | } |
jjg@1411 | 225 | }, |
jjg@1411 | 226 | |
jjg@1411 | 227 | // ----- help options ----- |
jjg@1411 | 228 | |
jjg@1411 | 229 | HELP("-help") { |
jjg@1411 | 230 | @Override |
jjg@1411 | 231 | public void process(Helper helper) { |
jjg@1411 | 232 | helper.usage(); |
jjg@1411 | 233 | } |
jjg@1411 | 234 | }, |
jjg@1411 | 235 | |
jjg@1411 | 236 | X("-X") { |
jjg@1411 | 237 | @Override |
jjg@1411 | 238 | public void process(Helper helper) { |
jjg@1411 | 239 | helper.Xusage(); |
jjg@1411 | 240 | } |
jjg@1411 | 241 | }; |
jjg@1411 | 242 | |
jjg@1411 | 243 | public final String opt; |
jjg@1411 | 244 | public final boolean hasArg; |
jjg@1411 | 245 | |
jjg@1411 | 246 | ToolOption(String opt) { |
jjg@1411 | 247 | this(opt, false); |
jjg@1411 | 248 | } |
jjg@1411 | 249 | |
jjg@1411 | 250 | ToolOption(String opt, boolean hasArg) { |
jjg@1411 | 251 | this.opt = opt; |
jjg@1411 | 252 | this.hasArg = hasArg; |
jjg@1411 | 253 | } |
jjg@1411 | 254 | |
jjg@1411 | 255 | void process(Helper helper, String arg) { } |
jjg@1411 | 256 | |
jjg@1411 | 257 | void process(Helper helper) { } |
jjg@1411 | 258 | |
jjg@1411 | 259 | static ToolOption get(String name) { |
jjg@1411 | 260 | for (ToolOption o: values()) { |
jjg@1411 | 261 | if (name.equals(o.opt)) |
jjg@1411 | 262 | return o; |
jjg@1411 | 263 | } |
jjg@1411 | 264 | return null; |
jjg@1411 | 265 | } |
jjg@1411 | 266 | |
jjg@1411 | 267 | static abstract class Helper { |
jjg@1411 | 268 | /** List of decoded options. */ |
jjg@1411 | 269 | final ListBuffer<String[]> options = new ListBuffer<String[]>(); |
jjg@1411 | 270 | |
jjg@1411 | 271 | /** Selected packages, from -subpackages. */ |
jjg@1411 | 272 | final ListBuffer<String> subPackages = new ListBuffer<String>(); |
jjg@1411 | 273 | |
jjg@1411 | 274 | /** Excluded packages, from -exclude. */ |
jjg@1411 | 275 | final ListBuffer<String> excludedPackages = new ListBuffer<String>(); |
jjg@1411 | 276 | |
jjg@1411 | 277 | /** javac options, set by various options. */ |
jjg@1411 | 278 | Options compOpts; // = Options.instance(context) |
jjg@1411 | 279 | |
jjg@1411 | 280 | /* Encoding for javac, and files written? set by -encoding. */ |
jjg@1411 | 281 | String encoding = null; |
jjg@1411 | 282 | |
jjg@1411 | 283 | /** Set by -breakiterator. */ |
jjg@1411 | 284 | boolean breakiterator = false; |
jjg@1411 | 285 | |
jjg@1411 | 286 | /** Set by -quiet. */ |
jjg@1411 | 287 | boolean quiet = false; |
jjg@1411 | 288 | |
jjg@1411 | 289 | /** Set by -Xclasses. */ |
jjg@1411 | 290 | boolean docClasses = false; |
jjg@1411 | 291 | |
jjg@1411 | 292 | /** Set by -Xwerror. */ |
jjg@1411 | 293 | boolean rejectWarnings = false; |
jjg@1411 | 294 | |
jjg@1411 | 295 | /** Set by -prompt. */ |
jjg@1411 | 296 | boolean promptOnError; |
jjg@1411 | 297 | |
jjg@1411 | 298 | /** Set by -locale. */ |
jjg@1411 | 299 | String docLocale = ""; |
jjg@1411 | 300 | |
jjg@1411 | 301 | /** Set by -public, private, -protected, -package. */ |
jjg@1411 | 302 | ModifierFilter showAccess = null; |
jjg@1411 | 303 | |
jjg@1411 | 304 | abstract void usage(); |
jjg@1411 | 305 | abstract void Xusage(); |
jjg@1411 | 306 | |
jjg@1411 | 307 | abstract void usageError(String msg, Object... args); |
jjg@1411 | 308 | |
jjg@1411 | 309 | protected void addToList(ListBuffer<String> list, String str){ |
jjg@1411 | 310 | StringTokenizer st = new StringTokenizer(str, ":"); |
jjg@1411 | 311 | String current; |
jjg@1411 | 312 | while(st.hasMoreTokens()){ |
jjg@1411 | 313 | current = st.nextToken(); |
jjg@1411 | 314 | list.append(current); |
jjg@1411 | 315 | } |
jjg@1411 | 316 | } |
jjg@1411 | 317 | |
jjg@1411 | 318 | protected void setFilter(long filterBits) { |
jjg@1411 | 319 | if (showAccess != null) { |
jjg@1411 | 320 | usageError("main.incompatible.access.flags"); |
jjg@1411 | 321 | } |
jjg@1411 | 322 | showAccess = new ModifierFilter(filterBits); |
jjg@1411 | 323 | } |
jjg@1411 | 324 | |
jjg@1411 | 325 | private void setCompilerOpt(String opt, String arg) { |
jjg@1411 | 326 | if (compOpts.get(opt) != null) { |
jjg@1411 | 327 | usageError("main.option.already.seen", opt); |
jjg@1411 | 328 | } |
jjg@1411 | 329 | compOpts.put(opt, arg); |
jjg@1411 | 330 | } |
jjg@1411 | 331 | } |
jjg@1411 | 332 | } |