nl.toolforge.karma.core.cmd.util
Class DependencyHelper

java.lang.Object
  extended bynl.toolforge.karma.core.cmd.util.DependencyHelper

public final class DependencyHelper
extends java.lang.Object

Dependency management is heavily used by Karma. This helper class provides methods to resolve dependencies, check them, etc.

Version:
$Id: DependencyHelper.java,v 1.28 2004/11/16 22:28:02 hippe Exp $
Author:
D.A. Smedes

Field Summary
static java.lang.String MODULE_DEPENDENCIES_PROPERTIES
           
 
Constructor Summary
DependencyHelper(Manifest currentManifest)
           
 
Method Summary
 void createModuleDependenciesFilter(Module module)
          Create a properties file that contains mappings from module name to module name plus version.
 java.util.Set getAllDependencies(Module module, boolean doTest, boolean doPackage)
           
 java.util.Set getAllLevels(Module module)
          Traverses the modules' dependencies, and traverses all module dependencies as well (recursively), calculating the set of dependencies that are unique.
 java.lang.String getClassPath(Module module)
          Returns the classpath for module, or an empty String if no dependencies exist.
 java.util.Set getJarDependencies(Module module, boolean doPackage)
          Gets a Set of DependencyPaths, each one identifying a jar-file.
 java.util.Set getModuleDependencies(Module module, boolean doTest, boolean doPackage)
          Gets a Set of DependencyPaths, each one identifying the path to a module dependency (a dependency of module to another Module).
 java.util.Set getModuleDependencies(Module module, boolean doTest, boolean doPackage, Module.Type moduleType)
          Gets a Set of DependencyPaths, each one identifying the path to a module dependency (a dependency of module to another Module).
 java.lang.String getTestClassPath(Module module)
          Returns the classpath for module, or an empty String if no dependencies exist.
 boolean hasModuleDependency(Module module, Module dependency, boolean doPackage)
          Check whether a certain module has an other module as a dependency.
 java.lang.String resolveArchiveName(Module module)
          Determines the correct archive name for module.
 java.lang.String resolveArtifactName(Module module)
          Determines the correct artifact name for module.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODULE_DEPENDENCIES_PROPERTIES

public static final java.lang.String MODULE_DEPENDENCIES_PROPERTIES
See Also:
Constant Field Values
Constructor Detail

DependencyHelper

public DependencyHelper(Manifest currentManifest)
Method Detail

getClassPath

public java.lang.String getClassPath(Module module)
                              throws ModuleTypeException,
                                     DependencyException
Returns the classpath for module, or an empty String if no dependencies exist.

Parameters:
module - The module for which a classpath should be determined.
Returns:
See method description.
Throws:
ModuleTypeException
DependencyException

getTestClassPath

public java.lang.String getTestClassPath(Module module)
                                  throws ModuleTypeException,
                                         DependencyException
Returns the classpath for module, or an empty String if no dependencies exist.

The classpath consists of:

Parameters:
module - The module for which the test classpath should be determined.
Returns:
See method description.
Throws:
ModuleTypeException
DependencyException

getAllDependencies

public java.util.Set getAllDependencies(Module module,
                                        boolean doTest,
                                        boolean doPackage)
                                 throws ModuleTypeException,
                                        DependencyException
Throws:
ModuleTypeException
DependencyException

getModuleDependencies

public java.util.Set getModuleDependencies(Module module,
                                           boolean doTest,
                                           boolean doPackage,
                                           Module.Type moduleType)
                                    throws ModuleTypeException,
                                           DependencyException
Gets a Set of DependencyPaths, each one identifying the path to a module dependency (a dependency of module to another Module).

Parameters:
module - The module for which a dependency-path should be determined.
doTest - Whether to include test resources for all deps.
doPackage - Whether to include only the deps that are to be packaged or all deps.
moduleType - Only return modules of the specified type. Return all types when null.
Returns:
See method description.
Throws:
DependencyException - When a dependency for a module is not available.
ModuleTypeException

getModuleDependencies

public java.util.Set getModuleDependencies(Module module,
                                           boolean doTest,
                                           boolean doPackage)
                                    throws ModuleTypeException,
                                           DependencyException
Gets a Set of DependencyPaths, each one identifying the path to a module dependency (a dependency of module to another Module).

Parameters:
module - The module for which a dependency-path should be determined.
doTest - Whether to include test resources for all deps.
doPackage - Whether to include only the deps that are to be packaged or all deps.
Returns:
See method description.
Throws:
DependencyException - When a dependency for a module is not available.
ModuleTypeException

createModuleDependenciesFilter

public void createModuleDependenciesFilter(Module module)
                                    throws DependencyException
Create a properties file that contains mappings from module name to module name plus version. E.g. karma-core -> karma-core_0-1.

The properties file is called 'module-dependencies.properties' and is stored in the build directory of the given module.

Throws:
DependencyException

hasModuleDependency

public boolean hasModuleDependency(Module module,
                                   Module dependency,
                                   boolean doPackage)
Check whether a certain module has an other module as a dependency.

Parameters:
module - The module for which is checked whether it has dependency as a dependency.
dependency - The module for which to check whether it is a dependency of the current module.
doPackage - Whether to include only the deps that are to be packaged or all deps.
Returns:
Whether the given module had the other given module as a dependency.

getJarDependencies

public java.util.Set getJarDependencies(Module module,
                                        boolean doPackage)
                                 throws DependencyException

Gets a Set of DependencyPaths, each one identifying a jar-file. Jar files are looked up Maven-style (see ModuleDependency.

Parameters:
module - The module for which jar dependencies should be determined.
doPackage - Indicate if the dependencies that are to be packaged (<package="true">) should be included (true) or all dependencies should be included (false).
Returns:
A Set containing DependencyPaths
Throws:
DependencyException - When a jar dependency is not phsyically available on disk. A check is performed on the existence of the jar file in either the local jar repository (WorkingContext.getLocalRepository()) or in the lib module that is specified as being part of the manifest.

resolveArtifactName

public java.lang.String resolveArtifactName(Module module)
                                     throws DependencyException
Determines the correct artifact name for module. The artifact-name is determined as follows:

Parameters:
module - The module for which to determine the artifact name.
Returns:
The artifact name
Throws:
DependencyException

resolveArchiveName

public java.lang.String resolveArchiveName(Module module)
                                    throws ModuleTypeException,
                                           DependencyException

Determines the correct archive name for module. The archive name is determined as follows:

The extension is .war if the module is a webapp-module and .ear if the module is an eapp-module

Parameters:
module - A SourceModule instance.
Returns:
The archive-name as determined the way as described above.
Throws:
ModuleTypeException
DependencyException

getAllLevels

public java.util.Set getAllLevels(Module module)
                           throws ManifestException,
                                  DependencyException
Traverses the modules' dependencies, and traverses all module dependencies as well (recursively), calculating the set of dependencies that are unique. A dependency is not unique if the artifact-name already exists in the set but with another version. This will result in a DependencyException.

Parameters:
module -
Returns:
A Set containing all dependencies, all the way down to the lowest
Throws:
ManifestException
DependencyException


Copyright © 2002-2004 Toolforge. All Rights Reserved.