8003562: Provide a command-line tool to find static dependencies
Mandy Chung
mandy.chung at oracle.com
Tue Dec 4 12:15:29 PST 2012
Alan - thanks for the feedback. I have made several changes to the jdeps
tool. Here is the new webrev at:
http://cr.openjdk.java.net/~mchung/jdk8/webrevs/8003562/langtools-webrev.01/
I'll send out a formal code review request once I add the new unit tests.
$ jdeps -h
Usage: jdeps <options> <files....>
where possible options include:
-version Version information
-classpath <path> Specify where to find class files
-v --verbose Print class-level dependencies
-v:class Print class-level dependencies
-v:package Print package-level dependencies
-v:summary Print dependency summary
-p <package name> Restrict analysis to classes in this package
(may be given multiple times)
-e <regex> Restrict analysis to packages matching pattern
(-p and -e are exclusive)
-P --profile Show profile or the file containing a package
-r --recursive Traverse all dependencies recursively
-d <depth> Specify the depth of the transitive
dependency analysis
-r option is equivalent to setting depth to 0.
-all Process all classes specified in -classpath
Changes include:
1. Added -v:class, -v:package and -v:summary options to select the
dependency output
The default is package-level dependency. -v:summary only shows the
dependencies across the boundaries in the given classpath or files.
$ jdeps -classpath jfxrt.jar -v:summaryEnsemble.jar
Ensemble.jar -> jfxrt.jar
Ensemble.jar -> rt.jar
2. If only -classpath is given (taken from the -classpath in launching
the application) but no input file, -all can be used to process all
class files from the given classpath.
3. The output is now grouped by each input file/dir/jar file. By
default, it will show the source of the dependency if it's coming from
the given classpath or input files. Use -P to show the Profile and
platform information.
4. -r option is repurposed for finding transitive dependencies
recursively. I concur with Alan that --reverse is not needed since it
only changes the output but not the dependency analysis. To find the
usage of a specific class/package, -p and -e options can be used to
diagnose dependency issue.
Mandy
On 11/27/12 3:18 PM, Mandy Chung wrote:
> As part of prepare for modules [1], this RFE is to provide a
> command-line tool in JDK8 so that developers can understand the static
> dependencies of their applications and libraries.As part of Project
> Jigsaw, a useful class analyzer [2] was developed that makes it very
> easy to identify the dependencies based on the classfile library
> thathas also been enhanced to support dependency analysis [3].
>
> Inspired by the sample tool that Jon Gibbons developed, we propose
> this new command-line name as "jdeps".
>
> $ ./bin/jdeps -h
> Usage: jdeps <options> <files....>
> where possible options include:
> -version Version information
> -classpath <path> Specify where to find class files
> -v --verbose Print class-level dependencies
> -r --reverse Invert the dependencies in the output
> -p Restrict analysis to classes in this package
> (may be given multiple times)
> -e --regex Restrict analysis to packages matching pattern
> (-p and -e are exclusive)
> -P --profile Show profile or the file containing a package
> -d --depth Specify the depth of the transitive
> dependency analysis
> Default depth is 1. Set depth to 0 to
> traverse all dependencies.
> -all Show all classes and members with no breakdown
>
> The jdeps tool shows package-level dependencies of the input files
> that can be .class files, a directory, or a JAR file. Specify the
> depth for the transitive dependency analysis; otherwise, it only
> analyzes the input files. jdeps -P option will show where the
> class/package comes from. For Java SE API, it will show the Profile
> name (I implement a workaround for now until the profile work is in
> jdk8). For JDK internal APIs, they will not be exported in modular
> world. jdeps will indicate any usage of the JDK internal APIs in the
> output to help developers prepare for transitioning to modules.
>
> See below for a few sample output.
>
> Webrev at:
> http://cr.openjdk.java.net/~mchung/jdk8/webrevs/8003562/
>
> The implementation classes for jdeps are in the langtools repo along
> with the com.sun.tools.classfile library. I'm working on adding more
> unit tests. I'd like to get this webrev out to begin the discussion
> and get review feedback.
>
> Thanks
> Mandy
> [1] http://openjdk.java.net/jeps/162
> [2]
> http://hg.openjdk.java.net/jigsaw/jigsaw/jdk/raw-file/543b0d24a920/make/tools/classanalyzer/classanalyzer.html
> [3] http://bugs.sun.com/view_bug.do?bug_id=6907575
More information about the compiler-dev
mailing list