org.schmant.project.java
Class JavaProjectDependencies

java.lang.Object
  extended by org.schmant.support.AbstractArgumentChecker
      extended by org.schmant.project.java.JavaProjectDependencies
All Implemented Interfaces:
Observer, ProjectDependencies, TaskDependency

public class JavaProjectDependencies
extends AbstractArgumentChecker
implements ProjectDependencies, Observer

This is a ProjectDependencies implementation for handling compile dependencies between JavaProject:s.

In addition to the dependency handling defined in ProjectDependencies, it also keeps tracks of the directories where each project's class files are stored. The class file directory is registered by the build script by calling registerClassDirectory(JavaProject, Object) or registerClassDirectories(JavaProject, Collection). Later on they are retrieved when compiling the dependent project by giving its compile task a JavaProjectClasspathDecorator.

See the user's guide for an example.

Since:
0.5
Author:
Karl Gustafsson

Constructor Summary
JavaProjectDependencies()
           
 
Method Summary
 Collection<Object> getClassDirectories()
          Get all registered class directories
 Collection<Object> getClassDirectories(JavaProject p)
          Get the directories for built classes for the specified project.
 Collection<? extends TaskDependency> getDependencies(Project p)
          Get dependency objects for the given project.
 Observable getDependencyObservable()
          Observable that will fire with the dependency as argument when all dependencies are satisfied.
 Lock getSatisfiedStateLock()
          Get the Lock that protects the dependency's satisfied property.
 boolean isSatisfied()
          Is this dependency satisfied?
 void registerClassDirectories(JavaProject p, Collection<?> c)
          Register a collection of class directories for a Java project.
 void registerClassDirectory(JavaProject p, Object d)
          Register one class directory for a Java project.
 void registerDependency(Project p, TaskDependency d)
          Register a dependency for a project.
 void update(Observable obs, Object o)
           
 
Methods inherited from class org.schmant.support.AbstractArgumentChecker
check, check, check, check
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaProjectDependencies

public JavaProjectDependencies()
Method Detail

registerDependency

public void registerDependency(Project p,
                               TaskDependency d)
Description copied from interface: ProjectDependencies
Register a dependency for a project. When the registered dependency flags that it is satisfied, that project's dependency is satisfied. Use this to register the actual dependencies for a project.

Specified by:
registerDependency in interface ProjectDependencies

getClassDirectories

public Collection<Object> getClassDirectories(JavaProject p)
Get the directories for built classes for the specified project.

Parameters:
p - The project.
Returns:
The directories where the project's built class files are (or will end up).

getClassDirectories

public Collection<Object> getClassDirectories()
Get all registered class directories

Returns:
All registered class directories.

registerClassDirectory

public void registerClassDirectory(JavaProject p,
                                   Object d)
Register one class directory for a Java project.

Parameters:
p - The project.
d - The class directory.

registerClassDirectories

public void registerClassDirectories(JavaProject p,
                                     Collection<?> c)
Register a collection of class directories for a Java project.

Parameters:
p - The project.
c - The collection of directories.

getDependencies

public Collection<? extends TaskDependency> getDependencies(Project p)
Description copied from interface: ProjectDependencies
Get dependency objects for the given project. A project dependency object fires when all the project's registered dependencies have been satisfied.

Specified by:
getDependencies in interface ProjectDependencies
Parameters:
p - The project
Returns:
Dependency objects for all the projects that the supplied project depends on. When all dependency objects have fired, the project's dependencies are satisfied. The objects returned are not objects that have been registered with ProjectDependencies.registerDependency(Project, TaskDependency).

update

public void update(Observable obs,
                   Object o)
Specified by:
update in interface Observer

isSatisfied

public boolean isSatisfied()
Description copied from interface: TaskDependency
Is this dependency satisfied?

Implementation note: This method should be protected by the same lock that can be retrieved by calling TaskDependency.getSatisfiedStateLock().

Specified by:
isSatisfied in interface TaskDependency
Returns:
true if the dependency is satisfied.

getSatisfiedStateLock

public Lock getSatisfiedStateLock()
Description copied from interface: TaskDependency
Get the Lock that protects the dependency's satisfied property. This lock must be locked before the dependency's satisfied state can be update.

An external class can lock this to ensure that the satisfied state is not updated while it holds the lock.

Specified by:
getSatisfiedStateLock in interface TaskDependency
Returns:
The lock used to protect the satisfied state.
See Also:
TaskDependency.isSatisfied()

getDependencyObservable

public Observable getDependencyObservable()
Description copied from interface: TaskDependency
Observable that will fire with the dependency as argument when all dependencies are satisfied.

Implementation note: The thread firing an event must own the satisfied state lock on the task dependency object.

Specified by:
getDependencyObservable in interface TaskDependency
Returns:
An Observable to observe.