JDK 11 jdk.jdeps.jmod - JDeps Tool

JDK 11 jdk.jdeps.jmod is the JMOD file for JDK 11 JDeps tool, which can be invoked by the "jdeps" command.

JDK 11 JDeps tool compiled class files are stored in \fyicenter\jdk-11.0.1\jmods\jdk.jdeps.jmod.

JDK 11 JDeps tool compiled class files are also linked and stored in the \fyicenter\jdk-11.0.1\lib\modules JImage file.

JDK 11 JDeps tool source code files are stored in \fyicenter\jdk-11.0.1\lib\src.zip\jdk.jdeps.

You can click and view the content of each source code file in the list below.

✍: FYIcenter

com/sun/tools/jdeprscan/scan/ClassFinder.java

/*
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */

package com.sun.tools.jdeprscan.scan;

import com.sun.tools.classfile.ClassFile;
import com.sun.tools.classfile.ConstantPoolException;

import java.io.IOException;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.stream.Stream;

/**
 * A simple search path for classes.
 */
public class ClassFinder {
    final List<PathEntry> list = new ArrayList<>();
    final boolean verbose;

    public ClassFinder(boolean verbose) {
        this.verbose = verbose;
    }

    /**
     * Adds a directory to this finder's search path, ignoring errors.
     *
     * @param dirName the directory to add
     */
    public void addDir(String dirName) {
        Path dir = Paths.get(dirName);

        if (Files.isDirectory(dir)) {
            list.add(new DirPathEntry(dir));
        }
    }

    /**
     * Adds a jar file to this finder's search path, ignoring errors.
     *
     * @param jarName the jar file name to add
     */
    public void addJar(String jarName) {
        try {
            list.add(new JarPathEntry(new JarFile(jarName)));
        } catch (IOException ignore) { }
    }

    /**
     * Adds the JRT filesystem to this finder's search path.
     */
    public void addJrt() {
        list.add(new JrtPathEntry());
    }

    /**
     * Searches the class path for a class with the given name,
     * returning a ClassFile for it. Returns null if not found.
     *
     * @param className the class to search for
     * @return a ClassFile instance, or null if not found
     */
    public ClassFile find(String className) {
        for (PathEntry pe : list) {
            ClassFile cf = pe.find(className);
            if (cf != null) {
                return cf;
            }
        }
        return null;
    }

    /**
     * An entry in this finder's class path.
     */
    interface PathEntry {
        /**
         * Returns a ClassFile instance corresponding to this name,
         * or null if it's not present in this entry.
         *
         * @param className the class to search for
         * @return a ClassFile instance, or null if not found
         */
        ClassFile find(String className);
    }

    /**
     * An entry that represents a jar file.
     */
    class JarPathEntry implements PathEntry {
        final JarFile jarFile;

        JarPathEntry(JarFile jf) {
            jarFile = jf;
        }

        @Override
        public ClassFile find(String className) {
            JarEntry entry = jarFile.getJarEntry(className + ".class");
            if (entry == null) {
                return null;
            }
            try {
                return ClassFile.read(jarFile.getInputStream(entry));
            } catch (IOException | ConstantPoolException ex) {
                if (verbose) {
                    ex.printStackTrace();
                }
            }
            return null;
        }
    }

    /**
     * An entry that represents a directory containing a class hierarchy.
     */
    class DirPathEntry implements PathEntry {
        final Path dir;

        DirPathEntry(Path dir) {
            this.dir = dir;
        }

        @Override
        public ClassFile find(String className) {
            Path classFileName = dir.resolve(className + ".class");
            try {
                return ClassFile.read(classFileName);
            } catch (NoSuchFileException nsfe) {
                // not found, return silently
            } catch (IOException | ConstantPoolException ex) {
                if (verbose) {
                    ex.printStackTrace();
                }
            }
            return null;
        }
    }

    /**
     * An entry that represents the JRT filesystem in the running image.
     *
     * JRT filesystem structure is:
     *     /packages/<dotted-pkgname>/<modlink>
     * where modlink is a symbolic link to /modules/<modname> which is
     * the top of the usual package-class hierarchy
     */
    class JrtPathEntry implements PathEntry {
        final FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));

        @Override
        public ClassFile find(String className) {
            int end = className.lastIndexOf('/');
            if (end < 0) {
                return null;
            }
            String pkg = "/packages/" + className.substring(0, end)
                                                 .replace('/', '.');
            try (Stream<Path> mods = Files.list(fs.getPath(pkg))) {
                Optional<Path> opath =
                    mods.map(path -> path.resolve(className + ".class"))
                        .filter(Files::exists)
                        .findFirst();
                if (opath.isPresent()) {
                    return ClassFile.read(opath.get());
                } else {
                    return null;
                }
            } catch (NoSuchFileException nsfe) {
                // not found, return silently
            } catch (IOException | ConstantPoolException ex) {
                if (verbose) {
                    ex.printStackTrace();
                }
            }
            return null;
        }
    }
}

com/sun/tools/jdeprscan/scan/ClassFinder.java

 

JDK 11 jdk.jdi.jmod - JDI Tool

JDK 11 jdk.jconsole.jmod - JConsole Tool

Download and Use JDK 11

⇑⇑ FAQ for JDK (Java Development Kit)

2020-07-07, 5282👍, 0💬