*/
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
*/
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.
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
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
{
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
{
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
{
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
{
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
{
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
{
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;
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
}
- @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()
{
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;
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 );
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( ) );
+ }
}
}