org.apache.archiva.metadata.repository.file
Class FileMetadataRepository

java.lang.Object
  extended by org.apache.archiva.metadata.repository.file.FileMetadataRepository
All Implemented Interfaces:
MetadataRepository

public class FileMetadataRepository
extends Object
implements MetadataRepository


Nested Class Summary
private static class FileMetadataRepository.ArtifactComparator
           
 
Field Summary
private  ArchivaConfiguration configuration
           
private  org.slf4j.Logger log
           
private static String METADATA_KEY
           
private  Map<String,MetadataFacetFactory> metadataFacetFactories
           
private static String NAMESPACE_METADATA_KEY
           
private static String PROJECT_METADATA_KEY
           
private static String PROJECT_VERSION_METADATA_KEY
           
 
Constructor Summary
FileMetadataRepository(Map<String,MetadataFacetFactory> metadataFacetFactories, ArchivaConfiguration configuration)
           
 
Method Summary
 void addMetadataFacet(String repositoryId, MetadataFacet metadataFacet)
           
 boolean canObtainAccess(Class<?> aClass)
           
private static void clearMetadataFacetProperties(Collection<MetadataFacet> facetList, Properties properties, String prefix)
           
 void close()
           
private  void getArtifacts(List<ArtifactMetadata> artifacts, String repoId, String ns)
           
 List<ArtifactMetadata> getArtifacts(String repoId)
           
 Collection<ArtifactMetadata> getArtifacts(String repoId, String namespace, String projectId, String projectVersion)
           
private  void getArtifactsByChecksum(List<ArtifactMetadata> artifacts, String repositoryId, String ns, String checksum)
           
 List<ArtifactMetadata> getArtifactsByChecksum(String repositoryId, String checksum)
           
private  void getArtifactsByDateRange(List<ArtifactMetadata> artifacts, String repoId, String ns, Date startTime, Date endTime)
           
 List<ArtifactMetadata> getArtifactsByDateRange(String repoId, Date startTime, Date endTime)
          if startTime or endTime are null they are not used for search
 Collection<String> getArtifactVersions(String repoId, String namespace, String projectId, String projectVersion)
           
private  File getBaseDirectory(String repoId)
           
private  File getDirectory(String repoId)
           
private  File getMetadataDirectory(String repoId, String facetId)
           
 MetadataFacet getMetadataFacet(String repositoryId, String facetId, String name)
           
 List<String> getMetadataFacets(String repoId, String facetId)
           
 Collection<String> getNamespaces(String repoId, String baseNamespace)
           
 ProjectMetadata getProject(String repoId, String namespace, String projectId)
          basically just checking it exists not complete data returned
 Collection<ProjectVersionReference> getProjectReferences(String repoId, String namespace, String projectId, String projectVersion)
          Retrieve project references from the metadata repository.
 Collection<String> getProjects(String repoId, String namespace)
           
 ProjectVersionMetadata getProjectVersion(String repoId, String namespace, String projectId, String projectVersion)
           
 Collection<String> getProjectVersions(String repoId, String namespace, String projectId)
           
 Collection<String> getRepositories()
           
 Collection<String> getRootNamespaces(String repoId)
           
 boolean hasMetadataFacet(String repositoryId, String facetId)
           
private  String join(Collection<String> ids)
           
<T> T
obtainAccess(Class<T> aClass)
           
private  Properties readOrCreateProperties(File directory, String propertiesKey)
           
private  Properties readProperties(File directory, String propertiesKey)
           
private  void recurse(List<String> facets, String prefix, File directory)
           
 void removeArtifact(ArtifactMetadata artifactMetadata, String baseVersion)
          used for deleting timestamped version of SNAPSHOT artifacts
 void removeArtifact(String repositoryId, String namespace, String project, String projectVersion, MetadataFacet metadataFacet)
          FIXME implements this !!!!
 void removeArtifact(String repoId, String namespace, String project, String version, String id)
           
 void removeMetadataFacet(String repoId, String facetId, String name)
           
 void removeMetadataFacets(String repositoryId, String facetId)
           
 void removeNamespace(String repositoryId, String project)
           
 void removeProject(String repositoryId, String namespace, String projectId)
          remove a project
 void removeProjectVersion(String repoId, String namespace, String projectId, String projectVersion)
           
 void removeRepository(String repoId)
          Delete a repository's metadata.
 void revert()
          implementations can throw RuntimeException
 void save()
          implementations can throw RuntimeException
