]> source.dussan.org Git - archiva.git/commitdiff
[MRM-544] archiva-backend-security@590762
authorMaria Odea B. Ching <oching@apache.org>
Wed, 31 Oct 2007 11:07:24 +0000 (11:07 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Wed, 31 Oct 2007 11:07:24 +0000 (11:07 +0000)
- remove artifact in index if artifact no longer exists in the file system
- added tests

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

archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/stubs/LuceneRepositoryContentIndexFactoryStub.java
archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/stubs/LuceneRepositoryContentIndexStub.java
archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumer.java
archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/conf/repository-manager.xml [new file with mode: 0644]
archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/maven/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumerTest.java [new file with mode: 0644]
archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/maven/archiva/consumers/lucene/stubs/LuceneRepositoryContentIndexFactoryStub.java [new file with mode: 0644]
archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/maven/archiva/consumers/lucene/stubs/LuceneRepositoryContentIndexStub.java [new file with mode: 0644]
archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/resources/org/apache/maven/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumerTest.xml [new file with mode: 0644]
archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/resources/test-repo/org/apache/maven/archiva/archiva-lucene-cleanup/1.0/archiva-lucene-cleanup-1.0.jar [new file with mode: 0644]
archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/RepositoryContentIndex.java
archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryContentIndex.java

index 2572fab65f62af057d55188c60bdcd449c4a5ce9..fce937f99e1f048a76718bacdee22e943b5efd5c 100644 (file)
@@ -34,7 +34,7 @@ public class LuceneRepositoryContentIndexFactoryStub
 {
 
     public RepositoryContentIndex createBytecodeIndex( ManagedRepositoryConfiguration repository )
-    {
+    {        
         // TODO Auto-generated method stub
         return new LuceneRepositoryContentIndexStub();
     }
index 82e90f1926a90fcc8ff71695c5988b0533aecb5a..e9966def2bd1b9865fefbe1f5b1f03719f37254a 100644 (file)
@@ -126,5 +126,12 @@ public class LuceneRepositoryContentIndexStub
         // TODO Auto-generated method stub
 
     }
+    
+    public void deleteRecord( LuceneRepositoryContentRecord record )
+        throws RepositoryIndexException
+    {        
+        // TODO Auto-generated method stub
+        
+    }
 
 }
index 32a9ce938ab6598eefc499b7f455830fa7d509e7..a6f729395fd5dc33af052c98f2e59fb798308751 100644 (file)
@@ -22,19 +22,27 @@ package org.apache.maven.archiva.consumers.lucene;
 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.indexer.RepositoryContentIndex;
+import org.apache.maven.archiva.indexer.RepositoryContentIndexFactory;
+import org.apache.maven.archiva.indexer.RepositoryIndexException;
+import org.apache.maven.archiva.indexer.bytecode.BytecodeRecord;
+import org.apache.maven.archiva.indexer.filecontent.FileContentRecord;
+import org.apache.maven.archiva.indexer.hashcodes.HashcodesRecord;
 import org.apache.maven.archiva.model.ArchivaArtifact;
+import org.apache.maven.archiva.repository.ManagedRepositoryContent;
+import org.apache.maven.archiva.repository.RepositoryContentFactory;
+import org.apache.maven.archiva.repository.RepositoryException;
 
+import java.io.File;
 import java.util.List;
 
 /**
- * LuceneCleanupRemoveIndexedConsumer 
- *
+ * LuceneCleanupRemoveIndexedConsumer
+ * 
  * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
  * @version $Id$
- * 
  * @plexus.component role="org.apache.maven.archiva.consumers.DatabaseCleanupConsumer"
- *                   role-hint="not-present-remove-indexed"
- *                   instantiation-strategy="per-lookup"
+ *                   role-hint="not-present-remove-indexed" instantiation-strategy="per-lookup"
  */
 public class LuceneCleanupRemoveIndexedConsumer
     extends AbstractMonitoredConsumer
@@ -50,6 +58,16 @@ public class LuceneCleanupRemoveIndexedConsumer
      */
     private String description;
 
+    /**
+     * @plexus.requirement role-hint="lucene"
+     */
+    private RepositoryContentIndexFactory repoIndexFactory;
+
+    /**
+     * @plexus.requirement
+     */
+    private RepositoryContentFactory repoFactory;
+
     public void beginScan()
     {
         // TODO Auto-generated method stub
@@ -71,8 +89,41 @@ public class LuceneCleanupRemoveIndexedConsumer
     public void processArchivaArtifact( ArchivaArtifact artifact )
         throws ConsumerException
     {
-        // TODO Auto-generated method stub
-
+        try
+        {   
+            ManagedRepositoryContent repoContent =
+                repoFactory.getManagedRepositoryContent( artifact.getModel().getRepositoryId() );
+
+            File file = new File( repoContent.getRepoRoot(), repoContent.toPath( artifact ) );
+            
+            if( !file.exists() )
+            {   
+                RepositoryContentIndex bytecodeIndex = repoIndexFactory.createBytecodeIndex( repoContent.getRepository() );
+                RepositoryContentIndex hashcodesIndex = repoIndexFactory.createHashcodeIndex( repoContent.getRepository() );
+                RepositoryContentIndex fileContentIndex =
+                    repoIndexFactory.createFileContentIndex( repoContent.getRepository() );
+    
+                FileContentRecord fileContentRecord = new FileContentRecord();
+                fileContentRecord.setFilename( repoContent.toPath( artifact ) );
+                fileContentIndex.deleteRecord( fileContentRecord );
+    
+                HashcodesRecord hashcodesRecord = new HashcodesRecord();
+                hashcodesRecord.setArtifact( artifact );
+                hashcodesIndex.deleteRecord( hashcodesRecord );
+    
+                BytecodeRecord bytecodeRecord = new BytecodeRecord();
+                bytecodeRecord.setArtifact( artifact );
+                bytecodeIndex.deleteRecord( bytecodeRecord );
+            }                
+        }
+        catch ( RepositoryException e )
+        {
+            throw new ConsumerException( "Can't run index cleanup consumer: " + e.getMessage() );
+        }
+        catch ( RepositoryIndexException e )
+        {
+            throw new ConsumerException( e.getMessage() );
+        }
     }
 
     public String getDescription()
@@ -90,4 +141,13 @@ public class LuceneCleanupRemoveIndexedConsumer
         return false;
     }
 
+    public void setRepositoryIndexFactory( RepositoryContentIndexFactory repoIndexFactory )
+    {
+        this.repoIndexFactory = repoIndexFactory;
+    }
+
+    public void setRepositoryContentFactory( RepositoryContentFactory repoFactory )
+    {
+        this.repoFactory = repoFactory;
+    }
 }
