]> source.dussan.org Git - archiva.git/commitdiff
[MRM-37 and MRM-527]
authorMaria Odea B. Ching <oching@apache.org>
Mon, 15 Oct 2007 11:16:38 +0000 (11:16 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Mon, 15 Oct 2007 11:16:38 +0000 (11:16 +0000)
- added code for cleaning up the database of artifacts that are no longer existing in the repository
(DatabaseCleanupRemoveArtifactConsumer and DatabaseCleanupRemoveProjectConsumer)
- created tests for database cleanup of removed artifacts
- updated some of the test cases (in archiva-database and archiva-scheduled modules) to reflect the changes in thedb cleanup consumers

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@584735 13f79535-47bb-0310-9956-ffa450edef68

14 files changed:
archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumer.java
archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumer.java
archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/AbstractDatabaseCleanupTest.java [new file with mode: 0644]
archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumerTest.java [new file with mode: 0644]
archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumerTest.java [new file with mode: 0644]
archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumerTest.xml [new file with mode: 0644]
archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumerTest.xml [new file with mode: 0644]
archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/test-repo/org/apache/maven/archiva/do-not-cleanup-artifact-test/1.0/do-not-cleanup-artifact-test-1.0.jar [new file with mode: 0644]
archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/test-repo/org/apache/maven/archiva/do-not-cleanup-artifact-test/1.0/do-not-cleanup-artifact-test-1.0.pom [new file with mode: 0644]
archiva-database/src/main/java/org/apache/maven/archiva/database/updater/DatabaseConsumers.java
archiva-database/src/test/java/org/apache/maven/archiva/database/updater/TestDatabaseCleanupConsumer.java
archiva-database/src/test/resources/archiva-test.xml
archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/TestDatabaseCleanupConsumer.java
archiva-scheduled/src/test/resources/archiva-test.xml

index 33df01ac4fbac2263dc4146f7cc3817bcfad6389..6d462c2fbac38e81960bee178bdc7f1a24d29e74 100644 (file)
@@ -23,13 +23,23 @@ import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
 import org.apache.maven.archiva.consumers.ConsumerException;
 import org.apache.maven.archiva.consumers.DatabaseCleanupConsumer;
 import org.apache.maven.archiva.model.ArchivaArtifact;
+import org.apache.maven.archiva.database.ArtifactDAO;
+import org.apache.maven.archiva.database.ArchivaDatabaseException;
+import org.apache.maven.archiva.repository.ManagedRepositoryContent;
+import org.apache.maven.archiva.repository.RepositoryContentFactory;
+import org.apache.maven.archiva.repository.RepositoryException;
+import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
+import org.apache.maven.archiva.repository.layout.LayoutException;
+import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory;
 
 import java.util.List;
+import java.io.File;
 
 /**
- * DatabaseCleanupRemoveArtifactConsumer 
+ * Consumer for cleaning up the database of artifacts that are no longer existing in the repository. 
  *
  * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ *         <a href="mailto:oching@apache.org">Maria Odea Ching</a>
  * @version $Id$
  * 
  * @plexus.component role="org.apache.maven.archiva.consumers.DatabaseCleanupConsumer"
@@ -50,6 +60,21 @@ public class DatabaseCleanupRemoveArtifactConsumer
      */
     private String description;
 
+    /**
+     * @plexus.requirement role-hint="jdo"
+     */
+    private ArtifactDAO artifactDAO;
+
+    /**
+     * @plexus.requirement
+     */
+    private BidirectionalRepositoryLayoutFactory layoutFactory;
+    
+    /**
+     * @plexus.requirement
+     */
+    private RepositoryContentFactory repositoryFactory;
+
     public void beginScan()
     {
         // TODO Auto-generated method stub
@@ -59,21 +84,38 @@ public class DatabaseCleanupRemoveArtifactConsumer
     public void completeScan()
     {
         // TODO Auto-generated method stub
-
     }
 
     public List<String> getIncludedTypes()
-    {
-        // TODO Auto-generated method stub
-        return null;
+    {   
+       return null;
     }
 
     public void processArchivaArtifact( ArchivaArtifact artifact )
         throws ConsumerException
-    {
-        // TODO Auto-generated method stub
-
-    }
+    {  
+       try
+       {
+               ManagedRepositoryContent repositoryContent = 
+                       repositoryFactory.getManagedRepositoryContent( artifact.getModel().getRepositoryId() );
+        
+               File file = new File( repositoryContent.getRepoRoot(), toPath( artifact ) );
+               
+               if( !file.exists() )
+               {                            
+                       artifactDAO.deleteArtifact( artifact );
+               }               
+       }
+       catch ( RepositoryException re )
+       {
+               throw new ConsumerException( "Can't run database cleanup remove artifact consumer: " + 
+                               re.getMessage() );
+       }
+       catch ( ArchivaDatabaseException e )
+        {
+            throw new ConsumerException( e.getMessage() );
+        }
+    }          
 
     public String getDescription()
     {
@@ -90,4 +132,34 @@ public class DatabaseCleanupRemoveArtifactConsumer
         return false;
     }
 
+    public void setArtifactDAO( ArtifactDAO artifactDAO)
+    {
+        this.artifactDAO = artifactDAO;
+    }
+
+    public void setBidirectionalRepositoryLayoutFactory( BidirectionalRepositoryLayoutFactory layoutFactory )
+    {
+        this.layoutFactory = layoutFactory;
+    }
+    
+    public void setRepositoryFactory( RepositoryContentFactory repositoryFactory )
+    {
+        this.repositoryFactory = repositoryFactory;
+    }
+
+    private String toPath( ArchivaArtifact artifact )
+    {
+        try
+        {
+            BidirectionalRepositoryLayout layout = layoutFactory.getLayout( artifact );
+
+            return layout.toPath( artifact );
+        }
+        catch ( LayoutException e )
+        {
+            getLogger().warn( "Unable to calculate path for artifact: " + artifact );
+            return null;
+        }
+    }
+    
 }
index 2aa21c96e0e847f245c5ff200107a769ffcbe1db..6203fc9ea5faeb6014b55a27e74e2e349824cd76 100644 (file)
@@ -19,17 +19,31 @@ package org.apache.maven.archiva.consumers.database;
  * under the License.
  */
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
 import org.apache.maven.archiva.consumers.ConsumerException;
 import org.apache.maven.archiva.consumers.DatabaseCleanupConsumer;
 import org.apache.maven.archiva.model.ArchivaArtifact;
+import org.apache.maven.archiva.model.ArchivaProjectModel;
+import org.apache.maven.archiva.repository.ManagedRepositoryContent;
+import org.apache.maven.archiva.repository.RepositoryContentFactory;
+import org.apache.maven.archiva.repository.RepositoryException;
+import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
+import org.apache.maven.archiva.repository.layout.LayoutException;
+import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory;
+import org.apache.maven.archiva.database.ProjectModelDAO;
+import org.apache.maven.archiva.database.ArchivaDatabaseException;
 
 import java.util.List;
+import java.util.ArrayList;
+import java.io.File;
 
 /**
- * DatabaseCleanupRemoveProjectConsumer 
+ * Consumer for removing or deleting from the database the project models fo artifacts that have been
+ * deleted/removed from the repository.
  *
  * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ *         <a href="mailto:oching@apache.org">Maria Odea Ching</a>
  * @version $Id$
  * 
  * @plexus.component role="org.apache.maven.archiva.consumers.DatabaseCleanupConsumer"
@@ -50,29 +64,72 @@ public class DatabaseCleanupRemoveProjectConsumer
      */
     private String description;
 
+    /**
+     * @plexus.requirement role-hint="jdo"
+     */
+    private ProjectModelDAO projectModelDAO;
+
+    /**
+     * @plexus.requirement
+     */
+    private BidirectionalRepositoryLayoutFactory layoutFactory;
+    
+    /**
+     * @plexus.requirement
+     */
+    private RepositoryContentFactory repositoryFactory;
+
     public void beginScan()
     {
         // TODO Auto-generated method stub
-
     }
 
     public void completeScan()
     {
         // TODO Auto-generated method stub
-
     }
 
     public List<String> getIncludedTypes()
-    {
-        // TODO Auto-generated method stub
-        return null;
+    {          
+       return null;
     }
 
     public void processArchivaArtifact( ArchivaArtifact artifact )
         throws ConsumerException
-    {
-        // TODO Auto-generated method stub
-
+    {          
+       if ( !StringUtils.equals( "pom", artifact.getType() ) )
+        {
+            // Not a pom.  Skip it.
+            return;
+        }
+       
+       try
+       {
+               ManagedRepositoryContent repositoryContent = 
+                       repositoryFactory.getManagedRepositoryContent( artifact.getModel().getRepositoryId() );
+               
+               File file = new File( repositoryContent.getRepoRoot(), toPath( artifact ) );
+               
+               if( !file.exists() )
+               {                       
+                       ArchivaProjectModel projectModel = projectModelDAO.getProjectModel( 
+                                       artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() );   
+                       
+                       projectModelDAO.deleteProjectModel( projectModel );                     
+               }
+       }
+       catch ( RepositoryException re )
+       {
+               re.printStackTrace();
+               throw new ConsumerException( "Can't run database cleanup remove artifact consumer: " + 
+                               re.getMessage() );
+       }
+       catch ( ArchivaDatabaseException e )
+        {
+               e.printStackTrace();
+            throw new ConsumerException( e.getMessage() );
+        }      
+      
     }
 
     public String getDescription()
@@ -88,6 +145,36 @@ public class DatabaseCleanupRemoveProjectConsumer
     public boolean isPermanent()
     {
         return false;
+    }    
+
+    private String toPath( ArchivaArtifact artifact )
+    {
+        try
+        {
+            BidirectionalRepositoryLayout layout = layoutFactory.getLayout( artifact );
+
+            return layout.toPath( artifact );
+        }
+        catch ( LayoutException e )
+        {
+            getLogger().warn( "Unable to calculate path for artifact: " + artifact );
+            return null;
+        }
+    }
+
+    public void setProjectModelDAO( ProjectModelDAO projectModelDAO )
+    {
+        this.projectModelDAO = projectModelDAO;
     }
 
+    public void setBidirectionalRepositoryLayoutFactory( BidirectionalRepositoryLayoutFactory layoutFactory )
+    {
+        this.layoutFactory = layoutFactory;
+    }
+    
+    public void setRepositoryFactory( RepositoryContentFactory repositoryFactory )
+    {
+        this.repositoryFactory = repositoryFactory;
+    }
+    
 }
diff --git a/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/AbstractDatabaseCleanupTest.java b/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/AbstractDatabaseCleanupTest.java
new file mode 100644 (file)
index 0000000..e49ff49
--- /dev/null
@@ -0,0 +1,104 @@
+package org.apache.maven.archiva.consumers.database;
+
+/*
+ * 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.
+ */
+
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.FileUtils;
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.configuration.Configuration;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.repository.RepositoryContentFactory;
+import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory;
+import org.apache.maven.archiva.model.ArchivaArtifact;
+import org.apache.maven.archiva.model.ArchivaArtifactModel;
+import org.apache.maven.archiva.model.ArchivaProjectModel;
+
+import java.io.File;
+
+/**
+ * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ */
+public class AbstractDatabaseCleanupTest
+    extends PlexusTestCase
+{
+    ArchivaConfiguration archivaConfig;
+
+    BidirectionalRepositoryLayoutFactory layoutFactory;
+    
+    RepositoryContentFactory repositoryFactory;
+
+    public static final String TEST_GROUP_ID = "org.apache.maven.archiva";
+
+    public static final String TEST_ARTIFACT_ID = "cleanup-artifact-test";
+
+    public static final String TEST_VERSION = "1.0";
+
+    public static final String TEST_REPO_ID = "test-repo";
+
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        // archiva configuration (need to update the repository url)
+        File userFile = getTestFile( "target/test/repository-manager.xml" );
+        userFile.delete();
+        assertFalse( userFile.exists() );
+
+        userFile.getParentFile().mkdirs();
+        FileUtils.copyFileToDirectory( getTestFile( "src/test/conf/repository-manager.xml" ),
+                                       userFile.getParentFile() );
+
+        archivaConfig = (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "database-cleanup" );
+
+        Configuration configuration = archivaConfig.getConfiguration();
+        ManagedRepositoryConfiguration repo = configuration.findManagedRepositoryById( TEST_REPO_ID );
+        repo.setLocation( new File( getBasedir(), "src/test/resources/test-repo" ).toString() );
+
+        archivaConfig.save( configuration );
+
+        // set bidirectional repository layout factory
+        layoutFactory = (BidirectionalRepositoryLayoutFactory) lookup( BidirectionalRepositoryLayoutFactory.class );
+        
+        repositoryFactory = (RepositoryContentFactory) lookup( RepositoryContentFactory.class );
+    }
+
+    protected ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String type )
+    {
+        ArchivaArtifactModel model = new ArchivaArtifactModel();
+        model.setGroupId( groupId );
+        model.setArtifactId( artifactId );
+        model.setVersion( version );
+        model.setType( type );
+        model.setRepositoryId( TEST_REPO_ID );
+
+        return new ArchivaArtifact( model );
+    }
+
+    protected ArchivaProjectModel createProjectModel( String groupId, String artifactId, String version )
+    {
+        ArchivaProjectModel projectModel = new ArchivaProjectModel();
+        projectModel.setGroupId( groupId );
+        projectModel.setArtifactId( artifactId );
+        projectModel.setVersion( version );
+
+        return projectModel;
+    }
+}
diff --git a/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumerTest.java b/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumerTest.java
new file mode 100644 (file)
index 0000000..1e49321
--- /dev/null
@@ -0,0 +1,84 @@
+package org.apache.maven.archiva.consumers.database;
+
+/*
+ * 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.
+ */
+
+import org.easymock.MockControl;
+import org.apache.maven.archiva.model.ArchivaArtifact;
+import org.apache.maven.archiva.database.ArtifactDAO;
+
+/**
+ * Test for DatabaseCleanupRemoveArtifactConsumerTest
+ *
+ * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ */
+public class DatabaseCleanupRemoveArtifactConsumerTest
+    extends AbstractDatabaseCleanupTest
+{
+    private MockControl artifactDAOControl;
+
+    private ArtifactDAO artifactDAOMock;
+
+    private DatabaseCleanupRemoveArtifactConsumer dbCleanupRemoveArtifactConsumer;
+
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        dbCleanupRemoveArtifactConsumer = new DatabaseCleanupRemoveArtifactConsumer();
+
+        artifactDAOControl = MockControl.createControl( ArtifactDAO.class );
+
+        artifactDAOMock = (ArtifactDAO) artifactDAOControl.getMock();
+
+        dbCleanupRemoveArtifactConsumer.setArtifactDAO( artifactDAOMock );
+        
+        dbCleanupRemoveArtifactConsumer.setBidirectionalRepositoryLayoutFactory( layoutFactory );
+        
+        dbCleanupRemoveArtifactConsumer.setRepositoryFactory( repositoryFactory );
+    }
+
+    public void testIfArtifactWasNotDeleted()
+        throws Exception
+    {
+        ArchivaArtifact artifact = createArtifact( TEST_GROUP_ID, "do-not-cleanup-artifact-test", TEST_VERSION, "jar" );
+
+        artifactDAOControl.replay();
+
+        dbCleanupRemoveArtifactConsumer.processArchivaArtifact( artifact );
+
+        artifactDAOControl.verify();
+    }
+
+    public void testIfArtifactWasDeleted()
+        throws Exception
+    {
+        ArchivaArtifact artifact = createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, "jar" );
+
+        artifactDAOMock.deleteArtifact( artifact );
+
+        artifactDAOControl.replay();
+
+        dbCleanupRemoveArtifactConsumer.processArchivaArtifact( artifact );
+
+        artifactDAOControl.verify();
+    }
+
+}
diff --git a/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumerTest.java b/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumerTest.java
new file mode 100644 (file)
index 0000000..646d3b0
--- /dev/null
@@ -0,0 +1,110 @@
+package org.apache.maven.archiva.consumers.database;
+
+/*
+ * 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.
+ */
+
+import org.easymock.MockControl;
+import org.apache.maven.archiva.database.ProjectModelDAO;
+import org.apache.maven.archiva.model.ArchivaArtifact;
+import org.apache.maven.archiva.model.ArchivaProjectModel;
+
+/**
+ * Test for DatabaseCleanupRemoveProjectConsumer
+ *
+ * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ */
+public class DatabaseCleanupRemoveProjectConsumerTest
+       extends AbstractDatabaseCleanupTest
+{
+    private MockControl projectModelDAOControl;
+
+    private ProjectModelDAO projectModelDAOMock;
+
+    private DatabaseCleanupRemoveProjectConsumer dbCleanupRemoveProjectConsumer;
+
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        dbCleanupRemoveProjectConsumer = new DatabaseCleanupRemoveProjectConsumer();
+
+        projectModelDAOControl = MockControl.createControl( ProjectModelDAO.class );
+
+        projectModelDAOMock = (ProjectModelDAO) projectModelDAOControl.getMock();
+
+        dbCleanupRemoveProjectConsumer.setProjectModelDAO( projectModelDAOMock );
+        
+        dbCleanupRemoveProjectConsumer.setBidirectionalRepositoryLayoutFactory( layoutFactory );
+        
+        dbCleanupRemoveProjectConsumer.setRepositoryFactory( repositoryFactory );
+    }
+
+    public void testIfArtifactWasNotDeleted()
+        throws Exception
+    {
+        ArchivaArtifact artifact = createArtifact( TEST_GROUP_ID, "do-not-cleanup-artifact-test", TEST_VERSION, "pom" );
+
+        projectModelDAOControl.replay();
+
+        dbCleanupRemoveProjectConsumer.processArchivaArtifact( artifact );
+
+        projectModelDAOControl.verify();
+    }
+
+    public void testIfArtifactWasDeleted()
+        throws Exception
+    {
+        ArchivaArtifact artifact = createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, "pom" );
+
+        ArchivaProjectModel projectModel = createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION );
+
+        //this should return a value
+        projectModelDAOControl.expectAndReturn(
+            projectModelDAOMock.getProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ),
+            (ArchivaProjectModel) projectModel );
+
+        projectModelDAOMock.deleteProjectModel( projectModel );
+
+        projectModelDAOControl.replay();
+
+        dbCleanupRemoveProjectConsumer.processArchivaArtifact( artifact );
+
+        projectModelDAOControl.verify();
+    }
+    
+    public void testIfArtifactWasNotAPom()
+       throws Exception
+       {
+       ArchivaArtifact artifact = createArtifact( TEST_GROUP_ID, "do-not-cleanup-artifact-test", TEST_VERSION, "jar" );
+
+        projectModelDAOControl.replay();
+
+        dbCleanupRemoveProjectConsumer.processArchivaArtifact( artifact );
+
+        projectModelDAOControl.verify();
+       }
+
+    public void tearDown()
+        throws Exception
+    {
+        super.tearDown();
+    }
+
+}
diff --git a/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumerTest.xml b/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumerTest.xml
new file mode 100644 (file)
index 0000000..1a2bc20
--- /dev/null
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  ~ 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.
+  -->
+
+<component-set>
+  <components>
+    <component>
+      <role>org.apache.maven.archiva.consumers.DatabaseCleanupConsumer</role>
+      <role-hint>not-present-remove-db-artifact</role-hint>
+      <implementation>org.apache.maven.archiva.consumers.database.DatabaseCleanupRemoveArtifactConsumer</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
+          <role-hint>database-cleanup</role-hint>
+        </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory</role>
+        </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.database.ArtifactDAO</role>
+          <role-hint>jdo</role-hint>
+        </requirement>
+      </requirements>
+    </component>
+    <component>
+      <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
+      <role-hint>database-cleanup</role-hint>
+      <implementation>org.apache.maven.archiva.configuration.DefaultArchivaConfiguration</implementation>
+      <requirements>
+        <requirement>
+          <role>org.codehaus.plexus.registry.Registry</role>
+          <role-hint>database-cleanup</role-hint>
+        </requirement>
+      </requirements>
+    </component>
+    <component>
+      <role>org.codehaus.plexus.registry.Registry</role>
+      <role-hint>database-cleanup</role-hint>
+      <implementation>org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry</implementation>
+      <configuration>
+        <properties>
+          <xml fileName="${basedir}/target/test/repository-manager.xml" config-optional="true" config-forceCreate="true"
+                 config-name="org.apache.maven.archiva.base" config-at="org.apache.maven.archiva"/>
+        </properties>
+      </configuration>
+    </component>
+    <component>
+      <role>org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory</role>
+      <implementation>org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
+          <role-hint>database-cleanup</role-hint>
+        </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout</role>
+          <field-name>layouts</field-name>
+        </requirement>
+      </requirements>
+    </component>
+    <component>
+      <role>org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout</role>
+      <role-hint>default</role-hint>
+      <implementation>org.apache.maven.archiva.repository.layout.DefaultBidirectionalRepositoryLayout</implementation>
+    </component>
+    
+    <component>
+      <role>org.apache.maven.archiva.repository.RepositoryContentFactory</role>      
+      <implementation>org.apache.maven.archiva.repository.RepositoryContentFactory</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
+          <role-hint>database-cleanup</role-hint>
+        </requirement>
+      </requirements>
+    </component>
+  </components>
+</component-set>
\ No newline at end of file
diff --git a/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumerTest.xml b/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumerTest.xml
new file mode 100644 (file)
index 0000000..ded6624
--- /dev/null
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  ~ 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.
+  -->
+
+<component-set>
+  <components>
+    <component>
+      <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
+      <role-hint>database-cleanup</role-hint>
+      <implementation>org.apache.maven.archiva.configuration.DefaultArchivaConfiguration</implementation>
+      <requirements>
+        <requirement>
+          <role>org.codehaus.plexus.registry.Registry</role>
+          <role-hint>database-cleanup</role-hint>
+        </requirement>
+      </requirements>
+    </component>
+    <component>
+      <role>org.codehaus.plexus.registry.Registry</role>
+      <role-hint>database-cleanup</role-hint>
+      <implementation>org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry</implementation>
+      <configuration>
+        <properties>
+          <xml fileName="${basedir}/target/test/repository-manager.xml" config-optional="true" config-forceCreate="true"
+                 config-name="org.apache.maven.archiva.base" config-at="org.apache.maven.archiva"/>
+        </properties>
+      </configuration>
+    </component>
+    <component>
+      <role>org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory</role>
+      <implementation>org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
+          <role-hint>database-cleanup</role-hint>
+        </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout</role>
+          <field-name>layouts</field-name>
+        </requirement>
+      </requirements>
+    </component>
+    <component>
+      <role>org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout</role>
+      <role-hint>default</role-hint>
+      <implementation>org.apache.maven.archiva.repository.layout.DefaultBidirectionalRepositoryLayout</implementation>
+    </component>
+    
+    <component>
+      <role>org.apache.maven.archiva.repository.RepositoryContentFactory</role>      
+      <implementation>org.apache.maven.archiva.repository.RepositoryContentFactory</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
+          <role-hint>database-cleanup</role-hint>
+        </requirement>
+      </requirements>
+    </component>
+  </components>
+</component-set>
\ No newline at end of file
diff --git a/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/test-repo/org/apache/maven/archiva/do-not-cleanup-artifact-test/1.0/do-not-cleanup-artifact-test-1.0.jar b/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/test-repo/org/apache/maven/archiva/do-not-cleanup-artifact-test/1.0/do-not-cleanup-artifact-test-1.0.jar
new file mode 100644 (file)
index 0000000..4201a06
Binary files /dev/null and b/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/test-repo/org/apache/maven/archiva/do-not-cleanup-artifact-test/1.0/do-not-cleanup-artifact-test-1.0.jar differ
diff --git a/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/test-repo/org/apache/maven/archiva/do-not-cleanup-artifact-test/1.0/do-not-cleanup-artifact-test-1.0.pom b/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/test-repo/org/apache/maven/archiva/do-not-cleanup-artifact-test/1.0/do-not-cleanup-artifact-test-1.0.pom
new file mode 100644 (file)
index 0000000..94b5b2e
--- /dev/null
@@ -0,0 +1,5 @@
+<project>
+  <groupId>org.apache.maven.archiva</groupId>
+  <artifactId>do-not-cleanup-artifact-test</artifactId>
+  <version>1.0</version>
+</project>
\ No newline at end of file
index 4d588496893c09af10f92d2af6b3d2f571e03553..01dee02fd7291d46572093160a23695a55d00d1a 100644 (file)
@@ -95,7 +95,7 @@ public class DatabaseConsumers
                 DatabaseCleanupConsumer consumer = (DatabaseCleanupConsumer) object;
                 DatabaseScanningConfiguration config = archivaConfiguration.getConfiguration().getDatabaseScanning();
 
