com.sun.tools.classfile.Dependency.Location Java Examples

The following examples show how to use com.sun.tools.classfile.Dependency.Location. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Analyzer.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visit(Location o, Location t) {
    Archive targetArchive = findArchive(t);
    if (filter.accepts(o, archive, t, targetArchive)) {
        addDep(o, t);
        if (archive != targetArchive && !requires.contains(targetArchive)) {
            requires.add(targetArchive);
        }
    }
    if (targetArchive instanceof JDKArchive) {
        Profile p = Profile.getProfile(t.getPackageName());
        if (profile == null || (p != null && p.compareTo(profile) > 0)) {
            profile = p;
        }
    }
}
 
Example #2
Source File: Analyzer.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected Dep addDep(Location o, Location t) {
    String origin = getLocationName(o);
    String target = getLocationName(t);
    Archive targetArchive = findArchive(t);
    if (curDep != null &&
            curDep.origin().equals(origin) &&
            curDep.originArchive() == archive &&
            curDep.target().equals(target) &&
            curDep.targetArchive() == targetArchive) {
        return curDep;
    }

    Dep e = new Dep(origin, archive, target, targetArchive);
    if (deps.contains(e)) {
        for (Dep e1 : deps) {
            if (e.equals(e1)) {
                curDep = e1;
            }
        }
    } else {
        deps.add(e);
        curDep = e;
    }
    return curDep;
}
 
Example #3
Source File: Analyzer.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected Dep addDep(Location o, Location t) {
    String origin = getLocationName(o);
    String target = getLocationName(t);
    Archive targetArchive = findArchive(t);
    if (curDep != null &&
            curDep.origin().equals(origin) &&
            curDep.originArchive() == archive &&
            curDep.target().equals(target) &&
            curDep.targetArchive() == targetArchive) {
        return curDep;
    }

    Dep e = new Dep(origin, archive, target, targetArchive);
    if (deps.contains(e)) {
        for (Dep e1 : deps) {
            if (e.equals(e1)) {
                curDep = e1;
            }
        }
    } else {
        deps.add(e);
        curDep = e;
    }
    return curDep;
}
 
Example #4
Source File: Analyzer.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visit(Location o, Location t) {
    Archive targetArchive = findArchive(t);
    if (filter.accepts(o, archive, t, targetArchive)) {
        addDep(o, t);
        if (archive != targetArchive && !requires.contains(targetArchive)) {
            requires.add(targetArchive);
        }
    }
    if (targetArchive instanceof JDKArchive) {
        Profile p = Profile.getProfile(t.getPackageName());
        if (profile == null || (p != null && p.compareTo(profile) > 0)) {
            profile = p;
        }
    }
}
 
Example #5
Source File: Analyzer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected Dep addDep(Location o, Location t) {
    String origin = getLocationName(o);
    String target = getLocationName(t);
    Archive targetArchive = findArchive(t);
    if (curDep != null &&
            curDep.origin().equals(origin) &&
            curDep.originArchive() == archive &&
            curDep.target().equals(target) &&
            curDep.targetArchive() == targetArchive) {
        return curDep;
    }

    Dep e = new Dep(origin, archive, target, targetArchive);
    if (deps.contains(e)) {
        for (Dep e1 : deps) {
            if (e.equals(e1)) {
                curDep = e1;
            }
        }
    } else {
        deps.add(e);
        curDep = e;
    }
    return curDep;
}
 
Example #6
Source File: GetDeps.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void addDependency(Dependency d) {
    Location o = (reverse ? d.getTarget() : d.getOrigin());
    SortedSet<Dependency> odeps = map.get(o);
    if (odeps == null) {
        Comparator<Dependency> c = (reverse ? originComparator : targetComparator);
        map.put(o, odeps = new TreeSet<Dependency>(c));
    }
    odeps.add(d);
}
 
Example #7
Source File: Archive.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void visitDependences(Visitor v) {
    for (Map.Entry<Location,Set<Location>> e: deps.entrySet()) {
        for (Location target : e.getValue()) {
            v.visit(e.getKey(), target);
        }
    }
}
 