diff --git a/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/conf/repository-manager.xml b/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/conf/repository-manager.xml
new file mode 100644 (file)
index 0000000..4e2e394
--- /dev/null
@@ -0,0 +1,129 @@
+<?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.
+  -->
+
+<configuration>
+  <version>1</version>
+  <repositories>
+    <repository>
+      <id>test-repo</id>
+      <name>Test Repository</name>
+      <url>file://src/test/resources/test-repo</url>
+      <layout>default</layout>
+      <releases>true</releases>
+      <snapshots>true</snapshots>
+      <indexed>true</indexed>
+      <refreshCronExpression>0 0 * * ?</refreshCronExpression>
+      <daysOlder>0</daysOlder>
+      <retentionCount>2</retentionCount>
+    </repository>
+  </repositories>
+
+  <proxyConnectors/>
+
+  <networkProxies>
+    <networkProxy>
+      <id>example</id>
+      <protocol>http</protocol>
+      <host>proxy.mycompany.com</host>
+      <port>8080</port>
+      <username>myself</username>
+      <password>mypass</password>
+    </networkProxy>
+  </networkProxies>
+
+  <repositoryScanning>
+    <fileTypes>
+      <fileType>
+        <id>artifacts</id>
+        <patterns>
+          <pattern>**/*.pom</pattern>
+          <pattern>**/*.jar</pattern>
+          <pattern>**/*.ear</pattern>
+          <pattern>**/*.war</pattern>
+        </patterns>
+      </fileType>
+      <fileType>
+        <id>indexable-content</id>
+        <patterns>
+          <pattern>**/*.txt</pattern>
+          <pattern>**/*.TXT</pattern>
+        </patterns>
+      </fileType>
+      <fileType>
+        <id>auto-remove</id>
+        <patterns>
+          <pattern>**/*.bak</pattern>
+          <pattern>**/*~</pattern>
+          <pattern>**/*-</pattern>
+        </patterns>
+      </fileType>
+      <fileType>
+        <id>ignored</id>
+        <patterns>
+          <pattern>**/.htaccess</pattern>
+          <pattern>**/KEYS</pattern>
+          <pattern>**/*.rb</pattern>
+          <pattern>**/*.sh</pattern>
+          <pattern>**/.svn/**</pattern>
+          <pattern>**/.DAV/**</pattern>
+        </patterns>
+      </fileType>
+    </fileTypes>
+    <knownContentConsumers>
+      <knownContentConsumer>update-db-artifact</knownContentConsumer>
+      <knownContentConsumer>create-missing-checksums</knownContentConsumer>
+      <knownContentConsumer>update-db-repository-metadata</knownContentConsumer>
+      <knownContentConsumer>validate-checksum</knownContentConsumer>
+      <knownContentConsumer>validate-signature</knownContentConsumer>
+      <knownContentConsumer>index-content</knownContentConsumer>
+      <knownContentConsumer>auto-remove</knownContentConsumer>
+      <knownContentConsumer>auto-rename</knownContentConsumer>
+      <knownContentConsumer>repository-purge</knownContentConsumer>
+    </knownContentConsumers>
+    <invalidContentConsumers>
+      <invalidContentConsumer>update-db-bad-content</invalidContentConsumer>
+    </invalidContentConsumers>
+  </repositoryScanning>
+
+  <databaseScanning>
+    <cronExpression>0 0 * * ?</cronExpression>
+    <unprocessedConsumers>
+      <unprocessedConsumer>index-artifact</unprocessedConsumer>
+      <unprocessedConsumer>update-db-project</unprocessedConsumer>
+      <unprocessedConsumer>validate-repository-metadata</unprocessedConsumer>
+      <unprocessedConsumer>index-archive-toc</unprocessedConsumer>
+      <unprocessedConsumer>update-db-bytecode-stats</unprocessedConsumer>
+      <unprocessedConsumer>index-public-methods</unprocessedConsumer>
+    </unprocessedConsumers>
+    <cleanupConsumers>
+      <cleanupConsumer>not-present-remove-db-artifact</cleanupConsumer>
+      <cleanupConsumer>not-present-remove-db-project</cleanupConsumer>
+      <cleanupConsumer>not-present-remove-indexed</cleanupConsumer>
+    </cleanupConsumers>
+  </databaseScanning>
+
+  <webapp>
+    <ui>
+      <showFindArtifacts>true</showFindArtifacts>
+      <appletFindEnabled>true</appletFindEnabled>
+    </ui>
+  </webapp>
+
+</configuration>
diff --git a/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/maven/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumerTest.java b/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/maven/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumerTest.java
new file mode 100644 (file)
index 0000000..64eeae2
--- /dev/null
@@ -0,0 +1,77 @@
+package org.apache.maven.archiva.consumers.lucene;
+
+/*
+ * 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.apache.maven.archiva.consumers.DatabaseCleanupConsumer;
+import org.apache.maven.archiva.model.ArchivaArtifact;
+import org.apache.maven.archiva.model.ArchivaArtifactModel;
+import org.codehaus.plexus.PlexusTestCase;
+
+/**
+ * LuceneCleanupRemoveIndexedConsumerTest
+ * 
+ * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ * @version
+ */
+public class LuceneCleanupRemoveIndexedConsumerTest
+    extends PlexusTestCase
+{
+    private DatabaseCleanupConsumer luceneCleanupRemoveIndexConsumer;
+    
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+        
+        luceneCleanupRemoveIndexConsumer = (DatabaseCleanupConsumer) 
+            lookup( DatabaseCleanupConsumer.class, "lucene-cleanup" );     
+    }
+    
+    public void testIfArtifactExists()
+        throws Exception
+    {      
+        ArchivaArtifact artifact = createArtifact( 
+              "org.apache.maven.archiva", "archiva-lucene-cleanup", "1.0", "jar" );
+        
+        luceneCleanupRemoveIndexConsumer.processArchivaArtifact( artifact );              
+    }
+    
+    public void testIfArtifactDoesNotExist()
+        throws Exception
+    {
+        ArchivaArtifact artifact = createArtifact( 
+              "org.apache.maven.archiva", "deleted-artifact", "1.0", "jar" );
+        
+        luceneCleanupRemoveIndexConsumer.processArchivaArtifact( artifact );             
+    }
+        
+    private 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" );
+
+        return new ArchivaArtifact( model );
+    }
+    
+}
diff --git a/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/maven/archiva/consumers/lucene/stubs/LuceneRepositoryContentIndexFactoryStub.java b/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/maven/archiva/consumers/lucene/stubs/LuceneRepositoryContentIndexFactoryStub.java
new file mode 100644 (file)
index 0000000..b7ede95
--- /dev/null
@@ -0,0 +1,55 @@
+package org.apache.maven.archiva.consumers.lucene.stubs;
+
+/*
+ * 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.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.indexer.RepositoryContentIndex;
+import org.apache.maven.archiva.indexer.RepositoryContentIndexFactory;
+import org.apache.maven.archiva.indexer.lucene.LuceneRepositoryContentIndex;
+
+/**
+ * LuceneRepositoryContenIndexFactoryStub
+ * 
+ * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ * @version
+ */
+public class LuceneRepositoryContentIndexFactoryStub
+    implements RepositoryContentIndexFactory
+{
+
+    public RepositoryContentIndex createBytecodeIndex( ManagedRepositoryConfiguration repository )
+    {        
+        // TODO Auto-generated method stub        
+        return new LuceneRepositoryContentIndexStub(); 
+    }
+
+    public RepositoryContentIndex createFileContentIndex( ManagedRepositoryConfiguration repository )
+    {
+        // TODO Auto-generated method stub
+        return new LuceneRepositoryContentIndexStub();
+    }
+
+    public RepositoryContentIndex createHashcodeIndex( ManagedRepositoryConfiguration repository )
+    {
+        // TODO Auto-generated method stub
+        return new LuceneRepositoryContentIndexStub();
+    }
+
+}
diff --git a/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/maven/archiva/consumers/lucene/stubs/LuceneRepositoryContentIndexStub.java b/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/maven/archiva/consumers/lucene/stubs/LuceneRepositoryContentIndexStub.java
new file mode 100644 (file)
index 0000000..a5b40c8
--- /dev/null
@@ -0,0 +1,145 @@
+package org.apache.maven.archiva.consumers.lucene.stubs;
+
+/*
+ * 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 java.io.File;
+import java.util.Collection;
+
+import junit.framework.Assert;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Searchable;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.indexer.RepositoryContentIndex;
+import org.apache.maven.archiva.indexer.RepositoryIndexException;
+import org.apache.maven.archiva.indexer.RepositoryIndexSearchException;
+import org.apache.maven.archiva.indexer.lucene.LuceneEntryConverter;
+import org.apache.maven.archiva.indexer.lucene.LuceneRepositoryContentRecord;
+
+/**
+ * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ * @version
+ */
+public class LuceneRepositoryContentIndexStub
+    implements RepositoryContentIndex
+{
+
+    public void deleteRecords( Collection records )
+        throws RepositoryIndexException
+    {
+        // TODO Auto-generated method stub
+        Assert.assertEquals( 2, records.size() );
+    }
+
+    public boolean exists()
+        throws RepositoryIndexException
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    public Collection getAllRecordKeys()
+        throws RepositoryIndexException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Analyzer getAnalyzer()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public LuceneEntryConverter getEntryConverter()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public String getId()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public File getIndexDirectory()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public QueryParser getQueryParser()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public ManagedRepositoryConfiguration getRepository()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Searchable getSearchable()
+        throws RepositoryIndexSearchException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void indexRecords( Collection records )
+        throws RepositoryIndexException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void modifyRecord( LuceneRepositoryContentRecord record )
+        throws RepositoryIndexException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void modifyRecords( Collection records )
+        throws RepositoryIndexException
+    {
+        // TODO Auto-generated method stub
+
+    }
+    
+    public void deleteRecord( LuceneRepositoryContentRecord record )
+        throws RepositoryIndexException
+    {   
+        Assert.assertNotNull( record );      
+        
+        // fail since the record to be deleted should only be the deleted-artifact-1.0.jar 
+        // according to the tests
+        if( record.getPrimaryKey().equals( 
+                "org/apache/maven/archiva/archiva-lucene-cleanup/1.0/archiva-lucene-cleanup-1.0.jar" ) && 
+                record.getPrimaryKey().equals( "org.apache.maven.archiva:archiva-lucene-cleanup:1.0:jar" ) )
+        {
+            Assert.fail();
+        }
+    }
+
+}
diff --git a/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/resources/org/apache/maven/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumerTest.xml b/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/resources/org/apache/maven/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumerTest.xml
new file mode 100644 (file)
index 0000000..99a7a2d
--- /dev/null
@@ -0,0 +1,78 @@
+<?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>lucene-cleanup</role-hint>
+      <implementation>org.apache.maven.archiva.consumers.lucene.LuceneCleanupRemoveIndexedConsumer</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.archiva.indexer.RepositoryContentIndexFactory</role>
+          <role-hint>lucene-cleanup</role-hint>
+          <field-name>repoIndexFactory</field-name>
+        </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.repository.RepositoryContentFactory</role>
+        </requirement>
+      </requirements>
+    </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>lucene-cleanup</role-hint>          
+        </requirement>
+      </requirements>
+    </component>
+    <component>
+      <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
+      <role-hint>lucene-cleanup</role-hint>
+      <implementation>org.apache.maven.archiva.configuration.DefaultArchivaConfiguration</implementation>
+      <requirements>
+        <requirement>
+          <role>org.codehaus.plexus.registry.Registry</role>
+          <role-hint>lucene-cleanup</role-hint>
+        </requirement>
+      </requirements>
+    </component>
+    <component>
+      <role>org.codehaus.plexus.registry.Registry</role>
+      <role-hint>lucene-cleanup</role-hint>
+      <implementation>org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry</implementation>
+      <configuration>
+        <properties>
+          <xml fileName="${basedir}/src/test/conf/repository-manager.xml"
+               config-name="org.apache.maven.archiva" config-at="org.apache.maven.archiva"/>
+        </properties>
+      </configuration>
+    </component>
+    <component>
+      <role>org.apache.maven.archiva.indexer.RepositoryContentIndexFactory</role>
+      <implementation>org.apache.maven.archiva.consumers.lucene.stubs.LuceneRepositoryContentIndexFactoryStub</implementation>
+      <role-hint>lucene-cleanup</role-hint>
+    </component>
+    
+  </components>
+</component-set>
diff --git a/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/resources/test-repo/org/apache/maven/archiva/archiva-lucene-cleanup/1.0/archiva-lucene-cleanup-1.0.jar b/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/resources/test-repo/org/apache/maven/archiva/archiva-lucene-cleanup/1.0/archiva-lucene-cleanup-1.0.jar
new file mode 100644 (file)
index 0000000..e69de29
index b45f5727a25d41eca03977cef10c5cef56941a07..be089107e512ed6ce34f7242f5050176389cabe8 100644 (file)
@@ -80,6 +80,15 @@ public interface RepositoryContentIndex
      */
     void deleteRecords( Collection records )
         throws RepositoryIndexException;
