Refactoring ManagedRepositoryContent

This commit is contained in:
Martin Stockhammer 2020-02-10 23:21:32 +01:00
parent 13856a6060
commit f6f495d494
16 changed files with 568 additions and 170 deletions

View File

@ -234,6 +234,10 @@ protected void purge( Set<ArtifactReference> references )
{ {
log.warn( "skip error deleting artifact {}: {}", reference, e.getMessage( ) ); log.warn( "skip error deleting artifact {}: {}", reference, e.getMessage( ) );
} }
catch ( org.apache.archiva.repository.ContentAccessException e )
{
e.printStackTrace( );
}
boolean snapshotVersion = VersionUtil.isSnapshot( reference.getVersion( ) ); boolean snapshotVersion = VersionUtil.isSnapshot( reference.getVersion( ) );

View File

@ -181,6 +181,10 @@ public void process( String path )
{ {
log.error( "Could not remove metadata during cleanup of released snapshots of {}", path, e ); log.error( "Could not remove metadata during cleanup of released snapshots of {}", path, e );
} }
catch ( org.apache.archiva.repository.ContentAccessException e )
{
e.printStackTrace( );
}
} }

View File

@ -115,7 +115,7 @@ public void process( String path )
{ {
if ( newArtifactFile.getModificationTime().toEpochMilli() < olderThanThisDate.getTimeInMillis( ) ) if ( newArtifactFile.getModificationTime().toEpochMilli() < olderThanThisDate.getTimeInMillis( ) )
{ {
artifactsToDelete.addAll( repository.getRelatedArtifacts( newArtifactReference ) ); artifactsToDelete.addAll( repository.getRelatedArtifacts( repository.toVersion(newArtifactReference) ) );
} }
} }
// Is this a timestamp snapshot "1.0-20070822.123456-42" ? // Is this a timestamp snapshot "1.0-20070822.123456-42" ?
@ -125,7 +125,7 @@ else if ( VersionUtil.isUniqueSnapshot( newArtifactReference.getVersion( ) ) )
if ( timestampCal.getTimeInMillis( ) < olderThanThisDate.getTimeInMillis( ) ) if ( timestampCal.getTimeInMillis( ) < olderThanThisDate.getTimeInMillis( ) )
{ {
artifactsToDelete.addAll( repository.getRelatedArtifacts( newArtifactReference ) ); artifactsToDelete.addAll( repository.getRelatedArtifacts( repository.toVersion(newArtifactReference) ) );
} }
} }
} }
@ -139,6 +139,10 @@ else if ( VersionUtil.isUniqueSnapshot( newArtifactReference.getVersion( ) ) )
{ {
log.debug( "Not processing file that is not an artifact: {}", e.getMessage( ) ); log.debug( "Not processing file that is not an artifact: {}", e.getMessage( ) );
} }
catch ( org.apache.archiva.repository.ContentAccessException e )
{
e.printStackTrace( );
}
} }
private Calendar uniqueSnapshotToCalendar( String version ) private Calendar uniqueSnapshotToCalendar( String version )

View File

@ -94,7 +94,8 @@ public void process( String path )
{ {
break; break;
} }
artifactsToDelete.addAll( repository.getRelatedArtifacts( getNewArtifactReference( artifact, version ) ) ); VersionedReference ref = repository.toVersion( getNewArtifactReference( artifact, version ) );
artifactsToDelete.addAll( repository.getRelatedArtifacts( ref ) );
} }
purge( artifactsToDelete ); purge( artifactsToDelete );
} }
@ -107,6 +108,10 @@ public void process( String path )
{ {
log.error( "Repostory artifact not found {}", path ); log.error( "Repostory artifact not found {}", path );
} }
catch ( org.apache.archiva.repository.ContentAccessException e )
{
e.printStackTrace( );
}
} }
/* /*

View File

@ -20,8 +20,8 @@
*/ */
/** /**
* ContentNotFoundException is thrown in response for requests for content that is not the repository.
* *
* ContentNotFoundException is thrown in response for requests for content that is not in the repository.
* *
*/ */
public class ContentNotFoundException public class ContentNotFoundException

View File

