]> source.dussan.org Git - archiva.git/commitdiff
fix junit correctly delete timestamped snapshot
authorOlivier Lamy <olamy@apache.org>
Mon, 25 Jun 2012 15:55:07 +0000 (15:55 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 25 Jun 2012 15:55:07 +0000 (15:55 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1353618 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/repository.xml
archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java
archiva-modules/plugins/metadata-store-jcr/src/main/resources/org/apache/archiva/metadata/repository/jcr/repository.xml

index e69ce4631c3c361ff81764ac038ce17f1063f646..333912f1d03cb8cf58ea501bd0026dc979974ee8 100644 (file)
@@ -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
index 8c66330980f6ba1c0dc9973ac0ff81408f532c70..89d6fdb0123af08f98c926866c870fa42c26a6f1 100644 (file)
@@ -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<Artifact> 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";
+
 
 }
index 0be86ebbda71dd73e2a7fbd4ade5149c25924833..117e640eb10879e1987002f596b42451def3f7b1 100644 (file)
   </Security>
   <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default"/>
   <Workspace name="${wsp.name}">
-    <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+    <FileSystem class="org.apache.jackrabbit.core.fs.mem.MemoryFileSystem"/>
+    <!--FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
       <param name="path" value="${wsp.home}"/>
-    </FileSystem>
+    </FileSystem-->
     <PersistenceManager class="org.apache.jackrabbit.core.persistence.bundle.BundleFsPersistenceManager"/>
     <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
       <param name="path" value="${wsp.home}/index"/>
     </SearchIndex>
   </Workspace>
   <Versioning rootPath="${rep.home}/version">
-    <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+    <FileSystem class="org.apache.jackrabbit.core.fs.mem.MemoryFileSystem"/>
+    <!--FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
       <param name="path" value="${rep.home}/version"/>
-    </FileSystem>
+    </FileSystem-->
     <PersistenceManager class="org.apache.jackrabbit.core.persistence.bundle.BundleFsPersistenceManager"/>
   </Versioning>
 </Repository>
index 60e536357886f999eaa343fc37dc4b70298bd76d..1d3b88ebf87811fb84dccc503716d71a1e2e4a8b 100644 (file)
@@ -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
index 3b5a9e2bdbf67966f3cf181d9f62c2a5a67d8160..e5be2d2b38987a116f86b2e6b6d9107f1c2381d6 100644 (file)
@@ -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;
     }
index ad61c8de9114001678325f30984b279d4579c0af..76236f54d99bf1e54ed935c960761eaf08419c06 100644 (file)
@@ -18,7 +18,7 @@
   -->
 
 <!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.6//EN"
-    "http://jackrabbit.apache.org/dtd/repository-1.6.dtd">
+    "http://jackrabbit.apache.org/dtd/repository-2.0.dtd">
 
 <!-- START SNIPPET: default-repository -->
 <Repository>