VersionedReference ref = new VersionedReference();
ref.setArtifactId( artifact.getArtifactId() );
ref.setGroupId( artifact.getGroupId() );
ref.setVersion( artifact.getVersion() );
ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId );
if ( StringUtils.isNotBlank( artifact.getClassifier() ) )
{
if ( StringUtils.isBlank( artifact.getPackaging() ) )
{
throw new ArchivaRestServiceException( "You must configure a type/packaging when using classifier",
400 );
}
ArtifactReference artifactReference = new ArtifactReference();
artifactReference.setArtifactId( artifact.getArtifactId() );
artifactReference.setGroupId( artifact.getGroupId() );
artifactReference.setVersion( artifact.getVersion() );
artifactReference.setClassifier( artifact.getClassifier() );
artifactReference.setType( artifact.getPackaging() );
repository.deleteArtifact( artifactReference );
// TODO cleanup facet which contains classifier information
return Boolean.TRUE;
}
String path = repository.toMetadataPath( ref );
int index = path.lastIndexOf( '/' );
path = path.substring( 0, index );
File targetPath = new File( repoConfig.getLocation(), path );
if ( !targetPath.exists() )
{
throw new ContentNotFoundException(
artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() );
}
// TODO: this should be in the storage mechanism so that it is all tied together
// delete from file system
repository.deleteVersion( ref );
File metadataFile = getMetadata( targetPath.getAbsolutePath() );
ArchivaRepositoryMetadata metadata = getMetadata( metadataFile );
updateMetadata( metadata, metadataFile, lastUpdatedTimestamp, artifact );
MetadataRepository metadataRepository = repositorySession.getRepository();
Collection<ArtifactMetadata> artifacts =
metadataRepository.getArtifacts( repositoryId, artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion() );
for ( ArtifactMetadata artifactMetadata : artifacts )
{
// TODO: mismatch between artifact (snapshot) version and project (base) version here
if ( artifact.getVersion().equals( artifact.getVersion() ) )
{
metadataRepository.removeArtifact( artifactMetadata.getRepositoryId(),
artifactMetadata.getNamespace(), artifactMetadata.getProject(),
artifact.getVersion(), artifactMetadata.getId() );
// TODO: move into the metadata repository proper - need to differentiate attachment of
// repository metadata to an artifact
for ( RepositoryListener listener : listeners )
{
listener.deleteArtifact( metadataRepository, repository.getId(),
artifactMetadata.getNamespace(), artifactMetadata.getProject(),
artifactMetadata.getVersion(), artifactMetadata.getId() );
}
triggerAuditEvent( repositoryId, path, AuditEvent.REMOVE_FILE );