-                return config.getUnprocessedConsumers().contains( consumer.getId() );
+                return config.getCleanupConsumers().contains( consumer.getId() );
             }
 
             return satisfies;
index b30f9cef48faee17af592febcf9d5880bd58fbe2..0062a8945e1e01c90abfac938df0f5d2143ad30b 100644 (file)
@@ -70,12 +70,12 @@ public class TestDatabaseCleanupConsumer
 
     public String getDescription()
     {
-        return "Test Consumer for Database Unprocessed";
+        return "Test Consumer for Database Cleanup";
     }
 
     public String getId()
     {
-        return "test-db-unprocessed";
+        return "test-db-cleanup";
     }
 
     public boolean isPermanent()
index 66021220be57bdc25520c8afd343acded16d6e7c..838e6fc671eefe1a4f5be65b8274944906ff5464 100644 (file)
     </unprocessedConsumers>
     <cleanupConsumers>
       <cleanupConsumer>test-db-cleanup</cleanupConsumer>
-      <cleanupConsumer>not-present-remove-db-artifact</cleanupConsumer>
-      <cleanupConsumer>not-present-remove-db-project</cleanupConsumer>
-      <cleanupConsumer>not-present-remove-indexed</cleanupConsumer>
     </cleanupConsumers>
   </databaseScanning>
 
index c15edb1872c299ecc8df74bf50a2d17eeeb2272f..ff697987779338acec2eab9b2a3278f7c6ee8553 100644 (file)
@@ -70,12 +70,12 @@ public class TestDatabaseCleanupConsumer
 
     public String getDescription()
     {
-        return "Test Consumer for Database Unprocessed";
+        return "Test Consumer for Database Cleanup";
     }
 
     public String getId()
     {
-        return "test-db-unprocessed";
+        return "test-db-cleanup";
     }
 
     public boolean isPermanent()
index 32b43b1bf331856bfab55554b48464870df0509b..3f2310c7b3727a883981049389110e1d1162ef3d 100644 (file)
     </unprocessedConsumers>
     <cleanupConsumers>
       <cleanupConsumer>test-db-cleanup</cleanupConsumer>
-      <cleanupConsumer>not-present-remove-db-artifact</cleanupConsumer>
-      <cleanupConsumer>not-present-remove-db-project</cleanupConsumer>
-      <cleanupConsumer>not-present-remove-indexed</cleanupConsumer>
     </cleanupConsumers>
   </databaseScanning>