private  void setProperty(Properties properties, String name, String value)
           
 void updateArtifact(String repoId, String namespace, String projectId, String projectVersion, ArtifactMetadata artifact)
           
private  void updateArtifactFacets(ArtifactMetadata artifact, Properties properties)
           
 void updateNamespace(String repoId, String namespace)
          create the namespace in the repository.
 void updateProject(String repoId, ProjectMetadata project)
          Update metadata for a particular project in the metadata repository, or create it if it does not already exist.
private  void updateProject(String repoId, String namespace, String id)
           
private  void updateProjectReference(String repoId, String namespace, String projectId, String projectVersion, ProjectVersionReference reference)
           
 void updateProjectVersion(String repoId, String namespace, String projectId, ProjectVersionMetadata versionMetadata)
           
private  void updateProjectVersionFacets(ProjectVersionMetadata versionMetadata, Properties properties)
           
private  void writeProperties(Properties properties, File directory, String propertiesKey)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

metadataFacetFactories

private final Map<String,MetadataFacetFactory> metadataFacetFactories

configuration

private final ArchivaConfiguration configuration

log

private org.slf4j.Logger log

PROJECT_METADATA_KEY

private static final String PROJECT_METADATA_KEY
See Also:
Constant Field Values

PROJECT_VERSION_METADATA_KEY

private static final String PROJECT_VERSION_METADATA_KEY
See Also:
Constant Field Values

NAMESPACE_METADATA_KEY

private static final String NAMESPACE_METADATA_KEY
See Also:
Constant Field Values

METADATA_KEY

private static final String METADATA_KEY
See Also:
Constant Field Values
Constructor Detail

FileMetadataRepository

public FileMetadataRepository(Map<String,MetadataFacetFactory> metadataFacetFactories,
                              ArchivaConfiguration configuration)
Method Detail

getBaseDirectory

private File getBaseDirectory(String repoId)

getDirectory

private File getDirectory(String repoId)

updateProject

public void updateProject(String repoId,
                          ProjectMetadata project)
Description copied from interface: MetadataRepository
Update metadata for a particular project in the metadata repository, or create it if it does not already exist.

Specified by:
updateProject in interface MetadataRepository
Parameters:
repoId - the repository the project is in
project - the project metadata to create or update

updateProject

private void updateProject(String repoId,
                           String namespace,
                           String id)

updateProjectVersion

public void updateProjectVersion(String repoId,
                                 String namespace,
                                 String projectId,
                                 ProjectVersionMetadata versionMetadata)
Specified by:
updateProjectVersion in interface MetadataRepository

updateProjectVersionFacets

private void updateProjectVersionFacets(ProjectVersionMetadata versionMetadata,
                                        Properties properties)

clearMetadataFacetProperties

private static void clearMetadataFacetProperties(Collection<MetadataFacet> facetList,
                                                 Properties properties,
                                                 String prefix)

updateProjectReference

private void updateProjectReference(String repoId,
                                    String namespace,
                                    String projectId,
                                    String projectVersion,
                                    ProjectVersionReference reference)

updateNamespace

public void updateNamespace(String repoId,
                            String namespace)
Description copied from interface: MetadataRepository
create the namespace in the repository. (if not exist)

Specified by:
updateNamespace in interface MetadataRepository

getMetadataFacets

public List<String> getMetadataFacets(String repoId,
                                      String facetId)
Specified by:
getMetadataFacets in interface MetadataRepository

hasMetadataFacet

public boolean hasMetadataFacet(String repositoryId,
                                String facetId)
                         throws MetadataRepositoryException
Specified by:
hasMetadataFacet in interface MetadataRepository
Returns:
true if the repository datas for this facetId
Throws:
MetadataRepositoryException

