提交 8b358888 编写于 作者: M mchung

8068937: jdeps shows "not found" if target class has no reference other than its own package

Reviewed-by: alanb
上级 8838db9d
......@@ -223,7 +223,7 @@ public class Analyzer {
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);
}
}
......
......@@ -489,9 +489,11 @@ class JdepsTask {
List<Archive> archives = new ArrayList<>();
Deque<String> roots = new LinkedList<>();
List<Path> 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 @@ class JdepsTask {
sourceLocations.addAll(archives);
List<Archive> 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 @@ class JdepsTask {
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 @@ class JdepsTask {
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 @@ class JdepsTask {
}
}
private List<Archive> getClassPathArchives(String paths) throws IOException {
/*
* Returns the list of Archive specified in cpaths and not included
* initialArchives
*/
private List<Archive> getClassPathArchives(String cpaths, List<Path> initialArchives)
throws IOException
{
List<Archive> result = new ArrayList<>();
if (paths.isEmpty()) {
if (cpaths.isEmpty()) {
return result;
}
for (String p : paths.split(File.pathSeparator)) {
List<Path> paths = new ArrayList<>();
for (String p : cpaths.split(File.pathSeparator)) {
if (p.length() > 0) {
List<Path> 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<Path> 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<Path> 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 = "";
......
......@@ -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 @@ public class Basic {
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",
......
/*
* 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";
}
}
/*
* 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 {
}
/*
* 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 {
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册