Removing API methods for repository content

This commit is contained in:
Martin Stockhammer 2020-04-21 18:40:17 +02:00
parent bf6ac66644
commit 7c0b0387a3
6 changed files with 22 additions and 175 deletions

View File

@ -312,19 +312,6 @@ public interface ManagedRepositoryContent extends RepositoryContent
*/
VersionedReference toVersion( ArtifactReference artifactReference);
/**
* Returns a artifact reference for the given coordinates.
* @param groupId the group id
* @param artifactId the artifact id
* @param version the version
* @param type the type
* @param classifier the classifier
* @return a artifact reference object
*/
ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier);
/**
* Delete from the managed repository all files / directories associated with the
@ -391,26 +378,6 @@ public interface ManagedRepositoryContent extends RepositoryContent
*/
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>
* Gather up the list of related artifacts to the ArtifactReference provided.
@ -430,22 +397,6 @@ public interface ManagedRepositoryContent extends RepositoryContent
throws ContentNotFoundException, LayoutException, ContentAccessException;
/**
* 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.
* This method is the same as {@link #getRelatedArtifacts(ArtifactReference)} but may also return
* e.g. hash files.
*
* @param reference
* @return
*/
List<StorageAsset> getRelatedAssets(ArtifactReference reference) throws ContentNotFoundException, LayoutException, ContentAccessException;
/**
* Returns all artifacts that belong to a given version
* @param reference the version reference

View File

@ -63,12 +63,6 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
return null;
}
@Override
public ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier )
{
return null;
}
@Override
public void deleteItem( ContentItem item ) throws ItemNotFoundException, ContentAccessException
{
@ -218,24 +212,12 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
return null;
}
@Override
public List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{
return null;
}
@Override
public List<ArtifactReference> getRelatedArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{
return null;
}
@Override
public List<StorageAsset> getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{
return null;
}
@Override
public List<ArtifactReference> getArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{

View File

@ -79,12 +79,6 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
return null;
}
@Override
public ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier )
{
return null;
}
@Override
public void deleteItem( ContentItem item ) throws ItemNotFoundException, ContentAccessException
{
@ -229,24 +223,12 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
return repository.getId();
}
@Override
public List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{
return null;
}
@Override
public List<ArtifactReference> getRelatedArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{
return null;
}
@Override
public List<StorageAsset> getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{
return null;
}
@Override
public List<ArtifactReference> getArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{

View File

@ -83,12 +83,6 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
return null;
}
@Override
public ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier )
{
return null;
}
@Override
public void deleteItem( ContentItem item ) throws ItemNotFoundException, ContentAccessException
{
@ -233,24 +227,12 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
return repository.getId();
}
@Override
public List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{
return null;
}
@Override
public List<ArtifactReference> getRelatedArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{
return null;
}
@Override
public List<StorageAsset> getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{
return null;
}
@Override
public List<ArtifactReference> getArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{

View File

@ -20,7 +20,6 @@ package org.apache.archiva.repository.maven.content;
import org.apache.archiva.common.filelock.FileLockManager;
import org.apache.archiva.common.utils.FileUtils;
import org.apache.archiva.common.utils.VersionUtil;
import org.apache.archiva.configuration.FileTypes;
import org.apache.archiva.metadata.maven.MavenMetadataReader;
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
@ -927,11 +926,6 @@ public class ManagedDefaultRepositoryContent
return toVersion( artifactReference.getGroupId( ), artifactReference.getArtifactId( ), artifactReference.getVersion( ) );
}
@Override
public ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier) {
return new ArtifactReference( ).groupId( groupId ).artifactId( artifactId ).version( version ).type( type ).classifier( classifier );
}
@Override
public void deleteVersion( VersionedReference ref ) throws ContentNotFoundException, ContentAccessException
@ -1154,69 +1148,6 @@ public class ManagedDefaultRepositoryContent
}
@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 repoDir = artifactFile.getParent();
String ext;
if (!artifactFile.isContainer()) {
ext = StringUtils.substringAfterLast( artifactFile.getName(), ".");
} else {
ext = "";
}
if ( !repoDir.exists())
{
throw new ContentNotFoundException(
"Unable to get related artifacts using a non-existant directory: " + repoDir.getPath() );
}
if ( !repoDir.isContainer() )
{
throw new ContentNotFoundException(
"Unable to get related artifacts using a non-directory: " + repoDir.getPath() );
}
// First gather up the versions found as artifacts in the managed repository.
try (Stream<? extends StorageAsset> stream = repoDir.list().stream() ) {
return stream.filter(
asset -> !asset.isContainer())
.map(path -> {
try {
return toArtifactReference(path.getPath());
} catch (LayoutException e) {
log.debug( "Not processing file that is not an artifact: {}", e.getMessage() );
return null;
}
}).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
public List<StorageAsset> getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
{
return null;
}
@Override
public String getRepoRoot()
{

View File

@ -51,6 +51,8 @@ import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.RepositoryNotFoundException;
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.content.ItemNotFoundException;
import org.apache.archiva.repository.content.base.ArchivaItemSelector;
import org.apache.archiva.repository.storage.fs.FsStorageUtil;
import org.apache.archiva.repository.storage.RepositoryStorage;
import org.apache.archiva.repository.storage.StorageAsset;
@ -787,6 +789,16 @@ public class DefaultRepositoriesService
artifactReference.setClassifier( artifact.getClassifier() );
artifactReference.setType( artifact.getType() );
ArchivaItemSelector selector = ArchivaItemSelector.builder( )
.withNamespace( artifact.getGroupId( ) )
.withProjectId( artifact.getArtifactId( ) )
.withVersion( artifact.getVersion( ) )
.withClassifier( artifact.getClassifier( ) )
.withArtifactId( artifact.getArtifactId( ) )
.withType( artifact.getType( ) )
.includeRelatedArtifacts()
.build( );
MetadataRepository metadataRepository = repositorySession.getRepository();
String path = repository.toMetadataPath( ref );
@ -798,9 +810,16 @@ public class DefaultRepositoriesService
throw new ArchivaRestServiceException( "You must configure a type/packaging when using classifier",
400, null );
}
List<ArtifactReference> artifacts = repository.getRelatedArtifacts( artifactReference );
for (ArtifactReference aRef : artifacts ) {
repository.deleteArtifact( aRef );
List<? extends org.apache.archiva.repository.content.Artifact> artifactItems = repository.getArtifacts( selector );
for ( org.apache.archiva.repository.content.Artifact aRef : artifactItems ) {
try
{
repository.deleteItem( aRef );
}
catch ( ItemNotFoundException e )
{
log.error( "Could not delete item, seems to be deleted by other thread. {}, {} ", aRef, e.getMessage( ) );
}
}
}