diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/pom.xml b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/pom.xml
index 647efa5db..006f23c67 100644
--- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/pom.xml
+++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/pom.xml
@@ -22,6 +22,10 @@
org.apache.maven.indexer
indexer-core
+
+ com.google.guava
+ guava
+
javax.inject
javax.inject
@@ -39,5 +43,6 @@
slf4j-simple
test
+
diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java
index 978472c22..f0643df8b 100644
--- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java
+++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java
@@ -21,20 +21,20 @@ package org.apache.archiva.scheduler.indexing;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.index.ArtifactContext;
import org.apache.maven.index.ArtifactContextProducer;
-import org.apache.maven.index.ArtifactInfo;
import org.apache.maven.index.DefaultArtifactContextProducer;
-import org.apache.maven.index.IndexerEngine;
+import org.apache.maven.index.FlatSearchRequest;
+import org.apache.maven.index.FlatSearchResponse;
+import org.apache.maven.index.MAVEN;
import org.apache.maven.index.NexusIndexer;
import org.apache.maven.index.artifact.IllegalArtifactCoordinateException;
import org.apache.maven.index.context.IndexingContext;
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
+import org.apache.maven.index.expr.SourcedSearchExpression;
import org.apache.maven.index.packer.IndexPacker;
import org.apache.maven.index.packer.IndexPackingRequest;
import org.codehaus.plexus.taskqueue.Task;
@@ -63,11 +63,6 @@ public class ArchivaIndexingTaskExecutor
{
private Logger log = LoggerFactory.getLogger( ArchivaIndexingTaskExecutor.class );
- /**
- * plexus.requirement
- */
- private IndexerEngine indexerEngine;
-
/**
* plexus.requirement
*/
@@ -88,15 +83,15 @@ public class ArchivaIndexingTaskExecutor
artifactContextProducer = new DefaultArtifactContextProducer();
- indexerEngine = plexusSisuBridge.lookup( IndexerEngine.class, "default" );
-
indexPacker = plexusSisuBridge.lookup( IndexPacker.class, "default" );
+
+ nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );
}
public void executeTask( Task task )
throws TaskExecutionException
{
- synchronized ( indexerEngine )
+ synchronized ( nexusIndexer )
{
ArtifactIndexingTask indexingTask = (ArtifactIndexingTask) task;
@@ -116,8 +111,8 @@ public class ArchivaIndexingTaskExecutor
{
try
{
- log.debug(
- "Creating indexing context on resource: {}", indexingTask.getResourceFile().getPath() );
+ log.debug( "Creating indexing context on resource: {}",
+ indexingTask.getResourceFile().getPath() );
context = ArtifactIndexingTask.createContext( repository, nexusIndexer );
}
catch ( IOException e )
@@ -146,35 +141,61 @@ public class ArchivaIndexingTaskExecutor
{
if ( indexingTask.getAction().equals( ArtifactIndexingTask.Action.ADD ) )
{
- IndexSearcher s = context.getIndexSearcher();
- String uinfo = ac.getArtifactInfo().getUinfo();
- TopDocs d = s.search( new TermQuery( new Term( ArtifactInfo.UINFO, uinfo ) ), 1 );
- if ( d.totalHits == 0 )
+ //IndexSearcher s = context.getIndexSearcher();
+ //String uinfo = ac.getArtifactInfo().getUinfo();
+ //TopDocs d = s.search( new TermQuery( new Term( ArtifactInfo.UINFO, uinfo ) ), 1 );
+
+ BooleanQuery q = new BooleanQuery();
+ q.add( nexusIndexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression(
+ ac.getArtifactInfo().groupId ) ), BooleanClause.Occur.MUST );
+ q.add( nexusIndexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression(
+ ac.getArtifactInfo().artifactId ) ), BooleanClause.Occur.MUST );
+ q.add( nexusIndexer.constructQuery( MAVEN.VERSION, new SourcedSearchExpression(
+ ac.getArtifactInfo().version ) ), BooleanClause.Occur.MUST );
+ if (ac.getArtifactInfo().classifier != null)
+ {
+ q.add( nexusIndexer.constructQuery( MAVEN.CLASSIFIER, new SourcedSearchExpression(
+ ac.getArtifactInfo().classifier ) ), BooleanClause.Occur.MUST );
+ }
+ if (ac.getArtifactInfo().packaging != null)
+ {
+ q.add( nexusIndexer.constructQuery( MAVEN.PACKAGING, new SourcedSearchExpression(
+ ac.getArtifactInfo().packaging ) ), BooleanClause.Occur.MUST );
+ }
+ FlatSearchRequest flatSearchRequest = new FlatSearchRequest( q, context );
+ FlatSearchResponse flatSearchResponse = nexusIndexer.searchFlat( flatSearchRequest );
+ if ( flatSearchResponse.getResults().isEmpty() )
+ //if ( d.totalHits == 0 )
{
log.debug( "Adding artifact '{}' to index..", ac.getArtifactInfo() );
- indexerEngine.index( context, ac );
- context.getIndexWriter().commit();
+ //indexerEngine.index( context, ac );
+ //context.getIndexWriter().commit();
+ nexusIndexer.addArtifactToIndex( ac, context );
}
else
{
log.debug( "Updating artifact '{}' in index..", ac.getArtifactInfo() );
- indexerEngine.update( context, ac );
- context.getIndexWriter().commit();
+ // TODO check if update exists !!
+ nexusIndexer.deleteArtifactFromIndex( ac, context );
+ nexusIndexer.addArtifactToIndex( ac, context );
}
+ //nexusIndexer.scan( context, true );
+
+ context.updateTimestamp();
+
// close the context if not a repo scan request
if ( !indexingTask.isExecuteOnEntireRepo() )
{
log.debug( "Finishing indexing task on resource file : {}",
- indexingTask.getResourceFile().getPath() );
+ indexingTask.getResourceFile().getPath() );
finishIndexingTask( indexingTask, repository, context );
}
}
else
{
log.debug( "Removing artifact '{}' from index..", ac.getArtifactInfo() );
- indexerEngine.remove( context, ac );
- context.getIndexWriter().commit();
+ nexusIndexer.deleteArtifactFromIndex( ac, context );
}
}
}
@@ -217,6 +238,8 @@ public class ArchivaIndexingTaskExecutor
}
finally
{
+ /*
+ olamy don't close it anymore as it nullify IndexSearcher
if ( context != null )
{
try
@@ -229,16 +252,10 @@ public class ArchivaIndexingTaskExecutor
throw new TaskExecutionException( "Error occurred while closing context: " + e.getMessage() );
}
}
+ */
}
}
-
-
- public void setIndexerEngine( IndexerEngine indexerEngine )
- {
- this.indexerEngine = indexerEngine;
- }
-
public void setIndexPacker( IndexPacker indexPacker )
{
this.indexPacker = indexPacker;
diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArtifactIndexingTask.java b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArtifactIndexingTask.java
index 4b2276509..15a07752e 100644
--- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArtifactIndexingTask.java
+++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArtifactIndexingTask.java
@@ -184,9 +184,6 @@ public class ArtifactIndexingTask
managedRepository.toURI().toURL().toString(),
indexDirectory.toURI().toURL().toString(), ArchivaNexusIndexerUtil.FULL_INDEX );
- //IndexingContext context =
- // new DefaultIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory,
- // null, null, ArchivaNexusIndexerUtil.FULL_INDEX, false );
context.setSearchable( repository.isScanned() );
return context;
}
diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/resources/META-INF/plexus/components.xml b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/resources/META-INF/plexus/components.xml
deleted file mode 100644
index 68e97ab8d..000000000
--- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/resources/META-INF/plexus/components.xml
+++ /dev/null
@@ -1,63 +0,0 @@
-
-
-
-
-
-
-
- org.codehaus.plexus.taskqueue.TaskQueue
- indexing
- org.codehaus.plexus.taskqueue.DefaultTaskQueue
- plexus-configurable
-
-
-
-
-
-
-
-
-
-
-
- org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor
- indexing
- org.codehaus.plexus.taskqueue.execution.ThreadedTaskQueueExecutor
- singleton
-
-
- org.codehaus.plexus.taskqueue.execution.TaskExecutor
- indexing
-
-
- org.codehaus.plexus.taskqueue.TaskQueue
- indexing
-
-
-
- indexing
-
-
-
-
diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java
index 9a2831169..3aa625a29 100644
--- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java
+++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java
@@ -32,12 +32,11 @@ import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.index.ArtifactInfo;
import org.apache.maven.index.FlatSearchRequest;
import org.apache.maven.index.FlatSearchResponse;
-import org.apache.maven.index.IndexerEngine;
import org.apache.maven.index.MAVEN;
import org.apache.maven.index.NexusIndexer;
import org.apache.maven.index.context.IndexingContext;
+import org.apache.maven.index.expr.SourcedSearchExpression;
import org.apache.maven.index.expr.StringSearchExpression;
-import org.apache.maven.index.packer.IndexPacker;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -68,18 +67,12 @@ public class ArchivaIndexingTaskExecutorTest
@Inject
private ArchivaIndexingTaskExecutor indexingExecutor;
- private IndexerEngine indexerEngine;
-
- private IndexPacker indexPacker;
-
private ManagedRepositoryConfiguration repositoryConfig;
private Configuration configuration;
private NexusIndexer indexer;
- private IndexingContext context;
-
@Inject
PlexusSisuBridge plexusSisuBridge;
@@ -89,10 +82,6 @@ public class ArchivaIndexingTaskExecutorTest
{
super.setUp();
- //indexingExecutor = new ArchivaIndexingTaskExecutor();
- //indexingExecutor.setPlexusSisuBridge( plexusSisuBridge );
- indexingExecutor.initialize();
-
repositoryConfig = new ManagedRepositoryConfiguration();
repositoryConfig.setId( "test-repo" );
repositoryConfig.setLocation( "target/test-classes/test-repo" );
@@ -106,25 +95,16 @@ public class ArchivaIndexingTaskExecutorTest
configuration.addManagedRepository( repositoryConfig );
indexer = plexusSisuBridge.lookup( NexusIndexer.class );
- indexerEngine = plexusSisuBridge.lookup( IndexerEngine.class );
- indexPacker = plexusSisuBridge.lookup( IndexPacker.class );
-
- indexingExecutor.setIndexerEngine( indexerEngine );
- indexingExecutor.setIndexPacker( indexPacker );
-
- context = ArtifactIndexingTask.createContext( repositoryConfig, indexer );
-
+ ArtifactIndexingTask.createContext( repositoryConfig, indexer );
}
@After
public void tearDown()
throws Exception
{
- //context.close( true );
- //indexer.removeIndexingContext( context, true );
- for (IndexingContext indexingContext : indexer.getIndexingContexts().values())
+ for ( IndexingContext indexingContext : indexer.getIndexingContexts().values() )
{
indexer.removeIndexingContext( indexingContext, true );
}
@@ -141,6 +121,11 @@ public class ArchivaIndexingTaskExecutorTest
super.tearDown();
}
+ protected IndexingContext getIndexingContext()
+ {
+ return indexer.getIndexingContexts().get( repositoryConfig.getId() );
+ }
+
@Test
public void testAddArtifactToIndex()
throws Exception
@@ -149,7 +134,8 @@ public class ArchivaIndexingTaskExecutorTest
"org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
ArtifactIndexingTask task =
- new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD, context );
+ new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
+ getIndexingContext() );
indexingExecutor.executeTask( task );
@@ -160,16 +146,16 @@ public class ArchivaIndexingTaskExecutorTest
indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ),
Occur.SHOULD );
- if (!indexer.getIndexingContexts().containsKey( repositoryConfig.getId() ))
+ if ( !indexer.getIndexingContexts().containsKey( repositoryConfig.getId() ) )
{
IndexingContext context = indexer.addIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(),
- new File( repositoryConfig.getLocation() ),
- new File( repositoryConfig.getLocation(), ".indexer" ),
- null, null, ArchivaNexusIndexerUtil.FULL_INDEX );
+ new File( repositoryConfig.getLocation() ),
+ new File( repositoryConfig.getLocation(),
+ ".indexer" ), null, null,
+ ArchivaNexusIndexerUtil.FULL_INDEX );
context.setSearchable( true );
}
-
FlatSearchRequest request = new FlatSearchRequest( q );
FlatSearchResponse response = indexer.searchFlat( request );
@@ -194,7 +180,8 @@ public class ArchivaIndexingTaskExecutorTest
"org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
ArtifactIndexingTask task =
- new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD, context );
+ new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
+ getIndexingContext() );
indexingExecutor.executeTask( task );
indexingExecutor.executeTask( task );
@@ -226,60 +213,55 @@ public class ArchivaIndexingTaskExecutorTest
"org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
ArtifactIndexingTask task =
- new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD, context );
+ new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
+ getIndexingContext() );
- // remove artifact from index
+ // add artifact to index
indexingExecutor.executeTask( task );
BooleanQuery q = new BooleanQuery();
- q.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "org.apache.archiva" ) ),
+ q.add( indexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( "org.apache.archiva" ) ),
Occur.SHOULD );
- q.add(
- indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ),
- Occur.SHOULD );
+ //q.add(
+ // indexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression( "archiva-index-methods-jar-test" ) ),
+ // Occur.SHOULD );
- IndexSearcher searcher = indexer.getIndexingContexts().get( repositoryConfig.getId() ).getIndexSearcher();
+ FlatSearchRequest flatSearchRequest =
+ new FlatSearchRequest( q, indexer.getIndexingContexts().get( repositoryConfig.getId() ) );
- TopDocs topDocs = searcher.search( q, null, 10 );
-
- searcher.close();
+ FlatSearchResponse response = indexer.searchFlat( flatSearchRequest );
assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
assertFalse( new File( repositoryConfig.getLocation(), ".index" ).exists() );
// should return 1 hit
- assertEquals( 1, topDocs.totalHits );
-
- searcher.close();
-
- context = ArtifactIndexingTask.createContext( repositoryConfig, indexer );
+ assertEquals( 1, response.getTotalHitsCount() );
// remove added artifact from index
- task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.DELETE, context );
+ task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.DELETE,
+ getIndexingContext() );
indexingExecutor.executeTask( task );
- task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.FINISH, context );
+ task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.FINISH,
+ getIndexingContext() );
indexingExecutor.executeTask( task );
q = new BooleanQuery();
- q.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "org.apache.archiva" ) ),
+ q.add( indexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( "org.apache.archiva" ) ),
+ Occur.SHOULD );
+ q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID,
+ new SourcedSearchExpression( "archiva-index-methods-jar-test" ) ),
Occur.SHOULD );
- q.add(
- indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ),
- Occur.SHOULD );
-
- searcher = indexer.getIndexingContexts().get( repositoryConfig.getId() ).getIndexSearcher();
-
- topDocs = searcher.search( q, null, 10 );
assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
assertTrue( new File( repositoryConfig.getLocation(), ".index" ).exists() );
- // artifact should have been removed from the index!
- assertEquals( 0, topDocs.totalHits );
+ flatSearchRequest = new FlatSearchRequest( q, getIndexingContext() );
+
+ response = indexer.searchFlat( flatSearchRequest );
+ // artifact should have been removed from the index!
+ assertEquals( 0, response.getTotalHitsCount() );//.totalHits );
- context.close( true );
- searcher.close();
// TODO: test it was removed from the packaged index also
}
@@ -291,11 +273,13 @@ public class ArchivaIndexingTaskExecutorTest
"org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
ArtifactIndexingTask task =
- new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD, context );
+ new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.ADD,
+ getIndexingContext() );
indexingExecutor.executeTask( task );
- task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.FINISH, context );
+ task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.FINISH,
+ getIndexingContext() );
indexingExecutor.executeTask( task );