net.sf.taverna.raven.repository.impl
Class LocalRepository

java.lang.Object
  extended by net.sf.taverna.raven.repository.impl.LocalRepository
All Implemented Interfaces:
Repository

public class LocalRepository
extends java.lang.Object
implements Repository

Represents the state of a local Maven2 repository on disk. Manages the queue of pending fetches. Create an instance of this class using the static getRepository(File base) method passing it the location of the on disk maven2 repository to access or create.

Author:
Tom Oinn

Method Summary
 void addArtifact(Artifact a1)
          Add a new artifact to this repository.
 void addRemoteRepository(java.net.URL repositoryURL)
          Add a reference to a remote repository to be used to fetch pom and jar files.
 void addRepositoryListener(RepositoryListener l)
          Add a new repository listener to be notified of status changes within this Repository implementation
 Artifact artifactForClass(java.lang.Class<?> c)
          Given a Class object return the Artifact whose LocalArtifactClassLoader created it.
 void clean()
          Clean the local repository by removing invalid artifacts and directories.
 java.util.List<Artifact> getArtifacts()
          Return all Artifacts within this repository
 java.util.List<Artifact> getArtifacts(ArtifactStatus s)
          Return all artifacts with the specified ArtifactStatus
 DownloadStatus getDownloadStatus(Artifact a)
          If the artifact specified is in either PomFetching or JarFetching state this returns a DownloadStatus object which provides a non updating snapshot of the file size (if known) and total bytes downloaded.
 java.lang.ClassLoader getLoader(Artifact a1, java.lang.ClassLoader parent)
          Get a ClassLoader for the specified artifact
static Repository getRepository(java.io.File base)
          Get a new or cached instance of LocalRepository for the supplied base directory, this is the method to use when you want to get hold of a Repository.
static Repository getRepository(java.io.File base, java.lang.ClassLoader loader, java.util.Set<Artifact> systemArtifacts)
          Get a new or cached instance of LocalRepository.
 ArtifactStatus getStatus(Artifact a)
          Status for a given Artifact
 java.io.File jarFile(Artifact a)
          File object for JAR for the specified artifact.
 void prependRemoteRepository(java.net.URL repositoryURL)
          Adds a remote repository, but adds it at the start of the list.
 void removeRepositoryListener(RepositoryListener l)
          Remove a listener from the list of interested observers
 java.lang.String toString()
           
 void update()
          Scan the status table, perform actions on each item based on the status.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getRepository

public static Repository getRepository(java.io.File base)
Get a new or cached instance of LocalRepository for the supplied base directory, this is the method to use when you want to get hold of a Repository.

Parameters:
base - The base directory for the m2 repository on disk
Returns:
Repository instance for the base directory

getRepository

public static Repository getRepository(java.io.File base,
                                       java.lang.ClassLoader loader,
                                       java.util.Set<Artifact> systemArtifacts)
Get a new or cached instance of LocalRepository. If the instance is created then use the supplied ClassLoader for the specified set of Artifacts should they be required.


addArtifact

public void addArtifact(Artifact a1)
Description copied from interface: Repository
Add a new artifact to this repository. If the artifact already exists no action will be taken, otherwise it will be created and given the status ArtifactStatus.Queued

Specified by:
addArtifact in interface Repository
Parameters:
a1 - Artifact to query status

addRemoteRepository

public void addRemoteRepository(java.net.URL repositoryURL)
Description copied from interface: Repository
Add a reference to a remote repository to be used to fetch pom and jar files. Repositories are scanned in turn until a match is found.

Specified by:
addRemoteRepository in interface Repository

addRepositoryListener

public void addRepositoryListener(RepositoryListener l)
Add a new repository listener to be notified of status changes within this Repository implementation

Specified by:
addRepositoryListener in interface Repository

artifactForClass

public Artifact artifactForClass(java.lang.Class<?> c)
                          throws ArtifactNotFoundException
Given a Class object return the Artifact whose LocalArtifactClassLoader created it. If the classloader was not an instance of LocalArtifactClassLoader then return null

Specified by:
artifactForClass in interface Repository
Throws:
ArtifactNotFoundException

clean

public void clean()
Clean the local repository by removing invalid artifacts and directories.

Empty directories will always be removed.


getArtifacts

public java.util.List<Artifact> getArtifacts()
Return all Artifacts within this repository

Specified by:
getArtifacts in interface Repository
Returns:
a copy of the current list of all known Artifacts within the Repository

getArtifacts

public java.util.List<Artifact> getArtifacts(ArtifactStatus s)
Return all artifacts with the specified ArtifactStatus

Specified by:
getArtifacts in interface Repository
Returns:
a list of all known Artifacts with the given ArtifactStatus within this Repository

getDownloadStatus

public DownloadStatus getDownloadStatus(Artifact a)
                                 throws ArtifactStateException,
                                        ArtifactNotFoundException
If the artifact specified is in either PomFetching or JarFetching state this returns a DownloadStatus object which provides a non updating snapshot of the file size (if known) and total bytes downloaded. The intent is to use this for progress bars within any client GUI code.

Specified by:
getDownloadStatus in interface Repository
Parameters:
a - Artifact to get status for
Returns:
DownloadStatus object representing the state of the current download for this artifact
Throws:
ArtifactNotFoundException - if this repository doesn't contain the specified artifact.
ArtifactStateException - if the artifact is found but isn't involved in a download at the present time.

getLoader

public java.lang.ClassLoader getLoader(Artifact a1,
                                       java.lang.ClassLoader parent)
                                throws ArtifactNotFoundException,
                                       ArtifactStateException
Description copied from interface: Repository
Get a ClassLoader for the specified artifact

Specified by:
getLoader in interface Repository
Parameters:
a1 - The artifact to set up the classloader for
parent - Optional parent ClassLoader, may be null for no parent
Returns:
ClassLoader for the specified artifact
Throws:
ArtifactNotFoundException
ArtifactStateException

getStatus

public ArtifactStatus getStatus(Artifact a)
Status for a given Artifact

Specified by:
getStatus in interface Repository
Parameters:
a - Artifact to get status for
Returns:
ArtifactStatus representing the state of the artifact within this repository, or ArtifactStatus.Unknown if there is no such artifact

jarFile

public java.io.File jarFile(Artifact a)
File object for JAR for the specified artifact. Note that this file might be outside #artifactDir(Artifact) as it could have been found in a local repository by fetchLocal(ArtifactImpl, String).


prependRemoteRepository

public void prependRemoteRepository(java.net.URL repositoryURL)
Adds a remote repository, but adds it at the start of the list. This is used by Plugins that specify their repositories that we know need to be checked first.

Parameters:
repositoryURL -

removeRepositoryListener

public void removeRepositoryListener(RepositoryListener l)
Description copied from interface: Repository
Remove a listener from the list of interested observers

Specified by:
removeRepositoryListener in interface Repository

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

update

public void update()
Description copied from interface: Repository
Scan the status table, perform actions on each item based on the status. If an item is Queued then start downloading the POM If the item has a downloaded POM then parse it, add any unknown dependencies to the status with Queued state and start downloading the jar file If the item has a jar file then traverse dependencies and determine whether all transitive dependencies are satisfied in which case mark as Ready state Repeat this until all dependencies are resolved or failed

Specified by:
update in interface Repository