+    
+    /**
+     * Delete a record from the index. Simply ignore the request any did not exist.
+     *
+     * @param record the record to be deleted
+     * @throws RepositoryIndexException if there is a problem removing the record
+     */
+    void deleteRecord( LuceneRepositoryContentRecord record )
+        throws RepositoryIndexException;
 
     /**
      * Retrieve all primary keys of records in the index.
index 369d67535f3dade6165327df0965aacea665f938..469418cdfb3d72b727debc00a3ce7ee4d414f818 100644 (file)
@@ -234,6 +234,38 @@ public class LuceneRepositoryContentIndex
         }
     }
     
+    public void deleteRecord( LuceneRepositoryContentRecord record )
+        throws RepositoryIndexException
+    {
+        synchronized( repository )
+        {
+            if ( exists() )
+            {
+                IndexReader indexReader = null;
+                try
+                {
+                    indexReader = IndexReader.open( indexLocation );    
+                    
+                    if ( record != null )
+                    {
+                        Term term = new Term( LuceneDocumentMaker.PRIMARY_KEY, record.getPrimaryKey() );
+                        
+                        indexReader.deleteDocuments( term );                            
+                    }                    
+                }
+                catch ( IOException e )
+                {
+                    throw new RepositoryIndexException( "Error deleting document: " + e.getMessage(), e );
+                }
+                finally
+                {
+                    closeQuietly( indexReader );
+                }
+            }
+        }
+    }
+    
+    
     public Collection getAllRecordKeys()
         throws RepositoryIndexException
     {