mirror of https://github.com/apache/archiva.git
Refactoring ManagedRepositoryContent
This commit is contained in:
parent
13856a6060
commit
f6f495d494
|
@ -234,6 +234,10 @@ public abstract class AbstractRepositoryPurge
|
|||
{
|
||||
log.warn( "skip error deleting artifact {}: {}", reference, e.getMessage( ) );
|
||||
}
|
||||
catch ( org.apache.archiva.repository.ContentAccessException e )
|
||||
{
|
||||
e.printStackTrace( );
|
||||
}
|
||||
|
||||
boolean snapshotVersion = VersionUtil.isSnapshot( reference.getVersion( ) );
|
||||
|
||||
|
|
|
@ -181,6 +181,10 @@ public class CleanupReleasedSnapshotsRepositoryPurge
|
|||
{
|
||||
log.error( "Could not remove metadata during cleanup of released snapshots of {}", path, e );
|
||||
}
|
||||
catch ( org.apache.archiva.repository.ContentAccessException e )
|
||||
{
|
||||
e.printStackTrace( );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ public class DaysOldRepositoryPurge
|
|||
{
|
||||
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" ?
|
||||
|
@ -125,7 +125,7 @@ public class DaysOldRepositoryPurge
|
|||
|
||||
if ( timestampCal.getTimeInMillis( ) < olderThanThisDate.getTimeInMillis( ) )
|
||||
{
|
||||
artifactsToDelete.addAll( repository.getRelatedArtifacts( newArtifactReference ) );
|
||||
artifactsToDelete.addAll( repository.getRelatedArtifacts( repository.toVersion(newArtifactReference) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -139,6 +139,10 @@ public class DaysOldRepositoryPurge
|
|||
{
|
||||
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 )
|
||||
|
|
|
@ -94,7 +94,8 @@ public class RetentionCountRepositoryPurge
|
|||
{
|
||||
break;
|
||||
}
|
||||
artifactsToDelete.addAll( repository.getRelatedArtifacts( getNewArtifactReference( artifact, version ) ) );
|
||||
VersionedReference ref = repository.toVersion( getNewArtifactReference( artifact, version ) );
|
||||
artifactsToDelete.addAll( repository.getRelatedArtifacts( ref ) );
|
||||
}
|
||||
purge( artifactsToDelete );
|
||||
}
|
||||
|
@ -107,6 +108,10 @@ public class RetentionCountRepositoryPurge
|
|||
{
|
||||
log.error( "Repostory artifact not found {}", path );
|
||||
}
|
||||
catch ( org.apache.archiva.repository.ContentAccessException e )
|
||||
{
|
||||
e.printStackTrace( );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -20,8 +20,8 @@ package org.apache.archiva.repository;
|
|||
*/
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
|
@ -48,7 +48,15 @@ public interface ManagedRepositoryContent extends RepositoryContent
|
|||
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
|
||||
* @return the version reference
|
||||
|
@ -75,7 +83,7 @@ public interface ManagedRepositoryContent extends RepositoryContent
|
|||
* @throws ContentNotFoundException
|
||||
*/
|
||||
void deleteVersion( VersionedReference reference )
|
||||
throws ContentNotFoundException;
|
||||
throws ContentNotFoundException, ContentAccessException;
|
||||
|
||||
/**
|
||||
* delete a specified artifact from the repository
|
||||
|
@ -84,7 +92,7 @@ public interface ManagedRepositoryContent extends RepositoryContent
|
|||
* @throws ContentNotFoundException
|
||||
*/
|
||||
void deleteArtifact( ArtifactReference artifactReference )
|
||||
throws ContentNotFoundException;
|
||||
throws ContentNotFoundException, ContentAccessException;
|
||||
|
||||
/**
|
||||
* @param groupId
|
||||
|
@ -92,7 +100,7 @@ public interface ManagedRepositoryContent extends RepositoryContent
|
|||
* @since 1.4-M3
|
||||
*/
|
||||
void deleteGroupId( String groupId )
|
||||
throws ContentNotFoundException;
|
||||
throws ContentNotFoundException, ContentAccessException;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -101,7 +109,15 @@ public interface ManagedRepositoryContent extends RepositoryContent
|
|||
* @throws ContentNotFoundException
|
||||
*/
|
||||
void deleteProject( String namespace, String projectId )
|
||||
throws RepositoryException;
|
||||
throws ContentNotFoundException, ContentAccessException;
|
||||
|
||||
|
||||
/**
|
||||
* Deletes a project
|
||||
* @param reference
|
||||
*/
|
||||
void deleteProject(ProjectReference reference) throws ContentNotFoundException, ContentAccessException;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -115,6 +131,26 @@ 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.
|
||||
|
@ -130,9 +166,8 @@ public interface ManagedRepositoryContent extends RepositoryContent
|
|||
* @return the list of ArtifactReferences for related artifacts, if
|
||||
* @throws ContentNotFoundException if the initial artifact reference does not exist within the repository.
|
||||
*/
|
||||
List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
|
||||
throws ContentNotFoundException, LayoutException;
|
||||
|
||||
List<ArtifactReference> getRelatedArtifacts( VersionedReference reference )
|
||||
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.
|
||||
|
@ -142,14 +177,14 @@ public interface ManagedRepositoryContent extends RepositoryContent
|
|||
* @param reference
|
||||
* @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
|
||||
* @param reference the version reference
|
||||
* @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 @@ public interface ManagedRepositoryContent extends RepositoryContent
|
|||
* @throws LayoutException
|
||||
*/
|
||||
Set<String> getVersions( ProjectReference reference )
|
||||
throws ContentNotFoundException, LayoutException;
|
||||
throws ContentNotFoundException, LayoutException, ContentAccessException;
|
||||
|
||||
|
||||
|
||||
|
@ -202,7 +237,7 @@ public interface ManagedRepositoryContent extends RepositoryContent
|
|||
* @throws ContentNotFoundException if the versioned reference does not exist within the repository.
|
||||
*/
|
||||
Set<String> getVersions( VersionedReference reference )
|
||||
throws ContentNotFoundException;
|
||||
throws ContentNotFoundException, ContentAccessException, LayoutException;
|
||||
|
||||
/**
|
||||
* Determines if the artifact referenced exists in the repository.
|
||||
|
@ -210,7 +245,7 @@ public interface ManagedRepositoryContent extends RepositoryContent
|
|||
* @param reference the artifact reference to check for.
|
||||
* @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.
|
||||
|
@ -218,7 +253,7 @@ public interface ManagedRepositoryContent extends RepositoryContent
|
|||
* @param reference the project reference to check for.
|
||||
* @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.
|
||||
|
@ -226,7 +261,7 @@ public interface ManagedRepositoryContent extends RepositoryContent
|
|||
* @param reference the version reference to check for.
|
||||
* @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
|
||||
|
@ -236,6 +271,14 @@ public interface ManagedRepositoryContent extends RepositoryContent
|
|||
*/
|
||||
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.
|
||||
*
|
||||
|
|
|
@ -43,13 +43,11 @@ import org.apache.archiva.repository.ContentNotFoundException;
|
|||
import org.apache.archiva.repository.LayoutException;
|
||||
import org.apache.archiva.repository.ManagedRepositoryContent;
|
||||
import org.apache.archiva.repository.RemoteRepositoryContent;
|
||||
import org.apache.archiva.repository.Repository;
|
||||
import org.apache.archiva.repository.RepositoryRegistry;
|
||||
import org.apache.archiva.repository.RepositoryType;
|
||||
import org.apache.archiva.repository.metadata.MetadataReader;
|
||||
import org.apache.archiva.repository.metadata.RepositoryMetadataException;
|
||||
import org.apache.archiva.repository.storage.StorageAsset;
|
||||
import org.apache.archiva.xml.XMLException;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
|
@ -148,7 +146,15 @@ public class MetadataTools
|
|||
VersionedReference reference )
|
||||
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
|
||||
// maven-metadata-${proxyId}.xml files that may be present.
|
||||
|
@ -519,7 +525,15 @@ public class MetadataTools
|
|||
metadata.setArtifactId( reference.getArtifactId() );
|
||||
|
||||
// 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.
|
||||
// TODO: do we know this information instead?
|
||||
|
|
|
@ -23,11 +23,11 @@ import org.apache.archiva.model.ArchivaArtifact;
|
|||
import org.apache.archiva.model.ArtifactReference;
|
||||
import org.apache.archiva.model.ProjectReference;
|
||||
import org.apache.archiva.model.VersionedReference;
|
||||
import org.apache.archiva.repository.ContentAccessException;
|
||||
import org.apache.archiva.repository.ContentNotFoundException;
|
||||
import org.apache.archiva.repository.LayoutException;
|
||||
import org.apache.archiva.repository.ManagedRepository;
|
||||
import org.apache.archiva.repository.ManagedRepositoryContent;
|
||||
import org.apache.archiva.repository.RepositoryException;
|
||||
import org.apache.archiva.repository.storage.StorageAsset;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -48,6 +48,12 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VersionedReference toGenericVersion( ArtifactReference artifactReference )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VersionedReference toVersion( ArtifactReference artifactReference )
|
||||
{
|
||||
|
@ -61,25 +67,31 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
|
|||
}
|
||||
|
||||
@Override
|
||||
public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException
|
||||
public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException
|
||||
public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException, ContentAccessException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteGroupId( String groupId ) throws ContentNotFoundException
|
||||
public void deleteGroupId( String groupId ) throws ContentNotFoundException, ContentAccessException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@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 class ManagedRepositoryContentMock implements ManagedRepositoryContent
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException, LayoutException
|
||||
public List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StorageAsset> getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException
|
||||
public List<ArtifactReference> getRelatedArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
@ -121,31 +139,31 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException
|
||||
public Set<String> getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getVersions( VersionedReference reference ) throws ContentNotFoundException
|
||||
public Set<String> getVersions( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException, LayoutException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContent( ArtifactReference reference )
|
||||
public boolean hasContent( ArtifactReference reference ) throws ContentAccessException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContent( ProjectReference reference )
|
||||
public boolean hasContent( ProjectReference reference ) throws ContentAccessException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContent( VersionedReference reference )
|
||||
public boolean hasContent( VersionedReference reference ) throws ContentAccessException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -156,6 +174,12 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
|
|||
this.repository = repo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageAsset toFile( VersionedReference reference )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArtifactReference toArtifactReference( String path ) throws LayoutException
|
||||
{
|
||||
|
|
|
@ -64,6 +64,12 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VersionedReference toGenericVersion( ArtifactReference artifactReference )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VersionedReference toVersion( ArtifactReference artifactReference )
|
||||
{
|
||||
|
@ -77,25 +83,31 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
|
|||
}
|
||||
|
||||
@Override
|
||||
public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException
|
||||
public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException
|
||||
public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException, ContentAccessException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteGroupId( String groupId ) throws ContentNotFoundException
|
||||
public void deleteGroupId( String groupId ) throws ContentNotFoundException, ContentAccessException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@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 class ManagedRepositoryContentMock implements ManagedRepositoryContent
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException, LayoutException
|
||||
public List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StorageAsset> getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException
|
||||
public List<ArtifactReference> getRelatedArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
@ -148,31 +166,31 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException
|
||||
public Set<String> getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getVersions( VersionedReference reference ) throws ContentNotFoundException
|
||||
public Set<String> getVersions( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException, LayoutException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContent( ArtifactReference reference )
|
||||
public boolean hasContent( ArtifactReference reference ) throws ContentAccessException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContent( ProjectReference reference )
|
||||
public boolean hasContent( ProjectReference reference ) throws ContentAccessException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContent( VersionedReference reference )
|
||||
public boolean hasContent( VersionedReference reference ) throws ContentAccessException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -183,6 +201,12 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
|
|||
this.repository = repo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageAsset toFile( VersionedReference reference )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map<ArtifactReference, String> refs = new HashMap<>();
|
||||
|
||||
@Override
|
||||
|
|
|
@ -68,6 +68,12 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VersionedReference toGenericVersion( ArtifactReference artifactReference )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VersionedReference toVersion( ArtifactReference artifactReference )
|
||||
{
|
||||
|
@ -81,25 +87,31 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
|
|||
}
|
||||
|
||||
@Override
|
||||
public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException
|
||||
public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException
|
||||
public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException, ContentAccessException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteGroupId( String groupId ) throws ContentNotFoundException
|
||||
public void deleteGroupId( String groupId ) throws ContentNotFoundException, ContentAccessException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@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 class ManagedRepositoryContentMock implements ManagedRepositoryContent
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException, LayoutException
|
||||
public List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StorageAsset> getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException
|
||||
public List<ArtifactReference> getRelatedArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
@ -152,31 +170,31 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException
|
||||
public Set<String> getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getVersions( VersionedReference reference ) throws ContentNotFoundException
|
||||
public Set<String> getVersions( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException, LayoutException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContent( ArtifactReference reference )
|
||||
public boolean hasContent( ArtifactReference reference ) throws ContentAccessException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContent( ProjectReference reference )
|
||||
public boolean hasContent( ProjectReference reference ) throws ContentAccessException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContent( VersionedReference reference )
|
||||
public boolean hasContent( VersionedReference reference ) throws ContentAccessException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -187,6 +205,12 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
|
|||
this.repository = repo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageAsset toFile( VersionedReference reference )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map<ArtifactReference, String> refs = new HashMap<>();
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.archiva.repository.content.maven2;
|
|||
*/
|
||||
|
||||
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.configuration.FileTypes;
|
||||
import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
|
||||
|
@ -29,12 +28,12 @@ import org.apache.archiva.model.ArchivaArtifact;
|
|||
import org.apache.archiva.model.ArtifactReference;
|
||||
import org.apache.archiva.model.ProjectReference;
|
||||
import org.apache.archiva.model.VersionedReference;
|
||||
import org.apache.archiva.repository.ContentAccessException;
|
||||
import org.apache.archiva.repository.ContentNotFoundException;
|
||||
import org.apache.archiva.repository.EditableManagedRepository;
|
||||
import org.apache.archiva.repository.LayoutException;
|
||||
import org.apache.archiva.repository.ManagedRepository;
|
||||
import org.apache.archiva.repository.ManagedRepositoryContent;
|
||||
import org.apache.archiva.repository.RepositoryException;
|
||||
import org.apache.archiva.repository.storage.StorageAsset;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
@ -44,10 +43,10 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -94,11 +93,13 @@ public class ManagedDefaultRepositoryContent
|
|||
*/
|
||||
@Override
|
||||
public VersionedReference toVersion( String groupId, String artifactId, String version ) {
|
||||
VersionedReference ref = new VersionedReference();
|
||||
ref.setGroupId(groupId);
|
||||
ref.setArtifactId(artifactId);
|
||||
ref.setVersion(version);
|
||||
return ref;
|
||||
return new VersionedReference().groupId( groupId ).artifactId( artifactId ).version( version );
|
||||
}
|
||||
|
||||
@Override
|
||||
public VersionedReference toGenericVersion( ArtifactReference artifactReference )
|
||||
{
|
||||
return toVersion( artifactReference.getGroupId( ), artifactReference.getArtifactId( ), VersionUtil.getBaseVersion( artifactReference.getVersion( ) ));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,102 +108,133 @@ public class ManagedDefaultRepositoryContent
|
|||
* @return
|
||||
*/
|
||||
public VersionedReference toVersion( ArtifactReference artifactReference) {
|
||||
return toVersion( artifactReference.getGroupId( ), artifactReference.getArtifactId( ), VersionUtil.getBaseVersion( artifactReference.getVersion( ) ));
|
||||
return toVersion( artifactReference.getGroupId( ), artifactReference.getArtifactId( ), artifactReference.getVersion( ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier) {
|
||||
ArtifactReference ar = new ArtifactReference( );
|
||||
ar.setGroupId( groupId );
|
||||
ar.setArtifactId( artifactId );
|
||||
ar.setVersion( version );
|
||||
ar.setType( type );
|
||||
ar.setClassifier( classifier );
|
||||
return ar;
|
||||
return new ArtifactReference( ).groupId( groupId ).artifactId( artifactId ).version( version ).type( type ).classifier( classifier );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deleteVersion( VersionedReference reference )
|
||||
public void deleteVersion( VersionedReference ref ) throws ContentNotFoundException, ContentAccessException
|
||||
{
|
||||
Path projectDir = getRepoDir().resolve(toPath(reference));
|
||||
if ( Files.exists(projectDir) && Files.isDirectory(projectDir) )
|
||||
final String path = toPath( ref );
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
@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) )
|
||||
if ( Files.isDirectory(deleteTarget) )
|
||||
{
|
||||
try
|
||||
{
|
||||
org.apache.archiva.common.utils.FileUtils.deleteDirectory( projDirectory );
|
||||
org.apache.archiva.common.utils.FileUtils.deleteDirectory( deleteTarget );
|
||||
}
|
||||
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
|
||||
{
|
||||
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
|
||||
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( );
|
||||
Path filePath = repoDir.resolve( toPath( artifactReference ) );
|
||||
Path parentPath = filePath.getParent( );
|
||||
if ( Files.exists(filePath) )
|
||||
Path deleteTarget = repoDir.resolve( path );
|
||||
if ( Files.exists(deleteTarget) )
|
||||
{
|
||||
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
|
||||
public void deleteGroupId( String groupId )
|
||||
throws ContentNotFoundException
|
||||
throws ContentNotFoundException, ContentAccessException
|
||||
{
|
||||
Path directory = getRepoDir( ).resolve( toPath( groupId ) );
|
||||
if ( Files.exists(directory) )
|
||||
final String path = toPath( groupId );
|
||||
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
|
||||
{
|
||||
org.apache.archiva.common.utils.FileUtils.deleteDirectory( directory );
|
||||
org.apache.archiva.common.utils.FileUtils.deleteDirectory( deleteTarget );
|
||||
}
|
||||
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 class ManagedDefaultRepositoryContent
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
|
||||
throws ContentNotFoundException, LayoutException
|
||||
public List<ArtifactReference> getRelatedArtifacts( VersionedReference reference )
|
||||
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 repoDir = artifactFile.getParent();
|
||||
String ext;
|
||||
if (!artifactFile.isContainer()) {
|
||||
ext = StringUtils.substringAfterLast( artifactFile.getName(), ".");
|
||||
} else {
|
||||
ext = "";
|
||||
}
|
||||
|
||||
if ( !repoDir.exists())
|
||||
{
|
||||
|
@ -234,25 +370,33 @@ public class ManagedDefaultRepositoryContent
|
|||
// First gather up the versions found as artifacts in the managed repository.
|
||||
|
||||
try (Stream<StorageAsset> stream = repoDir.list().stream() ) {
|
||||
return stream.filter(asset -> !asset.isContainer()).map(path -> {
|
||||
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;
|
||||
}
|
||||
return toArtifactReference(path.getPath());
|
||||
} catch (LayoutException e) {
|
||||
log.debug( "Not processing file that is not an artifact: {}", e.getMessage() );
|
||||
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
|
||||
public List<StorageAsset> getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException
|
||||
public List<StorageAsset> getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -288,19 +432,20 @@ public class ManagedDefaultRepositoryContent
|
|||
*/
|
||||
@Override
|
||||
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));
|
||||
if ( !Files.exists(projDir) )
|
||||
{
|
||||
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) )
|
||||
{
|
||||
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();
|
||||
|
@ -312,45 +457,50 @@ public class ManagedDefaultRepositoryContent
|
|||
.collect(Collectors.toSet());
|
||||
} catch (IOException 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) {
|
||||
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 {
|
||||
throw e;
|
||||
} else {
|
||||
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
|
||||
public Set<String> getVersions( VersionedReference reference )
|
||||
throws ContentNotFoundException
|
||||
throws ContentNotFoundException, ContentAccessException, LayoutException
|
||||
{
|
||||
try(Stream<ArtifactReference> stream = getArtifactStream( reference ))
|
||||
{
|
||||
return stream.filter( Objects::nonNull )
|
||||
.map( ar -> ar.getVersion( ) )
|
||||
.collect( Collectors.toSet( ) );
|
||||
}
|
||||
catch ( LayoutException | IOException e )
|
||||
{
|
||||
throw new ContentNotFoundException( e.getMessage( ), e );
|
||||
} catch (IOException e) {
|
||||
final String path = toPath( reference );
|
||||
log.error("Could not read directory from repository {} - {}: ", getId(), path, e.getMessage(), e);
|
||||
throw new ContentAccessException( "Could not read path for repository "+getId()+": "+ path, e );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContent( ArtifactReference reference )
|
||||
public boolean hasContent( ArtifactReference reference ) throws ContentAccessException
|
||||
{
|
||||
StorageAsset artifactFile = toFile( reference );
|
||||
return artifactFile.exists() && !artifactFile.isContainer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContent( ProjectReference reference )
|
||||
public boolean hasContent( ProjectReference reference ) throws ContentAccessException
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -364,16 +514,22 @@ public class ManagedDefaultRepositoryContent
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContent( VersionedReference reference )
|
||||
public boolean hasContent( VersionedReference reference ) throws ContentAccessException
|
||||
{
|
||||
try
|
||||
{
|
||||
return ( getFirstArtifact( reference ) != null );
|
||||
}
|
||||
catch ( IOException | LayoutException | ContentNotFoundException e )
|
||||
catch ( LayoutException | ContentNotFoundException e )
|
||||
{
|
||||
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
|
||||
|
@ -439,6 +595,12 @@ public class ManagedDefaultRepositoryContent
|
|||
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.
|
||||
*
|
||||
|
@ -481,15 +643,17 @@ public class ManagedDefaultRepositoryContent
|
|||
.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 ))
|
||||
{
|
||||
return stream.collect( Collectors.toList( ) );
|
||||
} catch ( IOException e )
|
||||
{
|
||||
log.error( "Could not access the repository files: ", e.getMessage( ), e );
|
||||
throw new ContentNotFoundException( e.getMessage( ), 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 );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -279,7 +279,7 @@ public class ManagedDefaultRepositoryContentTest
|
|||
}
|
||||
|
||||
@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" );
|
||||
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
|
||||
|
@ -298,8 +298,8 @@ public class ManagedDefaultRepositoryContentTest
|
|||
|
||||
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.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.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" ) ) );
|
||||
|
||||
|
||||
|
@ -307,7 +307,7 @@ public class ManagedDefaultRepositoryContentTest
|
|||
|
||||
|
||||
@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" );
|
||||
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
|
||||
|
@ -327,7 +327,7 @@ public class ManagedDefaultRepositoryContentTest
|
|||
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.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.md5" ) ) );
|
||||
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
|
||||
|
@ -336,7 +336,7 @@ public class ManagedDefaultRepositoryContentTest
|
|||
}
|
||||
|
||||
@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" );
|
||||
assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
|
||||
|
@ -357,4 +357,41 @@ public class ManagedDefaultRepositoryContentTest
|
|||
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" ) ) );
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
|
@ -96,7 +96,6 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
|
@ -684,7 +683,7 @@ public class DefaultRepositoriesService
|
|||
|
||||
MetadataRepository metadataRepository = repositorySession.getRepository();
|
||||
|
||||
List<ArtifactReference> related = repository.getRelatedArtifacts( artifactReference );
|
||||
List<ArtifactReference> related = repository.getRelatedArtifacts( repository.toVersion(artifactReference) );
|
||||
log.debug( "related: {}", related );
|
||||
for ( ArtifactReference artifactRef : related )
|
||||
{
|
||||
|
@ -793,7 +792,7 @@ public class DefaultRepositoriesService
|
|||
artifactReference.setGroupId( artifact.getGroupId() );
|
||||
artifactReference.setVersion( artifact.getVersion() );
|
||||
artifactReference.setClassifier( artifact.getClassifier() );
|
||||
artifactReference.setType( artifact.getPackaging() );
|
||||
artifactReference.setType( artifact.getType() );
|
||||
|
||||
MetadataRepository metadataRepository = repositorySession.getRepository();
|
||||
|
||||
|
@ -806,8 +805,10 @@ public class DefaultRepositoriesService
|
|||
throw new ArchivaRestServiceException( "You must configure a type/packaging when using classifier",
|
||||
400, null );
|
||||
}
|
||||
|
||||
repository.deleteArtifact( artifactReference );
|
||||
List<ArtifactReference> artifacts = repository.getRelatedArtifacts( artifactReference );
|
||||
for (ArtifactReference aRef : artifacts ) {
|
||||
repository.deleteArtifact( aRef );
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
|
@ -833,11 +834,18 @@ public class DefaultRepositoriesService
|
|||
}
|
||||
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 );
|
||||
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() );
|
||||
ArchivaRepositoryMetadata metadata = getMetadata( repository.getRepository().getType(), metadataFile );
|
||||
|
|
|
@ -303,6 +303,7 @@ public class RepositoriesServiceTest
|
|||
artifact.setVersion( "1.0.1" );
|
||||
artifact.setClassifier( "javadoc" );
|
||||
artifact.setPackaging( "jar" );
|
||||
artifact.setType( "javadoc" );
|
||||
artifact.setContext( SOURCE_REPO_ID );
|
||||
|
||||
RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );
|
||||
|
|
|
@ -40,7 +40,6 @@ import org.apache.archiva.indexer.merger.base.MergedRemoteIndexesTaskRequest;
|
|||
import org.apache.archiva.indexer.merger.TemporaryGroupIndex;
|
||||
import org.apache.archiva.indexer.search.RepositorySearch;
|
||||
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.repository.storage.RelocationException;
|
||||
import org.apache.archiva.metadata.repository.storage.RepositoryStorage;
|
||||
|
@ -66,7 +65,6 @@ import org.apache.archiva.repository.ReleaseScheme;
|
|||
import org.apache.archiva.repository.RepositoryGroup;
|
||||
import org.apache.archiva.repository.RepositoryRegistry;
|
||||
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.StorageAsset;
|
||||
import org.apache.archiva.metadata.audit.AuditListener;
|
||||
|
@ -104,7 +102,6 @@ import javax.inject.Inject;
|
|||
import javax.inject.Named;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
|
@ -671,6 +668,10 @@ public class ArchivaDavResourceFactory
|
|||
{
|
||||
log.warn( "Artifact path '{}' is invalid.", resourcePath );
|
||||
}
|
||||
catch ( org.apache.archiva.repository.ContentAccessException e )
|
||||
{
|
||||
e.printStackTrace( );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue