You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by oc...@apache.org on 2007/10/15 13:16:41 UTC

svn commit: r584735 - in /maven/archiva/trunk: archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/ archiva-base/ar...

Author: oching
Date: Mon Oct 15 04:16:38 2007
New Revision: 584735

URL: http://svn.apache.org/viewvc?rev=584735&view=rev
Log:
[MRM-37 and MRM-527]
- 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 

Added:
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/AbstractDatabaseCleanupTest.java
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumerTest.java
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumerTest.java
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/maven/
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/maven/archiva/
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/maven/archiva/consumers/
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/maven/archiva/consumers/database/
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumerTest.xml
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumerTest.xml
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/test-repo/
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/test-repo/org/
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/test-repo/org/apache/
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/test-repo/org/apache/maven/
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/test-repo/org/apache/maven/archiva/
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/test-repo/org/apache/maven/archiva/do-not-cleanup-artifact-test/
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/test-repo/org/apache/maven/archiva/do-not-cleanup-artifact-test/1.0/
    maven/archiva/trunk/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   (with props)
    maven/archiva/trunk/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
Modified:
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumer.java
    maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumer.java
    maven/archiva/trunk/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/DatabaseConsumers.java
    maven/archiva/trunk/archiva-database/src/test/java/org/apache/maven/archiva/database/updater/TestDatabaseCleanupConsumer.java
    maven/archiva/trunk/archiva-database/src/test/resources/archiva-test.xml
    maven/archiva/trunk/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/TestDatabaseCleanupConsumer.java
    maven/archiva/trunk/archiva-scheduled/src/test/resources/archiva-test.xml

Modified: maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumer.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumer.java?rev=584735&r1=584734&r2=584735&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumer.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumer.java Mon Oct 15 04:16:38 2007
@@ -23,13 +23,23 @@
 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 @@
      */
     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 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 @@
         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;
+        }
+    }
+    
 }

Modified: maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumer.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumer.java?rev=584735&r1=584734&r2=584735&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumer.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumer.java Mon Oct 15 04:16:38 2007
@@ -19,17 +19,31 @@
  * 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 @@
      */
     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 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;
+    }
+    
 }

Added: maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/AbstractDatabaseCleanupTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/AbstractDatabaseCleanupTest.java?rev=584735&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/AbstractDatabaseCleanupTest.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/AbstractDatabaseCleanupTest.java Mon Oct 15 04:16:38 2007
@@ -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;
+    }
+}

Added: maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumerTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumerTest.java?rev=584735&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumerTest.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumerTest.java Mon Oct 15 04:16:38 2007
@@ -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();
+    }
+
+}

Added: maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumerTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumerTest.java?rev=584735&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumerTest.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumerTest.java Mon Oct 15 04:16:38 2007
@@ -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();
+    }
+
+}

Added: maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumerTest.xml
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumerTest.xml?rev=584735&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumerTest.xml (added)
+++ maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumerTest.xml Mon Oct 15 04:16:38 2007
@@ -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

Added: maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumerTest.xml
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumerTest.xml?rev=584735&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumerTest.xml (added)
+++ maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/test/resources/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumerTest.xml Mon Oct 15 04:16:38 2007
@@ -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

Added: maven/archiva/trunk/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
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/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?rev=584735&view=auto
==============================================================================
Binary file - no diff available.

Propchange: maven/archiva/trunk/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
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: maven/archiva/trunk/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
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/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?rev=584735&view=auto
==============================================================================
--- maven/archiva/trunk/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 (added)
+++ maven/archiva/trunk/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 Mon Oct 15 04:16:38 2007
@@ -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

Modified: maven/archiva/trunk/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/DatabaseConsumers.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/DatabaseConsumers.java?rev=584735&r1=584734&r2=584735&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/DatabaseConsumers.java (original)
+++ maven/archiva/trunk/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/DatabaseConsumers.java Mon Oct 15 04:16:38 2007
@@ -95,7 +95,7 @@
                 DatabaseCleanupConsumer consumer = (DatabaseCleanupConsumer) object;
                 DatabaseScanningConfiguration config = archivaConfiguration.getConfiguration().getDatabaseScanning();
 
-                return config.getUnprocessedConsumers().contains( consumer.getId() );
+                return config.getCleanupConsumers().contains( consumer.getId() );
             }
 
             return satisfies;

