< prev index next >
src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Analyzer.java
Print this page
@@ -30,17 +30,19 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
+import java.lang.module.ModuleDescriptor;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Dependency Analyzer.
@@ -72,10 +74,11 @@
protected final Filter filter;
protected final Map<Archive, Dependences> results = new HashMap<>();
protected final Map<Location, Archive> locationToArchive = new HashMap<>();
static final Archive NOT_FOUND
= new Archive(JdepsTask.getMessage("artifact.not.found"));
+ static final Predicate<Archive> ANY = a -> true;
/**
* Constructs an Analyzer instance.
*
* @param type Type of the dependency analysis
@@ -159,11 +162,11 @@
/**
* Visit the dependencies of the given source.
* If the requested level is SUMMARY, it will visit the required archives list.
*/
- void visitDependences(Archive source, Visitor v, Type level) {
+ void visitDependences(Archive source, Visitor v, Type level, Predicate<Archive> targetFilter) {
if (level == Type.SUMMARY) {
final Dependences result = results.get(source);
final Set<Archive> reqs = result.requires();
Stream<Archive> stream = reqs.stream();
if (reqs.isEmpty()) {
@@ -182,11 +185,11 @@
});
} else {
Dependences result = results.get(source);
if (level != type) {
// requesting different level of analysis
- result = new Dependences(source, level);
+ result = new Dependences(source, level, targetFilter);
source.visitDependences(result);
}
result.dependencies().stream()
.sorted(Comparator.comparing(Dep::origin)
.thenComparing(Dep::target))
@@ -194,11 +197,15 @@
d.target(), d.targetArchive()));
}
}
void visitDependences(Archive source, Visitor v) {
- visitDependences(source, v, type);
+ visitDependences(source, v, type, ANY);
+ }
+
+ void visitDependences(Archive source, Visitor v, Type level) {
+ visitDependences(source, v, level, ANY);
}
/**
* Dependences contains the dependencies for an Archive that can have one or
* more classes.
@@ -206,16 +213,21 @@
class Dependences implements Archive.Visitor {
protected final Archive archive;
protected final Set<Archive> requires;
protected final Set<Dep> deps;
protected final Type level;
+ protected final Predicate<Archive> targetFilter;
private Profile profile;
Dependences(Archive archive, Type level) {
+ this(archive, level, ANY);
+ }
+ Dependences(Archive archive, Type level, Predicate<Archive> targetFilter) {
this.archive = archive;
this.deps = new HashSet<>();
this.requires = new HashSet<>();
this.level = level;
+ this.targetFilter = targetFilter;
}
Set<Dep> dependencies() {
return deps;
}
@@ -264,11 +276,11 @@
}
@Override
public void visit(Location o, Location t) {
Archive targetArchive = findArchive(t);
- if (filter.accepts(o, archive, t, targetArchive)) {
+ if (filter.accepts(o, archive, t, targetArchive) && targetFilter.test(targetArchive)) {
addDep(o, t);
if (archive != targetArchive && !requires.contains(targetArchive)) {
requires.add(targetArchive);
}
}
@@ -366,17 +378,25 @@
origin, originArchive.getName(),
target, targetArchive.getName());
}
}
+ /*
+ * Returns true if the given archive represents not found.
+ */
+ static boolean notFound(Archive archive) {
+ return archive == NOT_FOUND || archive == REMOVED_JDK_INTERNALS;
+ }
+
static final Jdk8Internals REMOVED_JDK_INTERNALS = new Jdk8Internals();
static class Jdk8Internals extends Module {
- private final String JDK8_INTERNALS = "/com/sun/tools/jdeps/resources/jdk8_internals.txt";
+ private static final String NAME = "JDK removed internal API";
+ private static final String JDK8_INTERNALS = "/com/sun/tools/jdeps/resources/jdk8_internals.txt";
private final Set<String> jdk8Internals;
private Jdk8Internals() {
- super("JDK removed internal API");
+ super(NAME, ModuleDescriptor.newModule("jdk8internals").build(), true);
try (InputStream in = JdepsTask.class.getResourceAsStream(JDK8_INTERNALS);
BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
this.jdk8Internals = reader.lines()
.filter(ln -> !ln.startsWith("#"))
.collect(Collectors.toSet());
@@ -392,15 +412,10 @@
return jdk8Internals.contains(pn);
}
@Override
- public String name() {
- return getName();
- }
-
- @Override
public boolean isJDK() {
return true;
}
@Override
< prev index next >