aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2019-08-06 22:06:57 +0200
committerMartin Stockhammer <martin_s@apache.org>2019-08-06 22:06:57 +0200
commit21d5cf53fe45111fdb030b307715780703032de7 (patch)
tree8331f135e7349cad9996a9cd222d7fc401877fd2 /archiva-modules/archiva-base
parenteca0097d857aa4739a6387c67d22a9a355a46fa1 (diff)
downloadarchiva-21d5cf53fe45111fdb030b307715780703032de7.tar.gz
archiva-21d5cf53fe45111fdb030b307715780703032de7.zip
Refactoring repository metadata session handling
Diffstat (limited to 'archiva-modules/archiva-base')
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurge.java34
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java2
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java30
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java18
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java26
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java18
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java36
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java22
8 files changed, 92 insertions, 94 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 c4706158c..a8cf4b7f2 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
@@ -23,10 +23,7 @@ import org.apache.archiva.common.utils.VersionUtil;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.facets.AuditEvent;
import org.apache.archiva.metadata.model.maven2.MavenArtifactFacet;
-import org.apache.archiva.metadata.repository.MetadataRepository;
-import org.apache.archiva.metadata.repository.MetadataRepositoryException;
-import org.apache.archiva.metadata.repository.MetadataResolutionException;
-import org.apache.archiva.metadata.repository.RepositorySession;
+import org.apache.archiva.metadata.repository.*;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.repository.ContentNotFoundException;
import org.apache.archiva.repository.ManagedRepositoryContent;
@@ -203,7 +200,7 @@ public abstract class AbstractRepositoryPurge
{
try
{
- metaResolved.put( metaBaseId, metadataRepository.getArtifacts( , repository.getId( ),
+ metaResolved.put( metaBaseId, metadataRepository.getArtifacts(repositorySession, repository.getId( ),
reference.getGroupId( ), reference.getArtifactId( ), baseVersion ) );
}
catch ( MetadataResolutionException e )
@@ -314,18 +311,22 @@ public abstract class AbstractRepositoryPurge
}
projectLevelMetadata.add( info.projectVersionLevel( ) );
}
- metadataRepository.save( );
+ try {
+ repositorySession.save( );
+ } catch (MetadataSessionException e) {
+ log.error("Could not save sesion {}", e.getMessage());
+ }
Collection<ArtifactMetadata> artifacts = null;
// Get remaining artifacts and remove project if empty
for ( ArtifactInfo info : projectLevelMetadata )
{
try
{
- artifacts = metadataRepository.getArtifacts( , repository.getId( ), info.getNamespace( ),
+ artifacts = metadataRepository.getArtifacts(repositorySession , repository.getId( ), info.getNamespace( ),
info.getName( ), info.getProjectVersion( ) );
if ( artifacts.size( ) == 0 )
{
- metadataRepository.removeProjectVersion( , repository.getId( ),
+ metadataRepository.removeProjectVersion(repositorySession , repository.getId( ),
info.getNamespace( ), info.getName( ), info.getProjectVersion( ) );
log.debug( "Removed project version from MetadataRepository {}", info );
}
@@ -335,7 +336,12 @@ public abstract class AbstractRepositoryPurge
log.error( "Could not remove project version from MetadataRepository {}: {}", info, e.getMessage( ), e );
}
}
- metadataRepository.save( );
+ try {
+ repositorySession.save( );
+ } catch (MetadataSessionException e) {
+ log.error("Could not save sesion {}", e.getMessage());
+
+ }
}
@@ -360,14 +366,18 @@ public abstract class AbstractRepositoryPurge
version = artifactInfo.getProjectVersion( );
MavenArtifactFacet mavenArtifactFacetToCompare = new MavenArtifactFacet( );
mavenArtifactFacetToCompare.setClassifier( artifactInfo.getClassifier( ) );
- metadataRepository.removeArtifact( , repository.getId( ), groupId,
+ metadataRepository.removeArtifact(repositorySession , repository.getId( ), groupId,
artifactId, version, mavenArtifactFacetToCompare );
- metadataRepository.save( );
+ try {
+ repositorySession.save( );
+ } catch (MetadataSessionException e) {
+ log.error("Could not save session {}", e.getMessage());
+ }
}
}
else
{
- metadataRepository.removeArtifact( , artifactMetadata, artifactInfo.getProjectVersion( ) );
+ metadataRepository.removeArtifact(repositorySession , artifactMetadata, artifactInfo.getProjectVersion( ) );
}
}
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 5c33d44b9..7030ac74b 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
@@ -158,7 +158,7 @@ public class CleanupReleasedSnapshotsRepositoryPurge
artifactRef.getArtifactId( ), artifactRef.getVersion( ),
artifactFile.getFileName().toString() );
}
- metadataRepository.removeProjectVersion( , repository.getId( ),
+ metadataRepository.removeProjectVersion( repositorySession, repository.getId( ),
artifactRef.getGroupId( ), artifactRef.getArtifactId( ), artifactRef.getVersion( ) );
needsMetadataUpdate = true;
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java
index 034aab925..fdd86cb94 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java
@@ -127,7 +127,7 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
// Provide the metadata list
List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
- when(metadataRepository.getArtifacts( , TEST_REPO_ID,
+ when(metadataRepository.getArtifacts(repositorySession , TEST_REPO_ID,
projectNs, projectName, projectVersion )).thenReturn(ml);
@@ -137,8 +137,8 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
// Verify the metadataRepository invocations
// complete snapshot version removal for released
- verify(metadataRepository, times(1)).removeProjectVersion( , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
- verify(metadataRepository, never()).removeProjectVersion( , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq("2.3") );
+ verify(metadataRepository, times(1)).removeProjectVersion(repositorySession , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
+ verify(metadataRepository, never()).removeProjectVersion(repositorySession , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq("2.3") );
// check if the snapshot was removed
assertDeleted( projectRoot + "/2.3-SNAPSHOT" );
@@ -246,11 +246,11 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
// Provide the metadata list
List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
- when(metadataRepository.getArtifacts( , TEST_REPO_ID,
+ when(metadataRepository.getArtifacts(repositorySession , TEST_REPO_ID,
projectNs, projectName, projectVersion )).thenReturn(ml);
List<ArtifactMetadata> ml2 = getArtifactMetadataFromDir(RELEASES_TEST_REPO_ID , projectName, repo.getParent(), releaseDir );
- when(metadataRepository.getArtifacts( , RELEASES_TEST_REPO_ID,
+ when(metadataRepository.getArtifacts(repositorySession , RELEASES_TEST_REPO_ID,
projectNs, projectName, releaseVersion )).thenReturn(ml2);
@@ -260,8 +260,8 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
// Verify the metadataRepository invocations
// Complete version removal for cleanup
- verify(metadataRepository, times(1)).removeProjectVersion( , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
- verify(metadataRepository, never()).removeProjectVersion( , eq(RELEASES_TEST_REPO_ID), eq(projectNs), eq(projectName), eq(releaseVersion) );
+ verify(metadataRepository, times(1)).removeProjectVersion(repositorySession , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
+ verify(metadataRepository, never()).removeProjectVersion(repositorySession , eq(RELEASES_TEST_REPO_ID), eq(projectNs), eq(projectName), eq(releaseVersion) );
// check if the snapshot was removed
@@ -317,13 +317,13 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
// Provide the metadata list
List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
- when(metadataRepository.getArtifacts( , TEST_REPO_ID,
+ when(metadataRepository.getArtifacts(repositorySession , TEST_REPO_ID,
projectNs, projectName, projectVersion )).thenReturn(ml);
List<ArtifactMetadata> m2 = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir2 );
- when(metadataRepository.getArtifacts( , TEST_REPO_ID,
+ when(metadataRepository.getArtifacts(repositorySession , TEST_REPO_ID,
projectNs, projectName, "2.0.3-SNAPSHOT" )).thenReturn(ml);
List<ArtifactMetadata> m3 = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir3 );
- when(metadataRepository.getArtifacts( , TEST_REPO_ID,
+ when(metadataRepository.getArtifacts(repositorySession , TEST_REPO_ID,
projectNs, projectName, "2.0.4-SNAPSHOT" )).thenReturn(ml);
@@ -333,11 +333,11 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
// Verify the metadataRepository invocations
// No removal
- verify(metadataRepository, never()).removeProjectVersion( , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
- verify(metadataRepository, never()).removeProjectVersion( , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq("2.0.3-SNAPSHOT") );
- verify(metadataRepository, never()).removeProjectVersion( , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq("2.0.4-SNAPSHOT") );
- verify(metadataRepository, never()).removeArtifact( , any(ArtifactMetadata.class), any(String.class) );
- verify(metadataRepository, never()).removeArtifact( , any(String.class), any(String.class), any(String.class), any(String.class), any( MetadataFacet.class) );
+ verify(metadataRepository, never()).removeProjectVersion(repositorySession , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
+ verify(metadataRepository, never()).removeProjectVersion(repositorySession , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq("2.0.3-SNAPSHOT") );
+ verify(metadataRepository, never()).removeProjectVersion(repositorySession , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq("2.0.4-SNAPSHOT") );
+ verify(metadataRepository, never()).removeArtifact(repositorySession , any(ArtifactMetadata.class), any(String.class) );
+ verify(metadataRepository, never()).removeArtifact(repositorySession , any(String.class), any(String.class), any(String.class), any(String.class), any( MetadataFacet.class) );
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java
index 36b225e47..651e90a3c 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java
@@ -112,7 +112,7 @@ public class DaysOldRepositoryPurgeTest
// Provide the metadata list
List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
- when(metadataRepository.getArtifacts( , TEST_REPO_ID,
+ when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
projectNs, projectName, projectVersion )).thenReturn(ml);
repoPurge.process( PATH_TO_BY_DAYS_OLD_ARTIFACT );
@@ -120,9 +120,9 @@ public class DaysOldRepositoryPurgeTest
listenerControl.verify();
// Verify the metadataRepository invocations
- verify(metadataRepository, never()).removeProjectVersion( , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
+ verify(metadataRepository, never()).removeProjectVersion(repositorySession , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
- verify(metadataRepository, times(2)).removeArtifact( , metadataArg.capture(), eq(projectVersion) );
+ verify(metadataRepository, times(2)).removeArtifact(repositorySession , metadataArg.capture(), eq(projectVersion) );
List<ArtifactMetadata> metaL = metadataArg.getAllValues();
for (ArtifactMetadata meta : metaL) {
assertTrue(meta.getId().startsWith(projectName));
@@ -197,7 +197,7 @@ public class DaysOldRepositoryPurgeTest
// Provide the metadata list
List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
- when(metadataRepository.getArtifacts( , TEST_REPO_ID,
+ when(metadataRepository.getArtifacts(repositorySession , TEST_REPO_ID,
projectNs, projectName, projectVersion )).thenReturn(ml);
@@ -206,9 +206,9 @@ public class DaysOldRepositoryPurgeTest
listenerControl.verify();
// Verify the metadataRepository invocations
- verify(metadataRepository, never()).removeProjectVersion( , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
+ verify(metadataRepository, never()).removeProjectVersion(repositorySession , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
- verify(metadataRepository, times(deletedVersions.size())).removeArtifact( , metadataArg.capture(), eq(projectVersion) );
+ verify(metadataRepository, times(deletedVersions.size())).removeArtifact(repositorySession , metadataArg.capture(), eq(projectVersion) );
List<ArtifactMetadata> metaL = metadataArg.getAllValues();
for (ArtifactMetadata meta : metaL) {
assertTrue(meta.getId().startsWith(projectName));
@@ -296,7 +296,7 @@ public class DaysOldRepositoryPurgeTest
// Provide the metadata list
List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
- when(metadataRepository.getArtifacts( , TEST_REPO_ID,
+ when(metadataRepository.getArtifacts(repositorySession , TEST_REPO_ID,
projectNs, projectName, projectVersion )).thenReturn(ml);
@@ -305,9 +305,9 @@ public class DaysOldRepositoryPurgeTest
listenerControl.verify();
// Verify the metadataRepository invocations
- verify(metadataRepository, never()).removeProjectVersion( , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
+ verify(metadataRepository, never()).removeProjectVersion(repositorySession , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
- verify(metadataRepository, times(deletedVersions.size())).removeArtifact( , metadataArg.capture(), eq(projectVersion) );
+ verify(metadataRepository, times(deletedVersions.size())).removeArtifact( repositorySession, metadataArg.capture(), eq(projectVersion) );
List<ArtifactMetadata> metaL = metadataArg.getAllValues();
for (ArtifactMetadata meta : metaL) {
assertTrue(meta.getId().startsWith(projectName));
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java
index 2e63c3307..d6f634fd9 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java
@@ -188,7 +188,7 @@ public class RepositoryPurgeConsumerTest
// Provide the metadata list
List<ArtifactMetadata> ml = getArtifactMetadataFromDir( TEST_REPO_ID, projectName, repo, vDir );
- when(metadataRepository.getArtifacts( , TEST_REPO_ID,
+ when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
projectNs, projectName, projectVersion )).thenReturn(ml);
Set<String> deletedVersions = new HashSet<>();
deletedVersions.add("1.0RC1-20070504.153317-1");
@@ -197,9 +197,9 @@ public class RepositoryPurgeConsumerTest
repoPurgeConsumer.processFile( PATH_TO_BY_RETENTION_COUNT_ARTIFACT );
// Verify the metadataRepository invocations
- verify(metadataRepository, never()).removeProjectVersion( , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
+ verify(metadataRepository, never()).removeProjectVersion( repositorySession, eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
- verify(metadataRepository, times(2)).removeArtifact( , metadataArg.capture(), eq(projectVersion) );
+ verify(metadataRepository, times(2)).removeArtifact( repositorySession, metadataArg.capture(), eq(projectVersion) );
List<ArtifactMetadata> metaL = metadataArg.getAllValues();
for (ArtifactMetadata meta : metaL) {
assertTrue(meta.getId().startsWith(projectName));
@@ -291,7 +291,7 @@ public class RepositoryPurgeConsumerTest
// Provide the metadata list
List<ArtifactMetadata> ml = getArtifactMetadataFromDir( TEST_REPO_ID, projectName, repo, vDir );
- when(metadataRepository.getArtifacts( , TEST_REPO_ID,
+ when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
projectNs, projectName, projectVersion )).thenReturn(ml);
Set<String> deletedVersions = new HashSet<>();
deletedVersions.add("2.2-SNAPSHOT");
@@ -300,9 +300,9 @@ public class RepositoryPurgeConsumerTest
repoPurgeConsumer.processFile( PATH_TO_BY_DAYS_OLD_ARTIFACT );
// Verify the metadataRepository invocations
- verify(metadataRepository, never()).removeProjectVersion( , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
+ verify(metadataRepository, never()).removeProjectVersion( repositorySession, eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
- verify(metadataRepository, times(2)).removeArtifact( , metadataArg.capture(), eq(projectVersion) );
+ verify(metadataRepository, times(2)).removeArtifact( repositorySession, metadataArg.capture(), eq(projectVersion) );
List<ArtifactMetadata> metaL = metadataArg.getAllValues();
for (ArtifactMetadata meta : metaL) {
assertTrue(meta.getId().startsWith(projectName));
@@ -373,16 +373,16 @@ public class RepositoryPurgeConsumerTest
// Provide the metadata list
List<ArtifactMetadata> ml = getArtifactMetadataFromDir( TEST_REPO_ID, projectName, repo, vDir );
- when(metadataRepository.getArtifacts( , TEST_REPO_ID,
+ when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
projectNs, projectName, projectVersion )).thenReturn(ml);
repoPurgeConsumer.processFile(
CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO );
- verify(metadataRepository, never()).removeProjectVersion( , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
+ verify(metadataRepository, never()).removeProjectVersion( repositorySession, eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
- verify(metadataRepository, never()).removeArtifact( , any(), any() );
- verify(metadataRepository, never()).removeArtifact( , any(), any(), any(), any(), any(MetadataFacet.class) );
+ verify(metadataRepository, never()).removeArtifact( repositorySession, any(), any() );
+ verify(metadataRepository, never()).removeArtifact( repositorySession, any(), any(), any(), any(), any(MetadataFacet.class) );
// check if the snapshot wasn't removed
@@ -436,15 +436,15 @@ public class RepositoryPurgeConsumerTest
// Provide the metadata list
List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
- when(metadataRepository.getArtifacts( , TEST_REPO_ID,
+ when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
projectNs, projectName, projectVersion )).thenReturn(ml);
repoPurgeConsumer.processFile(
CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO );
- verify(metadataRepository, times(1)).removeProjectVersion( , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
+ verify(metadataRepository, times(1)).removeProjectVersion( repositorySession, eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
- verify(metadataRepository, never()).removeArtifact( , any(), any() );
+ verify(metadataRepository, never()).removeArtifact( repositorySession, any(), any() );
// check if the snapshot was removed
assertDeleted( projectRoot + "/2.3-SNAPSHOT" );
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java
index 734df37a4..ba16bc3d8 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java
@@ -115,7 +115,7 @@ public class RetentionCountRepositoryPurgeTest
// Provide the metadata list
List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
- when(metadataRepository.getArtifacts( , TEST_REPO_ID,
+ when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
projectNs, projectName, projectVersion )).thenReturn(ml);
@@ -124,9 +124,9 @@ public class RetentionCountRepositoryPurgeTest
listenerControl.verify();
// Verify the metadataRepository invocations
- verify(metadataRepository, never()).removeProjectVersion( , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
+ verify(metadataRepository, never()).removeProjectVersion( repositorySession, eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
- verify(metadataRepository, times(deletedVersions.size())).removeArtifact( , metadataArg.capture(), eq(projectVersion) );
+ verify(metadataRepository, times(deletedVersions.size())).removeArtifact( repositorySession, metadataArg.capture(), eq(projectVersion) );
List<ArtifactMetadata> metaL = metadataArg.getAllValues();
for (ArtifactMetadata meta : metaL) {
assertTrue(meta.getId().startsWith(projectName));
@@ -202,7 +202,7 @@ public class RetentionCountRepositoryPurgeTest
// Provide the metadata list
List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
- when(metadataRepository.getArtifacts( , TEST_REPO_ID,
+ when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
projectNs, projectName, projectVersion )).thenReturn(ml);
repoPurge.process( PATH_TO_BY_RETENTION_COUNT_POM );
@@ -210,9 +210,9 @@ public class RetentionCountRepositoryPurgeTest
listenerControl.verify();
// Verify the metadataRepository invocations
- verify(metadataRepository, never()).removeProjectVersion( , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
+ verify(metadataRepository, never()).removeProjectVersion( repositorySession, eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
- verify(metadataRepository, times(deletedVersions.size())).removeArtifact( , metadataArg.capture(), eq(projectVersion) );
+ verify(metadataRepository, times(deletedVersions.size())).removeArtifact( repositorySession, metadataArg.capture(), eq(projectVersion) );
List<ArtifactMetadata> metaL = metadataArg.getAllValues();
for (ArtifactMetadata meta : metaL) {
assertTrue(meta.getId().startsWith(projectName));
@@ -290,7 +290,7 @@ public class RetentionCountRepositoryPurgeTest
// Provide the metadata list
List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
- when(metadataRepository.getArtifacts( , TEST_REPO_ID,
+ when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
projectNs, projectName, projectVersion )).thenReturn(ml);
repoPurge.process( PATH_TO_TEST_ORDER_OF_DELETION );
@@ -298,9 +298,9 @@ public class RetentionCountRepositoryPurgeTest
listenerControl.verify();
// Verify the metadataRepository invocations
- verify(metadataRepository, never()).removeProjectVersion( , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
+ verify(metadataRepository, never()).removeProjectVersion( repositorySession, eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
- verify(metadataRepository, times(deletedVersions.size())).removeArtifact( , metadataArg.capture(), eq(projectVersion) );
+ verify(metadataRepository, times(deletedVersions.size())).removeArtifact( repositorySession, metadataArg.capture(), eq(projectVersion) );
List<ArtifactMetadata> metaL = metadataArg.getAllValues();
for (ArtifactMetadata meta : metaL) {
assertTrue(meta.getId().startsWith(projectName));
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java
index e93b032ac..f50cbbd81 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java
@@ -29,10 +29,7 @@ import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
-import org.apache.archiva.metadata.repository.MetadataRepository;
-import org.apache.archiva.metadata.repository.MetadataRepositoryException;
-import org.apache.archiva.metadata.repository.RepositorySession;
-import org.apache.archiva.metadata.repository.RepositorySessionFactory;
+import org.apache.archiva.metadata.repository.*;
import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest;
import org.apache.archiva.metadata.repository.storage.RepositoryStorage;
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException;
@@ -193,14 +190,14 @@ public class ArchivaMetadataCreationConsumer
// read the metadata and update it if it is newer or doesn't exist
artifact.setWhenGathered( whenGathered );
- metadataRepository.updateArtifact( , repoId, project.getNamespace(), project.getId(),
+ metadataRepository.updateArtifact(repositorySession , repoId, project.getNamespace(), project.getId(),
projectVersion, artifact );
if ( createVersionMetadata )
{
- metadataRepository.updateProjectVersion( , repoId, project.getNamespace(),
+ metadataRepository.updateProjectVersion(repositorySession , repoId, project.getNamespace(),
project.getId(), versionMetadata );
}
- metadataRepository.updateProject( , repoId, project );
+ metadataRepository.updateProject(repositorySession , repoId, project );
repositorySession.save();
}
catch ( MetadataRepositoryException e )
@@ -208,27 +205,28 @@ public class ArchivaMetadataCreationConsumer
log.warn(
"Error occurred persisting metadata for artifact:{} (repository:{}); message: {}" ,
path, repoId, e.getMessage(), e );
- repositorySession.revert();
+ try {
+ repositorySession.revert();
+ } catch (MetadataSessionException ex) {
+ log.error("Reverting failed {}", ex.getMessage());
+ }
}
catch ( RepositoryStorageRuntimeException e )
{
log.warn(
"Error occurred persisting metadata for artifact:{} (repository:{}); message: {}",
path, repoId, e.getMessage(), e );
- repositorySession.revert();
- }
- finally
+ try {
+ repositorySession.revert();
+ } catch (MetadataSessionException ex) {
+ log.error("Reverting failed {}", ex.getMessage());
+ }
+ } catch (MetadataSessionException e) {
+ throw new ConsumerException(e.getMessage(), e);
+ } finally
{
repositorySession.close();
}
- catch ( org.apache.archiva.metadata.repository.MetadataSessionException e )
- {
- e.printStackTrace( );
- }
- catch ( org.apache.archiva.metadata.repository.MetadataSessionException e )
- {
- e.printStackTrace( );
- }
}
@Override
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
index c8cf62aac..6d7d8d7c8 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
@@ -32,10 +32,7 @@ import org.apache.archiva.indexer.ArchivaIndexManager;
import org.apache.archiva.indexer.IndexManagerFactory;
import org.apache.archiva.indexer.IndexUpdateFailedException;
import org.apache.archiva.metadata.model.facets.AuditEvent;
-import org.apache.archiva.metadata.repository.MetadataRepository;
-import org.apache.archiva.metadata.repository.MetadataRepositoryException;
-import org.apache.archiva.metadata.repository.RepositorySession;
-import org.apache.archiva.metadata.repository.RepositorySessionFactory;
+import org.apache.archiva.metadata.repository.*;
import org.apache.archiva.metadata.repository.stats.model.RepositoryStatisticsManager;
import org.apache.archiva.redback.components.cache.Cache;
import org.apache.archiva.redback.components.registry.RegistryException;
@@ -352,7 +349,7 @@ public class DefaultManagedRepositoryAdmin
try
{
MetadataRepository metadataRepository = repositorySession.getRepository();
- metadataRepository.removeRepository( , repository.getId() );
+ metadataRepository.removeRepository(repositorySession , repository.getId() );
//invalidate cache
namespacesCache.remove( repository.getId() );
log.debug( "call repositoryStatisticsManager.deleteStatistics" );
@@ -363,15 +360,12 @@ public class DefaultManagedRepositoryAdmin
{
//throw new RepositoryAdminException( e.getMessage(), e );
log.warn( "skip error during removing repository from MetadataRepository:{}", e.getMessage(), e );
- }
- finally
+ } catch (MetadataSessionException e) {
+ log.warn( "skip error during removing repository from MetadataRepository:{}", e.getMessage(), e );
+ } finally
{
repositorySession.close();
}
- catch ( org.apache.archiva.metadata.repository.MetadataSessionException e )
- {
- e.printStackTrace( );
- }
}
if ( deleteContent )
@@ -526,7 +520,7 @@ public class DefaultManagedRepositoryAdmin
}
}
- catch ( MetadataRepositoryException e )
+ catch (MetadataRepositoryException | MetadataSessionException e )
{
throw new RepositoryAdminException( e.getMessage(), e );
}
@@ -534,10 +528,6 @@ public class DefaultManagedRepositoryAdmin
{
repositorySession.close();
}
- catch ( org.apache.archiva.metadata.repository.MetadataSessionException e )
- {
- e.printStackTrace( );
- }
if ( updateIndexContext )
{