Modified: maven/archiva/trunk/archiva-database/src/test/java/org/apache/maven/archiva/database/updater/TestDatabaseCleanupConsumer.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-database/src/test/java/org/apache/maven/archiva/database/updater/TestDatabaseCleanupConsumer.java?rev=584735&r1=584734&r2=584735&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-database/src/test/java/org/apache/maven/archiva/database/updater/TestDatabaseCleanupConsumer.java (original)
+++ maven/archiva/trunk/archiva-database/src/test/java/org/apache/maven/archiva/database/updater/TestDatabaseCleanupConsumer.java Mon Oct 15 04:16:38 2007
@@ -70,12 +70,12 @@
 
     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()

Modified: maven/archiva/trunk/archiva-database/src/test/resources/archiva-test.xml
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-database/src/test/resources/archiva-test.xml?rev=584735&r1=584734&r2=584735&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-database/src/test/resources/archiva-test.xml (original)
+++ maven/archiva/trunk/archiva-database/src/test/resources/archiva-test.xml Mon Oct 15 04:16:38 2007
@@ -146,9 +146,6 @@
     </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>
 

Modified: maven/archiva/trunk/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/TestDatabaseCleanupConsumer.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/TestDatabaseCleanupConsumer.java?rev=584735&r1=584734&r2=584735&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/TestDatabaseCleanupConsumer.java (original)
+++ maven/archiva/trunk/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/TestDatabaseCleanupConsumer.java Mon Oct 15 04:16:38 2007
@@ -70,12 +70,12 @@
 
     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()

Modified: maven/archiva/trunk/archiva-scheduled/src/test/resources/archiva-test.xml
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-scheduled/src/test/resources/archiva-test.xml?rev=584735&r1=584734&r2=584735&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-scheduled/src/test/resources/archiva-test.xml (original)
+++ maven/archiva/trunk/archiva-scheduled/src/test/resources/archiva-test.xml Mon Oct 15 04:16:38 2007
@@ -113,9 +113,6 @@
     </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>
 



Re: svn commit: r584735 - in /maven/archiva/trunk: archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/ archiva-base/ar...

Posted by Maria Odea Ching <oc...@exist.com>.
Okey dokey :) Thanks Joakim!

-Deng

Joakim Erdfelt wrote:
> Maria Odea Ching wrote:
>> Brett Porter wrote:
>>> Hi Deng,
>>>
>>> On 15/10/2007, at 7:16 PM, oching@apache.org wrote:
>>>
>>>> [MRM-37 and MRM-527]
>>>> - 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
>>>
>>> Cool - looks good. A couple of quick questions :)
>>>
>>>> + /**
>>>> + * @plexus.requirement
>>>> + */
>>>> + private BidirectionalRepositoryLayoutFactory layoutFactory;
>>>> +
>>>> + /**
>>>> + * @plexus.requirement
>>>> + */
>>>> + private RepositoryContentFactory repositoryFactory;
>>>> +
>>>
>>> I'm probably wrong, but I understood the content factory should be 
>>> used instead of the layoutFactory - does it provide a way to do this 
>>> instead, or did I misunderstand?
>>>
>>
>> I think the content factory only provides the repository 
>> configuration while the layout factory provides a means of getting 
>> the layout (BidirectionalRepositoryLayout) of the repository where 
>> the artifact is located and converting the path from the given 
>> artifact. I needed the content factory to get the repository url and 
>> the layout factory for the artifact path so I could get the absolute 
>> path to the actual artifact and check if it still exists. :)
>
> BidirectionalRepositoryLayout is going away.
> They are broken.
> They do not work.
> They will not be fixed.
> They encourage shortcuts (which is bad).
> Shortcuts encourage bugs (which is also bad).
> Bad code is ... uhm ... bad (which is also also bad).  ;-)
>
> Use the repositoryFactory.getManagedRepository(repoId) to get a 
> ManagedRepositoryContent object.
> Then use the .toFile() .toPath() .toArtifactReference() methods in 
> there.  They should have the same method signature that you are 
> familiar with in the old BidirectionalRepositoryLayout classes.
>
> I want to encourage operations against the repository to utilize those 
> objects, we have plenty of find/get methods already, and we even a 
> .deleteVersion(VersionedReference) method in there too.  If you can 
> think of more, let me know.
>


Re: svn commit: r584735 - in /maven/archiva/trunk: archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/ archiva-base/ar...

