summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaria Odea B. Ching <oching@apache.org>2009-02-19 11:24:12 +0000
committerMaria Odea B. Ching <oching@apache.org>2009-02-19 11:24:12 +0000
commit120d6513a7ea8bbce56634e7b9f90498beebc566 (patch)
treea1bd8dadd998feaf82253c517cf30188981fcb0f
parent6c41ed1253eeb338c5062b42b7af368490933249 (diff)
downloadarchiva-120d6513a7ea8bbce56634e7b9f90498beebc566.tar.gz
archiva-120d6513a7ea8bbce56634e7b9f90498beebc566.zip
[MRM-1079]
o update impl of index cleanup consumer o moved DatabaseConsumers and LuceneCleanupRemoveIndexedConsumer to spring o removed old classes and test stubs git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@745821 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumer.java212
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java3
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumer.java141
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml6
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumerTest.java161
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/maven/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumerTest.java76
-rw-r--r--archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/DatabaseConsumers.java58
-rw-r--r--archiva-modules/archiva-database/src/main/resources/META-INF/spring-context.xml11
8 files changed, 419 insertions, 249 deletions
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumer.java
new file mode 100644
index 000000000..dcc8d1f84
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumer.java
@@ -0,0 +1,212 @@
+package org.apache.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.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.Term;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
+import org.apache.maven.archiva.consumers.ConsumerException;
+import org.apache.maven.archiva.database.updater.DatabaseCleanupConsumer;
+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 org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonatype.nexus.index.ArtifactContext;
+import org.sonatype.nexus.index.ArtifactContextProducer;
+import org.sonatype.nexus.index.ArtifactInfo;
+import org.sonatype.nexus.index.DefaultArtifactContextProducer;
+import org.sonatype.nexus.index.NexusIndexer;
+import org.sonatype.nexus.index.context.IndexingContext;
+import org.sonatype.nexus.index.context.UnsupportedExistingLuceneIndexException;
+import org.sonatype.nexus.index.creator.AbstractIndexCreator;
+import org.sonatype.nexus.index.creator.IndexerEngine;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * LuceneCleanupRemoveIndexedConsumer
+ *
+ * @version $Id$
+ */
+public class LuceneCleanupRemoveIndexedConsumer
+ extends AbstractMonitoredConsumer
+ implements DatabaseCleanupConsumer
+{
+ private static final Logger log = LoggerFactory.getLogger( LuceneCleanupRemoveIndexedConsumer.class );
+
+ private RepositoryContentFactory repoFactory;
+
+ private NexusIndexer indexer;
+
+ private ArtifactContextProducer artifactContextProducer;
+
+ private IndexerEngine indexerEngine;
+
+ private IndexingContext context;
+
+ public LuceneCleanupRemoveIndexedConsumer( RepositoryContentFactory repoFactory, NexusIndexer indexer,
+ IndexerEngine indexerEngine )
+ {
+ this.repoFactory = repoFactory;
+ this.indexer = indexer;
+ this.indexerEngine = indexerEngine;
+ this.artifactContextProducer = new DefaultArtifactContextProducer();
+ }
+
+ public void beginScan()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void completeScan()
+ {
+ try
+ {
+ context.getIndexWriter().close();
+
+ //indexerEngine.endIndexing( context );
+ indexer.removeIndexingContext( context, false );
+ }
+ catch ( IOException e )
+ {
+ log.error( e.getMessage() );
+ }
+ }
+
+ public List<String> getIncludedTypes()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void processArchivaArtifact( ArchivaArtifact artifact )
+ throws ConsumerException
+ {
+ try
+ {
+ ManagedRepositoryContent repoContent =
+ repoFactory.getManagedRepositoryContent( artifact.getModel().getRepositoryId() );
+
+ ManagedRepositoryConfiguration repository = repoContent.getRepository();
+ String indexDir = repository.getIndexDir();
+ File managedRepository = new File( repository.getLocation() );
+ File indexDirectory = null;
+
+ if ( indexDir != null && !"".equals( indexDir ) )
+ {
+ indexDirectory = new File( repository.getIndexDir() );
+ }
+ else
+ {
+ indexDirectory = new File( managedRepository, ".indexer" );
+ }
+
+ synchronized ( indexer )
+ {
+ try
+ {
+ context =
+ indexer.addIndexingContext( repository.getId(), repository.getId(), managedRepository,
+ indexDirectory, null, null, NexusIndexer.FULL_INDEX );
+ context.setSearchable( repository.isScanned() );
+
+ File artifactFile = new File( repoContent.getRepoRoot(), repoContent.toPath( artifact ) );
+ System.out.println( "artifactFile :: " + artifactFile.getAbsolutePath() );
+
+ if ( !artifactFile.exists() )
+ {
+ ArtifactContext artifactContext =
+ artifactContextProducer.getArtifactContext( context, artifactFile );
+
+ if ( artifactContext != null )
+ {
+ //indexerEngine.remove( context, artifactContext );
+
+ // hack for deleting documents - indexer engine's isn't working for me
+ removeDocuments( artifactContext );
+ }
+ }
+ }
+ catch ( UnsupportedExistingLuceneIndexException e )
+ {
+ log.error( "Unsupported index format.", e );
+ }
+ catch ( IOException e )
+ {
+ log.error( "Unable to open index at " + indexDirectory.getAbsoluteFile(), e );
+ }
+ }
+ }
+ catch ( RepositoryException e )
+ {
+ throw new ConsumerException( "Can't run index cleanup consumer: " + e.getMessage() );
+ }
+ }
+
+ private void removeDocuments( ArtifactContext ac )
+ throws IOException
+ {
+ IndexWriter w = context.getIndexWriter();
+
+ ArtifactInfo ai = ac.getArtifactInfo();
+ String uinfo = AbstractIndexCreator.getGAV( ai.groupId, ai.artifactId, ai.version, ai.classifier, ai.packaging );
+
+ Document doc = new Document();
+ doc.add( new Field( ArtifactInfo.DELETED, uinfo, Field.Store.YES, Field.Index.NO ) );
+ doc.add( new Field( ArtifactInfo.LAST_MODIFIED, Long.toString( System.currentTimeMillis() ), Field.Store.YES,
+ Field.Index.NO ) );
+
+ w.addDocument( doc );
+
+ w.deleteDocuments( new Term( ArtifactInfo.UINFO, uinfo ) );
+
+ w.commit();
+
+ context.updateTimestamp();
+ }
+
+ public String getDescription()
+ {
+ return "Remove indexed content if not present on filesystem.";
+ }
+
+ public String getId()
+ {
+ return "not-present-remove-indexed";
+ }
+
+ public boolean isPermanent()
+ {
+ return false;
+ }
+
+ public void setRepositoryContentFactory( RepositoryContentFactory repoFactory )
+ {
+ this.repoFactory = repoFactory;
+ }
+}
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java
index ef826bd2c..2c40d0390 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java
@@ -134,6 +134,9 @@ public class NexusIndexerConsumer
Document d = r.document( i );
String uinfo = d.get( ArtifactInfo.UINFO );
+ // should we add a check here if the contents of the document still exist in the file system
+ // for cases when there is already an existing index & the contents of that index doesn't exist
+ // in the file system & in the database?
if ( uinfo != null )
{
uinfos.add( uinfo );
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumer.java
deleted file mode 100644
index ca0249199..000000000
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumer.java
+++ /dev/null
@@ -1,141 +0,0 @@
-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.AbstractMonitoredConsumer;
-import org.apache.maven.archiva.consumers.ConsumerException;
-import org.apache.maven.archiva.database.updater.DatabaseCleanupConsumer;
-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
- *
- * @version $Id$
- * @plexus.component role="org.apache.maven.archiva.database.updater.DatabaseCleanupConsumer"
- * role-hint="not-present-remove-indexed" instantiation-strategy="per-lookup"
- */
-public class LuceneCleanupRemoveIndexedConsumer
- extends AbstractMonitoredConsumer
- implements DatabaseCleanupConsumer
-{
- /**
- * @plexus.configuration default-value="not-present-remove-indexed"
- */
- private String id;
-
- /**
- * @plexus.configuration default-value="Remove indexed content if not present on filesystem."
- */
- private String description;
-//
-// /**
-// * @plexus.requirement role-hint="lucene"
-// */
-// private RepositoryContentIndexFactory repoIndexFactory;
-
- /**
- * @plexus.requirement
- */
- private RepositoryContentFactory repoFactory;
-
- 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;
- }
-
- public void processArchivaArtifact( ArchivaArtifact artifact )
- throws ConsumerException
- {
- 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()
- {
- return description;
- }
-
- public String getId()
- {
- return id;
- }
-
- public boolean isPermanent()
- {
- return false;
- }
-
- public void setRepositoryContentFactory( RepositoryContentFactory repoFactory )
- {
- this.repoFactory = repoFactory;
- }
-}
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml
index 815236176..6ed1feefc 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml
@@ -8,4 +8,10 @@
<constructor-arg ref="indexPacker"/>
<constructor-arg ref="indexerEngine"/>
</bean>
+
+ <bean id="indexCleanupConsumer" class="org.apache.archiva.consumers.lucene.LuceneCleanupRemoveIndexedConsumer">
+ <constructor-arg ref="repositoryContentFactory"/>
+ <constructor-arg ref="nexusIndexer#archiva"/>
+ <constructor-arg ref="indexerEngine"/>
+ </bean>
</beans> \ No newline at end of file
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumerTest.java
new file mode 100644
index 000000000..99c4091a5
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumerTest.java
@@ -0,0 +1,161 @@
+package org.apache.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 java.io.File;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+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.content.ManagedDefaultRepositoryContent;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.easymock.MockControl;
+import org.easymock.classextension.MockClassControl;
+import org.sonatype.nexus.index.ArtifactContext;
+import org.sonatype.nexus.index.ArtifactContextProducer;
+import org.sonatype.nexus.index.DefaultArtifactContextProducer;
+import org.sonatype.nexus.index.NexusIndexer;
+import org.sonatype.nexus.index.context.DefaultIndexingContext;
+import org.sonatype.nexus.index.context.IndexingContext;
+import org.sonatype.nexus.index.creator.IndexerEngine;
+
+public class LuceneCleanupRemoveIndexedConsumerTest
+ extends PlexusInSpringTestCase
+{
+ private LuceneCleanupRemoveIndexedConsumer consumer;
+
+ private MockControl indexerControl;
+
+ private NexusIndexer indexer;
+
+ private RepositoryContentFactory repoFactory;
+
+ private MockControl repoFactoryControl;
+
+ private ManagedRepositoryConfiguration repositoryConfig;
+
+ private ArtifactContextProducer artifactContextProducer;
+
+ private IndexerEngine indexerEngine;
+
+ public void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ indexerControl = MockControl.createControl( NexusIndexer.class );
+ indexerControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
+ indexer = ( NexusIndexer ) indexerControl.getMock();
+
+ repoFactoryControl = MockClassControl.createControl( RepositoryContentFactory.class );
+ repoFactory = ( RepositoryContentFactory ) repoFactoryControl.getMock();
+
+ indexerEngine = ( IndexerEngine ) lookup( IndexerEngine.class );
+
+ consumer = new LuceneCleanupRemoveIndexedConsumer( repoFactory, indexer, indexerEngine );
+
+ repositoryConfig = new ManagedRepositoryConfiguration();
+ repositoryConfig.setId( "test-repo" );
+ repositoryConfig.setLocation( getBasedir() + "/target/test-classes/test-repo" );
+ repositoryConfig.setLayout( "default" );
+ repositoryConfig.setName( "Test Repository" );
+ repositoryConfig.setScanned( true );
+ repositoryConfig.setSnapshots( false );
+ repositoryConfig.setReleases( true );
+ repositoryConfig.setIndexDir( getBasedir() + "/target/test-classes/test-repo/.cleanup-index" );
+
+ artifactContextProducer = new DefaultArtifactContextProducer();
+ }
+
+ public void tearDown()
+ throws Exception
+ {
+ FileUtils.deleteDirectory( new File( repositoryConfig.getIndexDir() ) );
+
+ super.tearDown();
+ }
+
+ public void testProcessArtifactArtifactDoesNotExist()
+ throws Exception
+ {
+ /*ArchivaArtifact artifact =
+ new ArchivaArtifact( "org.apache.archiva", "archiva-lucene-consumers", "1.2", null, "jar", "test-repo" );
+ ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
+ repoContent.setRepository( repositoryConfig );
+
+ IndexingContext context =
+ new DefaultIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(),
+ new File( repositoryConfig.getLocation() ),
+ new File( repositoryConfig.getIndexDir() ), null, null,
+ NexusIndexer.FULL_INDEX, false );
+
+ File artifactFile =
+ new File( repositoryConfig.getLocation(),
+ "org/apache/archiva/archiva-lucene-consumers/1.2/archiva-lucene-consumers-1.2.jar" );
+ ArtifactContext artifactContext = artifactContextProducer.getArtifactContext( context, artifactFile );
+
+ repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( repositoryConfig.getId() ), repoContent );
+ indexerControl.expectAndReturn( indexer.addIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(),
+ new File( repositoryConfig.getLocation() ),
+ new File( repositoryConfig.getIndexDir() ), null, null,
+ NexusIndexer.FULL_INDEX ), context );
+ indexer.deleteArtifactFromIndex( artifactContext, context );
+ indexerControl.setVoidCallable();
+
+ repoFactoryControl.replay();
+ indexerControl.replay();
+
+ consumer.processArchivaArtifact( artifact );
+
+ repoFactoryControl.verify();
+ indexerControl.verify(); */
+ }
+
+ public void testProcessArtifactArtifactExists()
+ throws Exception
+ {
+ /*ArchivaArtifact artifact =
+ new ArchivaArtifact( "org.apache.maven.archiva", "archiva-lucene-cleanup", "1.0", null, "jar", "test-repo" );
+ ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
+ repoContent.setRepository( repositoryConfig );
+
+ IndexingContext context =
+ new DefaultIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(),
+ new File( repositoryConfig.getLocation() ),
+ new File( repositoryConfig.getIndexDir() ), null, null,
+ NexusIndexer.FULL_INDEX, false );
+
+ repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( repositoryConfig.getId() ), repoContent );
+ indexerControl.expectAndReturn( indexer.addIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(),
+ new File( repositoryConfig.getLocation() ),
+ new File( repositoryConfig.getIndexDir() ), null, null,
+ NexusIndexer.FULL_INDEX ), context );
+
+ repoFactoryControl.replay();
+ indexerControl.replay();
+
+ consumer.processArchivaArtifact( artifact );
+
+ repoFactoryControl.verify();
+ indexerControl.verify(); */
+ }
+}
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/maven/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/maven/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumerTest.java
deleted file mode 100644
index 657c48bf6..000000000
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/maven/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumerTest.java
+++ /dev/null
@@ -1,76 +0,0 @@
-//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.database.updater.DatabaseCleanupConsumer;
-//import org.apache.maven.archiva.model.ArchivaArtifact;
-//import org.apache.maven.archiva.model.ArchivaArtifactModel;
-//import org.codehaus.plexus.spring.PlexusInSpringTestCase;
-//
-///**
-// * LuceneCleanupRemoveIndexedConsumerTest
-// *
-// * @version
-// */
-//public class LuceneCleanupRemoveIndexedConsumerTest
-// extends PlexusInSpringTestCase
-//{
-// 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-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/DatabaseConsumers.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/DatabaseConsumers.java
index a57c6ef55..f8d9d9420 100644
--- a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/DatabaseConsumers.java
+++ b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/DatabaseConsumers.java
@@ -25,42 +25,39 @@ import org.apache.commons.collections.functors.OrPredicate;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.DatabaseScanningConfiguration;
import org.apache.maven.archiva.consumers.functors.PermanentConsumerPredicate;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
/**
* DatabaseConsumers
*
* @version $Id$
- *
- * @plexus.component role="org.apache.maven.archiva.database.updater.DatabaseConsumers"
*/
public class DatabaseConsumers
- implements Initializable
-{
- /**
- * @plexus.requirement
- */
+ implements ApplicationContextAware
+{
private ArchivaConfiguration archivaConfiguration;
- /**
- * @plexus.requirement role="org.apache.maven.archiva.database.updater.DatabaseUnprocessedArtifactConsumer"
- */
- private List availableUnprocessedConsumers;
-
- /**
- * @plexus.requirement role="org.apache.maven.archiva.database.updater.DatabaseCleanupConsumer"
- */
- private List availableCleanupConsumers;
-
private Predicate selectedCleanupConsumers;
private Predicate selectedUnprocessedConsumers;
+
+ private ApplicationContext applicationContext;
+
+ public DatabaseConsumers( ArchivaConfiguration archivaConfiguration )
+ {
+ this.archivaConfiguration = archivaConfiguration;
+
+ Predicate permanentConsumers = new PermanentConsumerPredicate();
+ selectedCleanupConsumers = new OrPredicate( permanentConsumers, new SelectedCleanupConsumersPredicate() );
+ selectedUnprocessedConsumers = new OrPredicate( permanentConsumers, new SelectedUnprocessedConsumersPredicate() );
+ }
+
class SelectedUnprocessedConsumersPredicate
implements Predicate
{
@@ -99,15 +96,12 @@ public class DatabaseConsumers
}
}
- public void initialize()
- throws InitializationException
+ public void setApplicationContext( ApplicationContext applicationContext )
+ throws BeansException
{
- Predicate permanentConsumers = new PermanentConsumerPredicate();
-
- selectedCleanupConsumers = new OrPredicate( permanentConsumers, new SelectedCleanupConsumersPredicate() );
- selectedUnprocessedConsumers = new OrPredicate( permanentConsumers, new SelectedUnprocessedConsumersPredicate() );
+ this.applicationContext = applicationContext;
}
-
+
/**
* Get the {@link List} of {@link DatabaseUnprocessedArtifactConsumer} objects
* for those consumers selected due to the configuration.
@@ -117,7 +111,7 @@ public class DatabaseConsumers
public List getSelectedUnprocessedConsumers()
{
List ret = new ArrayList();
- ret.addAll( CollectionUtils.select( availableUnprocessedConsumers, selectedUnprocessedConsumers ) );
+ ret.addAll( CollectionUtils.select( getAvailableUnprocessedConsumers(), selectedUnprocessedConsumers ) );
return ret;
}
@@ -130,7 +124,7 @@ public class DatabaseConsumers
public List getSelectedCleanupConsumers()
{
List ret = new ArrayList();
- ret.addAll( CollectionUtils.select( availableCleanupConsumers, selectedCleanupConsumers ) );
+ ret.addAll( CollectionUtils.select( getAvailableCleanupConsumers(), selectedCleanupConsumers ) );
return ret;
}
@@ -141,8 +135,8 @@ public class DatabaseConsumers
* @return the list of all available {@link DatabaseUnprocessedArtifactConsumer} objects.
*/
public List getAvailableUnprocessedConsumers()
- {
- return Collections.unmodifiableList( this.availableUnprocessedConsumers );
+ {
+ return new ArrayList( applicationContext.getBeansOfType( DatabaseUnprocessedArtifactConsumer.class ).values() );
}
/**
@@ -153,6 +147,6 @@ public class DatabaseConsumers
*/
public List getAvailableCleanupConsumers()
{
- return Collections.unmodifiableList( this.availableCleanupConsumers );
+ return new ArrayList( applicationContext.getBeansOfType( DatabaseCleanupConsumer.class ).values() );
}
}
diff --git a/archiva-modules/archiva-database/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-database/src/main/resources/META-INF/spring-context.xml
new file mode 100644
index 000000000..53b798ec8
--- /dev/null
+++ b/archiva-modules/archiva-database/src/main/resources/META-INF/spring-context.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+
+ <bean id="databaseConsumers" class="org.apache.maven.archiva.database.updater.DatabaseConsumers" scope="prototype">
+ <constructor-arg>
+ <ref bean="archivaConfiguration"/>
+ </constructor-arg>
+ </bean>
+</beans> \ No newline at end of file