Example #8
Source File: GetDeps.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
void run(PrintWriter out, String... args) throws IOException, ClassFileNotFoundException {
    decodeArgs(args);

    final StandardJavaFileManager fm = new JavacFileManager(new Context(), false, null);
    if (classpath != null)
        fm.setLocation(StandardLocation.CLASS_PATH, classpath);

    ClassFileReader reader = new ClassFileReader(fm);

    Dependencies d = new Dependencies();

    if (regex != null)
        d.setFilter(Dependencies.getRegexFilter(Pattern.compile(regex)));

    if (packageNames.size() > 0)
        d.setFilter(Dependencies.getPackageFilter(packageNames, false));

    SortedRecorder r = new SortedRecorder(reverse);

    d.findAllDependencies(reader, rootClassNames, transitiveClosure, r);

    SortedMap<Location,SortedSet<Dependency>> deps = r.getMap();
    for (Map.Entry<Location, SortedSet<Dependency>> e: deps.entrySet()) {
        out.println(e.getKey());
        for (Dependency dep: e.getValue()) {
            out.println("    " + dep.getTarget());
        }
    }
}
 
Example #9
Source File: GetDeps.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
void run(PrintWriter out, String... args) throws IOException, ClassFileNotFoundException {
    decodeArgs(args);

    final StandardJavaFileManager fm = new JavacFileManager(new Context(), false, null);
    if (classpath != null)
        fm.setLocation(StandardLocation.CLASS_PATH, classpath);

    ClassFileReader reader = new ClassFileReader(fm);

    Dependencies d = new Dependencies();

    if (regex != null)
        d.setFilter(Dependencies.getRegexFilter(Pattern.compile(regex)));

    if (packageNames.size() > 0)
        d.setFilter(Dependencies.getPackageFilter(packageNames, false));

    SortedRecorder r = new SortedRecorder(reverse);

    d.findAllDependencies(reader, rootClassNames, transitiveClosure, r);

    SortedMap<Location,SortedSet<Dependency>> deps = r.getMap();
    for (Map.Entry<Location, SortedSet<Dependency>> e: deps.entrySet()) {
        out.println(e.getKey());
        for (Dependency dep: e.getValue()) {
            out.println("    " + dep.getTarget());
        }
    }
}
 
Example #10
Source File: Analyzer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private String getLocationName(Location o) {
    if (level == Type.CLASS || level == Type.VERBOSE) {
        return o.getClassName();
    } else {
        String pkg = o.getPackageName();
        return pkg.isEmpty() ? "<unnamed>" : pkg;
    }
}
 
Example #11
Source File: Archive.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void visitDependences(Visitor v) {
    for (Map.Entry<Location,Set<Location>> e: deps.entrySet()) {
        for (Location target : e.getValue()) {
            v.visit(e.getKey(), target);
        }
    }
}
 
Example #12
Source File: Archive.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void visitDependences(Visitor v) {
    for (Map.Entry<Location,Set<Location>> e: deps.entrySet()) {
        for (Location target : e.getValue()) {
            v.visit(e.getKey(), target);
        }
    }
}
 
Example #13
Source File: Analyzer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visit(Location o, Location t) {
    Archive targetArchive =
        this.archive.getClasses().contains(t) ? this.archive : map.get(t);
    if (targetArchive == null) {
        map.put(t, targetArchive = NOT_FOUND);
    }

    String origin = o.getClassName();
    String target = t.getClassName();
    add(origin, target, targetArchive, t.getPackageName());
}
 
Example #14
Source File: JdepsFilter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Filter depending on the containing archive or module
 */
@Override
public boolean accepts(Location origin, Archive originArchive,
                       Location target, Archive targetArchive) {
    if (findJDKInternals) {
        // accepts target that is JDK class but not exported
        Module module = targetArchive.getModule();
        return originArchive != targetArchive &&
                isJDKInternalPackage(module, target.getPackageName());
    } else if (filterSameArchive) {
        // accepts origin and target that from different archive
        return originArchive != targetArchive;
    }
    return true;
}
 
Example #15
Source File: GetDeps.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void addDependency(Dependency d) {
    Location o = (reverse ? d.getTarget() : d.getOrigin());
    SortedSet<Dependency> odeps = map.get(o);
    if (odeps == null) {
        Comparator<Dependency> c = (reverse ? originComparator : targetComparator);
        map.put(o, odeps = new TreeSet<Dependency>(c));
    }
    odeps.add(d);
}
 
Example #16
Source File: Analyzer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private String getLocationName(Location o) {
    if (level == Type.CLASS || level == Type.VERBOSE) {
        return o.getClassName();
    } else {
        String pkg = o.getPackageName();
        return pkg.isEmpty() ? "<unnamed>" : pkg;
    }
}
 
