diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Analyzer.java b/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Analyzer.java index 2e93ea14267..6e83e2196b7 100644 --- a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Analyzer.java +++ b/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Analyzer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -178,10 +178,8 @@ public class Analyzer { } stream.sorted(Comparator.comparing(Archive::getName)) .forEach(archive -> { - Profile profile = result.getTargetProfile(archive); v.visitDependence(source.getName(), source, - profile != null ? profile.profileName() - : archive.getName(), archive); + archive.getName(), archive); }); } else { Dependences result = results.get(source); @@ -216,7 +214,6 @@ public class Analyzer { protected final Set deps; protected final Type level; protected final Predicate targetFilter; - private Profile profile; Dependences(Archive archive, Type level) { this(archive, level, ANY); } @@ -236,14 +233,6 @@ public class Analyzer { return requires; } - Profile getTargetProfile(Archive target) { - if (target.getModule().isJDK()) { - return Profile.getProfile((Module) target); - } else { - return null; - } - } - /* * Returns the archive that contains the given location. */ @@ -284,12 +273,6 @@ public class Analyzer { requires.add(targetArchive); } } - if (targetArchive.getModule().isNamed()) { - Profile p = Profile.getProfile(t.getPackageName()); - if (profile == null || (p != null && p.compareTo(profile) > 0)) { - profile = p; - } - } } private Dep curDep; diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java b/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java index 36be678609c..4684dd32846 100644 --- a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java +++ b/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -126,27 +126,10 @@ public class JdepsConfiguration implements AutoCloseable { .map(nameToModule::get) .forEach(this.rootModules::add); - initProfiles(); - trace("resolved modules: %s%n", nameToModule.keySet().stream() .sorted().collect(joining("\n", "\n", ""))); } - private void initProfiles() { - // other system modules are not observed and not added in nameToModule map - Map systemModules = - system.moduleNames() - .collect(toMap(Function.identity(), (mn) -> { - Module m = nameToModule.get(mn); - if (m == null) { - ModuleReference mref = finder.find(mn).get(); - m = toModule(mref); - } - return m; - })); - Profile.init(systemModules); - } - private void addModuleReference(ModuleReference mref) { Module module = toModule(mref); nameToModule.put(mref.descriptor().name(), module); diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java b/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java index 52d8e0e8af0..8beed2590f5 100644 --- a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java +++ b/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -420,12 +420,6 @@ class JdepsTask { } }, - new Option(false, "-P", "-profile") { - void process(JdepsTask task, String opt, String arg) throws BadArgs { - task.options.showProfile = true; - } - }, - new Option(false, "-R", "-recursive", "--recursive") { void process(JdepsTask task, String opt, String arg) throws BadArgs { task.options.recursive = Options.RECURSIVE; @@ -515,9 +509,6 @@ class JdepsTask { if (options.version || options.fullVersion) { showVersion(options.fullVersion); } - if (options.showProfile && !options.nowarning) { - warning("warn.deprecated.option", "-profile"); - } if (options.help || options.version || options.fullVersion) { return EXIT_OK; } @@ -753,7 +744,6 @@ class JdepsTask { // default to package-level verbose JdepsWriter writer = new SimpleWriter(log, type, - options.showProfile, options.showModule); return run(config, writer, type); @@ -1079,7 +1069,6 @@ class JdepsTask { Type type = getAnalyzerType(); JdepsWriter writer = new DotFileWriter(dotOutputDir, type, - options.showProfile, options.showModule, options.showLabel); return run(config, writer, type); @@ -1225,7 +1214,6 @@ class JdepsTask { boolean help; boolean version; boolean fullVersion; - boolean showProfile; boolean showModule = true; boolean showSummary; boolean apiOnly; diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsWriter.java b/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsWriter.java index 1d3f7f07ac6..bd035a49137 100644 --- a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsWriter.java +++ b/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsWriter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -37,24 +37,21 @@ import java.util.Collection; import java.util.Comparator; import java.util.HashMap; import java.util.Map; -import java.util.Optional; public abstract class JdepsWriter { public static JdepsWriter newDotWriter(Path outputdir, Analyzer.Type type) { - return new DotFileWriter(outputdir, type, false, true, false); + return new DotFileWriter(outputdir, type, true, false); } public static JdepsWriter newSimpleWriter(PrintWriter writer, Analyzer.Type type) { - return new SimpleWriter(writer, type, false, true); + return new SimpleWriter(writer, type, true); } final Analyzer.Type type; - final boolean showProfile; final boolean showModule; - JdepsWriter(Analyzer.Type type, boolean showProfile, boolean showModule) { + JdepsWriter(Analyzer.Type type, boolean showModule) { this.type = type; - this.showProfile = showProfile; this.showModule = showModule; } @@ -64,8 +61,8 @@ public abstract class JdepsWriter { final boolean showLabel; final Path outputDir; DotFileWriter(Path dir, Analyzer.Type type, - boolean showProfile, boolean showModule, boolean showLabel) { - super(type, showProfile, showModule); + boolean showModule, boolean showLabel) { + super(type, showModule); this.showLabel = showLabel; this.outputDir = dir; } @@ -168,7 +165,7 @@ public abstract class JdepsWriter { String targetName = type == PACKAGE ? target : targetArchive.getName(); if (targetArchive.getModule().isJDK()) { Module m = (Module)targetArchive; - String n = showProfileOrModule(m); + String n = showModule(m); if (!n.isEmpty()) { targetName += " (" + n + ")"; } @@ -217,8 +214,8 @@ public abstract class JdepsWriter { static class SimpleWriter extends JdepsWriter { final PrintWriter writer; SimpleWriter(PrintWriter writer, Analyzer.Type type, - boolean showProfile, boolean showModule) { - super(type, showProfile, showModule); + boolean showModule) { + super(type, showModule); this.writer = writer; } @@ -284,9 +281,6 @@ public abstract class JdepsWriter { targetName = targetArchive.getModule().name(); } writer.format("%s -> %s", originArchive.getName(), targetName); - if (showProfile && targetArchive.getModule().isJDK()) { - writer.format(" (%s)", target); - } writer.format("%n"); } @@ -305,8 +299,7 @@ public abstract class JdepsWriter { } /** - * If the given archive is JDK archive, this method returns the profile name - * only if -profile option is specified; it accesses a private JDK API and + * If the given target is JDK module and the source accesses a private JDK API, * the returned value will have "JDK internal API" prefix * * For non-JDK archives, this method returns the file name of the archive. @@ -325,7 +318,7 @@ public abstract class JdepsWriter { // exported API if (module.isExported(pn) && !module.isJDKUnsupported()) { - return showProfileOrModule(module); + return showModule(module); } // JDK internal API @@ -338,26 +331,11 @@ public abstract class JdepsWriter { return module.name() + (isExported ? " (qualified)" : " (internal)"); } - String showProfileOrModule(Module m) { + String showModule(Module m) { String tag = ""; - if (showProfile) { - Profile p = Profile.getProfile(m); - if (p != null) { - tag = p.profileName(); - } - } else if (showModule) { + if (showModule) { tag = m.name(); } return tag; } - - Profile getProfile(String name) { - String pn = name; - if (type == CLASS || type == VERBOSE) { - int i = name.lastIndexOf('.'); - pn = i > 0 ? name.substring(0, i) : ""; - } - return Profile.getProfile(pn); - } - } diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Profile.java b/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Profile.java deleted file mode 100644 index 1da0d4a4b59..00000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Profile.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.jdeps; - -import java.io.IOException; -import java.lang.module.ModuleDescriptor; -import java.util.Arrays; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * Build the profile information. - */ -enum Profile { - COMPACT1("compact1", 1, "java.logging", - "java.scripting"), - COMPACT2("compact2", 2, "java.rmi", - "java.sql", - "java.xml", - "jdk.xml.dom", - "jdk.httpserver"), - COMPACT3("compact3", 3, "java.smartcardio", - "java.compiler", - "java.instrument", - "java.management", - "java.naming", - "java.prefs", - "java.security.jgss", - "java.security.sasl", - "java.sql.rowset", - "java.xml.crypto", - "jdk.management", - "jdk.naming.dns", - "jdk.naming.rmi", - "jdk.sctp", - "jdk.security.auth"); - - final String name; - final int profile; - final String[] mnames; - final Map modules = new HashMap<>(); - - Profile(String name, int profile, String... mnames) { - this.name = name; - this.profile = profile; - this.mnames = mnames; - } - - public String profileName() { - return name; - } - - @Override - public String toString() { - return mnames[0]; - } - - public static int getProfileCount() { - return JDK.isEmpty() ? 0 : Profile.values().length; - } - - /** - * Returns the Profile for the given package name; null if not found. - */ - public static Profile getProfile(String pn) { - for (Profile p : Profile.values()) { - for (Module m : p.modules.values()) { - if (m.packages().contains(pn)) { - return p; - } - } - } - return null; - } - - /* - * Returns the Profile for a given Module; null if not found. - */ - public static Profile getProfile(Module m) { - for (Profile p : Profile.values()) { - if (p.modules.containsValue(m)) { - return p; - } - } - return null; - } - - private static final Set JDK = new HashSet<>(); - static synchronized void init(Map systemModules) { - Arrays.stream(Profile.values()).forEach(p -> - // this includes platform-dependent module that may not exist - Arrays.stream(p.mnames) - .filter(systemModules::containsKey) - .map(systemModules::get) - .forEach(m -> p.addModule(systemModules, m))); - - // JDK modules should include full JRE plus other jdk.* modules - // Just include all installed modules. Assume jdeps is running - // in JDK image - JDK.addAll(systemModules.values()); - } - - private void addModule(Map systemModules, Module module) { - modules.put(module.name(), module); - module.descriptor().requires().stream() - .map(ModuleDescriptor.Requires::name) - .map(systemModules::get) - .forEach(m -> modules.put(m.name(), m)); - } - - // for debugging - public static void main(String[] args) throws IOException { - // initialize Profiles - new JdepsConfiguration.Builder().addmods(Set.of("ALL-SYSTEM")).build(); - - // find platform modules - if (Profile.getProfileCount() == 0) { - System.err.println("No profile is present in this JDK"); - } - for (Profile p : Profile.values()) { - String profileName = p.name; - System.out.format("%2d: %-10s %s%n", p.profile, profileName, p.modules); - } - System.out.println("All JDK modules:-"); - JDK.stream().sorted(Comparator.comparing(Module::name)) - .forEach(System.out::println); - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/resources/jdeps.properties b/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/resources/jdeps.properties index 3d859d9767f..a3250363863 100644 --- a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/resources/jdeps.properties +++ b/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/resources/jdeps.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -92,15 +92,12 @@ main.opt.ignore-missing-deps=\ \ --ignore-missing-deps Ignore missing dependences. main.opt.include=\n\ - \Options to filter classes to be analyzed:\n\ +\Options to filter classes to be analyzed:\n\ \ -include Restrict analysis to classes matching pattern\n\ \ This option filters the list of classes to\n\ \ be analyzed. It can be used together with\n\ \ -p and -e which apply pattern to the dependences -main.opt.P=\ -\ -P -profile Show profile containing a package. This option\n\ -\ is deprecated and may be removed in a future release. main.opt.cp=\ \ -cp \n\ \ -classpath \n\ @@ -235,7 +232,6 @@ err.invalid.arg.for.option=invalid argument for option: {0} err.option.after.class=option must be specified before classes: {0} err.genmoduleinfo.not.jarfile={0} is a modular JAR file that cannot be specified with the --generate-module-info option err.genmoduleinfo.unnamed.package={0} contains an unnamed package that is not allowed in a module -err.profiles.msg=No profile information err.exception.message={0} err.invalid.path=invalid path: {0} err.invalid.options={0} cannot be used with {1} option diff --git a/test/langtools/tools/jdeps/APIDeps.java b/test/langtools/tools/jdeps/APIDeps.java index edf4f75b7bc..05b4bd2f3a5 100644 --- a/test/langtools/tools/jdeps/APIDeps.java +++ b/test/langtools/tools/jdeps/APIDeps.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -96,32 +96,26 @@ public class APIDeps { "java.lang.management.ManagementFactory", "java.lang.management.RuntimeMXBean", "b.B", "c.C", "d.D", "f.F", "g.G"}, - new String[] {"compact1", "compact3", testDirBasename}, - new String[] {"-classpath", testDir.getPath(), "-verbose", "-P"}); + new String[] {"-classpath", testDir.getPath(), "-verbose"}); test(new File(mDir, "Foo.class"), new String[] {"c.I", "e.E", "f.F"}, - new String[] {testDirBasename}, - new String[] {"-classpath", testDir.getPath(), "-verbose:class", "-P"}); + new String[] {"-classpath", testDir.getPath(), "-verbose:class"}); test(new File(mDir, "Foo.class"), new String[] {"c.I", "e.E", "f.F", "m.Bar"}, - new String[] {testDirBasename}, - new String[] {"-classpath", testDir.getPath(), "-verbose:class", "-filter:none", "-P"}); + new String[] {"-classpath", testDir.getPath(), "-verbose:class", "-filter:none"}); test(new File(mDir, "Gee.class"), new String[] {"g.G", "sun.security.x509.X509CertInfo", "com.sun.tools.classfile.ClassFile", "com.sun.management.ThreadMXBean", "com.sun.source.tree.BinaryTree"}, - new String[] {testDirBasename, "JDK internal API", "compact3", ""}, - new String[] {"-classpath", testDir.getPath(), "-verbose", "-P"}); + new String[] {"-classpath", testDir.getPath(), "-verbose"}); // -jdkinternals test(new File(mDir, "Gee.class"), new String[] {"sun.security.x509.X509CertInfo", "com.sun.tools.classfile.ClassFile"}, - new String[] {"JDK internal API"}, new String[] {"-jdkinternals", "-quiet"}); // -jdkinternals parses all classes on -classpath and the input arguments test(new File(mDir, "Gee.class"), new String[] {"com.sun.tools.classfile.ClassFile", "sun.security.x509.X509CertInfo"}, - new String[] {"JDK internal API"}, // use -classpath tmp/a with no use of JDK internal API new String[] {"-classpath", dest.resolve("a").toString(), "-jdkinternals", "-quiet"}); @@ -130,29 +124,27 @@ public class APIDeps { new String[] {"java.lang.Object", "java.lang.String", "java.util.Set", "c.C", "d.D", "c.I", "e.E"}, - new String[] {"compact1", testDirBasename}, - new String[] {"-classpath", testDir.getPath(), "-verbose:class", "-P", "-apionly"}); + new String[] {"-classpath", testDir.getPath(), "-verbose:class", "-apionly"}); test(mDir, new String[] {"java.lang.Object", "java.lang.String", "java.util.Set", "c.C", "d.D", "c.I", "e.E", "m.Bar"}, - new String[] {"compact1", testDirBasename, mDir.getName()}, - new String[] {"-classpath", testDir.getPath(), "-verbose", "-P", "--api-only"}); + new String[] {"-classpath", testDir.getPath(), "-verbose", "--api-only"}); return errors; } - void test(File file, String[] expect, String[] profiles) { - test(file, expect, profiles, new String[0]); + void test(File file, String[] expect) { + test(file, expect, new String[0]); } - void test(File file, String[] expect, String[] profiles, String[] options) { + void test(File file, String[] expect, String[] options) { List args = new ArrayList<>(Arrays.asList(options)); if (file != null) { args.add(file.getPath()); } - checkResult("api-dependencies", expect, profiles, - jdeps(args.toArray(new String[0]))); + checkResult("api-dependencies", expect, + jdeps(args.toArray(new String[0])).keySet()); } Map jdeps(String... args) { @@ -197,33 +189,19 @@ public class APIDeps { } void checkResult(String label, String[] expect, Collection found) { - List list = Arrays.asList(expect); - if (!isEqual(list, found)) - error("Unexpected " + label + " found: '" + found + "', expected: '" + list + "'"); - } - - void checkResult(String label, String[] expect, String[] profiles, Map result) { // check the dependencies - checkResult(label, expect, result.keySet()); - // check profile information - Set values = new TreeSet<>(); - String internal = "JDK internal API"; - for (String s: result.values()) { - if (s.startsWith(internal)){ - values.add(internal); - } else { - values.add(s); - } + if (!isEqual(expect, found)) { + error("Unexpected " + label + " found: '" + found + + "', expected: '" + Arrays.toString(expect) + "'"); } - checkResult(label, profiles, values); } - boolean isEqual(List expected, Collection found) { - if (expected.size() != found.size()) + boolean isEqual(String[] expected, Collection found) { + if (expected.length != found.size()) return false; List list = new ArrayList<>(found); - list.removeAll(expected); + list.removeAll(Arrays.asList(expected)); return list.isEmpty(); } diff --git a/test/langtools/tools/jdeps/Basic.java b/test/langtools/tools/jdeps/Basic.java index 4251edbed6b..c3d85dd9c22 100644 --- a/test/langtools/tools/jdeps/Basic.java +++ b/test/langtools/tools/jdeps/Basic.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -56,41 +56,33 @@ public class Basic { File testDir = new File(System.getProperty("test.classes", ".")); // test a .class file test(new File(testDir, "Test.class"), - new String[] {"java.lang", "p"}, - new String[] {"compact1", "not found"}); + new String[] {"java.lang", "p"}); // test a directory test(new File(testDir, "p"), new String[] {"java.lang", "java.util", "java.lang.management", "javax.crypto"}, - new String[] {"compact1", "compact1", "compact3", "compact1"}, new String[] {"-classpath", testDir.getPath()}); // test class-level dependency output test(new File(testDir, "Test.class"), new String[] {"java.lang.Object", "java.lang.String", "p.Foo", "p.Bar"}, - new String[] {"compact1", "compact1", "not found", "not found"}, new String[] {"-verbose:class"}); // test -filter:none option test(new File(testDir, "p"), new String[] {"java.lang", "java.util", "java.lang.management", "javax.crypto", "p"}, - new String[] {"compact1", "compact1", "compact3", "compact1", "p"}, new String[] {"-classpath", testDir.getPath(), "-verbose:package", "-filter:none"}); // test -filter:archive option test(new File(testDir, "p"), new String[] {"java.lang", "java.util", "java.lang.management", "javax.crypto"}, - new String[] {"compact1", "compact1", "compact3", "compact1"}, new String[] {"-classpath", testDir.getPath(), "-verbose:package", "-filter:archive"}); // test -p option test(new File(testDir, "Test.class"), new String[] {"p.Foo", "p.Bar"}, - new String[] {"not found", "not found"}, new String[] {"-verbose:class", "-p", "p"}); // test -e option test(new File(testDir, "Test.class"), new String[] {"p.Foo", "p.Bar"}, - new String[] {"not found", "not found"}, new String[] {"-verbose:class", "-e", "p\\..*"}); test(new File(testDir, "Test.class"), new String[] {"java.lang"}, - new String[] {"compact1"}, new String[] {"-verbose:package", "-e", "java\\.lang\\..*"}); // parse p.C, p.SubClass and q.* @@ -98,22 +90,18 @@ public class Basic { // q.Gee depends on p.SubClass that should be found test(testDir, new String[] {"java.lang", "p"}, - new String[] {"compact1", testDir.getName()}, new String[] {"-include", "p.C|p.SubClass|q\\..*"}); test(testDir, new String[] {"java.lang", "p"}, - new String[] {"compact1", testDir.getName()}, new String[] {"-classpath", testDir.getPath(), "-include", "p.C|p.SubClass|q\\..*"}); // test -classpath and -include options test(null, new String[] {"java.lang", "java.util", "java.lang.management", "javax.crypto"}, - new String[] {"compact1", "compact1", "compact3", "compact1"}, new String[] {"-classpath", testDir.getPath(), "-include", "p.+|Test.class"}); test(new File(testDir, "Test.class"), new String[] {"java.lang.Object", "java.lang.String", "p.Foo", "p.Bar"}, - new String[] {"compact1", "compact1", testDir.getName(), testDir.getName()}, new String[] {"-v", "-classpath", testDir.getPath(), "Test.class"}); // split package p - move p/Foo.class to dir1 and p/Bar.class to dir2 @@ -134,40 +122,31 @@ public class Basic { cpath.append(File.pathSeparator).append(dir2.toString()); test(new File(testDir, "Test.class"), new String[] {"java.lang.Object", "java.lang.String", "p.Foo", "p.Bar"}, - new String[] {"compact1", "compact1", dir1.toFile().getName(), dir2.toFile().getName()}, new String[] {"-v", "-classpath", cpath.toString(), "Test.class"}); // tests --missing-deps option test(new File(testDir, "Test.class"), new String[] {"p.Foo", "p.Bar"}, - new String[] {"not found", "not found"}, new String[] {"--missing-deps"}); // no missing dependence test(new File(testDir, "Test.class"), - new String[0], new String[0], new String[] {"--missing-deps", "-classpath", cpath.toString()}); return errors; } - void test(File file, String[] expect, String[] profiles) { - test(file, expect, profiles, new String[0]); + void test(File file, String[] expect) { + test(file, expect, new String[0]); } - void test(File file, String[] expect, String[] profiles, String[] options) { + void test(File file, String[] expect, String[] options) { List args = new ArrayList<>(Arrays.asList(options)); if (file != null) { args.add(file.getPath()); } - List argsWithDashP = new ArrayList<>(); - argsWithDashP.add("-P"); - argsWithDashP.addAll(args); - // test without -P checkResult("dependencies", expect, jdeps(args.toArray(new String[0])).keySet()); - // test with -P - checkResult("profiles", expect, profiles, jdeps(argsWithDashP.toArray(new String[0]))); } Map jdeps(String... args) { @@ -216,21 +195,6 @@ public class Basic { error("Unexpected " + label + " found: '" + found + "', expected: '" + list + "'"); } - void checkResult(String label, String[] expect, String[] profiles, Map result) { - if (expect.length != profiles.length) - error("Invalid expected names and profiles"); - - // check the dependencies - checkResult(label, expect, result.keySet()); - // check profile information - checkResult(label, profiles, result.values()); - for (int i=0; i < expect.length; i++) { - String profile = result.get(expect[i]); - if (!profile.equals(profiles[i])) - error("Unexpected profile: '" + profile + "', expected: '" + profiles[i] + "'"); - } - } - boolean isEqual(List expected, Collection found) { if (expected.size() != found.size()) return false; diff --git a/test/langtools/tools/jdeps/DotFileTest.java b/test/langtools/tools/jdeps/DotFileTest.java index ec286162236..65f7adadb51 100644 --- a/test/langtools/tools/jdeps/DotFileTest.java +++ b/test/langtools/tools/jdeps/DotFileTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -67,64 +67,49 @@ public class DotFileTest { File testDir = dir.toFile(); // test a .class file test(new File(testDir, "Test.class"), - new String[] {"java.lang", "p"}, - new String[] {"compact1", "not found"}); + new String[] {"java.lang", "p"}); // test a directory test(new File(testDir, "p"), new String[] {"java.lang", "java.util", "java.lang.management", "javax.crypto"}, - new String[] {"compact1", "compact1", "compact3", "compact1"}, new String[] {"-classpath", testDir.getPath()}); // test class-level dependency output test(new File(testDir, "Test.class"), new String[] {"java.lang.Object", "java.lang.String", "p.Foo", "p.Bar"}, - new String[] {"compact1", "compact1", "not found", "not found"}, new String[] {"-verbose:class"}); // test -filter:none option test(new File(testDir, "p"), new String[] {"java.lang", "java.util", "java.lang.management", "javax.crypto", "p"}, - new String[] {"compact1", "compact1", "compact3", "compact1", "p"}, new String[] {"-classpath", testDir.getPath(), "-verbose:package", "-filter:none"}); // test -filter:archive option test(new File(testDir, "p"), new String[] {"java.lang", "java.util", "java.lang.management", "javax.crypto"}, - new String[] {"compact1", "compact1", "compact3", "compact1"}, new String[] {"-classpath", testDir.getPath(), "-verbose:package", "-filter:archive"}); - // test -p option - test(new File(testDir, "Test.class"), - new String[] {"p.Foo", "p.Bar"}, - new String[] {"not found", "not found"}, - new String[] {"-verbose:class", "-p", "p"}); // test -e option test(new File(testDir, "Test.class"), new String[] {"p.Foo", "p.Bar"}, - new String[] {"not found", "not found"}, new String[] {"-verbose:class", "-e", "p\\..*"}); test(new File(testDir, "Test.class"), new String[] {"java.lang"}, - new String[] {"compact1"}, new String[] {"-verbose:package", "-e", "java\\.lang\\..*"}); // test -classpath options test(new File(testDir, "Test.class"), new String[] {"java.lang.Object", "java.lang.String", "p.Foo", "p.Bar"}, - new String[] {"compact1", "compact1", testDir.getName(), testDir.getName()}, new String[] {"-v", "-classpath", testDir.getPath()}); testSummary(new File(testDir, "Test.class"), new String[] {"java.base", testDir.getName()}, - new String[] {"compact1", ""}, new String[] {"-classpath", testDir.getPath()}); testSummary(new File(testDir, "Test.class"), new String[] {"java.lang", "p"}, - new String[] {"compact1", testDir.getName()}, new String[] {"-v", "-classpath", testDir.getPath()}); return errors; } - void test(File file, String[] expect, String[] profiles) throws IOException { - test(file, expect, profiles, new String[0]); + void test(File file, String[] expect) throws IOException { + test(file, expect, new String[0]); } - void test(File file, String[] expect, String[] profiles, String[] options) + void test(File file, String[] expect, String[] options) throws IOException { Path dotfile = dotoutput.resolve(file.toPath().getFileName().toString() + ".dot"); @@ -138,17 +123,9 @@ public class DotFileTest { Map result = jdeps(args, dotfile); checkResult("dependencies", expect, result.keySet()); - - // with -P option - List argsWithDashP = new ArrayList<>(); - argsWithDashP.add("-P"); - argsWithDashP.addAll(args); - - result = jdeps(argsWithDashP, dotfile); - checkResult("profiles", expect, profiles, result); } - void testSummary(File file, String[] expect, String[] profiles, String[] options) + void testSummary(File file, String[] expect, String[] options) throws IOException { Path dotfile = dotoutput.resolve("summary.dot"); @@ -162,14 +139,6 @@ public class DotFileTest { Map result = jdeps(args, dotfile); checkResult("dependencies", expect, result.keySet()); - - // with -P option - List argsWithDashP = new ArrayList<>(); - argsWithDashP.add("-P"); - argsWithDashP.addAll(args); - - result = jdeps(argsWithDashP, dotfile); - checkResult("profiles", expect, profiles, result); } Map jdeps(List args, Path dotfile) throws IOException { @@ -213,33 +182,19 @@ public class DotFileTest { return result; } - void checkResult(String label, String[] expect, Collection found) { - List list = Arrays.asList(expect); - if (!isEqual(list, found)) - error("Unexpected " + label + " found: '" + found + "', expected: '" + list + "'"); - } - - void checkResult(String label, String[] expect, String[] profiles, Map result) { - if (expect.length != profiles.length) - error("Invalid expected names and profiles"); - + void checkResult(String label, String[] expect, Collection result) { // check the dependencies - checkResult(label, expect, result.keySet()); - // check profile information - checkResult(label, profiles, result.values()); - for (int i=0; i < expect.length; i++) { - String profile = result.get(expect[i]); - if (!profile.equals(profiles[i])) - error("Unexpected profile: '" + profile + "', expected: '" + profiles[i] + "'"); - } + if (!isEqual(expect, result)) + error("Unexpected " + label + " found: '" + result + + "', expected: '" + Arrays.toString(expect) + "'"); } - boolean isEqual(List expected, Collection found) { - if (expected.size() != found.size()) + boolean isEqual(String[] expected, Collection found) { + if (expected.length != found.size()) return false; List list = new ArrayList<>(found); - list.removeAll(expected); + list.removeAll(Arrays.asList(expected)); return list.isEmpty(); }