diff options
author | Martin Stockhammer <martin_s@apache.org> | 2019-08-04 22:40:04 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2019-08-04 22:40:04 +0200 |
commit | eca0097d857aa4739a6387c67d22a9a355a46fa1 (patch) | |
tree | 48752d7b63424b3e8b2bf47d11a692bfa69a6ff5 /archiva-modules/archiva-base | |
parent | ee2c1a7b2b623cf76c8a5deff5e8ddb836de2eaa (diff) | |
download | archiva-eca0097d857aa4739a6387c67d22a9a355a46fa1.tar.gz archiva-eca0097d857aa4739a6387c67d22a9a355a46fa1.zip |
Changing session handling for metadata API
Diffstat (limited to 'archiva-modules/archiva-base')
10 files changed, 142 insertions, 88 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 9ec198b73..c4706158c 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 @@ -38,8 +38,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -205,8 +203,8 @@ public abstract class AbstractRepositoryPurge { try { - metaResolved.put( metaBaseId, metadataRepository.getArtifacts( repository.getId( ), reference.getGroupId( ), - reference.getArtifactId( ), baseVersion ) ); + metaResolved.put( metaBaseId, metadataRepository.getArtifacts( , repository.getId( ), + reference.getGroupId( ), reference.getArtifactId( ), baseVersion ) ); } catch ( MetadataResolutionException e ) { @@ -284,7 +282,14 @@ public abstract class AbstractRepositoryPurge purgeSupportFiles( artifactFile ); } purgeMetadata( metadataRepository, metaRemovalList ); - repositorySession.save( ); + try + { + repositorySession.save( ); + } + catch ( org.apache.archiva.metadata.repository.MetadataSessionException e ) + { + e.printStackTrace( ); + } } } @@ -316,12 +321,12 @@ public abstract class AbstractRepositoryPurge { try { - artifacts = metadataRepository.getArtifacts( repository.getId( ), info.getNamespace( ), info.getName( ), - info.getProjectVersion( ) ); + artifacts = metadataRepository.getArtifacts( , repository.getId( ), info.getNamespace( ), + info.getName( ), info.getProjectVersion( ) ); if ( artifacts.size( ) == 0 ) { - metadataRepository.removeProjectVersion( repository.getId( ), info.getNamespace( ), - info.getName( ), info.getProjectVersion( ) ); + metadataRepository.removeProjectVersion( , repository.getId( ), + info.getNamespace( ), info.getName( ), info.getProjectVersion( ) ); log.debug( "Removed project version from MetadataRepository {}", info ); } } @@ -355,14 +360,14 @@ public abstract class AbstractRepositoryPurge version = artifactInfo.getProjectVersion( ); MavenArtifactFacet mavenArtifactFacetToCompare = new MavenArtifactFacet( ); mavenArtifactFacetToCompare.setClassifier( artifactInfo.getClassifier( ) ); - metadataRepository.removeArtifact( repository.getId( ), groupId, artifactId, - version, mavenArtifactFacetToCompare ); + metadataRepository.removeArtifact( , repository.getId( ), groupId, + artifactId, version, mavenArtifactFacetToCompare ); metadataRepository.save( ); } } else { - metadataRepository.removeArtifact( artifactMetadata, artifactInfo.getProjectVersion( ) ); + metadataRepository.removeArtifact( , 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 e36b394d7..5c33d44b9 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,8 +158,8 @@ public class CleanupReleasedSnapshotsRepositoryPurge artifactRef.getArtifactId( ), artifactRef.getVersion( ), artifactFile.getFileName().toString() ); } - metadataRepository.removeProjectVersion( repository.getId( ), artifactRef.getGroupId( ), - artifactRef.getArtifactId( ), artifactRef.getVersion( ) ); + metadataRepository.removeProjectVersion( , repository.getId( ), + artifactRef.getGroupId( ), artifactRef.getArtifactId( ), artifactRef.getVersion( ) ); needsMetadataUpdate = true; } diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumer.java index e1d91563a..6c153f215 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumer.java @@ -137,7 +137,14 @@ public class RepositoryPurgeConsumer ManagedRepositoryContent repositoryContent; repositoryContent = repository.getContent(); - repositorySession = repositorySessionFactory.createSession( ); + try + { + repositorySession = repositorySessionFactory.createSession( ); + } + catch ( org.apache.archiva.metadata.repository.MetadataRepositoryException e ) + { + e.printStackTrace( ); + } if (repository.supportsFeature( ArtifactCleanupFeature.class )) { 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 01f9a2919..034aab925 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,8 +127,8 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest // Provide the metadata list List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir ); - when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, - projectName, projectVersion)).thenReturn(ml); + when(metadataRepository.getArtifacts( , TEST_REPO_ID, + projectNs, projectName, projectVersion )).thenReturn(ml); repoPurge.process( PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO ); @@ -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( , 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") ); // check if the snapshot was removed assertDeleted( projectRoot + "/2.3-SNAPSHOT" ); @@ -246,12 +246,12 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest // Provide the metadata list List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir ); - when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, - projectName, projectVersion)).thenReturn(ml); + when(metadataRepository.getArtifacts( , 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, projectNs, - projectName, releaseVersion)).thenReturn(ml2); + when(metadataRepository.getArtifacts( , RELEASES_TEST_REPO_ID, + projectNs, projectName, releaseVersion )).thenReturn(ml2); repoPurge.process( PATH_TO_RELEASED_SNAPSHOT_IN_DIFF_REPO ); @@ -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( , 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) ); // check if the snapshot was removed @@ -317,14 +317,14 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest // Provide the metadata list List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir ); - when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, - projectName, projectVersion)).thenReturn(ml); + when(metadataRepository.getArtifacts( , 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, projectNs, - projectName, "2.0.3-SNAPSHOT")).thenReturn(ml); + when(metadataRepository.getArtifacts( , 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, projectNs, - projectName, "2.0.4-SNAPSHOT")).thenReturn(ml); + when(metadataRepository.getArtifacts( , TEST_REPO_ID, + projectNs, projectName, "2.0.4-SNAPSHOT" )).thenReturn(ml); repoPurge.process( CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_HIGHER_SNAPSHOT_EXISTS_IN_SAME_REPO ); @@ -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( , 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) ); 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 3c7083700..36b225e47 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,17 +112,17 @@ public class DaysOldRepositoryPurgeTest // Provide the metadata list List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir ); - when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, - projectName, projectVersion)).thenReturn(ml); + when(metadataRepository.getArtifacts( , TEST_REPO_ID, + projectNs, projectName, projectVersion )).thenReturn(ml); repoPurge.process( PATH_TO_BY_DAYS_OLD_ARTIFACT ); listenerControl.verify(); // Verify the metadataRepository invocations - 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(projectVersion) ); ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class); - verify(metadataRepository, times(2)).removeArtifact(metadataArg.capture(), eq(projectVersion)); + verify(metadataRepository, times(2)).removeArtifact( , metadataArg.capture(), eq(projectVersion) ); List<ArtifactMetadata> metaL = metadataArg.getAllValues(); for (ArtifactMetadata meta : metaL) { assertTrue(meta.getId().startsWith(projectName)); @@ -197,8 +197,8 @@ public class DaysOldRepositoryPurgeTest // Provide the metadata list List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir ); - when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, - projectName, projectVersion)).thenReturn(ml); + when(metadataRepository.getArtifacts( , TEST_REPO_ID, + projectNs, projectName, projectVersion )).thenReturn(ml); repoPurge.process( PATH_TO_TEST_ORDER_OF_DELETION ); @@ -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( , 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( , metadataArg.capture(), eq(projectVersion) ); List<ArtifactMetadata> metaL = metadataArg.getAllValues(); for (ArtifactMetadata meta : metaL) { assertTrue(meta.getId().startsWith(projectName)); @@ -296,8 +296,8 @@ public class DaysOldRepositoryPurgeTest // Provide the metadata list List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir ); - when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, - projectName, projectVersion)).thenReturn(ml); + when(metadataRepository.getArtifacts( , TEST_REPO_ID, + projectNs, projectName, projectVersion )).thenReturn(ml); repoPurge.process( PATH_TO_BY_DAYS_OLD_METADATA_DRIVEN_ARTIFACT ); @@ -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( , 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( , 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 9ad64bd47..2e63c3307 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,8 +188,8 @@ public class RepositoryPurgeConsumerTest // Provide the metadata list List<ArtifactMetadata> ml = getArtifactMetadataFromDir( TEST_REPO_ID, projectName, repo, vDir ); - when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, - projectName, projectVersion)).thenReturn(ml); + when(metadataRepository.getArtifacts( , TEST_REPO_ID, + projectNs, projectName, projectVersion )).thenReturn(ml); Set<String> deletedVersions = new HashSet<>(); deletedVersions.add("1.0RC1-20070504.153317-1"); deletedVersions.add("1.0RC1-20070504.160758-2"); @@ -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( , 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( , metadataArg.capture(), eq(projectVersion) ); List<ArtifactMetadata> metaL = metadataArg.getAllValues(); for (ArtifactMetadata meta : metaL) { assertTrue(meta.getId().startsWith(projectName)); @@ -291,8 +291,8 @@ public class RepositoryPurgeConsumerTest // Provide the metadata list List<ArtifactMetadata> ml = getArtifactMetadataFromDir( TEST_REPO_ID, projectName, repo, vDir ); - when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, - projectName, projectVersion)).thenReturn(ml); + when(metadataRepository.getArtifacts( , TEST_REPO_ID, + projectNs, projectName, projectVersion )).thenReturn(ml); Set<String> deletedVersions = new HashSet<>(); deletedVersions.add("2.2-SNAPSHOT"); deletedVersions.add("2.2-20061118.060401-2"); @@ -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( , 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( , 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, projectNs, - projectName, projectVersion)).thenReturn(ml); + when(metadataRepository.getArtifacts( , 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( , 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( , any(), any() ); + verify(metadataRepository, never()).removeArtifact( , 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, projectNs, - projectName, projectVersion)).thenReturn(ml); + when(metadataRepository.getArtifacts( , 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( , 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() ); // 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 d80a0b693..734df37a4 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,8 +115,8 @@ public class RetentionCountRepositoryPurgeTest // Provide the metadata list List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir ); - when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, - projectName, projectVersion)).thenReturn(ml); + when(metadataRepository.getArtifacts( , TEST_REPO_ID, + projectNs, projectName, projectVersion )).thenReturn(ml); repoPurge.process( PATH_TO_BY_RETENTION_COUNT_ARTIFACT ); @@ -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( , 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( , metadataArg.capture(), eq(projectVersion) ); List<ArtifactMetadata> metaL = metadataArg.getAllValues(); for (ArtifactMetadata meta : metaL) { assertTrue(meta.getId().startsWith(projectName)); @@ -202,17 +202,17 @@ public class RetentionCountRepositoryPurgeTest // Provide the metadata list List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir ); - when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, - projectName, projectVersion)).thenReturn(ml); + when(metadataRepository.getArtifacts( , TEST_REPO_ID, + projectNs, projectName, projectVersion )).thenReturn(ml); repoPurge.process( PATH_TO_BY_RETENTION_COUNT_POM ); listenerControl.verify(); // Verify the metadataRepository invocations - 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(projectVersion) ); ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class); - verify(metadataRepository, times(deletedVersions.size())).removeArtifact(metadataArg.capture(), eq(projectVersion)); + verify(metadataRepository, times(deletedVersions.size())).removeArtifact( , metadataArg.capture(), eq(projectVersion) ); List<ArtifactMetadata> metaL = metadataArg.getAllValues(); for (ArtifactMetadata meta : metaL) { assertTrue(meta.getId().startsWith(projectName)); @@ -290,17 +290,17 @@ public class RetentionCountRepositoryPurgeTest // Provide the metadata list List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir ); - when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, - projectName, projectVersion)).thenReturn(ml); + when(metadataRepository.getArtifacts( , TEST_REPO_ID, + projectNs, projectName, projectVersion )).thenReturn(ml); repoPurge.process( PATH_TO_TEST_ORDER_OF_DELETION ); listenerControl.verify(); // Verify the metadataRepository invocations - 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(projectVersion) ); ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class); - verify(metadataRepository, times(deletedVersions.size())).removeArtifact(metadataArg.capture(), eq(projectVersion)); + verify(metadataRepository, times(deletedVersions.size())).removeArtifact( , 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 407b2399b..e93b032ac 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 @@ -138,7 +138,15 @@ public class ArchivaMetadataCreationConsumer throws ConsumerException { - RepositorySession repositorySession = repositorySessionFactory.createSession(); + RepositorySession repositorySession = null; + try + { + repositorySession = repositorySessionFactory.createSession(); + } + catch ( MetadataRepositoryException e ) + { + e.printStackTrace( ); + } try { // note that we do minimal processing including checksums and POM information for performance of @@ -185,14 +193,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(), projectVersion, - artifact ); + metadataRepository.updateArtifact( , repoId, project.getNamespace(), project.getId(), + projectVersion, artifact ); if ( createVersionMetadata ) { - metadataRepository.updateProjectVersion( repoId, project.getNamespace(), project.getId(), - versionMetadata ); + metadataRepository.updateProjectVersion( , repoId, project.getNamespace(), + project.getId(), versionMetadata ); } - metadataRepository.updateProject( repoId, project ); + metadataRepository.updateProject( , repoId, project ); repositorySession.save(); } catch ( MetadataRepositoryException e ) @@ -213,6 +221,14 @@ public class ArchivaMetadataCreationConsumer { 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-mock/src/main/java/org/apache/archiva/mock/MockRepositorySessionFactory.java b/archiva-modules/archiva-base/archiva-mock/src/main/java/org/apache/archiva/mock/MockRepositorySessionFactory.java index 0a8ba431a..be33011cd 100644 --- a/archiva-modules/archiva-base/archiva-mock/src/main/java/org/apache/archiva/mock/MockRepositorySessionFactory.java +++ b/archiva-modules/archiva-base/archiva-mock/src/main/java/org/apache/archiva/mock/MockRepositorySessionFactory.java @@ -22,7 +22,9 @@ package org.apache.archiva.mock; import org.apache.archiva.metadata.repository.AbstractMetadataRepository; import org.apache.archiva.metadata.repository.AbstractRepositorySessionFactory; import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.metadata.repository.MetadataResolver; +import org.apache.archiva.metadata.repository.MetadataSessionException; import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.springframework.stereotype.Service; @@ -51,7 +53,7 @@ public class MockRepositorySessionFactory extends AbstractRepositorySessionFacto } @Override - public RepositorySession createSession() + public RepositorySession createSession() throws MetadataRepositoryException { return new RepositorySession( repository, resolver ) { @@ -62,7 +64,7 @@ public class MockRepositorySessionFactory extends AbstractRepositorySessionFacto } @Override - public void save() + public void save() throws MetadataSessionException { // no op } 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 445d920b1..c8cf62aac 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 @@ -340,11 +340,19 @@ public class DefaultManagedRepositoryAdmin if ( !stagedOne ) { - RepositorySession repositorySession = getRepositorySessionFactory().createSession(); + RepositorySession repositorySession = null; + try + { + repositorySession = getRepositorySessionFactory().createSession(); + } + catch ( MetadataRepositoryException e ) + { + e.printStackTrace( ); + } try { MetadataRepository metadataRepository = repositorySession.getRepository(); - metadataRepository.removeRepository( repository.getId() ); + metadataRepository.removeRepository( , repository.getId() ); //invalidate cache namespacesCache.remove( repository.getId() ); log.debug( "call repositoryStatisticsManager.deleteStatistics" ); @@ -360,6 +368,10 @@ public class DefaultManagedRepositoryAdmin { repositorySession.close(); } + catch ( org.apache.archiva.metadata.repository.MetadataSessionException e ) + { + e.printStackTrace( ); + } } if ( deleteContent ) @@ -492,7 +504,15 @@ public class DefaultManagedRepositoryAdmin } // Save the repository configuration. - RepositorySession repositorySession = getRepositorySessionFactory().createSession(); + RepositorySession repositorySession = null; + try + { + repositorySession = getRepositorySessionFactory().createSession(); + } + catch ( MetadataRepositoryException e ) + { + e.printStackTrace( ); + } try { @@ -514,6 +534,10 @@ public class DefaultManagedRepositoryAdmin { repositorySession.close(); } + catch ( org.apache.archiva.metadata.repository.MetadataSessionException e ) + { + e.printStackTrace( ); + } if ( updateIndexContext ) { |