Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

DependencyChecker



The DependencyChecker check if a Jar file or a JarDependencies has dependencies to a set of packages or classes.

Basic usage

The basic usage of the checker uses one of the following methods:
By default sub-packages of the classes or packages specified for the check are considered in the check.

Examples

   Set<String> set = new HashSet<>();
   set.add("java.util");
   DependencyChecker checker = new DependencyChecker();
   boolean dependsOn = checker.check(<myJarFile>, set);
   Set<String> set = new HashSet<>();
   set.add("java.util.List");
   DependencyChecker checker = new DependencyChecker();
   boolean dependsOn = checker.check(<myJarFile>, set);

Non-strict check

Several methods of the checker allow to specify if sub-packages of the classes or packages specified for the check are considered in the check: For example:
   Set<String> set = new HashSet<>();
   set.add("java.awt");
   DependencyChecker checker = new DependencyChecker();
   boolean dependsOn = checker.check(<myJarFile>, set, false); // sub-packages of java.awt will not be considered

Excluding classes

It is possible to exclude classes from the check in the packages specified for the check. To allow to exclude some packages, you need to use the PackagePath class.

Examples

This example will check the dependencies from the java.awt.geom package, excluding the java.awt.geom.Area Class:
   PackagePath awt = new PackagePath("java.awt.geom");
   awt.excludeClass("java.awt.geom.Area");
   DependencyChecker checker = new DependencyChecker();
   boolean dependsOn = checker.checkPackages(<myJarFile>, awt);
This other example will check the dependencies from both the java.awt.geom and javax.swing packages, excluding the java.awt.geom.Area Class:
   Set<String> excluded = new HashSet<>();
   set.add("java.awt.geom.Area");
   Set<PackagePath> awtgeom = PackagePath.createPackagePathsFromArray(excluded, "java.awt.geom", "javax.swing");    
   DependencyChecker checker = new DependencyChecker();
   boolean dependsOn = checker.checkPackages(<myJarFile>, awtgeom);

See also


Categories: General

Copyright 2019 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 licence