# HG changeset patch # User mchung # Date 1432167088 25200 # Wed May 20 17:11:28 2015 -0700 # Node ID 6b43535fb9f8d3292d340717780686c7c050c288 # Parent 31ceef0452728f2630c8fa5893b3f184779de2d7 8068937: jdeps shows "not found" if target class has no reference other than its own package Reviewed-by: alanb diff --git a/src/share/classes/com/sun/tools/jdeps/Analyzer.java b/src/share/classes/com/sun/tools/jdeps/Analyzer.java --- a/src/share/classes/com/sun/tools/jdeps/Analyzer.java +++ b/src/share/classes/com/sun/tools/jdeps/Analyzer.java @@ -223,7 +223,7 @@ Archive targetArchive = findArchive(t); if (filter.accepts(o, archive, t, targetArchive)) { addDep(o, t); - if (!requires.contains(targetArchive)) { + if (archive != targetArchive && !requires.contains(targetArchive)) { requires.add(targetArchive); } } diff --git a/src/share/classes/com/sun/tools/jdeps/JdepsTask.java b/src/share/classes/com/sun/tools/jdeps/JdepsTask.java --- a/src/share/classes/com/sun/tools/jdeps/JdepsTask.java +++ b/src/share/classes/com/sun/tools/jdeps/JdepsTask.java @@ -489,9 +489,11 @@ List archives = new ArrayList<>(); Deque roots = new LinkedList<>(); + List paths = new ArrayList<>(); for (String s : classes) { Path p = Paths.get(s); if (Files.exists(p)) { + paths.add(p); archives.add(Archive.getInstance(p)); } else { if (isValidClassName(s)) { @@ -504,7 +506,7 @@ sourceLocations.addAll(archives); List classpaths = new ArrayList<>(); // for class file lookup - classpaths.addAll(getClassPathArchives(options.classpath)); + classpaths.addAll(getClassPathArchives(options.classpath, paths)); if (options.includePattern != null) { archives.addAll(classpaths); } @@ -545,6 +547,9 @@ deque.add(cn); } a.addClass(d.getOrigin(), d.getTarget()); + } else { + // ensure that the parsed class is added the archive + a.addClass(d.getOrigin()); } } for (String name : a.reader().skippedEntries()) { @@ -592,6 +597,9 @@ if (!doneClasses.contains(cn) && !deque.contains(cn)) { deque.add(cn); } + } else { + // ensure that the parsed class is added the archive + a.addClass(d.getOrigin()); } } } @@ -743,36 +751,52 @@ } } - private List getClassPathArchives(String paths) throws IOException { + /* + * Returns the list of Archive specified in cpaths and not included + * initialArchives + */ + private List getClassPathArchives(String cpaths, List initialArchives) + throws IOException + { List result = new ArrayList<>(); - if (paths.isEmpty()) { + if (cpaths.isEmpty()) { return result; } - for (String p : paths.split(File.pathSeparator)) { + + List paths = new ArrayList<>(); + for (String p : cpaths.split(File.pathSeparator)) { if (p.length() > 0) { - List files = new ArrayList<>(); // wildcard to parse all JAR files e.g. -classpath dir/* int i = p.lastIndexOf(".*"); if (i > 0) { Path dir = Paths.get(p.substring(0, i)); try (DirectoryStream stream = Files.newDirectoryStream(dir, "*.jar")) { for (Path entry : stream) { - files.add(entry); + paths.add(entry); } } } else { - files.add(Paths.get(p)); - } - for (Path f : files) { - if (Files.exists(f)) { - result.add(Archive.getInstance(f)); - } + paths.add(Paths.get(p)); } } } + for (Path p : paths) { + if (Files.exists(p) && !hasSameFile(initialArchives, p)) { + result.add(Archive.getInstance(p)); + } + } return result; } + private boolean hasSameFile(List paths, Path p2) throws IOException { + for (Path p1 : paths) { + if (Files.isSameFile(p1, p2)) { + return true; + } + } + return false; + } + class RawOutputFormatter implements Analyzer.Visitor { private final PrintWriter writer; private String pkg = ""; diff --git a/test/tools/jdeps/Basic.java b/test/tools/jdeps/Basic.java --- a/test/tools/jdeps/Basic.java +++ b/test/tools/jdeps/Basic.java @@ -23,9 +23,9 @@ /* * @test - * @bug 8003562 8005428 8015912 8027481 8048063 + * @bug 8003562 8005428 8015912 8027481 8048063 8068937 * @summary Basic tests for jdeps tool - * @build Test p.Foo p.Bar javax.activity.NotCompactProfile + * @build Test p.Foo p.Bar p.C p.SubClass q.Gee javax.activity.NotCompactProfile * @run main Basic */ @@ -111,6 +111,19 @@ new String[] {"compact1"}, new String[] {"-verbose:package", "-e", "java\\.lang\\..*"}); + // parse p.C, p.SubClass and q.* + // p.SubClass have no dependency other than p.C + // 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", diff --git a/test/tools/jdeps/p/C.java b/test/tools/jdeps/p/C.java new file mode 100644 --- /dev/null +++ b/test/tools/jdeps/p/C.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2015, 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. + * + * 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 p; + +public class C { + public String name() { + return "C"; + } +} diff --git a/test/tools/jdeps/p/SubClass.java b/test/tools/jdeps/p/SubClass.java new file mode 100644 --- /dev/null +++ b/test/tools/jdeps/p/SubClass.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2015, 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. + * + * 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 p; + +// SubClass only references types in package p +public class SubClass extends C { +} diff --git a/test/tools/jdeps/q/Gee.java b/test/tools/jdeps/q/Gee.java new file mode 100644 --- /dev/null +++ b/test/tools/jdeps/q/Gee.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2015, 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. + * + * 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 q; + +public class Gee extends p.SubClass { +}