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

Reviewed-by: alanb
This commit is contained in:
Mandy Chung 2015-01-27 19:50:41 -08:00
parent a67e9f2d36
commit 5035f5b1d4
7 changed files with 141 additions and 25 deletions

View File

@ -218,7 +218,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);
}
}

View File

@ -75,20 +75,11 @@ public class Archive {
}
public void addClass(Location origin) {
Set<Location> set = deps.get(origin);
if (set == null) {
set = new HashSet<>();
deps.put(origin, set);
}
deps.computeIfAbsent(origin, _k -> new HashSet<>());
}
public void addClass(Location origin, Location target) {
Set<Location> set = deps.get(origin);
if (set == null) {
set = new HashSet<>();
deps.put(origin, set);
}
set.add(target);
deps.computeIfAbsent(origin, _k -> new HashSet<>()).add(target);
}
public Set<Location> getClasses() {
@ -115,6 +106,10 @@ public class Archive {
return filename;
}
public Path path() {
return path;
}
interface Visitor {
void visit(Location origin, Location target);
}

View File

@ -611,6 +611,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()) {
@ -643,6 +646,7 @@ class JdepsTask {
// if name is a fully-qualified class name specified
// from command-line, this class might already be parsed
doneClasses.add(classFileName);
for (Dependency d : finder.findDependencies(cf)) {
if (depth == 0) {
// ignore the dependency
@ -654,6 +658,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());
}
}
}
@ -809,36 +816,53 @@ 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)
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 path : paths) {
boolean found = initialArchives.stream()
.map(Archive::path)
.anyMatch(p -> isSameFile(path, p));
if (!found && Files.exists(path)) {
result.add(Archive.getInstance(path));
}
}
return result;
}
private boolean isSameFile(Path p1, Path p2) {
try {
return Files.isSameFile(p1, p2);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
class RawOutputFormatter implements Analyzer.Visitor {
private final PrintWriter writer;
private String pkg = "";

View File

@ -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
*/
@ -90,6 +90,18 @@ 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",

View File

@ -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";
}
}

View File

@ -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 {
}

View File

@ -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 {
}