Example #17
Source File: Analyzer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public boolean contains(Location location) {
    String cn = location.getClassName();
    int i = cn.lastIndexOf('.');
    String pn = i > 0 ? cn.substring(0, i) : "";

    return jdk8Internals.contains(pn);
}
 
Example #18
Source File: DependencyFinder.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private Set<Location> waitForTasksCompleted() {
    try {
        Set<Location> targets = new HashSet<>();
        FutureTask<Set<Location>> task;
        while ((task = tasks.poll()) != null) {
            // wait for completion
            if (!task.isDone())
                targets.addAll(task.get());
        }
        return targets;
    } catch (InterruptedException|ExecutionException e) {
        throw new Error(e);
    }
}
 
Example #19
Source File: Analyzer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void buildLocationArchiveMap(List<Archive> archives) {
    // build a map from Location to Archive
    for (Archive archive: archives) {
        for (Location l: archive.getClasses()) {
            if (!map.containsKey(l)) {
                map.put(l, archive);
            } else {
                // duplicated class warning?
            }
        }
    }
}
 
Example #20
Source File: Analyzer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
Archive findArchive(Location t) {
    Archive target = archive.getClasses().contains(t) ? archive : map.get(t);
    if (target == null) {
        map.put(t, target = NOT_FOUND);
    }
    return target;
}
 
Example #21
Source File: Analyzer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
Archive findArchive(Location t) {
    Archive target = archive.getClasses().contains(t) ? archive : map.get(t);
    if (target == null) {
        map.put(t, target = NOT_FOUND);
    }
    return target;
}
 
Example #22
Source File: JdepsTask.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private boolean run() throws IOException {
    // parse classfiles and find all dependencies
    findDependencies();

    Analyzer analyzer = new Analyzer(options.verbose, new Analyzer.Filter() {
        @Override
        public boolean accepts(Location origin, Archive originArchive,
                               Location target, Archive targetArchive)
        {
            if (options.findJDKInternals) {
                // accepts target that is JDK class but not exported
                return isJDKArchive(targetArchive) &&
                          !((JDKArchive) targetArchive).isExported(target.getClassName());
            } else if (options.filterSameArchive) {
                // accepts origin and target that from different archive
                return originArchive != targetArchive;
            }
            return true;
        }
    });

    // analyze the dependencies
    analyzer.run(sourceLocations);

    // output result
    if (options.dotOutputDir != null) {
        Path dir = Paths.get(options.dotOutputDir);
        Files.createDirectories(dir);
        generateDotFiles(dir, analyzer);
    } else {
        printRawOutput(log, analyzer);
    }

    if (options.findJDKInternals && !options.nowarning) {
        showReplacements(analyzer);
    }
    return true;
}
 
Example #23
Source File: Analyzer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void buildLocationArchiveMap(List<Archive> archives) {
    // build a map from Location to Archive
    for (Archive archive: archives) {
        for (Location l: archive.getClasses()) {
            if (!map.containsKey(l)) {
                map.put(l, archive);
            } else {
                // duplicated class warning?
            }
        }
    }
}
 
Example #24
Source File: GetDeps.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void addDependency(Dependency d) {
    Location o = (reverse ? d.getTarget() : d.getOrigin());
    SortedSet<Dependency> odeps = map.get(o);
    if (odeps == null) {
        Comparator<Dependency> c = (reverse ? originComparator : targetComparator);
        map.put(o, odeps = new TreeSet<Dependency>(c));
    }
    odeps.add(d);
}
 
Example #25
Source File: GetDeps.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void run(PrintWriter out, String... args) throws IOException, ClassFileNotFoundException {
    decodeArgs(args);

    final StandardJavaFileManager fm = new JavacFileManager(new Context(), false, null);
    if (classpath != null)
        fm.setLocation(StandardLocation.CLASS_PATH, classpath);

    ClassFileReader reader = new ClassFileReader(fm);

    Dependencies d = new Dependencies();

    if (regex != null)
        d.setFilter(Dependencies.getRegexFilter(Pattern.compile(regex)));

    if (packageNames.size() > 0)
        d.setFilter(Dependencies.getPackageFilter(packageNames, false));

    SortedRecorder r = new SortedRecorder(reverse);

    d.findAllDependencies(reader, rootClassNames, transitiveClosure, r);

    SortedMap<Location,SortedSet<Dependency>> deps = r.getMap();
    for (Map.Entry<Location, SortedSet<Dependency>> e: deps.entrySet()) {
        out.println(e.getKey());
        for (Dependency dep: e.getValue()) {
            out.println("    " + dep.getTarget());
        }
    }
}
 
