test last maven indexer version

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1384116 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-09-12 20:44:51 +00:00
parent a9c1f18895
commit 7756665404
7 changed files with 60 additions and 44 deletions

View File

@ -41,7 +41,6 @@ import org.apache.maven.index.context.IndexCreator;
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.expr.StringSearchExpression;
import org.apache.maven.index.expr.UserInputSearchExpression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -61,7 +60,7 @@ import java.util.Set;
/**
* RepositorySearch implementation which uses the Nexus Indexer for searching.
*/
@Service( "nexusSearch" )
@Service ("nexusSearch")
public class NexusRepositorySearch
implements RepositorySearch
{
@ -160,9 +159,9 @@ public class NexusRepositorySearch
if ( StringUtils.isNotBlank( searchFields.getArtifactId() ) )
{
q.add(
indexer.constructQuery( MAVEN.ARTIFACT_ID, new UserInputSearchExpression( searchFields.getArtifactId() ) ),
Occur.MUST );
q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID,
new UserInputSearchExpression( searchFields.getArtifactId() ) ),
Occur.MUST );
}
if ( StringUtils.isNotBlank( searchFields.getVersion() ) )
@ -173,15 +172,15 @@ public class NexusRepositorySearch
if ( StringUtils.isNotBlank( searchFields.getPackaging() ) )
{
q.add( indexer.constructQuery( MAVEN.PACKAGING, new UserInputSearchExpression( searchFields.getPackaging() ) ),
Occur.MUST );
q.add(
indexer.constructQuery( MAVEN.PACKAGING, new UserInputSearchExpression( searchFields.getPackaging() ) ),
Occur.MUST );
}
if ( StringUtils.isNotBlank( searchFields.getClassName() ) )
{
q.add(
indexer.constructQuery( MAVEN.CLASSNAMES, new UserInputSearchExpression( searchFields.getClassName() ) ),
Occur.MUST );
q.add( indexer.constructQuery( MAVEN.CLASSNAMES,
new UserInputSearchExpression( searchFields.getClassName() ) ), Occur.MUST );
}
if ( StringUtils.isNotBlank( searchFields.getBundleSymbolicName() ) )
@ -193,9 +192,9 @@ public class NexusRepositorySearch
if ( StringUtils.isNotBlank( searchFields.getBundleVersion() ) )
{
q.add(
indexer.constructQuery( OSGI.VERSION, new UserInputSearchExpression( searchFields.getBundleVersion() ) ),
Occur.MUST );
q.add( indexer.constructQuery( OSGI.VERSION,
new UserInputSearchExpression( searchFields.getBundleVersion() ) ),
Occur.MUST );
}
if ( StringUtils.isNotBlank( searchFields.getBundleExportPackage() ) )
@ -241,9 +240,9 @@ public class NexusRepositorySearch
if ( StringUtils.isNotBlank( searchFields.getClassifier() ) )
{
q.add(
indexer.constructQuery( MAVEN.CLASSIFIER, new UserInputSearchExpression( searchFields.getClassifier() ) ),
Occur.MUST );
q.add( indexer.constructQuery( MAVEN.CLASSIFIER,
new UserInputSearchExpression( searchFields.getClassifier() ) ),
Occur.MUST );
}
if ( q.getClauses() == null || q.getClauses().length <= 0 )
@ -437,6 +436,7 @@ public class NexusRepositorySearch
throws RepositorySearchException
{
List<IndexingContext> indexContexts = getIndexingContexts( selectedRepos );
if ( indexContexts == null || indexContexts.isEmpty() )
{
return Collections.emptyList();
@ -455,8 +455,10 @@ public class NexusRepositorySearch
{
throw new RepositorySearchException( e.getMessage(), e );
}
}
protected List<? extends IndexCreator> getAllIndexCreators()
{
return mavenIndexerUtils.getAllIndexCreators();

View File

@ -211,7 +211,7 @@ public abstract class AbstractNexusRepositorySearch
}
// force flushing
context.getIndexWriter().commit();
context.getIndexWriter().close( true );
//context.getIndexWriter().close( true );
// wait for io flush ....
//Thread.sleep( 2000 );
context.setSearchable( true );

View File

@ -127,7 +127,7 @@ public class NexusRepositorySearchTest
archivaConfigControl.verify();
assertNotNull( results );
assertEquals( "total hints not 1", 1, results.getTotalHits() );
assertEquals( "total hints not 3", 3, results.getTotalHits() );
//TODO: search for class & package names
}
@ -194,7 +194,7 @@ public class NexusRepositorySearchTest
archivaConfigControl.verify();
assertNotNull( results );
assertEquals( 1, results.getTotalHits() );
assertEquals( 2, results.getTotalHits() );
SearchResultHit hit = results.getHits().get( 0 );
assertEquals( "org.apache.archiva", hit.getGroupId() );

View File

@ -135,6 +135,11 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>slf4j-impl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-lightweight</artifactId>

View File