@ -48,7 +48,15 @@ public interface ManagedRepositoryContent extends RepositoryContent
VersionedReference toVersion( String groupId, String artifactId, String version ); VersionedReference toVersion( String groupId, String artifactId, String version );
/** /**
* Return the version reference the artifact is part of. * Returns the version reference that represents the generic version, which means that
* snapshot versions are converted to <VERSION>-SNAPSHOT
* @param artifactReference the artifact reference
* @return the generic version
*/
VersionedReference toGenericVersion( ArtifactReference artifactReference );
/**
* Return the version reference that matches exactly the version string of the artifact
* *
* @param artifactReference The artifact reference * @param artifactReference The artifact reference
* @return the version reference * @return the version reference
@ -75,7 +83,7 @@ public interface ManagedRepositoryContent extends RepositoryContent
* @throws ContentNotFoundException * @throws ContentNotFoundException
*/ */
void deleteVersion( VersionedReference reference ) void deleteVersion( VersionedReference reference )
throws ContentNotFoundException; throws ContentNotFoundException, ContentAccessException;
/** /**
* delete a specified artifact from the repository * delete a specified artifact from the repository
@ -84,7 +92,7 @@ void deleteVersion( VersionedReference reference )
* @throws ContentNotFoundException * @throws ContentNotFoundException
*/ */
void deleteArtifact( ArtifactReference artifactReference ) void deleteArtifact( ArtifactReference artifactReference )
throws ContentNotFoundException; throws ContentNotFoundException, ContentAccessException;
/** /**
* @param groupId * @param groupId
@ -92,7 +100,7 @@ void deleteArtifact( ArtifactReference artifactReference )
* @since 1.4-M3 * @since 1.4-M3
*/ */
void deleteGroupId( String groupId ) void deleteGroupId( String groupId )
throws ContentNotFoundException; throws ContentNotFoundException, ContentAccessException;
/** /**
* *
@ -101,7 +109,15 @@ void deleteGroupId( String groupId )
* @throws ContentNotFoundException * @throws ContentNotFoundException
*/ */
void deleteProject( String namespace, String projectId ) void deleteProject( String namespace, String projectId )
throws RepositoryException; throws ContentNotFoundException, ContentAccessException;
/**
* Deletes a project
* @param reference
*/
void deleteProject(ProjectReference reference) throws ContentNotFoundException, ContentAccessException;
/** /**
* <p> * <p>
@ -115,6 +131,26 @@ void deleteProject( String namespace, String projectId )
*/ */
String getId(); String getId();
/**
* <p>
* Gather up the list of related artifacts to the ArtifactReference provided.
* If type and / or classifier of the reference is set, this returns only a list of artifacts that is directly
* related to the given artifact, like checksums.
* If type and classifier is <code>null</code> it will return the same artifacts as
* {@link #getRelatedArtifacts(VersionedReference)}
* </p>
* <p>
* <strong>NOTE:</strong> Some layouts (such as maven 1 "legacy") are not compatible with this query.
* </p>
*
* @param reference the reference to work off of.
* @return the list of ArtifactReferences for related artifacts, if
* @throws ContentNotFoundException if the initial artifact reference does not exist within the repository.
* @see #getRelatedArtifacts(VersionedReference)
*/
List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
throws ContentNotFoundException, LayoutException, ContentAccessException;
/** /**
* <p> * <p>
* Gather up the list of related artifacts to the ArtifactReference provided. * Gather up the list of related artifacts to the ArtifactReference provided.
@ -130,9 +166,8 @@ void deleteProject( String namespace, String projectId )
* @return the list of ArtifactReferences for related artifacts, if * @return the list of ArtifactReferences for related artifacts, if
* @throws ContentNotFoundException if the initial artifact reference does not exist within the repository. * @throws ContentNotFoundException if the initial artifact reference does not exist within the repository.
*/ */
List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference ) List<ArtifactReference> getRelatedArtifacts( VersionedReference reference )
throws ContentNotFoundException, LayoutException; throws ContentNotFoundException, LayoutException, ContentAccessException;
/** /**
* Returns all the assets that belong to a given artifact type. The list returned contain * Returns all the assets that belong to a given artifact type. The list returned contain
* all the files that correspond to the given artifact reference. * all the files that correspond to the given artifact reference.
@ -142,14 +177,14 @@ List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
* @param reference * @param reference
* @return * @return
*/ */
List<StorageAsset> getRelatedAssets(ArtifactReference reference) throws ContentNotFoundException, LayoutException; List<StorageAsset> getRelatedAssets(ArtifactReference reference) throws ContentNotFoundException, LayoutException, ContentAccessException;
/** /**
* Returns all artifacts that belong to a given version * Returns all artifacts that belong to a given version
* @param reference the version reference * @param reference the version reference
* @return the list of artifacts or a empty list * @return the list of artifacts or a empty list
*/ */
List<ArtifactReference> getArtifacts(VersionedReference reference) throws ContentNotFoundException, LayoutException; List<ArtifactReference> getArtifacts(VersionedReference reference) throws ContentNotFoundException, LayoutException, ContentAccessException;
@ -184,7 +219,7 @@ List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
* @throws LayoutException * @throws LayoutException
*/ */
Set<String> getVersions( ProjectReference reference ) Set<String> getVersions( ProjectReference reference )
throws ContentNotFoundException, LayoutException; throws ContentNotFoundException, LayoutException, ContentAccessException;
@ -202,7 +237,7 @@ Set<String> getVersions( ProjectReference reference )
* @throws ContentNotFoundException if the versioned reference does not exist within the repository. * @throws ContentNotFoundException if the versioned reference does not exist within the repository.
*/ */
Set<String> getVersions( VersionedReference reference ) Set<String> getVersions( VersionedReference reference )
throws ContentNotFoundException; throws ContentNotFoundException, ContentAccessException, LayoutException;
/** /**
* Determines if the artifact referenced exists in the repository. * Determines if the artifact referenced exists in the repository.
@ -210,7 +245,7 @@ Set<String> getVersions( VersionedReference reference )
* @param reference the artifact reference to check for. * @param reference the artifact reference to check for.
* @return true if the artifact referenced exists. * @return true if the artifact referenced exists.
*/ */
boolean hasContent( ArtifactReference reference ); boolean hasContent( ArtifactReference reference ) throws ContentAccessException;
/** /**
* Determines if the project referenced exists in the repository. * Determines if the project referenced exists in the repository.
@ -218,7 +253,7 @@ Set<String> getVersions( VersionedReference reference )
* @param reference the project reference to check for. * @param reference the project reference to check for.
* @return true it the project referenced exists. * @return true it the project referenced exists.
*/ */
boolean hasContent( ProjectReference reference ); boolean hasContent( ProjectReference reference ) throws ContentAccessException;
/** /**
* Determines if the version reference exists in the repository. * Determines if the version reference exists in the repository.
@ -226,7 +261,7 @@ Set<String> getVersions( VersionedReference reference )
* @param reference the version reference to check for. * @param reference the version reference to check for.
* @return true if the version referenced exists. * @return true if the version referenced exists.
*/ */
boolean hasContent( VersionedReference reference ); boolean hasContent( VersionedReference reference ) throws ContentAccessException;
/** /**
* Set the repository configuration to associate with this * Set the repository configuration to associate with this
@ -236,6 +271,14 @@ Set<String> getVersions( VersionedReference reference )
*/ */
void setRepository( ManagedRepository repo ); void setRepository( ManagedRepository repo );
/**
* Given an {@link ArtifactReference}, return the file reference to the artifact.
*
* @param reference the artifact reference to use.
* @return the relative path to the artifact.
*/
StorageAsset toFile( VersionedReference reference );
/** /**
* Given an {@link ArtifactReference}, return the file reference to the artifact. * Given an {@link ArtifactReference}, return the file reference to the artifact.
* *

View File

@ -43,13 +43,11 @@
import org.apache.archiva.repository.LayoutException; import org.apache.archiva.repository.LayoutException;
import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.RemoteRepositoryContent; import org.apache.archiva.repository.RemoteRepositoryContent;
import org.apache.archiva.repository.Repository;
import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.RepositoryType; import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.metadata.MetadataReader; import org.apache.archiva.repository.metadata.MetadataReader;
import org.apache.archiva.repository.metadata.RepositoryMetadataException; import org.apache.archiva.repository.metadata.RepositoryMetadataException;
import org.apache.archiva.repository.storage.StorageAsset; import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.xml.XMLException;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.math.NumberUtils;
@ -148,7 +146,15 @@ public Set<String> gatherSnapshotVersions( ManagedRepositoryContent managedRepos
VersionedReference reference ) VersionedReference reference )
throws LayoutException, IOException, ContentNotFoundException throws LayoutException, IOException, ContentNotFoundException
{ {
Set<String> foundVersions = managedRepository.getVersions( reference ); Set<String> foundVersions = null;
try
{
foundVersions = managedRepository.getVersions( reference );
}
catch ( org.apache.archiva.repository.ContentAccessException e )
{
e.printStackTrace( );
}
// Next gather up the referenced 'latest' versions found in any proxied repositories // Next gather up the referenced 'latest' versions found in any proxied repositories
// maven-metadata-${proxyId}.xml files that may be present. // maven-metadata-${proxyId}.xml files that may be present.
@ -519,7 +525,15 @@ public void updateMetadata( ManagedRepositoryContent managedRepository, ProjectR
metadata.setArtifactId( reference.getArtifactId() ); metadata.setArtifactId( reference.getArtifactId() );
// Gather up all versions found in the managed repository. // Gather up all versions found in the managed repository.
Set<String> allVersions = managedRepository.getVersions( reference ); Set<String> allVersions = null;
try
{
allVersions = managedRepository.getVersions( reference );
}
catch ( org.apache.archiva.repository.ContentAccessException e )
{
e.printStackTrace( );
}
// Gather up all plugins found in the managed repository. // Gather up all plugins found in the managed repository.
// TODO: do we know this information instead? // TODO: do we know this information instead?

View File

@ -23,11 +23,11 @@
import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.model.ProjectReference; import org.apache.archiva.model.ProjectReference;
import org.apache.archiva.model.VersionedReference; import org.apache.archiva.model.VersionedReference;
import org.apache.archiva.repository.ContentAccessException;
import org.apache.archiva.repository.ContentNotFoundException; import org.apache.archiva.repository.ContentNotFoundException;
import org.apache.archiva.repository.LayoutException; import org.apache.archiva.repository.LayoutException;
import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.storage.StorageAsset; import org.apache.archiva.repository.storage.StorageAsset;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -48,6 +48,12 @@ public VersionedReference toVersion( String groupId, String artifactId, String v
return null; return null;
} }
@Override
public VersionedReference toGenericVersion( ArtifactReference artifactReference )
{
return null;
}
@Override @Override
public VersionedReference toVersion( ArtifactReference artifactReference ) public VersionedReference toVersion( ArtifactReference artifactReference )
{ {
@ -61,25 +67,31 @@ public ArtifactReference toArtifact( String groupId, String artifactId, String v
} }
@Override @Override
public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException
{ {
} }
@Override @Override
public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException, ContentAccessException
{ {
} }
@Override @Override
public void deleteGroupId( String groupId ) throws ContentNotFoundException public void deleteGroupId( String groupId ) throws ContentNotFoundException, ContentAccessException
{ {
} }
@Override @Override
public void deleteProject( String namespace, String projectId ) throws RepositoryException public void deleteProject( String namespace, String projectId ) throws ContentNotFoundException, ContentAccessException
{
}
@Override
public void deleteProject( ProjectReference reference ) throws ContentNotFoundException, ContentAccessException
{ {
} }
@ -91,19 +103,25 @@ public String getId( )
} }
@Override @Override
public List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException, LayoutException public List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{ {
return null; return null;
} }
@Override @Override
public List<StorageAsset> getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException public List<ArtifactReference> getRelatedArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{ {
return null; return null;
} }
@Override @Override
public List<ArtifactReference> getArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException public List<StorageAsset> getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{
return null;
}
@Override
public List<ArtifactReference> getArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{ {
return null; return null;
} }
@ -121,31 +139,31 @@ public ManagedRepository getRepository( )
} }
@Override @Override
public Set<String> getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException public Set<String> getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{ {
return null; return null;
} }
@Override @Override
public Set<String> getVersions( VersionedReference reference ) throws ContentNotFoundException public Set<String> getVersions( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException, LayoutException
{ {
return null; return null;
} }
@Override @Override
public boolean hasContent( ArtifactReference reference ) public boolean hasContent( ArtifactReference reference ) throws ContentAccessException
{ {
return false; return false;
} }
@Override @Override
public boolean hasContent( ProjectReference reference ) public boolean hasContent( ProjectReference reference ) throws ContentAccessException
{ {
return false; return false;
} }
@Override @Override
public boolean hasContent( VersionedReference reference ) public boolean hasContent( VersionedReference reference ) throws ContentAccessException
{ {
return false; return false;
} }
@ -156,6 +174,12 @@ public void setRepository( ManagedRepository repo )
this.repository = repo; this.repository = repo;
} }
@Override
public StorageAsset toFile( VersionedReference reference )
{
return null;
}
@Override @Override
public ArtifactReference toArtifactReference( String path ) throws LayoutException public ArtifactReference toArtifactReference( String path ) throws LayoutException
{ {

View File

@ -64,6 +64,12 @@ public VersionedReference toVersion( String groupId, String artifactId, String v
return null; return null;
} }
@Override
public VersionedReference toGenericVersion( ArtifactReference artifactReference )
{
return null;
}
@Override @Override
public VersionedReference toVersion( ArtifactReference artifactReference ) public VersionedReference toVersion( ArtifactReference artifactReference )
{ {
@ -77,25 +83,31 @@ public ArtifactReference toArtifact( String groupId, String artifactId, String v
} }
@Override @Override
public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException
{ {
} }
@Override @Override
public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException, ContentAccessException
{ {
} }
@Override @Override
public void deleteGroupId( String groupId ) throws ContentNotFoundException public void deleteGroupId( String groupId ) throws ContentNotFoundException, ContentAccessException
{ {
} }
@Override @Override
public void deleteProject( String namespace, String projectId ) throws RepositoryException public void deleteProject( String namespace, String projectId ) throws ContentNotFoundException, ContentAccessException
{
}
@Override
public void deleteProject( ProjectReference reference ) throws ContentNotFoundException, ContentAccessException
{ {
} }
@ -107,19 +119,25 @@ public String getId( )
} }
@Override @Override
public List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException, LayoutException public List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{ {
return null; return null;
} }
@Override @Override
public List<StorageAsset> getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException public List<ArtifactReference> getRelatedArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{ {
return null; return null;
} }
@Override @Override
public List<ArtifactReference> getArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException public List<StorageAsset> getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{
return null;
}
@Override
public List<ArtifactReference> getArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{ {
return null; return null;
} }
@ -148,31 +166,31 @@ public ManagedRepository getRepository( )
} }
@Override @Override
public Set<String> getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException public Set<String> getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{ {
return null; return null;
} }
@Override @Override
public Set<String> getVersions( VersionedReference reference ) throws ContentNotFoundException public Set<String> getVersions( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException, LayoutException
{ {
return null; return null;
} }
@Override @Override
public boolean hasContent( ArtifactReference reference ) public boolean hasContent( ArtifactReference reference ) throws ContentAccessException
{ {
return false; return false;
} }
@Override @Override
public boolean hasContent( ProjectReference reference ) public boolean hasContent( ProjectReference reference ) throws ContentAccessException
{ {
return false; return false;
} }
@Override @Override
public boolean hasContent( VersionedReference reference ) public boolean hasContent( VersionedReference reference ) throws ContentAccessException
{ {
return false; return false;
} }
@ -183,6 +201,12 @@ public void setRepository( ManagedRepository repo )
this.repository = repo; this.repository = repo;
} }
@Override
public StorageAsset toFile( VersionedReference reference )
{
return null;
}
private Map<ArtifactReference, String> refs = new HashMap<>(); private Map<ArtifactReference, String> refs = new HashMap<>();
@Override @Override

View File

@ -68,6 +68,12 @@ public VersionedReference toVersion( String groupId, String artifactId, String v
return null; return null;
} }
@Override
public VersionedReference toGenericVersion( ArtifactReference artifactReference )
{
return null;
}
@Override @Override
public VersionedReference toVersion( ArtifactReference artifactReference ) public VersionedReference toVersion( ArtifactReference artifactReference )
{ {
@ -81,25 +87,31 @@ public ArtifactReference toArtifact( String groupId, String artifactId, String v
} }
@Override @Override
public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException
{ {
} }
@Override @Override
public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException, ContentAccessException
{ {
} }
@Override @Override
public void deleteGroupId( String groupId ) throws ContentNotFoundException public void deleteGroupId( String groupId ) throws ContentNotFoundException, ContentAccessException
{ {
} }
@Override @Override
public void deleteProject( String namespace, String projectId ) throws RepositoryException public void deleteProject( String namespace, String projectId ) throws ContentNotFoundException, ContentAccessException
{
}
@Override
public void deleteProject( ProjectReference reference ) throws ContentNotFoundException, ContentAccessException
{ {
} }
@ -111,19 +123,25 @@ public String getId( )
} }
@Override @Override
public List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException, LayoutException public List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{ {
return null; return null;
} }
@Override @Override
public List<StorageAsset> getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException public List<ArtifactReference> getRelatedArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{ {
return null; return null;
} }
@Override @Override
public List<ArtifactReference> getArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException public List<StorageAsset> getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{
return null;
}
@Override
public List<ArtifactReference> getArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{ {
return null; return null;
} }
@ -152,31 +170,31 @@ public ManagedRepository getRepository( )
} }
@Override @Override
public Set<String> getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException public Set<String> getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{ {
return null; return null;
} }
@Override @Override
public Set<String> getVersions( VersionedReference reference ) throws ContentNotFoundException public Set<String> getVersions( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException, LayoutException
{ {
return null; return null;
} }
@Override @Override
public boolean hasContent( ArtifactReference reference ) public boolean hasContent( ArtifactReference reference ) throws ContentAccessException
{ {
return false; return false;
} }
@Override @Override
public boolean hasContent( ProjectReference reference ) public boolean hasContent( ProjectReference reference ) throws ContentAccessException
{ {
return false; return false;
} }
@Override @Override
public boolean hasContent( VersionedReference reference ) public boolean hasContent( VersionedReference reference ) throws ContentAccessException
{ {
return false; return false;
} }
@ -187,6 +205,12 @@ public void setRepository( ManagedRepository repo )
this.repository = repo; this.repository = repo;
} }
@Override
public StorageAsset toFile( VersionedReference reference )
{
return null;
}
private Map<ArtifactReference, String> refs = new HashMap<>(); private Map<ArtifactReference, String> refs = new HashMap<>();
@Override @Override

View File

@ -20,7 +20,6 @@
*/ */
import org.apache.archiva.common.filelock.FileLockManager; import org.apache.archiva.common.filelock.FileLockManager;
import org.apache.archiva.common.utils.PathUtil;
import org.apache.archiva.common.utils.VersionUtil; import org.apache.archiva.common.utils.VersionUtil;
import org.apache.archiva.configuration.FileTypes; import org.apache.archiva.configuration.FileTypes;
import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider; import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
@ -29,12 +28,12 @@
import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.model.ProjectReference; import org.apache.archiva.model.ProjectReference;
import org.apache.archiva.model.VersionedReference; import org.apache.archiva.model.VersionedReference;
import org.apache.archiva.repository.ContentAccessException;
import org.apache.archiva.repository.ContentNotFoundException; import org.apache.archiva.repository.ContentNotFoundException;
import org.apache.archiva.repository.EditableManagedRepository; import org.apache.archiva.repository.EditableManagedRepository;
import org.apache.archiva.repository.LayoutException; import org.apache.archiva.repository.LayoutException;
import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.storage.StorageAsset; import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -44,10 +43,10 @@
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -94,11 +93,13 @@ public ManagedDefaultRepositoryContent( ManagedRepository repository, List<? ext
*/ */
@Override @Override
public VersionedReference toVersion( String groupId, String artifactId, String version ) { public VersionedReference toVersion( String groupId, String artifactId, String version ) {
VersionedReference ref = new VersionedReference(); return new VersionedReference().groupId( groupId ).artifactId( artifactId ).version( version );
ref.setGroupId(groupId); }
ref.setArtifactId(artifactId);
ref.setVersion(version); @Override
return ref; public VersionedReference toGenericVersion( ArtifactReference artifactReference )
{
return toVersion( artifactReference.getGroupId( ), artifactReference.getArtifactId( ), VersionUtil.getBaseVersion( artifactReference.getVersion( ) ));
} }
/** /**
@ -107,102 +108,133 @@ public VersionedReference toVersion( String groupId, String artifactId, String v
* @return * @return
*/ */
public VersionedReference toVersion( ArtifactReference artifactReference) { public VersionedReference toVersion( ArtifactReference artifactReference) {
return toVersion( artifactReference.getGroupId( ), artifactReference.getArtifactId( ), VersionUtil.getBaseVersion( artifactReference.getVersion( ) )); return toVersion( artifactReference.getGroupId( ), artifactReference.getArtifactId( ), artifactReference.getVersion( ) );
} }
@Override @Override
public ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier) { public ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier) {
ArtifactReference ar = new ArtifactReference( ); return new ArtifactReference( ).groupId( groupId ).artifactId( artifactId ).version( version ).type( type ).classifier( classifier );
ar.setGroupId( groupId );
ar.setArtifactId( artifactId );
ar.setVersion( version );
ar.setType( type );
ar.setClassifier( classifier );
return ar;
} }
@Override @Override
public void deleteVersion( VersionedReference reference ) public void deleteVersion( VersionedReference ref ) throws ContentNotFoundException, ContentAccessException
{ {
Path projectDir = getRepoDir().resolve(toPath(reference)); final String path = toPath( ref );
if ( Files.exists(projectDir) && Files.isDirectory(projectDir) ) final Path deleteTarget = getRepoDir().resolve(path);
if ( !Files.exists(deleteTarget) )
{ {
org.apache.archiva.common.utils.FileUtils.deleteQuietly( projectDir ); log.warn( "Version path for repository {} does not exist: {}", getId(), deleteTarget );
throw new ContentNotFoundException( "Version not found for repository "+getId()+": "+path );
} }
} if ( Files.isDirectory(deleteTarget) )
@Override
public void deleteProject( String namespace, String projectId )
throws RepositoryException
{
ProjectReference ref = new ProjectReference( );
ref.setGroupId( namespace );
ref.setArtifactId( projectId );
Path projDirectory = getRepoDir( ).resolve( toPath(ref) );
if ( !Files.exists(projDirectory) )
{
throw new ContentNotFoundException( "cannot found project " + namespace + ":" + projectId );
}
if ( Files.isDirectory(projDirectory) )
{ {
try try
{ {
org.apache.archiva.common.utils.FileUtils.deleteDirectory( projDirectory ); org.apache.archiva.common.utils.FileUtils.deleteDirectory( deleteTarget );
} }
catch ( IOException e ) catch ( IOException e )
{ {
throw new RepositoryException( e.getMessage(), e ); log.error( "Could not delete file path {}: {}", deleteTarget, e.getMessage( ), e );
throw new ContentAccessException( "Error while trying to delete path "+path+" from repository "+getId()+": "+e.getMessage( ), e );
}
} else {
log.warn( "Version path for repository {} is not a directory {}", getId(), deleteTarget );
throw new ContentNotFoundException( "Version path for repository "+getId()+" is not directory: " + path );
}
}
@Override
public void deleteProject( ProjectReference ref )
throws ContentNotFoundException, ContentAccessException
{
final String path = toPath( ref );
final Path deleteTarget = getRepoDir( ).resolve( path );
if ( !Files.exists(deleteTarget) )
{
log.warn( "Project path for repository {} does not exist: {}", getId(), deleteTarget );
throw new ContentNotFoundException( "Project not found for repository "+getId()+": "+path );
}
if ( Files.isDirectory(deleteTarget) )
{
try
{
org.apache.archiva.common.utils.FileUtils.deleteDirectory( deleteTarget );
}
catch ( IOException e )
{
log.error( "Could not delete file path {}: {}", deleteTarget, e.getMessage( ), e );
throw new ContentAccessException( "Error while trying to delete path "+path+" from repository "+getId()+": "+e.getMessage( ), e );
} }
} }
else else
{ {
log.warn( "project {}:{} is not a directory", namespace, projectId ); log.warn( "Project path for repository {} is not a directory {}", getId(), deleteTarget );
throw new ContentNotFoundException( "Project path for repository "+getId()+" is not directory: " + path );
} }
} }
@Override @Override
public void deleteArtifact( ArtifactReference artifactReference ) public void deleteProject( String namespace, String projectId ) throws ContentNotFoundException, ContentAccessException
{ {
this.deleteProject( new ProjectReference().groupId( namespace ).artifactId( projectId ) );
}
@Override
public void deleteArtifact( ArtifactReference ref ) throws ContentNotFoundException, ContentAccessException
{
final String path = toPath( ref );
final Path repoDir = getRepoDir( ); final Path repoDir = getRepoDir( );
Path filePath = repoDir.resolve( toPath( artifactReference ) ); Path deleteTarget = repoDir.resolve( path );
Path parentPath = filePath.getParent( ); if ( Files.exists(deleteTarget) )
if ( Files.exists(filePath) )
{ {
org.apache.archiva.common.utils.FileUtils.deleteQuietly( filePath ); try
{
if (Files.isDirectory( deleteTarget ))
{
org.apache.archiva.common.utils.FileUtils.deleteDirectory( deleteTarget );
} else {
Files.delete( deleteTarget );
}
}
catch ( IOException e )
{
log.error( "Could not delete file path {}: {}", deleteTarget, e.getMessage( ), e );
throw new ContentAccessException( "Error while trying to delete path "+path+" from repository "+getId()+": "+e.getMessage( ), e );
}
} else {
log.warn( "Artifact path for repository {} does not exist: {}", getId(), deleteTarget );
throw new ContentNotFoundException( "Artifact not found for repository "+getId()+": "+path );
} }
Path filePathmd5 = parentPath.resolve( filePath.getFileName().toString()+".md5" );
if ( Files.exists(filePathmd5) )
{
org.apache.archiva.common.utils.FileUtils.deleteQuietly( filePathmd5 );
}
Path filePathsha1 = parentPath.resolve( filePath.getFileName().toString()+ ".sha1" );
if ( Files.exists(filePathsha1) )
{
org.apache.archiva.common.utils.FileUtils.deleteQuietly( filePathsha1 );
}
} }
@Override @Override
public void deleteGroupId( String groupId ) public void deleteGroupId( String groupId )
throws ContentNotFoundException throws ContentNotFoundException, ContentAccessException
{ {
Path directory = getRepoDir( ).resolve( toPath( groupId ) ); final String path = toPath( groupId );
if ( Files.exists(directory) ) final Path deleteTarget = getRepoDir( ).resolve( path );
if (!Files.exists(deleteTarget)) {
log.warn( "Namespace path for repository {} does not exist: {}", getId(), deleteTarget );
throw new ContentNotFoundException( "Namespace not found for repository "+getId()+": "+path );
}
if ( Files.isDirectory(deleteTarget) )
{ {
try try
{ {
org.apache.archiva.common.utils.FileUtils.deleteDirectory( directory ); org.apache.archiva.common.utils.FileUtils.deleteDirectory( deleteTarget );
} }
catch ( IOException e ) catch ( IOException e )
{ {
log.warn( "skip error deleting directory {}:", directory, e ); log.error( "Could not delete file path {}: {}", deleteTarget, e.getMessage( ), e );
throw new ContentAccessException( "Error while trying to delete path "+path+" from repository "+getId()+": "+e.getMessage( ), e );
} }
} else {
log.warn( "Namespace path for repository {} is not a directory {}", getId(), deleteTarget );
throw new ContentNotFoundException( "Namespace path for repository "+getId()+" is not directory: " + path );
} }
} }
@ -213,11 +245,115 @@ public String getId()
} }
@Override @Override
public List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference ) public List<ArtifactReference> getRelatedArtifacts( VersionedReference reference )
throws ContentNotFoundException, LayoutException throws ContentNotFoundException, LayoutException, ContentAccessException
{ {
StorageAsset artifactDir = toFile( reference );
if ( !artifactDir.exists())
{
throw new ContentNotFoundException(
"Unable to get related artifacts using a non-existant directory: " + artifactDir.getPath() );
}
if ( !artifactDir.isContainer() )
{
throw new ContentNotFoundException(
"Unable to get related artifacts using a non-directory: " + artifactDir.getPath() );
}
// First gather up the versions found as artifacts in the managed repository.
try (Stream<StorageAsset> stream = artifactDir.list().stream() ) {
return stream.filter(asset -> !asset.isContainer()).map(path -> {
try {
ArtifactReference artifact = toArtifactReference(path.getPath());
if( artifact.getGroupId().equals( reference.getGroupId() ) && artifact.getArtifactId().equals(
reference.getArtifactId() ) && artifact.getVersion().equals( reference.getVersion() )) {
return artifact;
} else {
return null;
}
} catch (LayoutException e) {
log.debug( "Not processing file that is not an artifact: {}", e.getMessage() );
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toList());
} catch (RuntimeException e) {
Throwable cause = e.getCause( );
if (cause!=null) {
if (cause instanceof LayoutException) {
throw (LayoutException)cause;
} else
{
throw new ContentAccessException( cause.getMessage( ), cause );
}
} else {
throw new ContentAccessException( e.getMessage( ), e );
}
}
}
/*
* Create the filter for various combinations of classifier and type
*/
private Predicate<ArtifactReference> getChecker(ArtifactReference referenceObject, String extension) {
// TODO: Check, if extension is the correct parameter here
// We compare type with extension which works for artifacts like .jar.md5 but may
// be not the best way.
if (referenceObject.getClassifier()!=null && referenceObject.getType()!=null) {
return ((ArtifactReference a) ->
referenceObject.getGroupId().equals( a.getGroupId() )
&& referenceObject.getArtifactId().equals( a.getArtifactId() )
&& referenceObject.getVersion( ).equals( a.getVersion( ) )
&& ( (a.getType()==null)
|| referenceObject.getType().equals( a.getType() )
|| a.getType().startsWith(extension) )
&& referenceObject.getClassifier().equals( a.getClassifier() )
);
} else if (referenceObject.getClassifier()!=null && referenceObject.getType()==null){
return ((ArtifactReference a) ->
referenceObject.getGroupId().equals( a.getGroupId() )
&& referenceObject.getArtifactId().equals( a.getArtifactId() )
&& referenceObject.getVersion( ).equals( a.getVersion( ) )
&& referenceObject.getClassifier().equals( a.getClassifier() )
);
} else if (referenceObject.getClassifier()==null && referenceObject.getType()!=null){
return ((ArtifactReference a) ->
referenceObject.getGroupId().equals( a.getGroupId() )
&& referenceObject.getArtifactId().equals( a.getArtifactId() )
&& referenceObject.getVersion( ).equals( a.getVersion( ) )
&& ( (a.getType()==null)
|| referenceObject.getType().equals( a.getType() )
|| a.getType().startsWith(extension) )
);
} else {
return ((ArtifactReference a) ->
referenceObject.getGroupId().equals( a.getGroupId() )
&& referenceObject.getArtifactId().equals( a.getArtifactId() )
&& referenceObject.getVersion( ).equals( a.getVersion( ) )
);
}
}
@Override
public List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
throws ContentNotFoundException, LayoutException, ContentAccessException
{
if ( StringUtils.isEmpty( reference.getType() ) && StringUtils.isEmpty( reference.getClassifier() ) ) {
return getRelatedArtifacts( toVersion( reference ) );
}
StorageAsset artifactFile = toFile( reference ); StorageAsset artifactFile = toFile( reference );
StorageAsset repoDir = artifactFile.getParent(); StorageAsset repoDir = artifactFile.getParent();
String ext;
if (!artifactFile.isContainer()) {
ext = StringUtils.substringAfterLast( artifactFile.getName(), ".");
} else {
ext = "";
}
if ( !repoDir.exists()) if ( !repoDir.exists())
{ {
@ -234,25 +370,33 @@ public List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference
// First gather up the versions found as artifacts in the managed repository. // First gather up the versions found as artifacts in the managed repository.
try (Stream<StorageAsset> stream = repoDir.list().stream() ) { try (Stream<StorageAsset> stream = repoDir.list().stream() ) {
return stream.filter(asset -> !asset.isContainer()).map(path -> { return stream.filter(
asset -> !asset.isContainer())
.map(path -> {
try { try {
ArtifactReference artifact = toArtifactReference(path.getPath()); return toArtifactReference(path.getPath());
if( artifact.getGroupId().equals( reference.getGroupId() ) && artifact.getArtifactId().equals(
reference.getArtifactId() ) && artifact.getVersion().equals( reference.getVersion() )) {
return artifact;
} else {
return null;
}
} catch (LayoutException e) { } catch (LayoutException e) {
log.debug( "Not processing file that is not an artifact: {}", e.getMessage() ); log.debug( "Not processing file that is not an artifact: {}", e.getMessage() );
return null; return null;
} }
}).filter(Objects::nonNull).collect(Collectors.toList()); }).filter(Objects::nonNull).filter(getChecker( reference, ext )).collect(Collectors.toList());
} catch (RuntimeException e) {
Throwable cause = e.getCause( );
if (cause!=null) {
if (cause instanceof LayoutException) {
throw (LayoutException)cause;
} else
{
throw new ContentAccessException( cause.getMessage( ), cause );
}
} else {
throw new ContentAccessException( e.getMessage( ), e );
}
} }
} }
@Override @Override
public List<StorageAsset> getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException public List<StorageAsset> getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{ {
return null; return null;
} }
@ -288,19 +432,20 @@ public ManagedRepository getRepository()
*/ */
@Override @Override
public Set<String> getVersions( ProjectReference reference ) public Set<String> getVersions( ProjectReference reference )
throws ContentNotFoundException, LayoutException throws ContentNotFoundException, LayoutException, ContentAccessException
{ {
final String path = toPath( reference );
final Path projDir = getRepoDir().resolve(toPath(reference)); final Path projDir = getRepoDir().resolve(toPath(reference));
if ( !Files.exists(projDir) ) if ( !Files.exists(projDir) )
{ {
throw new ContentNotFoundException( throw new ContentNotFoundException(
"Unable to get Versions on a non-existant directory: " + projDir.toAbsolutePath() ); "Unable to get Versions on a non-existant directory for repository "+getId()+": " + path );
} }
if ( !Files.isDirectory(projDir) ) if ( !Files.isDirectory(projDir) )
{ {
throw new ContentNotFoundException( throw new ContentNotFoundException(
"Unable to get Versions on a non-directory: " + projDir.toAbsolutePath() ); "Unable to get Versions on a non-directory for repository "+getId()+": " + path );
} }
final String groupId = reference.getGroupId(); final String groupId = reference.getGroupId();
@ -312,45 +457,50 @@ public Set<String> getVersions( ProjectReference reference )
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} catch (IOException e) { } catch (IOException e) {
log.error("Could not read directory {}: {}", projDir, e.getMessage(), e); log.error("Could not read directory {}: {}", projDir, e.getMessage(), e);
throw new ContentAccessException( "Could not read path for repository "+getId()+": "+ path, e );
} catch (RuntimeException e) { } catch (RuntimeException e) {
if (e.getCause()!=null) Throwable cause = e.getCause( );
if (cause!=null)
{ {
if ( e.getCause( ) instanceof LayoutException ) if ( cause instanceof LayoutException )
{ {
throw (LayoutException) e.getCause( ); throw (LayoutException) cause;
} else {
log.error("Could not read directory {}: {}", projDir, cause.getMessage(), cause);
throw new ContentAccessException( "Could not read path for repository "+getId()+": "+ path, cause );
} }
}else { } else {
throw e; log.error("Could not read directory {}: {}", projDir, e.getMessage(), e);
throw new ContentAccessException( "Could not read path for repository "+getId()+": "+ path, cause );
} }
} }
return Collections.emptySet();
} }
@Override @Override
public Set<String> getVersions( VersionedReference reference ) public Set<String> getVersions( VersionedReference reference )
throws ContentNotFoundException throws ContentNotFoundException, ContentAccessException, LayoutException
{ {
try(Stream<ArtifactReference> stream = getArtifactStream( reference )) try(Stream<ArtifactReference> stream = getArtifactStream( reference ))
{ {
return stream.filter( Objects::nonNull ) return stream.filter( Objects::nonNull )
.map( ar -> ar.getVersion( ) ) .map( ar -> ar.getVersion( ) )
.collect( Collectors.toSet( ) ); .collect( Collectors.toSet( ) );
} } catch (IOException e) {
catch ( LayoutException | IOException e ) final String path = toPath( reference );
{ log.error("Could not read directory from repository {} - {}: ", getId(), path, e.getMessage(), e);
throw new ContentNotFoundException( e.getMessage( ), e ); throw new ContentAccessException( "Could not read path for repository "+getId()+": "+ path, e );
} }
} }
@Override @Override
public boolean hasContent( ArtifactReference reference ) public boolean hasContent( ArtifactReference reference ) throws ContentAccessException
{ {
StorageAsset artifactFile = toFile( reference ); StorageAsset artifactFile = toFile( reference );
return artifactFile.exists() && !artifactFile.isContainer(); return artifactFile.exists() && !artifactFile.isContainer();
} }
@Override @Override
public boolean hasContent( ProjectReference reference ) public boolean hasContent( ProjectReference reference ) throws ContentAccessException
{ {
try try
{ {
@ -364,16 +514,22 @@ public boolean hasContent( ProjectReference reference )
} }
@Override @Override
public boolean hasContent( VersionedReference reference ) public boolean hasContent( VersionedReference reference ) throws ContentAccessException
{ {
try try
{ {
return ( getFirstArtifact( reference ) != null ); return ( getFirstArtifact( reference ) != null );
} }
catch ( IOException | LayoutException | ContentNotFoundException e ) catch ( LayoutException | ContentNotFoundException e )
{ {
return false; return false;
} }
catch ( IOException e )
{
String path = toPath( reference );
log.error("Could not read directory from repository {} - {}: ", getId(), path, e.getMessage(), e);
throw new ContentAccessException( "Could not read path from repository " + getId( ) + ": " + path, e );
}
} }
@Override @Override
@ -439,6 +595,12 @@ public StorageAsset toFile( ArchivaArtifact reference )
return repository.getAsset( toPath( reference ) ); return repository.getAsset( toPath( reference ) );
} }
@Override
public StorageAsset toFile( VersionedReference reference )
{
return repository.getAsset( toPath( reference ) );
}
/** /**
* Get the first Artifact found in the provided VersionedReference location. * Get the first Artifact found in the provided VersionedReference location.
* *
@ -481,15 +643,17 @@ private Stream<ArtifactReference> getArtifactStream(VersionedReference reference
.map(this::toArtifactRef); .map(this::toArtifactRef);
} }
public List<ArtifactReference> getArtifacts(VersionedReference reference) throws ContentNotFoundException, LayoutException public List<ArtifactReference> getArtifacts(VersionedReference reference) throws ContentNotFoundException, LayoutException, ContentAccessException
{ {
try (Stream<ArtifactReference> stream = getArtifactStream( reference )) try (Stream<ArtifactReference> stream = getArtifactStream( reference ))
{ {
return stream.collect( Collectors.toList( ) ); return stream.collect( Collectors.toList( ) );
} catch ( IOException e ) } catch ( IOException e )
{ {
log.error( "Could not access the repository files: ", e.getMessage( ), e ); String path = toPath( reference );
throw new ContentNotFoundException( e.getMessage( ), e ); log.error("Could not read directory from repository {} - {}: ", getId(), path, e.getMessage(), e);
throw new ContentAccessException( "Could not read path from repository " + getId( ) + ": " + path, e );
} }
} }

View File

@ -279,7 +279,7 @@ private Path setupRepoCopy( String source, String target) throws IOException
} }
@Test @Test
public void testDeleteArtifactWithType() throws IOException public void testDeleteArtifactWithType() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
{ {
Path deleteRepo = setupRepoCopy( "delete-repository", "delete-repository-2" ); Path deleteRepo = setupRepoCopy( "delete-repository", "delete-repository-2" );
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) ); assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
@ -298,8 +298,8 @@ public void testDeleteArtifactWithType() throws IOException
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) ); assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) ); assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) ); assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) ); assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) ); assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
@ -307,7 +307,7 @@ public void testDeleteArtifactWithType() throws IOException
@Test @Test
public void testDeleteArtifactWithClassifier() throws IOException public void testDeleteArtifactWithClassifier() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
{ {
Path deleteRepo = setupRepoCopy( "default-repository", "default-repository-2" ); Path deleteRepo = setupRepoCopy( "default-repository", "default-repository-2" );
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) ); assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
@ -327,7 +327,7 @@ public void testDeleteArtifactWithClassifier() throws IOException
repoContent.deleteArtifact( ref ); repoContent.deleteArtifact( ref );
assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) ); assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar.sha1" ) ) ); assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar.sha1" ) ) );
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) ); assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) ); assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) ); assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
@ -336,7 +336,7 @@ public void testDeleteArtifactWithClassifier() throws IOException
} }
@Test @Test
public void testDeleteArtifactWithoutType() throws IOException public void testDeleteArtifactWithoutType() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
{ {
Path deleteRepo = setupRepoCopy( "default-repository", "default-repository-2" ); Path deleteRepo = setupRepoCopy( "default-repository", "default-repository-2" );
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) ); assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
@ -357,4 +357,41 @@ public void testDeleteArtifactWithoutType() throws IOException
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar" ) ) ); assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar" ) ) );
} }
@Test
public void testDeleteVersion() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
{
Path deleteRepo = setupRepoCopy( "delete-repository", "delete-repository-2" );
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
VersionedReference ref = new VersionedReference( ).groupId( "org.apache.maven" ).artifactId( "samplejar" ).version( "1.0" );
repoContent.deleteVersion( ref );
assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0" ) ) );
}
@Test
public void testDeleteProject() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
{
Path deleteRepo = setupRepoCopy( "delete-repository", "delete-repository-2" );
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
ProjectReference ref = new ProjectReference( ).groupId( "org.apache.maven" ).artifactId( "samplejar" );
repoContent.deleteProject( ref );
assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0" ) ) );
}
} }

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<configuration>
<Properties>
</Properties>
<appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{ISO8601_PERIOD} [%L] [%t] %-5level %logger{3} - %msg%n"/>
</Console>
<!--
<RandomAccessFile name="LogFile" fileName="target/test.log">
<PatternLayout pattern="%d{ISO8601_PERIOD} [%L] [%t] %-5level %logger{3} - %msg%n"/>
</RandomAccessFile>
-->
</appenders>
<loggers>
<logger name="org.apache.archiva" level="error"/>
<logger name="org.apache.archiva.maven" level="info"/>
<root level="error" includeLocation="true">
<appender-ref ref="console"/>
</root>
</loggers>
</configuration>

View File

@ -96,7 +96,6 @@
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.TimeZone; import java.util.TimeZone;
/** /**
@ -684,7 +683,7 @@ public Boolean removeProjectVersion( String repositoryId, String namespace, Stri
MetadataRepository metadataRepository = repositorySession.getRepository(); MetadataRepository metadataRepository = repositorySession.getRepository();
List<ArtifactReference> related = repository.getRelatedArtifacts( artifactReference ); List<ArtifactReference> related = repository.getRelatedArtifacts( repository.toVersion(artifactReference) );
log.debug( "related: {}", related ); log.debug( "related: {}", related );
for ( ArtifactReference artifactRef : related ) for ( ArtifactReference artifactRef : related )
{ {
@ -793,7 +792,7 @@ public Boolean deleteArtifact( Artifact artifact )
artifactReference.setGroupId( artifact.getGroupId() ); artifactReference.setGroupId( artifact.getGroupId() );
artifactReference.setVersion( artifact.getVersion() ); artifactReference.setVersion( artifact.getVersion() );
artifactReference.setClassifier( artifact.getClassifier() ); artifactReference.setClassifier( artifact.getClassifier() );
artifactReference.setType( artifact.getPackaging() ); artifactReference.setType( artifact.getType() );
MetadataRepository metadataRepository = repositorySession.getRepository(); MetadataRepository metadataRepository = repositorySession.getRepository();
@ -806,8 +805,10 @@ public Boolean deleteArtifact( Artifact artifact )
throw new ArchivaRestServiceException( "You must configure a type/packaging when using classifier", throw new ArchivaRestServiceException( "You must configure a type/packaging when using classifier",
400, null ); 400, null );
} }
List<ArtifactReference> artifacts = repository.getRelatedArtifacts( artifactReference );
repository.deleteArtifact( artifactReference ); for (ArtifactReference aRef : artifacts ) {
repository.deleteArtifact( aRef );
}
} }
else else
@ -833,11 +834,18 @@ public Boolean deleteArtifact( Artifact artifact )
} }
else else
{ {
List<ArtifactReference> related = repository.getRelatedArtifacts( artifactReference ); // We are deleting all version related artifacts for a snapshot version
VersionedReference versionRef = repository.toVersion( artifactReference );
List<ArtifactReference> related = repository.getRelatedArtifacts( versionRef );
log.debug( "related: {}", related ); log.debug( "related: {}", related );
for ( ArtifactReference artifactRef : related ) for ( ArtifactReference artifactRef : related )
{ {
repository.deleteArtifact( artifactRef ); try
{
repository.deleteArtifact( artifactRef );
} catch (ContentNotFoundException e) {
log.warn( "Artifact that should be deleted, was not found: {}", artifactRef );
}
} }
StorageAsset metadataFile = getMetadata( repo, targetPath.getPath() ); StorageAsset metadataFile = getMetadata( repo, targetPath.getPath() );
ArchivaRepositoryMetadata metadata = getMetadata( repository.getRepository().getType(), metadataFile ); ArchivaRepositoryMetadata metadata = getMetadata( repository.getRepository().getType(), metadataFile );

View File

@ -303,6 +303,7 @@ public void deleteArtifactWithClassifier()
artifact.setVersion( "1.0.1" ); artifact.setVersion( "1.0.1" );
artifact.setClassifier( "javadoc" ); artifact.setClassifier( "javadoc" );
artifact.setPackaging( "jar" ); artifact.setPackaging( "jar" );
artifact.setType( "javadoc" );
artifact.setContext( SOURCE_REPO_ID ); artifact.setContext( SOURCE_REPO_ID );
RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader ); RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );

View File

@ -40,7 +40,6 @@
import org.apache.archiva.indexer.merger.TemporaryGroupIndex; import org.apache.archiva.indexer.merger.TemporaryGroupIndex;
import org.apache.archiva.indexer.search.RepositorySearch; import org.apache.archiva.indexer.search.RepositorySearch;
import org.apache.archiva.indexer.search.RepositorySearchException; import org.apache.archiva.indexer.search.RepositorySearchException;
import org.apache.archiva.maven2.metadata.MavenMetadataReader;
import org.apache.archiva.metadata.model.facets.AuditEvent; import org.apache.archiva.metadata.model.facets.AuditEvent;
import org.apache.archiva.metadata.repository.storage.RelocationException; import org.apache.archiva.metadata.repository.storage.RelocationException;
import org.apache.archiva.metadata.repository.storage.RepositoryStorage; import org.apache.archiva.metadata.repository.storage.RepositoryStorage;
@ -66,7 +65,6 @@
import org.apache.archiva.repository.RepositoryGroup; import org.apache.archiva.repository.RepositoryGroup;
import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.RepositoryRequestInfo; import org.apache.archiva.repository.RepositoryRequestInfo;
import org.apache.archiva.repository.storage.FilesystemAsset;
import org.apache.archiva.repository.storage.FilesystemStorage; import org.apache.archiva.repository.storage.FilesystemStorage;
import org.apache.archiva.repository.storage.StorageAsset; import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.metadata.audit.AuditListener; import org.apache.archiva.metadata.audit.AuditListener;
@ -104,7 +102,6 @@
import javax.inject.Named; import javax.inject.Named;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
@ -671,6 +668,10 @@ private DavResource processRepository( final DavServletRequest request, ArchivaD
{ {
log.warn( "Artifact path '{}' is invalid.", resourcePath ); log.warn( "Artifact path '{}' is invalid.", resourcePath );
} }
catch ( org.apache.archiva.repository.ContentAccessException e )
{
e.printStackTrace( );
}
} }
/* /*