classpathhelper.search
Class JarFinder

java.lang.Object
  extended byclasspathhelper.search.JarFinder

public class JarFinder
extends java.lang.Object

Class that looks for jars relative to a root directory. The searching can optionally skip a provided classpath, in effect returning jars not on the classpath.

Usage


 JarFinder jarFinder = new JarFinder();
 File[] jars = jarFinder.findJarsUnderDir( new File("root"));
 // or, to ignore jars already on a classpath
 File[] jars2 = jarFinder.findJarsUnderDir( new File("root"), "jar1;jar2");
 

Since:
1.2
Author:
bharris

Constructor Summary
JarFinder()
           
 
Method Summary
 java.io.File[] findJarsUnderDir(java.io.File dir)
          Finds jar files under the root dir.
protected  void findJarsUnderDir(java.io.File dir, java.util.Collection ignore, java.util.Set retVal)
          Internal method that handles the recursion of searching for jars.
 java.io.File[] findJarsUnderDir(java.io.File dir, java.lang.String ignoreClassPath)
          Finds jar files under the root dir, ignoring jars on the supplied classpath.
protected  java.util.Collection parsePath(java.lang.String path)
          Internal method that parses a classpath like string into a collection of file objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JarFinder

public JarFinder()
Method Detail

findJarsUnderDir

public java.io.File[] findJarsUnderDir(java.io.File dir)
                                throws java.io.IOException
Finds jar files under the root dir.

Parameters:
dir - The root directory.
Returns:
An array of file objects corresponding to the jar files.
Throws:
java.io.IOException - If any I/O related errors occur.
Since:
1.2

findJarsUnderDir

public java.io.File[] findJarsUnderDir(java.io.File dir,
                                       java.lang.String ignoreClassPath)
                                throws java.io.IOException
Finds jar files under the root dir, ignoring jars on the supplied classpath.

Parameters:
dir - The root directory.
ignoreClassPath - A classpath string containing jars that will be ignored (class directories on classpath are also ignored).
Returns:
An array of file objects corresponding to the jar files.
Throws:
java.io.IOException - If any I/O related errors occur.
Since:
1.2

findJarsUnderDir

protected void findJarsUnderDir(java.io.File dir,
                                java.util.Collection ignore,
                                java.util.Set retVal)
                         throws java.io.IOException
Internal method that handles the recursion of searching for jars. Called by both findJarsUnderDir methods.

Parameters:
dir - The root directory.
ignore - A collection of File objects that represent files we will ignore.
retVal - The return value where found jar files will be added.
Throws:
java.io.IOException - If any I/O related errors occur.
Since:
1.2

parsePath

protected java.util.Collection parsePath(java.lang.String path)
Internal method that parses a classpath like string into a collection of file objects.

Parameters:
path - The class path. (directory/files seperated by File.pathSeparator).
Returns:
A collection of file objects corresponding to the class path.
Since:
1.2