Posted by Brett Porter <br...@apache.org>.
On 16/10/2007, at 12:51 PM, Joakim Erdfelt wrote:

> Use the repositoryFactory.getManagedRepository(repoId) to get a  
> ManagedRepositoryContent object.
> Then use the .toFile() .toPath() .toArtifactReference() methods in  
> there.  They should have the same method signature that you are  
> familiar with in the old BidirectionalRepositoryLayout classes.

I guess that's what I was thinking of. Good to know, thanks.

But I have some more comments :)

>> I think the content factory only provides the repository  
>> configuration while the layout factory provides a means of getting  
>> the layout (BidirectionalRepositoryLayout) of the repository where  
>> the artifact is located and converting the path from the given  
>> artifact. I needed the content factory to get the repository url  
>> and the layout factory for the artifact path so I could get the  
>> absolute path to the actual artifact and check if it still exists. :)
>
> BidirectionalRepositoryLayout is going away.

Please do not make this change before 1.0. We entered the beta series  
on the understanding of stabilising the code base - not only  
intending a feature freeze, but a proper code evolution path in my  
mind. Deprecate if you can (and must), though frankly I don't  
understand why this is such a big issue.

> They are broken.
> They do not work.
> They will not be fixed.
> They encourage shortcuts (which is bad).
> Shortcuts encourage bugs (which is also bad).
> Bad code is ... uhm ... bad (which is also also bad).  ;-)

I think you're over-reacting a little, no? :)

BiRL only appeared recently, after 0.9, supposedly to fix all the  
problems with the way it was done before - and now it's the root of  
all evil? :)

> I want to encourage operations against the repository to utilize  
> those objects

I think that's a great idea, so let's think about how we might  
encourage it.

Certainly deleting something is doing it by force, not  
encouragement... so we can rule that out :)

IMO, the only way to encourage the use of particular APIs is:
- by deprecating those that should not be used
- documenting the ones that should, in a centralised place that  
everyone can find.

There have been too many changes too Archiva for anyone to understand  
everything - even though I've looked at every single one, I can't  
keep up with the whole picture. I think we've discussed it before,  
and I believe the best way is for each module to be independently  
usable and documented, and with overviews tying them together so that  
folks know where to find what they need to use.

Agree?

Cheers,
Brett

--
Brett Porter - brett@apache.org
Blog: http://www.devzuz.org/blogs/bporter/

Re: svn commit: r584735 - in /maven/archiva/trunk: archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/ archiva-base/ar...

Posted by Joakim Erdfelt <jo...@erdfelt.com>.
Maria Odea Ching wrote:
> Brett Porter wrote:
>> Hi Deng,
>>
>> On 15/10/2007, at 7:16 PM, oching@apache.org wrote:
>>
>>> [MRM-37 and MRM-527]
>>> - 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
>>
>> Cool - looks good. A couple of quick questions :)
>>
>>> + /**
>>> + * @plexus.requirement
>>> + */
>>> + private BidirectionalRepositoryLayoutFactory layoutFactory;
>>> +
>>> + /**
>>> + * @plexus.requirement
>>> + */
>>> + private RepositoryContentFactory repositoryFactory;
>>> +
>>
>> I'm probably wrong, but I understood the content factory should be 
>> used instead of the layoutFactory - does it provide a way to do this 
>> instead, or did I misunderstand?
>>
>
> I think the content factory only provides the repository configuration 
> while the layout factory provides a means of getting the layout 
> (BidirectionalRepositoryLayout) of the repository where the artifact 
> is located and converting the path from the given artifact. I needed 
> the content factory to get the repository url and the layout factory 
> for the artifact path so I could get the absolute path to the actual 
> artifact and check if it still exists. :)

BidirectionalRepositoryLayout is going away.
They are broken.
They do not work.
They will not be fixed.
They encourage shortcuts (which is bad).
Shortcuts encourage bugs (which is also bad).
Bad code is ... uhm ... bad (which is also also bad).  ;-)

Use the repositoryFactory.getManagedRepository(repoId) to get a 
ManagedRepositoryContent object.
Then use the .toFile() .toPath() .toArtifactReference() methods in 
there.  They should have the same method signature that you are familiar 
with in the old BidirectionalRepositoryLayout classes.

I want to encourage operations against the repository to utilize those 
objects, we have plenty of find/get methods already, and we even a 
.deleteVersion(VersionedReference) method in there too.  If you can 
think of more, let me know.

