import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.metadata.audit.RepositoryListener;
+import org.apache.archiva.repository.content.ItemNotFoundException;
import org.apache.archiva.repository.content.ItemSelector;
import org.apache.archiva.repository.content.Project;
import org.apache.archiva.repository.content.Version;
return;
}
- ItemSelector selector = ArchivaItemSelector.builder( )
+ ItemSelector projectSelector = ArchivaItemSelector.builder( )
.withNamespace( artifactRef.getGroupId( ) )
.withProjectId( artifactRef.getArtifactId( ) )
.build();
if ( repo.getActiveReleaseSchemes().contains( ReleaseScheme.RELEASE ))
{
BaseRepositoryContentLayout repoContent = repo.getContent().getLayout( BaseRepositoryContentLayout.class );
- Project proj = repoContent.getProject( selector );
+ Project proj = repoContent.getProject( projectSelector );
for ( Version version : repoContent.getVersions( proj ) )
{
if ( !VersionUtil.isSnapshot( version.getVersion() ) )
versionRef.setGroupId( artifactRef.getGroupId( ) );
versionRef.setArtifactId( artifactRef.getArtifactId( ) );
+ ArchivaItemSelector.Builder versionSelectorBuilder = ArchivaItemSelector.builder( )
+ .withNamespace( artifactRef.getGroupId( ) )
+ .withProjectId( artifactRef.getArtifactId( ) )
+ .withArtifactId( artifactRef.getArtifactId( ) );
+
MetadataRepository metadataRepository = repositorySession.getRepository( );
if ( releasedVersions.contains( VersionUtil.getReleaseVersion( artifactRef.getVersion( ) ) ) )
{
- versionRef.setVersion( artifactRef.getVersion( ) );
- layout.deleteVersion( versionRef );
-
+ ArchivaItemSelector selector = versionSelectorBuilder.withVersion( artifactRef.getVersion( ) ).build( );
+ Version version = layout.getVersion( selector );
+ if (version.exists())
+ {
+ repository.deleteItem( version );
+ }
for ( RepositoryListener listener : listeners )
{
listener.deleteArtifact( metadataRepository, repository.getId( ), artifactRef.getGroupId( ),
{
log.debug( "Not processing file that is not an artifact: {}", e.getMessage( ) );
}
- catch ( ContentNotFoundException e )
- {
- throw new RepositoryPurgeException( e.getMessage( ), e );
- }
catch ( MetadataRepositoryException e )
{
log.error( "Could not remove metadata during cleanup of released snapshots of {}", path, e );
{
e.printStackTrace( );
}
+ catch ( ItemNotFoundException e )
+ {
+ log.error( "Could not find item to delete {}",e.getMessage( ), e );
+ }
}
{
// Ignore. (Just means we have no snapshot versions left to reference).
}
- catch ( RepositoryMetadataException e )
- {
- // Ignore.
- }
- catch ( IOException e )
- {
- // Ignore.
- }
- catch ( LayoutException e )
+ catch ( RepositoryMetadataException | IOException | LayoutException e )
{
// Ignore.
}
{
metadataTools.updateMetadata( repository, projectRef );
}
- catch ( ContentNotFoundException e )
+ catch ( ContentNotFoundException | RepositoryMetadataException | IOException | LayoutException e )
{
// Ignore. (Just means we have no snapshot versions left to reference).
}
- catch ( RepositoryMetadataException e )
- {
- // Ignore.
- }
- catch ( IOException e )
- {
- // Ignore.
- }
- catch ( LayoutException e )
- {
- // Ignore.
- }
+
}
}
VersionedReference toVersion( ArtifactReference artifactReference);
- /**
- * Delete from the managed repository all files / directories associated with the
- * provided version reference.
- *
- * @param reference the version reference to delete.
- * @throws ContentNotFoundException
- */
- void deleteVersion( VersionedReference reference )
- throws ContentNotFoundException, ContentAccessException;
-
-
-
/**
* delete a specified artifact from the repository
*
*/
StorageAsset toFile( VersionedReference reference );
- /**
- * 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( ArtifactReference reference );
-
}
}
- @Override
- public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException
- {
-
- }
-
-
@Override
public Version getVersion( ItemSelector versionCoordinates ) throws ContentAccessException, IllegalArgumentException
{
return null;
}
- @Override
- public StorageAsset toFile( ArtifactReference reference )
- {
- return null;
- }
-
@Override
public String toPath( ArtifactReference reference )
{
return null;
}
- @Override
- public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException
- {
-
- }
-
@Override
public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException, ContentAccessException
{
}
- @Override
- public StorageAsset toFile( ArtifactReference reference )
- {
- return getRepoRootAsset().resolve(refs.get(reference));
- }
-
private String formatAsDirectory( String directory )
{
return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR );
}
}
- @Override
- public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException
- {
-
- }
-
@Override
public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException, ContentAccessException
{
}
- @Override
- public StorageAsset toFile( ArtifactReference reference )
- {
- return getRepoRootAsset().resolve( refs.get(reference));
- }
-
private String formatAsDirectory( String directory )
{
return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR );
}
- @Override
- public void deleteVersion( VersionedReference ref ) throws ContentNotFoundException, ContentAccessException
- {
- final String path = toPath( ref );
- final Path deleteTarget = getRepoDir( ).resolve( path );
- if ( !Files.exists( deleteTarget ) )
- {
- 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 ) )
- {
- 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
- {
- 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
}
- @Override
- public StorageAsset toFile( ArtifactReference reference )
- {
- return repository.getAsset( toPath( reference ) );
- }
-
@Override
public StorageAsset toFile( VersionedReference reference )
{
}
- @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
{