src/share/classes/com/sun/tools/jdeps/JdepsTask.java

Fri, 18 Jul 2014 10:43:41 -0700

author
mchung
date
Fri, 18 Jul 2014 10:43:41 -0700
changeset 2539
a51b7fd0543b
parent 2538
1e39ae45d8ac
child 2702
9ca8d8713094
child 2802
6b43535fb9f8
permissions
-rw-r--r--

8050804: (jdeps) Recommend supported API to replace use of JDK internal API
Reviewed-by: dfuchs

mchung@1472 1 /*
mchung@2538 2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
mchung@1472 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
mchung@1472 4 *
mchung@1472 5 * This code is free software; you can redistribute it and/or modify it
mchung@1472 6 * under the terms of the GNU General Public License version 2 only, as
mchung@1472 7 * published by the Free Software Foundation. Oracle designates this
mchung@1472 8 * particular file as subject to the "Classpath" exception as provided
mchung@1472 9 * by Oracle in the LICENSE file that accompanied this code.
mchung@1472 10 *
mchung@1472 11 * This code is distributed in the hope that it will be useful, but WITHOUT
mchung@1472 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
mchung@1472 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
mchung@1472 14 * version 2 for more details (a copy is included in the LICENSE file that
mchung@1472 15 * accompanied this code).
mchung@1472 16 *
mchung@1472 17 * You should have received a copy of the GNU General Public License version
mchung@1472 18 * 2 along with this work; if not, write to the Free Software Foundation,
mchung@1472 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
mchung@1472 20 *
mchung@1472 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
mchung@1472 22 * or visit www.oracle.com if you need additional information or have any
mchung@1472 23 * questions.
mchung@1472 24 */
mchung@1472 25 package com.sun.tools.jdeps;
mchung@1472 26
mchung@2139 27 import com.sun.tools.classfile.AccessFlags;
mchung@1472 28 import com.sun.tools.classfile.ClassFile;
mchung@1472 29 import com.sun.tools.classfile.ConstantPoolException;
mchung@1472 30 import com.sun.tools.classfile.Dependencies;
mchung@1472 31 import com.sun.tools.classfile.Dependencies.ClassFileError;
mchung@1472 32 import com.sun.tools.classfile.Dependency;
mchung@2538 33 import com.sun.tools.classfile.Dependency.Location;
mchung@2139 34 import com.sun.tools.jdeps.PlatformClassPath.JDKArchive;
mchung@2538 35 import static com.sun.tools.jdeps.Analyzer.Type.*;
mchung@1472 36 import java.io.*;
mchung@2139 37 import java.nio.file.DirectoryStream;
mchung@2139 38 import java.nio.file.Files;
mchung@2139 39 import java.nio.file.Path;
mchung@2139 40 import java.nio.file.Paths;
mchung@1472 41 import java.text.MessageFormat;
mchung@1472 42 import java.util.*;
mchung@1472 43 import java.util.regex.Pattern;
mchung@1472 44
mchung@1472 45 /**
mchung@1472 46 * Implementation for the jdeps tool for static class dependency analysis.
mchung@1472 47 */
mchung@1472 48 class JdepsTask {
jjg@1648 49 static class BadArgs extends Exception {
mchung@1472 50 static final long serialVersionUID = 8765093759964640721L;
mchung@1472 51 BadArgs(String key, Object... args) {
mchung@1577 52 super(JdepsTask.getMessage(key, args));
mchung@1472 53 this.key = key;
mchung@1472 54 this.args = args;
mchung@1472 55 }
mchung@1472 56
mchung@1472 57 BadArgs showUsage(boolean b) {
mchung@1472 58 showUsage = b;
mchung@1472 59 return this;
mchung@1472 60 }
mchung@1472 61 final String key;
mchung@1472 62 final Object[] args;
mchung@1472 63 boolean showUsage;
mchung@1472 64 }
mchung@1472 65
mchung@1472 66 static abstract class Option {
mchung@1472 67 Option(boolean hasArg, String... aliases) {
mchung@1472 68 this.hasArg = hasArg;
mchung@1472 69 this.aliases = aliases;
mchung@1472 70 }
mchung@1472 71
mchung@1472 72 boolean isHidden() {
mchung@1472 73 return false;
mchung@1472 74 }
mchung@1472 75
mchung@1472 76 boolean matches(String opt) {
mchung@1472 77 for (String a : aliases) {
mchung@2139 78 if (a.equals(opt))
mchung@1472 79 return true;
mchung@2139 80 if (hasArg && opt.startsWith(a + "="))
mchung@1472 81 return true;
mchung@1472 82 }
mchung@1472 83 return false;
mchung@1472 84 }
mchung@1472 85
mchung@1472 86 boolean ignoreRest() {
mchung@1472 87 return false;
mchung@1472 88 }
mchung@1472 89
mchung@1472 90 abstract void process(JdepsTask task, String opt, String arg) throws BadArgs;
mchung@1472 91 final boolean hasArg;
mchung@1472 92 final String[] aliases;
mchung@1472 93 }
mchung@1472 94
mchung@1472 95 static abstract class HiddenOption extends Option {
mchung@1472 96 HiddenOption(boolean hasArg, String... aliases) {
mchung@1472 97 super(hasArg, aliases);
mchung@1472 98 }
mchung@1472 99
mchung@1472 100 boolean isHidden() {
mchung@1472 101 return true;
mchung@1472 102 }
mchung@1472 103 }
mchung@1472 104
mchung@1472 105 static Option[] recognizedOptions = {
mchung@2139 106 new Option(false, "-h", "-?", "-help") {
mchung@1472 107 void process(JdepsTask task, String opt, String arg) {
mchung@1472 108 task.options.help = true;
mchung@1472 109 }
mchung@1472 110 },
mchung@2139 111 new Option(true, "-dotoutput") {
mchung@2139 112 void process(JdepsTask task, String opt, String arg) throws BadArgs {
mchung@2139 113 Path p = Paths.get(arg);
mchung@2139 114 if (Files.exists(p) && (!Files.isDirectory(p) || !Files.isWritable(p))) {
mchung@2538 115 throw new BadArgs("err.invalid.path", arg);
mchung@2139 116 }
mchung@2139 117 task.options.dotOutputDir = arg;
mchung@2139 118 }
mchung@2139 119 },
mchung@2139 120 new Option(false, "-s", "-summary") {
mchung@1472 121 void process(JdepsTask task, String opt, String arg) {
mchung@1472 122 task.options.showSummary = true;
mchung@2538 123 task.options.verbose = SUMMARY;
mchung@1472 124 }
mchung@1472 125 },
mchung@2139 126 new Option(false, "-v", "-verbose",
mchung@2139 127 "-verbose:package",
mchung@2538 128 "-verbose:class") {
mchung@1472 129 void process(JdepsTask task, String opt, String arg) throws BadArgs {
mchung@2139 130 switch (opt) {
mchung@2139 131 case "-v":
mchung@2139 132 case "-verbose":
mchung@2538 133 task.options.verbose = VERBOSE;
mchung@2538 134 task.options.filterSameArchive = false;
mchung@2538 135 task.options.filterSamePackage = false;
mchung@2139 136 break;
mchung@2139 137 case "-verbose:package":
mchung@2538 138 task.options.verbose = PACKAGE;
mchung@2538 139 break;
mchung@2139 140 case "-verbose:class":
mchung@2538 141 task.options.verbose = CLASS;
mchung@2538 142 break;
mchung@2139 143 default:
mchung@2139 144 throw new BadArgs("err.invalid.arg.for.option", opt);
mchung@1472 145 }
mchung@1472 146 }
mchung@1472 147 },
mchung@2139 148 new Option(true, "-cp", "-classpath") {
mchung@1472 149 void process(JdepsTask task, String opt, String arg) {
mchung@1472 150 task.options.classpath = arg;
mchung@1472 151 }
mchung@1472 152 },
mchung@2139 153 new Option(true, "-p", "-package") {
mchung@1472 154 void process(JdepsTask task, String opt, String arg) {
mchung@1472 155 task.options.packageNames.add(arg);
mchung@1472 156 }
mchung@1472 157 },
mchung@2139 158 new Option(true, "-e", "-regex") {
mchung@1472 159 void process(JdepsTask task, String opt, String arg) {
mchung@1472 160 task.options.regex = arg;
mchung@1472 161 }
mchung@1472 162 },
mchung@2538 163
mchung@2538 164 new Option(true, "-f", "-filter") {
mchung@2538 165 void process(JdepsTask task, String opt, String arg) {
mchung@2538 166 task.options.filterRegex = arg;
mchung@2538 167 }
mchung@2538 168 },
mchung@2538 169 new Option(false, "-filter:package",
mchung@2538 170 "-filter:archive",
mchung@2538 171 "-filter:none") {
mchung@2538 172 void process(JdepsTask task, String opt, String arg) {
mchung@2538 173 switch (opt) {
mchung@2538 174 case "-filter:package":
mchung@2538 175 task.options.filterSamePackage = true;
mchung@2538 176 task.options.filterSameArchive = false;
mchung@2538 177 break;
mchung@2538 178 case "-filter:archive":
mchung@2538 179 task.options.filterSameArchive = true;
mchung@2538 180 task.options.filterSamePackage = false;
mchung@2538 181 break;
mchung@2538 182 case "-filter:none":
mchung@2538 183 task.options.filterSameArchive = false;
mchung@2538 184 task.options.filterSamePackage = false;
mchung@2538 185 break;
mchung@2538 186 }
mchung@2538 187 }
mchung@2538 188 },
mchung@2139 189 new Option(true, "-include") {
mchung@2139 190 void process(JdepsTask task, String opt, String arg) throws BadArgs {
mchung@2139 191 task.options.includePattern = Pattern.compile(arg);
mchung@2139 192 }
mchung@2139 193 },
mchung@2139 194 new Option(false, "-P", "-profile") {
mchung@1638 195 void process(JdepsTask task, String opt, String arg) throws BadArgs {
mchung@1472 196 task.options.showProfile = true;
mchung@2139 197 if (Profile.getProfileCount() == 0) {
jjg@1648 198 throw new BadArgs("err.option.unsupported", opt, getMessage("err.profiles.msg"));
mchung@1638 199 }
mchung@1472 200 }
mchung@1472 201 },
mchung@2139 202 new Option(false, "-apionly") {
mchung@2139 203 void process(JdepsTask task, String opt, String arg) {
mchung@2139 204 task.options.apiOnly = true;
mchung@2139 205 }
mchung@2139 206 },
mchung@2139 207 new Option(false, "-R", "-recursive") {
mchung@1472 208 void process(JdepsTask task, String opt, String arg) {
mchung@1472 209 task.options.depth = 0;
mchung@2538 210 // turn off filtering
mchung@2538 211 task.options.filterSameArchive = false;
mchung@2538 212 task.options.filterSamePackage = false;
mchung@1472 213 }
mchung@1472 214 },
mchung@2214 215 new Option(false, "-jdkinternals") {
mchung@2214 216 void process(JdepsTask task, String opt, String arg) {
mchung@2214 217 task.options.findJDKInternals = true;
mchung@2538 218 task.options.verbose = CLASS;
mchung@2214 219 if (task.options.includePattern == null) {
mchung@2214 220 task.options.includePattern = Pattern.compile(".*");
mchung@2214 221 }
mchung@2214 222 }
mchung@2214 223 },
mchung@2139 224 new Option(false, "-version") {
mchung@2139 225 void process(JdepsTask task, String opt, String arg) {
mchung@2139 226 task.options.version = true;
mchung@2139 227 }
mchung@2139 228 },
mchung@2139 229 new HiddenOption(false, "-fullversion") {
mchung@2139 230 void process(JdepsTask task, String opt, String arg) {
mchung@2139 231 task.options.fullVersion = true;
mchung@2139 232 }
mchung@2139 233 },
mchung@2172 234 new HiddenOption(false, "-showlabel") {
mchung@2172 235 void process(JdepsTask task, String opt, String arg) {
mchung@2172 236 task.options.showLabel = true;
mchung@2172 237 }
mchung@2172 238 },
mchung@2539 239 new HiddenOption(false, "-q", "-quiet") {
mchung@2539 240 void process(JdepsTask task, String opt, String arg) {
mchung@2539 241 task.options.nowarning = true;
mchung@2539 242 }
mchung@2539 243 },
mchung@2139 244 new HiddenOption(true, "-depth") {
mchung@1472 245 void process(JdepsTask task, String opt, String arg) throws BadArgs {
mchung@1472 246 try {
mchung@1472 247 task.options.depth = Integer.parseInt(arg);
mchung@1472 248 } catch (NumberFormatException e) {
jjg@1648 249 throw new BadArgs("err.invalid.arg.for.option", opt);
mchung@1472 250 }
mchung@1472 251 }
mchung@1472 252 },
mchung@1472 253 };
mchung@1472 254
mchung@1472 255 private static final String PROGNAME = "jdeps";
mchung@1472 256 private final Options options = new Options();
mchung@2539 257 private final List<String> classes = new ArrayList<>();
mchung@1472 258
mchung@1472 259 private PrintWriter log;
mchung@1472 260 void setLog(PrintWriter out) {
mchung@1472 261 log = out;
mchung@1472 262 }
mchung@1472 263
mchung@1472 264 /**
mchung@1472 265 * Result codes.
mchung@1472 266 */
mchung@1472 267 static final int EXIT_OK = 0, // Completed with no errors.
mchung@1472 268 EXIT_ERROR = 1, // Completed but reported errors.
mchung@1472 269 EXIT_CMDERR = 2, // Bad command-line arguments
mchung@1472 270 EXIT_SYSERR = 3, // System error or resource exhaustion.
mchung@1472 271 EXIT_ABNORMAL = 4;// terminated abnormally
mchung@1472 272
mchung@1472 273 int run(String[] args) {
mchung@1472 274 if (log == null) {
mchung@1472 275 log = new PrintWriter(System.out);
mchung@1472 276 }
mchung@1472 277 try {
mchung@1472 278 handleOptions(args);
mchung@1472 279 if (options.help) {
mchung@1472 280 showHelp();
mchung@1472 281 }
mchung@1472 282 if (options.version || options.fullVersion) {
mchung@1472 283 showVersion(options.fullVersion);
mchung@1472 284 }
mchung@2139 285 if (classes.isEmpty() && options.includePattern == null) {
mchung@1472 286 if (options.help || options.version || options.fullVersion) {
mchung@1472 287 return EXIT_OK;
mchung@1472 288 } else {
mchung@1472 289 showHelp();
mchung@1472 290 return EXIT_CMDERR;
mchung@1472 291 }
mchung@1472 292 }
mchung@1472 293 if (options.regex != null && options.packageNames.size() > 0) {
mchung@1472 294 showHelp();
mchung@1472 295 return EXIT_CMDERR;
mchung@1472 296 }
mchung@2214 297 if (options.findJDKInternals &&
mchung@2214 298 (options.regex != null || options.packageNames.size() > 0 || options.showSummary)) {
mchung@2214 299 showHelp();
mchung@2214 300 return EXIT_CMDERR;
mchung@2214 301 }
mchung@2538 302 if (options.showSummary && options.verbose != SUMMARY) {
mchung@1472 303 showHelp();
mchung@1472 304 return EXIT_CMDERR;
mchung@1472 305 }
mchung@1472 306 boolean ok = run();
mchung@1472 307 return ok ? EXIT_OK : EXIT_ERROR;
mchung@1472 308 } catch (BadArgs e) {
mchung@1472 309 reportError(e.key, e.args);
mchung@1472 310 if (e.showUsage) {
mchung@1472 311 log.println(getMessage("main.usage.summary", PROGNAME));
mchung@1472 312 }
mchung@1472 313 return EXIT_CMDERR;
mchung@1472 314 } catch (IOException e) {
mchung@1472 315 return EXIT_ABNORMAL;
mchung@1472 316 } finally {
mchung@1472 317 log.flush();
mchung@1472 318 }
mchung@1472 319 }
mchung@1472 320
mchung@2139 321 private final List<Archive> sourceLocations = new ArrayList<>();
mchung@1472 322 private boolean run() throws IOException {
mchung@2538 323 // parse classfiles and find all dependencies
mchung@1472 324 findDependencies();
mchung@2538 325
mchung@2538 326 Analyzer analyzer = new Analyzer(options.verbose, new Analyzer.Filter() {
mchung@2538 327 @Override
mchung@2539 328 public boolean accepts(Location origin, Archive originArchive,
mchung@2539 329 Location target, Archive targetArchive)
mchung@2539 330 {
mchung@2538 331 if (options.findJDKInternals) {
mchung@2538 332 // accepts target that is JDK class but not exported
mchung@2538 333 return isJDKArchive(targetArchive) &&
mchung@2538 334 !((JDKArchive) targetArchive).isExported(target.getClassName());
mchung@2538 335 } else if (options.filterSameArchive) {
mchung@2538 336 // accepts origin and target that from different archive
mchung@2538 337 return originArchive != targetArchive;
mchung@2538 338 }
mchung@2538 339 return true;
mchung@2538 340 }
mchung@2538 341 });
mchung@2538 342
mchung@2538 343 // analyze the dependencies
mchung@1577 344 analyzer.run(sourceLocations);
mchung@2538 345
mchung@2538 346 // output result
mchung@2139 347 if (options.dotOutputDir != null) {
mchung@2139 348 Path dir = Paths.get(options.dotOutputDir);
mchung@2139 349 Files.createDirectories(dir);
mchung@2139 350 generateDotFiles(dir, analyzer);
mchung@1577 351 } else {
mchung@2139 352 printRawOutput(log, analyzer);
mchung@1472 353 }
mchung@2539 354
mchung@2539 355 if (options.findJDKInternals && !options.nowarning) {
mchung@2539 356 showReplacements(analyzer);
mchung@2539 357 }
mchung@1472 358 return true;
mchung@1472 359 }
mchung@1472 360
mchung@2538 361 private void generateSummaryDotFile(Path dir, Analyzer analyzer) throws IOException {
mchung@2538 362 // If verbose mode (-v or -verbose option),
mchung@2538 363 // the summary.dot file shows package-level dependencies.
mchung@2538 364 Analyzer.Type summaryType =
mchung@2538 365 (options.verbose == PACKAGE || options.verbose == SUMMARY) ? SUMMARY : PACKAGE;
mchung@2139 366 Path summary = dir.resolve("summary.dot");
mchung@2538 367 try (PrintWriter sw = new PrintWriter(Files.newOutputStream(summary));
mchung@2538 368 SummaryDotFile dotfile = new SummaryDotFile(sw, summaryType)) {
mchung@2538 369 for (Archive archive : sourceLocations) {
mchung@2538 370 if (!archive.isEmpty()) {
mchung@2538 371 if (options.verbose == PACKAGE || options.verbose == SUMMARY) {
mchung@2538 372 if (options.showLabel) {
mchung@2538 373 // build labels listing package-level dependencies
mchung@2538 374 analyzer.visitDependences(archive, dotfile.labelBuilder(), PACKAGE);
mchung@2538 375 }
mchung@2538 376 }
mchung@2538 377 analyzer.visitDependences(archive, dotfile, summaryType);
mchung@2538 378 }
mchung@2139 379 }
mchung@2139 380 }
mchung@2538 381 }
mchung@2538 382
mchung@2538 383 private void generateDotFiles(Path dir, Analyzer analyzer) throws IOException {
mchung@2172 384 // output individual .dot file for each archive
mchung@2538 385 if (options.verbose != SUMMARY) {
mchung@2139 386 for (Archive archive : sourceLocations) {
mchung@2139 387 if (analyzer.hasDependences(archive)) {
mchung@2538 388 Path dotfile = dir.resolve(archive.getName() + ".dot");
mchung@2139 389 try (PrintWriter pw = new PrintWriter(Files.newOutputStream(dotfile));
mchung@2139 390 DotFileFormatter formatter = new DotFileFormatter(pw, archive)) {
mchung@2139 391 analyzer.visitDependences(archive, formatter);
mchung@2139 392 }
mchung@2139 393 }
mchung@2139 394 }
mchung@2139 395 }
mchung@2538 396 // generate summary dot file
mchung@2538 397 generateSummaryDotFile(dir, analyzer);
mchung@2139 398 }
mchung@2139 399
mchung@2139 400 private void printRawOutput(PrintWriter writer, Analyzer analyzer) {
mchung@2538 401 RawOutputFormatter depFormatter = new RawOutputFormatter(writer);
mchung@2538 402 RawSummaryFormatter summaryFormatter = new RawSummaryFormatter(writer);
mchung@2139 403 for (Archive archive : sourceLocations) {
mchung@2538 404 if (!archive.isEmpty()) {
mchung@2538 405 analyzer.visitDependences(archive, summaryFormatter, SUMMARY);
mchung@2538 406 if (analyzer.hasDependences(archive) && options.verbose != SUMMARY) {
mchung@2538 407 analyzer.visitDependences(archive, depFormatter);
mchung@2538 408 }
mchung@2139 409 }
mchung@2139 410 }
mchung@2139 411 }
mchung@2538 412
mchung@1472 413 private boolean isValidClassName(String name) {
mchung@1472 414 if (!Character.isJavaIdentifierStart(name.charAt(0))) {
mchung@1472 415 return false;
mchung@1472 416 }
mchung@1472 417 for (int i=1; i < name.length(); i++) {
mchung@1472 418 char c = name.charAt(i);
mchung@1472 419 if (c != '.' && !Character.isJavaIdentifierPart(c)) {
mchung@1472 420 return false;
mchung@1472 421 }
mchung@1472 422 }
mchung@1472 423 return true;
mchung@1472 424 }
mchung@1472 425
mchung@2538 426 /*
mchung@2538 427 * Dep Filter configured based on the input jdeps option
mchung@2538 428 * 1. -p and -regex to match target dependencies
mchung@2538 429 * 2. -filter:package to filter out same-package dependencies
mchung@2538 430 *
mchung@2538 431 * This filter is applied when jdeps parses the class files
mchung@2538 432 * and filtered dependencies are not stored in the Analyzer.
mchung@2538 433 *
mchung@2538 434 * -filter:archive is applied later in the Analyzer as the
mchung@2538 435 * containing archive of a target class may not be known until
mchung@2538 436 * the entire archive
mchung@2538 437 */
mchung@2538 438 class DependencyFilter implements Dependency.Filter {
mchung@2538 439 final Dependency.Filter filter;
mchung@2538 440 final Pattern filterPattern;
mchung@2538 441 DependencyFilter() {
mchung@2538 442 if (options.regex != null) {
mchung@2538 443 this.filter = Dependencies.getRegexFilter(Pattern.compile(options.regex));
mchung@2538 444 } else if (options.packageNames.size() > 0) {
mchung@2538 445 this.filter = Dependencies.getPackageFilter(options.packageNames, false);
mchung@2538 446 } else {
mchung@2538 447 this.filter = null;
mchung@2538 448 }
mchung@2538 449
mchung@2538 450 this.filterPattern =
mchung@2538 451 options.filterRegex != null ? Pattern.compile(options.filterRegex) : null;
mchung@2538 452 }
mchung@2538 453 @Override
mchung@2538 454 public boolean accepts(Dependency d) {
mchung@2538 455 if (d.getOrigin().equals(d.getTarget())) {
mchung@2538 456 return false;
mchung@2538 457 }
mchung@2538 458 String pn = d.getTarget().getPackageName();
mchung@2538 459 if (options.filterSamePackage && d.getOrigin().getPackageName().equals(pn)) {
mchung@2538 460 return false;
mchung@2538 461 }
mchung@2538 462
mchung@2538 463 if (filterPattern != null && filterPattern.matcher(pn).matches()) {
mchung@2538 464 return false;
mchung@2538 465 }
mchung@2538 466 return filter != null ? filter.accepts(d) : true;
mchung@1472 467 }
mchung@2139 468 }
mchung@1472 469
mchung@2538 470 /**
mchung@2538 471 * Tests if the given class matches the pattern given in the -include option
mchung@2538 472 * or if it's a public class if -apionly option is specified
mchung@2538 473 */
mchung@2139 474 private boolean matches(String classname, AccessFlags flags) {
mchung@2139 475 if (options.apiOnly && !flags.is(AccessFlags.ACC_PUBLIC)) {
mchung@2139 476 return false;
mchung@2139 477 } else if (options.includePattern != null) {
mchung@2139 478 return options.includePattern.matcher(classname.replace('/', '.')).matches();
mchung@2139 479 } else {
mchung@2139 480 return true;
mchung@2139 481 }
mchung@2139 482 }
mchung@2139 483
mchung@2139 484 private void findDependencies() throws IOException {
mchung@2139 485 Dependency.Finder finder =
mchung@2139 486 options.apiOnly ? Dependencies.getAPIFinder(AccessFlags.ACC_PROTECTED)
mchung@2139 487 : Dependencies.getClassDependencyFinder();
mchung@2538 488 Dependency.Filter filter = new DependencyFilter();
mchung@2139 489
mchung@2139 490 List<Archive> archives = new ArrayList<>();
mchung@2139 491 Deque<String> roots = new LinkedList<>();
mchung@1472 492 for (String s : classes) {
mchung@2139 493 Path p = Paths.get(s);
mchung@2139 494 if (Files.exists(p)) {
mchung@2538 495 archives.add(Archive.getInstance(p));
mchung@1472 496 } else {
mchung@1472 497 if (isValidClassName(s)) {
mchung@1472 498 roots.add(s);
mchung@1472 499 } else {
mchung@1472 500 warning("warn.invalid.arg", s);
mchung@1472 501 }
mchung@1472 502 }
mchung@1472 503 }
mchung@2172 504 sourceLocations.addAll(archives);
mchung@1472 505
mchung@2139 506 List<Archive> classpaths = new ArrayList<>(); // for class file lookup
mchung@2172 507 classpaths.addAll(getClassPathArchives(options.classpath));
mchung@2139 508 if (options.includePattern != null) {
mchung@2172 509 archives.addAll(classpaths);
mchung@1472 510 }
mchung@1472 511 classpaths.addAll(PlatformClassPath.getArchives());
mchung@1472 512
mchung@2172 513 // add all classpath archives to the source locations for reporting
mchung@1472 514 sourceLocations.addAll(classpaths);
mchung@1472 515
mchung@1472 516 // Work queue of names of classfiles to be searched.
mchung@1472 517 // Entries will be unique, and for classes that do not yet have
mchung@1472 518 // dependencies in the results map.
mchung@2139 519 Deque<String> deque = new LinkedList<>();
mchung@2139 520 Set<String> doneClasses = new HashSet<>();
mchung@1472 521
mchung@1472 522 // get the immediate dependencies of the input files
mchung@1472 523 for (Archive a : archives) {
mchung@1472 524 for (ClassFile cf : a.reader().getClassFiles()) {
mchung@1472 525 String classFileName;
mchung@1472 526 try {
mchung@1472 527 classFileName = cf.getName();
mchung@1472 528 } catch (ConstantPoolException e) {
mchung@1472 529 throw new ClassFileError(e);
mchung@1472 530 }
mchung@1577 531
mchung@2538 532 // tests if this class matches the -include or -apiOnly option if specified
mchung@2538 533 if (!matches(classFileName, cf.access_flags)) {
mchung@2538 534 continue;
mchung@2538 535 }
mchung@2538 536
mchung@2538 537 if (!doneClasses.contains(classFileName)) {
mchung@2538 538 doneClasses.add(classFileName);
mchung@2538 539 }
mchung@2538 540
mchung@2538 541 for (Dependency d : finder.findDependencies(cf)) {
mchung@2538 542 if (filter.accepts(d)) {
mchung@2538 543 String cn = d.getTarget().getName();
mchung@2538 544 if (!doneClasses.contains(cn) && !deque.contains(cn)) {
mchung@2538 545 deque.add(cn);
mchung@2538 546 }
mchung@2538 547 a.addClass(d.getOrigin(), d.getTarget());
mchung@2139 548 }
mchung@2538 549 }
mchung@2538 550 for (String name : a.reader().skippedEntries()) {
mchung@2538 551 warning("warn.skipped.entry", name, a.getPathName());
mchung@1472 552 }
mchung@1472 553 }
mchung@1472 554 }
mchung@1472 555
mchung@1472 556 // add Archive for looking up classes from the classpath
mchung@1472 557 // for transitive dependency analysis
mchung@1472 558 Deque<String> unresolved = roots;
mchung@1472 559 int depth = options.depth > 0 ? options.depth : Integer.MAX_VALUE;
mchung@1472 560 do {
mchung@1472 561 String name;
mchung@1472 562 while ((name = unresolved.poll()) != null) {
mchung@1472 563 if (doneClasses.contains(name)) {
mchung@1472 564 continue;
mchung@1472 565 }
mchung@1472 566 ClassFile cf = null;
mchung@1472 567 for (Archive a : classpaths) {
mchung@1472 568 cf = a.reader().getClassFile(name);
mchung@1472 569 if (cf != null) {
mchung@1472 570 String classFileName;
mchung@1472 571 try {
mchung@1472 572 classFileName = cf.getName();
mchung@1472 573 } catch (ConstantPoolException e) {
mchung@1472 574 throw new ClassFileError(e);
mchung@1472 575 }
mchung@1472 576 if (!doneClasses.contains(classFileName)) {
mchung@1472 577 // if name is a fully-qualified class name specified
mchung@1472 578 // from command-line, this class might already be parsed
mchung@1472 579 doneClasses.add(classFileName);
mchung@2538 580 // process @jdk.Exported for JDK classes
mchung@2538 581 if (isJDKArchive(a)) {
mchung@2538 582 ((JDKArchive)a).processJdkExported(cf);
mchung@2538 583 }
mchung@1577 584 for (Dependency d : finder.findDependencies(cf)) {
mchung@1577 585 if (depth == 0) {
mchung@1577 586 // ignore the dependency
mchung@1577 587 a.addClass(d.getOrigin());
mchung@1577 588 break;
mchung@1577 589 } else if (filter.accepts(d)) {
mchung@1577 590 a.addClass(d.getOrigin(), d.getTarget());
mchung@1577 591 String cn = d.getTarget().getName();
mchung@1577 592 if (!doneClasses.contains(cn) && !deque.contains(cn)) {
mchung@1577 593 deque.add(cn);
mchung@1472 594 }
mchung@1472 595 }
mchung@1472 596 }
mchung@1472 597 }
mchung@1472 598 break;
mchung@1472 599 }
mchung@1472 600 }
mchung@1472 601 if (cf == null) {
mchung@1577 602 doneClasses.add(name);
mchung@1472 603 }
mchung@1472 604 }
mchung@1472 605 unresolved = deque;
mchung@2139 606 deque = new LinkedList<>();
mchung@1472 607 } while (!unresolved.isEmpty() && depth-- > 0);
mchung@1472 608 }
mchung@1472 609
mchung@1472 610 public void handleOptions(String[] args) throws BadArgs {
mchung@1472 611 // process options
mchung@1472 612 for (int i=0; i < args.length; i++) {
mchung@1472 613 if (args[i].charAt(0) == '-') {
mchung@1472 614 String name = args[i];
mchung@1472 615 Option option = getOption(name);
mchung@1472 616 String param = null;
mchung@1472 617 if (option.hasArg) {
mchung@2139 618 if (name.startsWith("-") && name.indexOf('=') > 0) {
mchung@1472 619 param = name.substring(name.indexOf('=') + 1, name.length());
mchung@1472 620 } else if (i + 1 < args.length) {
mchung@1472 621 param = args[++i];
mchung@1472 622 }
mchung@1472 623 if (param == null || param.isEmpty() || param.charAt(0) == '-') {
mchung@1472 624 throw new BadArgs("err.missing.arg", name).showUsage(true);
mchung@1472 625 }
mchung@1472 626 }
mchung@1472 627 option.process(this, name, param);
mchung@1472 628 if (option.ignoreRest()) {
mchung@1472 629 i = args.length;
mchung@1472 630 }
mchung@1472 631 } else {
mchung@1472 632 // process rest of the input arguments
mchung@1472 633 for (; i < args.length; i++) {
mchung@1472 634 String name = args[i];
mchung@1472 635 if (name.charAt(0) == '-') {
mchung@1472 636 throw new BadArgs("err.option.after.class", name).showUsage(true);
mchung@1472 637 }
mchung@2139 638 classes.add(name);
mchung@1472 639 }
mchung@1472 640 }
mchung@1472 641 }
mchung@1472 642 }
mchung@1472 643
mchung@1472 644 private Option getOption(String name) throws BadArgs {
mchung@1472 645 for (Option o : recognizedOptions) {
mchung@1472 646 if (o.matches(name)) {
mchung@1472 647 return o;
mchung@1472 648 }
mchung@1472 649 }
mchung@1472 650 throw new BadArgs("err.unknown.option", name).showUsage(true);
mchung@1472 651 }
mchung@1472 652
mchung@1472 653 private void reportError(String key, Object... args) {
mchung@1472 654 log.println(getMessage("error.prefix") + " " + getMessage(key, args));
mchung@1472 655 }
mchung@1472 656
mchung@1472 657 private void warning(String key, Object... args) {
mchung@1472 658 log.println(getMessage("warn.prefix") + " " + getMessage(key, args));
mchung@1472 659 }
mchung@1472 660
mchung@1472 661 private void showHelp() {
mchung@1472 662 log.println(getMessage("main.usage", PROGNAME));
mchung@1472 663 for (Option o : recognizedOptions) {
mchung@1472 664 String name = o.aliases[0].substring(1); // there must always be at least one name
mchung@1472 665 name = name.charAt(0) == '-' ? name.substring(1) : name;
mchung@2538 666 if (o.isHidden() || name.equals("h") || name.startsWith("filter:")) {
mchung@1472 667 continue;
mchung@1472 668 }
mchung@1472 669 log.println(getMessage("main.opt." + name));
mchung@1472 670 }
mchung@1472 671 }
mchung@1472 672
mchung@1472 673 private void showVersion(boolean full) {
mchung@1472 674 log.println(version(full ? "full" : "release"));
mchung@1472 675 }
mchung@1472 676
mchung@1472 677 private String version(String key) {
mchung@1472 678 // key=version: mm.nn.oo[-milestone]
mchung@1472 679 // key=full: mm.mm.oo[-milestone]-build
mchung@1472 680 if (ResourceBundleHelper.versionRB == null) {
mchung@1472 681 return System.getProperty("java.version");
mchung@1472 682 }
mchung@1472 683 try {
mchung@1472 684 return ResourceBundleHelper.versionRB.getString(key);
mchung@1472 685 } catch (MissingResourceException e) {
mchung@1472 686 return getMessage("version.unknown", System.getProperty("java.version"));
mchung@1472 687 }
mchung@1472 688 }
mchung@1472 689
mchung@1577 690 static String getMessage(String key, Object... args) {
mchung@1472 691 try {
mchung@1472 692 return MessageFormat.format(ResourceBundleHelper.bundle.getString(key), args);
mchung@1472 693 } catch (MissingResourceException e) {
mchung@1472 694 throw new InternalError("Missing message: " + key);
mchung@1472 695 }
mchung@1472 696 }
mchung@1472 697
mchung@1472 698 private static class Options {
mchung@1472 699 boolean help;
mchung@1472 700 boolean version;
mchung@1472 701 boolean fullVersion;
mchung@1472 702 boolean showProfile;
mchung@1472 703 boolean showSummary;
mchung@2139 704 boolean apiOnly;
mchung@2172 705 boolean showLabel;
mchung@2214 706 boolean findJDKInternals;
mchung@2539 707 boolean nowarning;
mchung@2538 708 // default is to show package-level dependencies
mchung@2538 709 // and filter references from same package
mchung@2538 710 Analyzer.Type verbose = PACKAGE;
mchung@2538 711 boolean filterSamePackage = true;
mchung@2538 712 boolean filterSameArchive = false;
mchung@2538 713 String filterRegex;
mchung@2139 714 String dotOutputDir;
mchung@1472 715 String classpath = "";
mchung@1472 716 int depth = 1;
mchung@2139 717 Set<String> packageNames = new HashSet<>();
mchung@2139 718 String regex; // apply to the dependences
mchung@2139 719 Pattern includePattern; // apply to classes
mchung@1472 720 }
mchung@1472 721 private static class ResourceBundleHelper {
mchung@1472 722 static final ResourceBundle versionRB;
mchung@1472 723 static final ResourceBundle bundle;
mchung@2539 724 static final ResourceBundle jdkinternals;
mchung@1472 725
mchung@1472 726 static {
mchung@1472 727 Locale locale = Locale.getDefault();
mchung@1472 728 try {
mchung@1472 729 bundle = ResourceBundle.getBundle("com.sun.tools.jdeps.resources.jdeps", locale);
mchung@1472 730 } catch (MissingResourceException e) {
mchung@1472 731 throw new InternalError("Cannot find jdeps resource bundle for locale " + locale);
mchung@1472 732 }
mchung@1472 733 try {
mchung@1472 734 versionRB = ResourceBundle.getBundle("com.sun.tools.jdeps.resources.version");
mchung@1472 735 } catch (MissingResourceException e) {
mchung@1472 736 throw new InternalError("version.resource.missing");
mchung@1472 737 }
mchung@2539 738 try {
mchung@2539 739 jdkinternals = ResourceBundle.getBundle("com.sun.tools.jdeps.resources.jdkinternals");
mchung@2539 740 } catch (MissingResourceException e) {
mchung@2539 741 throw new InternalError("Cannot find jdkinternals resource bundle");
mchung@2539 742 }
mchung@1472 743 }
mchung@1472 744 }
mchung@1472 745
mchung@1472 746 private List<Archive> getClassPathArchives(String paths) throws IOException {
mchung@2139 747 List<Archive> result = new ArrayList<>();
mchung@1472 748 if (paths.isEmpty()) {
mchung@1472 749 return result;
mchung@1472 750 }
mchung@1472 751 for (String p : paths.split(File.pathSeparator)) {
mchung@1472 752 if (p.length() > 0) {
mchung@2139 753 List<Path> files = new ArrayList<>();
mchung@2139 754 // wildcard to parse all JAR files e.g. -classpath dir/*
mchung@2139 755 int i = p.lastIndexOf(".*");
mchung@2139 756 if (i > 0) {
mchung@2139 757 Path dir = Paths.get(p.substring(0, i));
mchung@2139 758 try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.jar")) {
mchung@2139 759 for (Path entry : stream) {
mchung@2139 760 files.add(entry);
mchung@2139 761 }
mchung@2139 762 }
mchung@2139 763 } else {
mchung@2139 764 files.add(Paths.get(p));
mchung@2139 765 }
mchung@2139 766 for (Path f : files) {
mchung@2139 767 if (Files.exists(f)) {
mchung@2538 768 result.add(Archive.getInstance(f));
mchung@2139 769 }
mchung@1472 770 }
mchung@1472 771 }
mchung@1472 772 }
mchung@1472 773 return result;
mchung@1472 774 }
mchung@2139 775
mchung@2139 776 class RawOutputFormatter implements Analyzer.Visitor {
mchung@2139 777 private final PrintWriter writer;
mchung@2538 778 private String pkg = "";
mchung@2139 779 RawOutputFormatter(PrintWriter writer) {
mchung@2139 780 this.writer = writer;
mchung@2139 781 }
mchung@2139 782 @Override
mchung@2538 783 public void visitDependence(String origin, Archive originArchive,
mchung@2538 784 String target, Archive targetArchive) {
mchung@2538 785 String tag = toTag(target, targetArchive);
mchung@2538 786 if (options.verbose == VERBOSE) {
mchung@2538 787 writer.format(" %-50s -> %-50s %s%n", origin, target, tag);
mchung@2214 788 } else {
mchung@2214 789 if (!origin.equals(pkg)) {
mchung@2214 790 pkg = origin;
mchung@2538 791 writer.format(" %s (%s)%n", origin, originArchive.getName());
mchung@2214 792 }
mchung@2538 793 writer.format(" -> %-50s %s%n", target, tag);
mchung@2139 794 }
mchung@2139 795 }
mchung@2139 796 }
mchung@2139 797
mchung@2538 798 class RawSummaryFormatter implements Analyzer.Visitor {
mchung@2538 799 private final PrintWriter writer;
mchung@2538 800 RawSummaryFormatter(PrintWriter writer) {
mchung@2538 801 this.writer = writer;
mchung@2538 802 }
mchung@2538 803 @Override
mchung@2538 804 public void visitDependence(String origin, Archive originArchive,
mchung@2538 805 String target, Archive targetArchive) {
mchung@2538 806 writer.format("%s -> %s", originArchive.getName(), targetArchive.getPathName());
mchung@2538 807 if (options.showProfile && JDKArchive.isProfileArchive(targetArchive)) {
mchung@2538 808 writer.format(" (%s)", target);
mchung@2538 809 }
mchung@2538 810 writer.format("%n");
mchung@2538 811 }
mchung@2538 812 }
mchung@2538 813
mchung@2538 814 class DotFileFormatter implements Analyzer.Visitor, AutoCloseable {
mchung@2139 815 private final PrintWriter writer;
mchung@2139 816 private final String name;
mchung@2139 817 DotFileFormatter(PrintWriter writer, Archive archive) {
mchung@2139 818 this.writer = writer;
mchung@2538 819 this.name = archive.getName();
mchung@2139 820 writer.format("digraph \"%s\" {%n", name);
mchung@2172 821 writer.format(" // Path: %s%n", archive.getPathName());
mchung@2139 822 }
mchung@2139 823
mchung@2139 824 @Override
mchung@2139 825 public void close() {
mchung@2139 826 writer.println("}");
mchung@2139 827 }
mchung@2139 828
mchung@2139 829 @Override
mchung@2538 830 public void visitDependence(String origin, Archive originArchive,
mchung@2538 831 String target, Archive targetArchive) {
mchung@2538 832 String tag = toTag(target, targetArchive);
mchung@2538 833 writer.format(" %-50s -> \"%s\";%n",
mchung@2538 834 String.format("\"%s\"", origin),
mchung@2538 835 tag.isEmpty() ? target
mchung@2538 836 : String.format("%s (%s)", target, tag));
mchung@2172 837 }
mchung@2172 838 }
mchung@2172 839
mchung@2538 840 class SummaryDotFile implements Analyzer.Visitor, AutoCloseable {
mchung@2538 841 private final PrintWriter writer;
mchung@2538 842 private final Analyzer.Type type;
mchung@2538 843 private final Map<Archive, Map<Archive,StringBuilder>> edges = new HashMap<>();
mchung@2538 844 SummaryDotFile(PrintWriter writer, Analyzer.Type type) {
mchung@2538 845 this.writer = writer;
mchung@2538 846 this.type = type;
mchung@2538 847 writer.format("digraph \"summary\" {%n");
mchung@2538 848 }
mchung@2538 849
mchung@2172 850 @Override
mchung@2538 851 public void close() {
mchung@2538 852 writer.println("}");
mchung@2538 853 }
mchung@2538 854
mchung@2538 855 @Override
mchung@2538 856 public void visitDependence(String origin, Archive originArchive,
mchung@2538 857 String target, Archive targetArchive) {
mchung@2538 858 String targetName = type == PACKAGE ? target : targetArchive.getName();
mchung@2538 859 if (type == PACKAGE) {
mchung@2538 860 String tag = toTag(target, targetArchive, type);
mchung@2538 861 if (!tag.isEmpty())
mchung@2538 862 targetName += " (" + tag + ")";
mchung@2538 863 } else if (options.showProfile && JDKArchive.isProfileArchive(targetArchive)) {
mchung@2538 864 targetName += " (" + target + ")";
mchung@2172 865 }
mchung@2538 866 String label = getLabel(originArchive, targetArchive);
mchung@2538 867 writer.format(" %-50s -> \"%s\"%s;%n",
mchung@2538 868 String.format("\"%s\"", origin), targetName, label);
mchung@2172 869 }
mchung@2538 870
mchung@2538 871 String getLabel(Archive origin, Archive target) {
mchung@2538 872 if (edges.isEmpty())
mchung@2538 873 return "";
mchung@2538 874
mchung@2538 875 StringBuilder label = edges.get(origin).get(target);
mchung@2538 876 return label == null ? "" : String.format(" [label=\"%s\",fontsize=9]", label.toString());
mchung@2538 877 }
mchung@2538 878
mchung@2538 879 Analyzer.Visitor labelBuilder() {
mchung@2538 880 // show the package-level dependencies as labels in the dot graph
mchung@2538 881 return new Analyzer.Visitor() {
mchung@2538 882 @Override
mchung@2538 883 public void visitDependence(String origin, Archive originArchive,
mchung@2538 884 String target, Archive targetArchive)
mchung@2538 885 {
mchung@2538 886 Map<Archive,StringBuilder> labels = edges.get(originArchive);
mchung@2538 887 if (!edges.containsKey(originArchive)) {
mchung@2538 888 edges.put(originArchive, labels = new HashMap<>());
mchung@2538 889 }
mchung@2538 890 StringBuilder sb = labels.get(targetArchive);
mchung@2538 891 if (sb == null) {
mchung@2538 892 labels.put(targetArchive, sb = new StringBuilder());
mchung@2538 893 }
mchung@2538 894 String tag = toTag(target, targetArchive, PACKAGE);
mchung@2538 895 addLabel(sb, origin, target, tag);
mchung@2172 896 }
mchung@2538 897
mchung@2538 898 void addLabel(StringBuilder label, String origin, String target, String tag) {
mchung@2538 899 label.append(origin).append(" -> ").append(target);
mchung@2538 900 if (!tag.isEmpty()) {
mchung@2538 901 label.append(" (" + tag + ")");
mchung@2538 902 }
mchung@2538 903 label.append("\\n");
mchung@2538 904 }
mchung@2538 905 };
mchung@2139 906 }
mchung@2172 907 }
mchung@2139 908
mchung@2538 909 /**
mchung@2538 910 * Test if the given archive is part of the JDK
mchung@2538 911 */
mchung@2538 912 private boolean isJDKArchive(Archive archive) {
mchung@2538 913 return JDKArchive.class.isInstance(archive);
mchung@2538 914 }
mchung@2538 915
mchung@2538 916 /**
mchung@2538 917 * If the given archive is JDK archive, this method returns the profile name
mchung@2538 918 * only if -profile option is specified; it accesses a private JDK API and
mchung@2538 919 * the returned value will have "JDK internal API" prefix
mchung@2538 920 *
mchung@2538 921 * For non-JDK archives, this method returns the file name of the archive.
mchung@2538 922 */
mchung@2538 923 private String toTag(String name, Archive source, Analyzer.Type type) {
mchung@2538 924 if (!isJDKArchive(source)) {
mchung@2538 925 return source.getName();
mchung@2172 926 }
mchung@2172 927
mchung@2538 928 JDKArchive jdk = (JDKArchive)source;
mchung@2538 929 boolean isExported = false;
mchung@2538 930 if (type == CLASS || type == VERBOSE) {
mchung@2538 931 isExported = jdk.isExported(name);
mchung@2538 932 } else {
mchung@2538 933 isExported = jdk.isExportedPackage(name);
mchung@2172 934 }
mchung@2538 935 Profile p = getProfile(name, type);
mchung@2538 936 if (isExported) {
mchung@2538 937 // exported API
mchung@2538 938 return options.showProfile && p != null ? p.profileName() : "";
mchung@2538 939 } else {
mchung@2538 940 return "JDK internal API (" + source.getName() + ")";
mchung@2172 941 }
mchung@2172 942 }
mchung@2538 943
mchung@2538 944 private String toTag(String name, Archive source) {
mchung@2538 945 return toTag(name, source, options.verbose);
mchung@2538 946 }
mchung@2538 947
mchung@2538 948 private Profile getProfile(String name, Analyzer.Type type) {
mchung@2538 949 String pn = name;
mchung@2538 950 if (type == CLASS || type == VERBOSE) {
mchung@2538 951 int i = name.lastIndexOf('.');
mchung@2538 952 pn = i > 0 ? name.substring(0, i) : "";
mchung@2172 953 }
mchung@2538 954 return Profile.getProfile(pn);
mchung@2139 955 }
mchung@2539 956
mchung@2539 957 /**
mchung@2539 958 * Returns the recommended replacement API for the given classname;
mchung@2539 959 * or return null if replacement API is not known.
mchung@2539 960 */
mchung@2539 961 private String replacementFor(String cn) {
mchung@2539 962 String name = cn;
mchung@2539 963 String value = null;
mchung@2539 964 while (value == null && name != null) {
mchung@2539 965 try {
mchung@2539 966 value = ResourceBundleHelper.jdkinternals.getString(name);
mchung@2539 967 } catch (MissingResourceException e) {
mchung@2539 968 // go up one subpackage level
mchung@2539 969 int i = name.lastIndexOf('.');
mchung@2539 970 name = i > 0 ? name.substring(0, i) : null;
mchung@2539 971 }
mchung@2539 972 }
mchung@2539 973 return value;
mchung@2539 974 };
mchung@2539 975
mchung@2539 976 private void showReplacements(Analyzer analyzer) {
mchung@2539 977 Map<String,String> jdkinternals = new TreeMap<>();
mchung@2539 978 boolean useInternals = false;
mchung@2539 979 for (Archive source : sourceLocations) {
mchung@2539 980 useInternals = useInternals || analyzer.hasDependences(source);
mchung@2539 981 for (String cn : analyzer.dependences(source)) {
mchung@2539 982 String repl = replacementFor(cn);
mchung@2539 983 if (repl != null && !jdkinternals.containsKey(cn)) {
mchung@2539 984 jdkinternals.put(cn, repl);
mchung@2539 985 }
mchung@2539 986 }
mchung@2539 987 }
mchung@2539 988 if (useInternals) {
mchung@2539 989 log.println();
mchung@2539 990 warning("warn.replace.useJDKInternals", getMessage("jdeps.wiki.url"));
mchung@2539 991 }
mchung@2539 992 if (!jdkinternals.isEmpty()) {
mchung@2539 993 log.println();
mchung@2539 994 log.format("%-40s %s%n", "JDK Internal API", "Suggested Replacement");
mchung@2539 995 log.format("%-40s %s%n", "----------------", "---------------------");
mchung@2539 996 for (Map.Entry<String,String> e : jdkinternals.entrySet()) {
mchung@2539 997 log.format("%-40s %s%n", e.getKey(), e.getValue());
mchung@2539 998 }
mchung@2539 999 }
mchung@2539 1000
mchung@2539 1001 }
mchung@1472 1002 }

mercurial