From 208ff50ae5e169fea618e45236153ad7a7bb4849 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 25 Jun 2012 15:55:07 +0000 Subject: [PATCH] fix junit correctly delete timestamped snapshot git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1353618 13f79535-47bb-0310-9956-ffa450edef68 --- .../services/DefaultRepositoriesService.java | 16 +++++-- .../services/RepositoriesServiceTest.java | 47 ++++++++++--------- .../src/test/repository.xml | 10 ++-- .../repository/MetadataRepository.java | 3 ++ .../repository/jcr/JcrMetadataRepository.java | 46 ++++++++++++++++-- .../metadata/repository/jcr/repository.xml | 2 +- 6 files changed, 90 insertions(+), 34 deletions(-) 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 e69ce4631..333912f1d 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 @@ -781,10 +781,18 @@ public class DefaultRepositoriesService } else { - metadataRepository.removeArtifact( artifactMetadata.getRepositoryId(), - artifactMetadata.getNamespace(), - artifactMetadata.getProject(), artifact.getVersion(), - artifactMetadata.getId() ); + if ( snapshotVersion ) + { + metadataRepository.removeArtifact( artifactMetadata, + VersionUtil.getBaseVersion( artifact.getVersion() ) ); + } + else + { + metadataRepository.removeArtifact( artifactMetadata.getRepositoryId(), + artifactMetadata.getNamespace(), + artifactMetadata.getProject(), artifact.getVersion(), + artifactMetadata.getId() ); + } } // TODO: move into the metadata repository proper - need to differentiate attachment of // repository metadata to an artifact 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 8c6633098..89d6fdb01 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 @@ -341,21 +341,6 @@ public class RepositoriesServiceTest } } - protected ManagedRepository getTestManagedRepository( String id, String path ) - { - String location = new File( FileUtil.getBasedir(), "target/" + path ).getAbsolutePath(); - return new ManagedRepository( id, id, location, "default", true, true, true, "2 * * * * ?", null, false, 80, 80, - true, false ); - } - - protected ManagedRepository getTestManagedRepository() - { - return getTestManagedRepository( "TEST", "test-repo" ); - } - - - static final String SNAPSHOT_REPO_ID = "snapshot-repo"; - @Test public void deleteSnapshot() throws Exception @@ -363,6 +348,10 @@ public class RepositoriesServiceTest File targetRepo = initSnapshotRepo(); try { + + RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader ); + //repositoriesService.scanRepositoryDirectoriesNow( SNAPSHOT_REPO_ID ); + BrowseService browseService = getBrowseService( authorizationHeader, false ); List artifacts = browseService.getArtifactDownloadInfos( "org.apache.archiva.redback.components", "spring-quartz", @@ -372,8 +361,6 @@ public class RepositoriesServiceTest Assertions.assertThat( artifacts ).isNotNull().isNotEmpty().hasSize( 10 ); - RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader ); - File artifactFile = new File( targetRepo, "org/apache/archiva/redback/components/spring-quartz/2.0-SNAPSHOT/spring-quartz-2.0-20120618.214127-1.jar" ); @@ -393,8 +380,10 @@ public class RepositoriesServiceTest artifact.setPackaging( "jar" ); artifact.setRepositoryId( SNAPSHOT_REPO_ID ); artifact.setContext( SNAPSHOT_REPO_ID ); + repositoriesService.deleteArtifact( artifact ); + artifacts = browseService.getArtifactDownloadInfos( "org.apache.archiva.redback.components", "spring-quartz", "2.0-SNAPSHOT", SNAPSHOT_REPO_ID ); @@ -436,10 +425,11 @@ public class RepositoriesServiceTest getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( SNAPSHOT_REPO_ID, true ); assertNull( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( SNAPSHOT_REPO_ID ) ); } - ManagedRepository managedRepository = getTestManagedRepository(); - managedRepository.setId( SNAPSHOT_REPO_ID ); - managedRepository.setLocation( targetRepo.getCanonicalPath() ); - managedRepository.setCronExpression( "* * * * * ?" ); + ManagedRepository managedRepository = + getTestManagedRepository( SNAPSHOT_REPO_ID, "repo-with-snapshots" ); + /*managedRepository.setId( SNAPSHOT_REPO_ID ); + managedRepository.setLocation( ); + managedRepository.setCronExpression( "* * * * * ?" );*/ getManagedRepositoriesService( authorizationHeader ).addManagedRepository( managedRepository ); assertNotNull( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( SNAPSHOT_REPO_ID ) ); @@ -458,5 +448,20 @@ public class RepositoriesServiceTest } + protected ManagedRepository getTestManagedRepository( String id, String path ) + { + String location = new File( FileUtil.getBasedir(), "target/" + path ).getAbsolutePath(); + return new ManagedRepository( id, id, location, "default", true, true, true, "2 * * * * ?", null, false, 80, 80, + true, false ); + } + + protected ManagedRepository getTestManagedRepository() + { + return getTestManagedRepository( "TEST", "test-repo" ); + } + + + static final String SNAPSHOT_REPO_ID = "snapshot-repo"; + } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/repository.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/repository.xml index 0be86ebbd..117e640eb 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/repository.xml +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/repository.xml @@ -32,18 +32,20 @@ - + + - + + diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java index 60e536357..1d3b88ebf 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java @@ -79,6 +79,9 @@ public interface MetadataRepository void removeArtifact( String repositoryId, String namespace, String project, String version, String id ) throws MetadataRepositoryException; + void removeArtifact( ArtifactMetadata artifactMetadata, String baseVersion ) + throws MetadataRepositoryException; + /** * @param repositoryId * @param namespace diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java index 3b5a9e2bd..e5be2d2b3 100644 --- a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java @@ -101,8 +101,6 @@ public class JcrMetadataRepository { this.metadataFacetFactories = metadataFacetFactories; this.repository = repository; - - //session = repository.login( new SimpleCredentials( "admin", "admin".toCharArray() ) ); } @@ -1003,6 +1001,48 @@ public class JcrMetadataRepository return getNodeNames( getProjectPath( repositoryId, namespace, projectId ), PROJECT_VERSION_NODE_TYPE ); } + public void removeArtifact( ArtifactMetadata artifactMetadata, String baseVersion ) + throws MetadataRepositoryException + { + + String repositoryId = artifactMetadata.getRepositoryId(); + + try + { + Node root = getJcrSession().getRootNode(); + String path = + getProjectVersionPath( repositoryId, artifactMetadata.getNamespace(), artifactMetadata.getProject(), + baseVersion ); + + if ( root.hasNode( path ) ) + { + Node node = root.getNode( path ); + + for ( Node n : JcrUtils.getChildNodes( node ) ) + { + if ( n.isNodeType( ARTIFACT_NODE_TYPE ) ) + { + if ( n.hasProperty( "version" ) ) + { + String version = n.getProperty( "version" ).getString(); + if ( StringUtils.equals( version, artifactMetadata.getVersion() ) ) + { + n.remove(); + } + } + + } + } + } + } + catch ( RepositoryException e ) + { + throw new MetadataRepositoryException( e.getMessage(), e ); + } + + + } + public void removeArtifact( String repositoryId, String namespace, String projectId, String projectVersion, String id ) throws MetadataRepositoryException @@ -1422,9 +1462,7 @@ public class JcrMetadataRepository { if ( this.jcrSession == null || !this.jcrSession.isLive() ) { - jcrSession = repository.login( new SimpleCredentials( "admin", "admin".toCharArray() ) ); - } return this.jcrSession; } diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/resources/org/apache/archiva/metadata/repository/jcr/repository.xml b/archiva-modules/plugins/metadata-store-jcr/src/main/resources/org/apache/archiva/metadata/repository/jcr/repository.xml index ad61c8de9..76236f54d 100644 --- a/archiva-modules/plugins/metadata-store-jcr/src/main/resources/org/apache/archiva/metadata/repository/jcr/repository.xml +++ b/archiva-modules/plugins/metadata-store-jcr/src/main/resources/org/apache/archiva/metadata/repository/jcr/repository.xml @@ -18,7 +18,7 @@ --> + "http://jackrabbit.apache.org/dtd/repository-2.0.dtd"> -- 2.39.5