recurse

private void recurse(List<String> facets,
                     String prefix,
                     File directory)

getMetadataFacet

public MetadataFacet getMetadataFacet(String repositoryId,
                                      String facetId,
                                      String name)
Specified by:
getMetadataFacet in interface MetadataRepository

addMetadataFacet

public void addMetadataFacet(String repositoryId,
                             MetadataFacet metadataFacet)
Specified by:
addMetadataFacet in interface MetadataRepository

removeMetadataFacets

public void removeMetadataFacets(String repositoryId,
                                 String facetId)
Specified by:
removeMetadataFacets in interface MetadataRepository

removeMetadataFacet

public void removeMetadataFacet(String repoId,
                                String facetId,
                                String name)
Specified by:
removeMetadataFacet in interface MetadataRepository

getArtifactsByDateRange

public List<ArtifactMetadata> getArtifactsByDateRange(String repoId,
                                                      Date startTime,
                                                      Date endTime)
Description copied from interface: MetadataRepository
if startTime or endTime are null they are not used for search

Specified by:
getArtifactsByDateRange in interface MetadataRepository
startTime - can be null
endTime - can be null
Returns:

getArtifactsByDateRange

private void getArtifactsByDateRange(List<ArtifactMetadata> artifacts,
                                     String repoId,
                                     String ns,
                                     Date startTime,
                                     Date endTime)

getArtifacts

public Collection<ArtifactMetadata> getArtifacts(String repoId,
                                                 String namespace,
                                                 String projectId,
                                                 String projectVersion)
Specified by:
getArtifacts in interface MetadataRepository

save

public void save()
Description copied from interface: MetadataRepository
implementations can throw RuntimeException

Specified by:
save in interface MetadataRepository

close

public void close()
Specified by:
close in interface MetadataRepository

revert

public void revert()
Description copied from interface: MetadataRepository
implementations can throw RuntimeException

Specified by:
revert in interface MetadataRepository

canObtainAccess

public boolean canObtainAccess(Class<?> aClass)
Specified by:
canObtainAccess in interface MetadataRepository

obtainAccess

public <T> T obtainAccess(Class<T> aClass)
Specified by:
obtainAccess in interface MetadataRepository

updateArtifactFacets

private void updateArtifactFacets(ArtifactMetadata artifact,
                                  Properties properties)

getRepositories

public Collection<String> getRepositories()
Specified by:
getRepositories in interface MetadataRepository

getArtifactsByChecksum

public List<ArtifactMetadata> getArtifactsByChecksum(String repositoryId,
                                                     String checksum)
Specified by:
getArtifactsByChecksum in interface MetadataRepository

removeNamespace

public void removeNamespace(String repositoryId,
                            String project)
                     throws MetadataRepositoryException
Specified by:
removeNamespace in interface MetadataRepository
project - (groupId for maven )
Throws:
MetadataRepositoryException

removeArtifact

public void removeArtifact(ArtifactMetadata artifactMetadata,
                           String baseVersion)
                    throws MetadataRepositoryException
Description copied from interface: MetadataRepository
used for deleting timestamped version of SNAPSHOT artifacts

Specified by:
removeArtifact in interface MetadataRepository
Parameters:
artifactMetadata - the artifactMetadata with the timestamped version (2.0-20120618.214135-2)
baseVersion - the base version of the snapshot (2.0-SNAPSHOT)
Throws:
MetadataRepositoryException

removeArtifact

public void removeArtifact(String repoId,
                           String namespace,
                           String project,
                           String version,
                           String id)
Specified by:
removeArtifact in interface MetadataRepository

removeArtifact

public void removeArtifact(String repositoryId,
                           String namespace,
                           String project,
                           String projectVersion,
                           MetadataFacet metadataFacet)
                    throws MetadataRepositoryException
FIXME implements this !!!!

Specified by:
removeArtifact in interface MetadataRepository
Parameters:
repositoryId -
namespace -
project -
projectVersion -
metadataFacet - will remove artifacts which have this MetadataFacet using equals
Throws:
MetadataRepositoryException

removeRepository

