aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-scheduler
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2012-09-12 20:44:51 +0000
committerOlivier Lamy <olamy@apache.org>2012-09-12 20:44:51 +0000
commit7756665404a3adda555d2c81cfab42a6d72b0de5 (patch)
tree475ca76493b5e2efae749ef4b64cf8035d4478f3 /archiva-modules/archiva-scheduler
parenta9c1f188955ddd6eec4ee0568f89520812db8538 (diff)
downloadarchiva-7756665404a3adda555d2c81cfab42a6d72b0de5.tar.gz
archiva-7756665404a3adda555d2c81cfab42a6d72b0de5.zip
test last maven indexer version
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1384116 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-scheduler')
-rw-r--r--archiva-modules/archiva-scheduler/archiva-scheduler-indexing/pom.xml5
-rw-r--r--archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java38
-rw-r--r--archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java19
3 files changed, 38 insertions, 24 deletions
diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/pom.xml b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/pom.xml
index e3a4a4b7f..355529317 100644
--- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/pom.xml
+++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/pom.xml
@@ -136,6 +136,11 @@
</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>
<scope>provided</scope>
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 aef6436fe..89705e7e8 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
@@ -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 );
- }
}
}
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 6b2fe9c84..60c9e1a65 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
@@ -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;