-- 
- Joakim Erdfelt
  joakim@erdfelt.com
  Open Source Software (OSS) Developer


Re: svn commit: r584735 - in /maven/archiva/trunk: archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/ archiva-base/ar...

Posted by Maria Odea Ching <oc...@exist.com>.
Brett Porter wrote:
> Hi Deng,
>
> On 15/10/2007, at 7:16 PM, oching@apache.org wrote:
>
>> [MRM-37 and MRM-527]
>> - 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
>
> Cool - looks good. A couple of quick questions :)
>
>> + /**
>> + * @plexus.requirement
>> + */
>> + private BidirectionalRepositoryLayoutFactory layoutFactory;
>> +
>> + /**
>> + * @plexus.requirement
>> + */
>> + private RepositoryContentFactory repositoryFactory;
>> +
>
> I'm probably wrong, but I understood the content factory should be 
> used instead of the layoutFactory - does it provide a way to do this 
> instead, or did I misunderstand?
>

I think the content factory only provides the repository configuration 
while the layout factory provides a means of getting the layout 
(BidirectionalRepositoryLayout) of the repository where the artifact is 
located and converting the path from the given artifact. I needed the 
content factory to get the repository url and the layout factory for the 
artifact path so I could get the absolute path to the actual artifact 
and check if it still exists. :)

>
>>
>> Modified: 
>> maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumer.java 
>>
>> URL: 
>> http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumer.java?rev=584735&r1=584734&r2=584735&view=diff 
>>
>> ============================================================================== 
>>
>> --- 
>> maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumer.java 
>> (original)
>> +++ 
>> maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveProjectConsumer.java 
>> Mon Oct 15 04:16:38 2007
>> @@ -19,17 +19,31 @@
>> * under the License.
>> */
>>
>
> ...
>
>> + 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() );
>> + }
>> +
>> }
>
> Couple of printStackTraces got left behind :)

Ooops, sorry about that :) I forgot to remove them.

>
> Cheers,
> Brett
>
> -- 
> Brett Porter - brett@apache.org
> Blog: http://www.devzuz.org/blogs/bporter/
>

Thanks,
Deng

Re: svn commit: r584735 - in /maven/archiva/trunk: archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ archiva-base/archiva-consumers/archiva-database-consumers/src/test/java/ archiva-base/ar...

Posted by Brett Porter <br...@apache.org>.
Hi Deng,

On 15/10/2007, at 7:16 PM, oching@apache.org wrote:

> [MRM-37 and MRM-527]
> - 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

Cool - looks good. A couple of quick questions :)

> +    /**
> +     * @plexus.requirement
> +     */
> +    private BidirectionalRepositoryLayoutFactory layoutFactory;
> +
> +    /**
> +     * @plexus.requirement
> +     */
> +    private RepositoryContentFactory repositoryFactory;
> +

I'm probably wrong, but I understood the content factory should be  
used instead of the layoutFactory - does it provide a way to do this  
instead, or did I misunderstand?


>
> Modified: maven/archiva/trunk/archiva-base/archiva-consumers/ 
> archiva-database-consumers/src/main/java/org/apache/maven/archiva/ 
> consumers/database/DatabaseCleanupRemoveProjectConsumer.java
> URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/ 
> archiva-consumers/archiva-database-consumers/src/main/java/org/ 
> apache/maven/archiva/consumers/database/ 
> DatabaseCleanupRemoveProjectConsumer.java? 
> rev=584735&r1=584734&r2=584735&view=diff
> ====================================================================== 
> ========
> --- maven/archiva/trunk/archiva-base/archiva-consumers/archiva- 
> database-consumers/src/main/java/org/apache/maven/archiva/consumers/ 
> database/DatabaseCleanupRemoveProjectConsumer.java (original)
> +++ maven/archiva/trunk/archiva-base/archiva-consumers/archiva- 
> database-consumers/src/main/java/org/apache/maven/archiva/consumers/ 
> database/DatabaseCleanupRemoveProjectConsumer.java Mon Oct 15  
> 04:16:38 2007
> @@ -19,17 +19,31 @@
>   * under the License.
>   */
>

...

> +    	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() );
> +        }    	
> +
>      }

Couple of printStackTraces got left behind :)

Cheers,
Brett

--
Brett Porter - brett@apache.org
Blog: http://www.devzuz.org/blogs/bporter/