aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurge.java4
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java4
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurge.java8
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java7
-rw-r--r--archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ContentNotFoundException.java2
-rw-r--r--archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java73
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/base/MetadataTools.java22
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java50
-rw-r--r--archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java48
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java48
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java338
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java49
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/log4j2-test.xml41
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java22
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java1
-rw-r--r--archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java7
16 files changed, 561 insertions, 163 deletions
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurge.java
index 6df43d78c..a8daf16a2 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurge.java
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurge.java
@@ -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( ) );
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java
index 56b3bf0cf..84a1d0f81 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java
@@ -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( );
+ }
}
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurge.java
index 1a443ee9a..f5ae868b8 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurge.java
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurge.java
@@ -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 )
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java
index 5cd523d93..af617c143 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java
@@ -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( );
+ }
}
/*
diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ContentNotFoundException.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ContentNotFoundException.java
index 7579debfe..63e7ee7c0 100644
--- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ContentNotFoundException.java
+++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ContentNotFoundException.java
@@ -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
diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java
index 294804475..5dd39cc45 100644
--- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java
+++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java
@@ -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>
@@ -118,6 +134,26 @@ public interface ManagedRepositoryContent extends RepositoryContent
/**
* <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.
* This typically includes the pom files, and those things with
* classifiers (such as doc, source code, test libs, etc...). Even if the classifier
* is set in the artifact reference, it may return artifacts with different classifiers.
@@ -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
@@ -242,6 +277,14 @@ public interface ManagedRepositoryContent extends RepositoryContent
* @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.
+ *
+ * @param reference the artifact reference to use.
+ * @return the relative path to the artifact.
+ */
StorageAsset toFile( ArtifactReference reference );
/**
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/base/MetadataTools.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/base/MetadataTools.java
index d85b3a320..b875be6ae 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/base/MetadataTools.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/base/MetadataTools.java
@@ -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?
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
index 3b42d2783..324843090 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
@@ -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;
@@ -49,6 +49,12 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
}
@Override
+ public VersionedReference toGenericVersion( ArtifactReference artifactReference )
+ {
+ return null;
+ }
+
+ @Override
public VersionedReference toVersion( ArtifactReference artifactReference )
{
return null;
@@ -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, ContentAccessException
{
}
@Override
- public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException
+ public void deleteGroupId( String groupId ) throws ContentNotFoundException, ContentAccessException
{
}
@Override
- public void deleteGroupId( String groupId ) throws ContentNotFoundException
+ public void deleteProject( String namespace, String projectId ) throws ContentNotFoundException, ContentAccessException
{
}
@Override
- public void deleteProject( String namespace, String projectId ) throws RepositoryException
+ 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;
}
@@ -157,6 +175,12 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
}
@Override
+ public StorageAsset toFile( VersionedReference reference )
+ {
+ return null;
+ }
+
+ @Override
public ArtifactReference toArtifactReference( String path ) throws LayoutException
{
return null;
diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java
index 6fec88e09..86d43d188 100644
--- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java
+++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java
@@ -65,6 +65,12 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
}
@Override
+ public VersionedReference toGenericVersion( ArtifactReference artifactReference )
+ {
+ return null;
+ }
+
+ @Override
public VersionedReference toVersion( ArtifactReference artifactReference )
{
return null;
@@ -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, ContentAccessException
{
}
@Override
- public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException
+ public void deleteGroupId( String groupId ) throws ContentNotFoundException, ContentAccessException
{
}
@Override
- public void deleteGroupId( String groupId ) throws ContentNotFoundException
+ public void deleteProject( String namespace, String projectId ) throws ContentNotFoundException, ContentAccessException
{
}
@Override
- public void deleteProject( String namespace, String projectId ) throws RepositoryException
+ 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
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
index 3aba949b2..f26334577 100644
--- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
+++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
@@ -69,6 +69,12 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent
}
@Override
+ public VersionedReference toGenericVersion( ArtifactReference artifactReference )
+ {
+ return null;
+ }
+
+ @Override
public VersionedReference toVersion( ArtifactReference artifactReference )
{
return null;
@@ -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, ContentAccessException
{
}
@Override
- public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException
+ public void deleteGroupId( String groupId ) throws ContentNotFoundException, ContentAccessException
{
}
@Override
- public void deleteGroupId( String groupId ) throws ContentNotFoundException
+ public void deleteProject( String namespace, String projectId ) throws ContentNotFoundException, ContentAccessException
{
}
@Override
- public void deleteProject( String namespace, String projectId ) throws RepositoryException
+ 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
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java
index 6336d0ae8..ba14ac075 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java
@@ -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 );
+ }
+ 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( String namespace, String projectId )
- throws RepositoryException
+ public void deleteProject( ProjectReference ref )
+ throws ContentNotFoundException, ContentAccessException
{
- ProjectReference ref = new ProjectReference( );
- ref.setGroupId( namespace );
- ref.setArtifactId( projectId );
- Path projDirectory = getRepoDir( ).resolve( toPath(ref) );
- if ( !Files.exists(projDirectory) )
+ final String path = toPath( ref );
+ final Path deleteTarget = getRepoDir( ).resolve( path );
+ if ( !Files.exists(deleteTarget) )
{
- throw new ContentNotFoundException( "cannot found project " + namespace + ":" + projectId );
+ log.warn( "Project path for repository {} does not exist: {}", getId(), deleteTarget );
+ throw new ContentNotFoundException( "Project not found for repository "+getId()+": "+path );
}
- 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( "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
{
- final Path repoDir = getRepoDir( );
- Path filePath = repoDir.resolve( toPath( artifactReference ) );
- Path parentPath = filePath.getParent( );
- if ( Files.exists(filePath) )
- {
- org.apache.archiva.common.utils.FileUtils.deleteQuietly( filePath );
- }
-
- Path filePathmd5 = parentPath.resolve( filePath.getFileName().toString()+".md5" );
+ this.deleteProject( new ProjectReference().groupId( namespace ).artifactId( projectId ) );
+ }
- if ( Files.exists(filePathmd5) )
+ @Override
+ public void deleteArtifact( ArtifactReference ref ) throws ContentNotFoundException, ContentAccessException
+ {
+ final String path = toPath( ref );
+ final Path repoDir = getRepoDir( );
+ Path deleteTarget = repoDir.resolve( path );
+ if ( Files.exists(deleteTarget) )
{
- org.apache.archiva.common.utils.FileUtils.deleteQuietly( filePathmd5 );
+ 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 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,27 +245,25 @@ public class ManagedDefaultRepositoryContent
}
@Override
- public List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
- throws ContentNotFoundException, LayoutException
+ public List<ArtifactReference> getRelatedArtifacts( VersionedReference reference )
+ throws ContentNotFoundException, LayoutException, ContentAccessException
{
- StorageAsset artifactFile = toFile( reference );
- StorageAsset repoDir = artifactFile.getParent();
-
- if ( !repoDir.exists())
+ StorageAsset artifactDir = toFile( reference );
+ if ( !artifactDir.exists())
{
throw new ContentNotFoundException(
- "Unable to get related artifacts using a non-existant directory: " + repoDir.getPath() );
+ "Unable to get related artifacts using a non-existant directory: " + artifactDir.getPath() );
}
- if ( !repoDir.isContainer() )
+ if ( !artifactDir.isContainer() )
{
throw new ContentNotFoundException(
- "Unable to get related artifacts using a non-directory: " + repoDir.getPath() );
+ "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 = repoDir.list().stream() ) {
+ try (Stream<StorageAsset> stream = artifactDir.list().stream() ) {
return stream.filter(asset -> !asset.isContainer()).map(path -> {
try {
ArtifactReference artifact = toArtifactReference(path.getPath());
@@ -248,11 +278,125 @@ public class ManagedDefaultRepositoryContent
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<StorageAsset> getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException
+ 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<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;
}
@@ -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 );
+
}
}
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java
index c921adf0f..03a9b428f 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java
@@ -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" ) ) );
+
+ }
}
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/log4j2-test.xml b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/log4j2-test.xml
new file mode 100644
index 000000000..9457ae8cd
--- /dev/null
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/log4j2-test.xml
@@ -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> \ No newline at end of file
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
index 4c6561bcc..c313cd9d7 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
@@ -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 );
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java
index 99a868822..7b765c2b1 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java
@@ -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 );
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java
index 7c56f6563..a2c90ec3c 100644
--- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java
+++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java
@@ -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( );
+ }
}
/*