public void removeRepository(String repoId)
Description copied from interface: MetadataRepository
Delete a repository's metadata. This includes all associated metadata facets.

Specified by:
removeRepository in interface MetadataRepository
Parameters:
repoId - the repository to delete

getArtifactsByChecksum

private void getArtifactsByChecksum(List<ArtifactMetadata> artifacts,
                                    String repositoryId,
                                    String ns,
                                    String checksum)

getMetadataDirectory

private File getMetadataDirectory(String repoId,
                                  String facetId)

join

private String join(Collection<String> ids)

setProperty

private void setProperty(Properties properties,
                         String name,
                         String value)

updateArtifact

public void updateArtifact(String repoId,
                           String namespace,
                           String projectId,
                           String projectVersion,
                           ArtifactMetadata artifact)
Specified by:
updateArtifact in interface MetadataRepository

readOrCreateProperties

private Properties readOrCreateProperties(File directory,
                                          String propertiesKey)

readProperties

private Properties readProperties(File directory,
                                  String propertiesKey)
                           throws IOException
Throws:
IOException

getProject

public ProjectMetadata getProject(String repoId,
                                  String namespace,
                                  String projectId)
Description copied from interface: MetadataRepository
basically just checking it exists not complete data returned

Specified by:
getProject in interface MetadataRepository
Returns:

getProjectVersion

public ProjectVersionMetadata getProjectVersion(String repoId,
                                                String namespace,
                                                String projectId,
                                                String projectVersion)
Specified by:
getProjectVersion in interface MetadataRepository

getArtifactVersions

public Collection<String> getArtifactVersions(String repoId,
                                              String namespace,
                                              String projectId,
                                              String projectVersion)
Specified by:
getArtifactVersions in interface MetadataRepository

getProjectReferences

public Collection<ProjectVersionReference> getProjectReferences(String repoId,
                                                                String namespace,
                                                                String projectId,
                                                                String projectVersion)
Description copied from interface: MetadataRepository
Retrieve project references from the metadata repository. Note that this is not built into the content model for a project version as a reference may be present (due to reverse-lookup of dependencies) before the actual project is, and we want to avoid adding a stub model to the content repository.

Specified by:
getProjectReferences in interface MetadataRepository
Parameters:
repoId - the repository ID to look within
namespace - the namespace of the project to get references to
projectId - the identifier of the project to get references to
projectVersion - the version of the project to get references to
Returns:
a list of project references

getRootNamespaces

public Collection<String> getRootNamespaces(String repoId)
Specified by:
getRootNamespaces in interface MetadataRepository

getNamespaces

public Collection<String> getNamespaces(String repoId,
                                        String baseNamespace)
Specified by:
getNamespaces in interface MetadataRepository

getProjects

public Collection<String> getProjects(String repoId,
                                      String namespace)
Specified by:
getProjects in interface MetadataRepository

getProjectVersions

public Collection<String> getProjectVersions(String repoId,
                                             String namespace,
                                             String projectId)
Specified by:
getProjectVersions in interface MetadataRepository

removeProject

public void removeProject(String repositoryId,
                          String namespace,
                          String projectId)
                   throws MetadataRepositoryException
Description copied from interface: MetadataRepository
remove a project

Specified by:
removeProject in interface MetadataRepository
Throws:
MetadataRepositoryException

removeProjectVersion

public void removeProjectVersion(String repoId,
                                 String namespace,
                                 String projectId,
                                 String projectVersion)
                          throws MetadataRepositoryException
Specified by:
removeProjectVersion in interface MetadataRepository
Throws:
MetadataRepositoryException

writeProperties

private void writeProperties(Properties properties,
                             File directory,
                             String propertiesKey)
                      throws IOException
Throws:
IOException

getArtifacts

public List<ArtifactMetadata> getArtifacts(String repoId)
Specified by:
getArtifacts in interface MetadataRepository

getArtifacts

private void getArtifacts(List<ArtifactMetadata> artifacts,
                          String repoId,
                          String ns)


Copyright © 2006-2013 The Apache Software Foundation. All Rights Reserved.