Example #26
Source File: GetDeps.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void addDependency(Dependency d) {
    Location o = (reverse ? d.getTarget() : d.getOrigin());
    SortedSet<Dependency> odeps = map.get(o);
    if (odeps == null) {
        Comparator<Dependency> c = (reverse ? originComparator : targetComparator);
        map.put(o, odeps = new TreeSet<Dependency>(c));
    }
    odeps.add(d);
}
 
Example #27
Source File: GetDeps.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
void run(PrintWriter out, String... args) throws IOException, ClassFileNotFoundException {
    decodeArgs(args);

    final StandardJavaFileManager fm = new JavacFileManager(new Context(), false, null);
    if (classpath != null)
        fm.setLocation(StandardLocation.CLASS_PATH, classpath);

    ClassFileReader reader = new ClassFileReader(fm);

    Dependencies d = new Dependencies();

    if (regex != null)
        d.setFilter(Dependencies.getRegexFilter(Pattern.compile(regex)));

    if (packageNames.size() > 0)
        d.setFilter(Dependencies.getPackageFilter(packageNames, false));

    SortedRecorder r = new SortedRecorder(reverse);

    d.findAllDependencies(reader, rootClassNames, transitiveClosure, r);

    SortedMap<Location,SortedSet<Dependency>> deps = r.getMap();
    for (Map.Entry<Location, SortedSet<Dependency>> e: deps.entrySet()) {
        out.println(e.getKey());
        for (Dependency dep: e.getValue()) {
            out.println("    " + dep.getTarget());
        }
    }
}
 
Example #28
Source File: GetDeps.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void addDependency(Dependency d) {
    Location o = (reverse ? d.getTarget() : d.getOrigin());
    SortedSet<Dependency> odeps = map.get(o);
    if (odeps == null) {
        Comparator<Dependency> c = (reverse ? originComparator : targetComparator);
        map.put(o, odeps = new TreeSet<Dependency>(c));
    }
    odeps.add(d);
}
 
Example #29
Source File: DependencyFinder.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private Set<Location> parse(Archive archive, Finder finder, String name)
    throws IOException
{
    ClassFile cf = archive.reader().getClassFile(name);
    if (cf == null) {
        throw new IllegalArgumentException(archive.getName() +
            " does not contain " + name);
    }

    if (cf.access_flags.is(AccessFlags.ACC_MODULE))
        return Collections.emptySet();

    Set<Location> targets = new HashSet<>();
    String cn;
    try {
        cn =  cf.getName().replace('/', '.');
    } catch (ConstantPoolException e) {
        throw new Dependencies.ClassFileError(e);
    }

    if (!finder.accept(archive, cn, cf.access_flags))
        return targets;

    // tests if this class matches the -include
    if (!filter.matches(cn))
        return targets;

    // skip checking filter.matches
    for (Dependency d : finder.findDependencies(cf)) {
        if (filter.accepts(d)) {
            targets.add(d.getTarget());
            archive.addClass(d.getOrigin(), d.getTarget());
        } else {
            // ensure that the parsed class is added the archive
            archive.addClass(d.getOrigin());
        }
        parsedClasses.putIfAbsent(d.getOrigin(), archive);
    }
    return targets;
}
 
Example #30
Source File: GetDeps.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
void run(PrintWriter out, String... args) throws IOException, ClassFileNotFoundException {
    decodeArgs(args);

    final StandardJavaFileManager fm = new JavacFileManager(new Context(), false, null);
    if (classpath != null)
        fm.setLocation(StandardLocation.CLASS_PATH, classpath);

    ClassFileReader reader = new ClassFileReader(fm);

    Dependencies d = new Dependencies();

    if (regex != null)
        d.setFilter(Dependencies.getRegexFilter(Pattern.compile(regex)));

    if (packageNames.size() > 0)
        d.setFilter(Dependencies.getPackageFilter(packageNames, false));

    SortedRecorder r = new SortedRecorder(reverse);

    d.findAllDependencies(reader, rootClassNames, transitiveClosure, r);

    SortedMap<Location,SortedSet<Dependency>> deps = r.getMap();
    for (Map.Entry<Location, SortedSet<Dependency>> e: deps.entrySet()) {
        out.println(e.getKey());
        for (Dependency dep: e.getValue()) {
            out.println("    " + dep.getTarget());
        }
    }
}