@ -25,6 +25,9 @@ import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
import org.apache.archiva.redback.components.taskqueue.Task;
import org.apache.archiva.redback.components.taskqueue.execution.TaskExecutionException;
import org.apache.archiva.redback.components.taskqueue.execution.TaskExecutor;
import org.apache.commons.lang.StringUtils;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
@ -34,14 +37,10 @@ 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.expr.SourcedSearchExpression;
import org.apache.maven.index.packer.IndexPacker;
import org.apache.maven.index.packer.IndexPackingRequest;
import org.apache.archiva.redback.components.taskqueue.Task;
import org.apache.archiva.redback.components.taskqueue.execution.TaskExecutionException;
import org.apache.archiva.redback.components.taskqueue.execution.TaskExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@ -50,14 +49,13 @@ import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
/**
* ArchivaIndexingTaskExecutor Executes all indexing tasks. Adding, updating and removing artifacts from the index are
* all performed by this executor. Add and update artifact in index tasks are added in the indexing task queue by the
* NexusIndexerConsumer while remove artifact from index tasks are added by the LuceneCleanupRemoveIndexedConsumer.
*/
@Service( "taskExecutor#indexing" )
@Service ("taskExecutor#indexing")
public class ArchivaIndexingTaskExecutor
implements TaskExecutor
{
@ -92,6 +90,14 @@ public class ArchivaIndexingTaskExecutor
}
/**
* depending on current {@link Action} you have.
* If {@link org.apache.archiva.scheduler.indexing.ArtifactIndexingTask.Action.FINISH} && isExecuteOnEntireRepo:
* repository will be scanned.
*
* @param task
* @throws TaskExecutionException
*/
public void executeTask( Task task )
throws TaskExecutionException
{
@ -108,9 +114,8 @@ public class ArchivaIndexingTaskExecutor
long start = System.currentTimeMillis();
nexusIndexer.scan( context, null, indexingTask.isOnlyUpdate() );
long end = System.currentTimeMillis();
log.info( "indexed maven repository: {}, onlyUpdate: {}, time {} ms",
Arrays.asList( repository.getId(), indexingTask.isOnlyUpdate(), ( end - start ) ).toArray(
new Object[3] ) );
log.info( "indexed maven repository: {}, onlyUpdate: {}, time {} ms", repository.getId(),
indexingTask.isOnlyUpdate(), ( end - start ) );
}
catch ( IOException e )
{
@ -126,7 +131,9 @@ public class ArchivaIndexingTaskExecutor
{
try
{
log.debug( "Creating indexing context on resource: {}", indexingTask.getResourceFile().getPath() );
log.debug( "Creating indexing context on resource: {}", ( indexingTask.getResourceFile() == null
? "none"
: indexingTask.getResourceFile().getPath() ) );
context = managedRepositoryAdmin.createIndexContext( repository );
}
catch ( RepositoryAdminException e )
@ -144,6 +151,11 @@ public class ArchivaIndexingTaskExecutor
try
{
File artifactFile = indexingTask.getResourceFile();
if ( artifactFile == null )
{
log.debug( "no artifact pass in indexing task so skip it" );
return;
}
ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile );
if ( ac != null )
@ -187,6 +199,7 @@ public class ArchivaIndexingTaskExecutor
}
context.updateTimestamp();
context.commit();
// close the context if not a repo scan request
if ( !indexingTask.isExecuteOnEntireRepo() )
@ -210,11 +223,6 @@ public class ArchivaIndexingTaskExecutor
throw new TaskExecutionException( "Error occurred while executing indexing task '" + indexingTask + "'",
e );
}
catch ( IllegalArtifactCoordinateException e )
{
log.error( "Error occurred while getting artifact context: " + e.getMessage() );
throw new TaskExecutionException( "Error occurred while getting artifact context.", e );
}
}
}

View File

@ -24,7 +24,7 @@ import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.common.plexusbridge.MavenIndexerUtils;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.commons.io.FileUtils;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.IndexSearcher;
@ -48,19 +48,17 @@ import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
/**
* ArchivaIndexingTaskExecutorTest
*/
@RunWith( ArchivaSpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
@RunWith (ArchivaSpringJUnit4ClassRunner.class)
@ContextConfiguration (locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" })
public class ArchivaIndexingTaskExecutorTest
extends TestCase
{
@ -196,10 +194,13 @@ public class ArchivaIndexingTaskExecutorTest
indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ),
Occur.SHOULD );
IndexSearcher searcher = indexer.getIndexingContexts().get( repositoryConfig.getId() ).getIndexSearcher();
IndexingContext ctx = indexer.getIndexingContexts().get( repositoryConfig.getId() );
IndexSearcher searcher = ctx.acquireIndexSearcher();
TopDocs topDocs = searcher.search( q, null, 10 );
searcher.close();
//searcher.close();
ctx.releaseIndexSearcher( searcher );
assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
assertFalse( new File( repositoryConfig.getLocation(), ".index" ).exists() );
@ -282,7 +283,7 @@ public class ArchivaIndexingTaskExecutorTest
indexingExecutor.executeTask( task );
task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.FINISH,
task = new ArtifactIndexingTask( repositoryConfig, null, ArtifactIndexingTask.Action.FINISH,
getIndexingContext() );
task.setExecuteOnEntireRepo( false );
@ -316,7 +317,7 @@ public class ArchivaIndexingTaskExecutorTest
}
private void unzipIndex( String indexDir, String destDir )
throws FileNotFoundException, IOException
throws IOException
{
final int buff = 2048;

View File

@ -65,7 +65,7 @@
<aether.version>1.13.1</aether.version>
<maven-model-converter.version>2.1</maven-model-converter.version>
<maven.indexer.version>4.1.3</maven.indexer.version>
<maven.indexer.version>5.0.0-SNAPSHOT</maven.indexer.version>
<wagon.version>2.2</wagon.version>
<redback.version>2.0-SNAPSHOT</redback.version>
<redback.cache.version>2.0-SNAPSHOT</redback.cache.version>