aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2012-01-16 22:57:03 +0000
committerOlivier Lamy <olamy@apache.org>2012-01-16 22:57:03 +0000
commitb15679f6a9e92581c44b8b54dbad582894da11d3 (patch)
tree287b3b62cd06017838954af7f8885ff00d720403 /archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers
parent9cc9c4d3d6fe58ae8879a322b81b044b06c29447 (diff)
downloadarchiva-b15679f6a9e92581c44b8b54dbad582894da11d3.tar.gz
archiva-b15679f6a9e92581c44b8b54dbad582894da11d3.zip
prevent NPE on initial scan at repository creation
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1232213 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers')
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java42
1 files changed, 37 insertions, 5 deletions
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 070e7b11c..9cbff9bd1 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
@@ -72,7 +72,7 @@ public class NexusIndexerConsumer
private ArchivaTaskScheduler<ArtifactIndexingTask> scheduler;
- private IndexingContext context;
+ private IndexingContext indexingContext;
private NexusIndexer nexusIndexer;
@@ -124,7 +124,7 @@ public class NexusIndexerConsumer
try
{
log.info( "Creating indexing context for repo : {}", repository.getId() );
- context = managedRepositoryAdmin.createIndexContext( repository );
+ indexingContext = managedRepositoryAdmin.createIndexContext( repository );
}
catch ( RepositoryAdminException e )
{
@@ -152,7 +152,7 @@ public class NexusIndexerConsumer
File artifactFile = new File( managedRepository, path );
ArtifactIndexingTask task =
- new ArtifactIndexingTask( repository, artifactFile, ArtifactIndexingTask.Action.ADD, context );
+ new ArtifactIndexingTask( repository, artifactFile, ArtifactIndexingTask.Action.ADD, getIndexingContext() );
try
{
log.debug( "Queueing indexing task '{}' to add or update the artifact in the index.", task );
@@ -177,7 +177,8 @@ public class NexusIndexerConsumer
// specify in indexing task that this is not a repo scan request!
ArtifactIndexingTask task =
- new ArtifactIndexingTask( repository, artifactFile, ArtifactIndexingTask.Action.ADD, context, false );
+ new ArtifactIndexingTask( repository, artifactFile, ArtifactIndexingTask.Action.ADD,
+ getIndexingContext(), false );
// only update index we don't need to scan the full repo here
task.setOnlyUpdate( true );
try
@@ -194,6 +195,19 @@ public class NexusIndexerConsumer
public void completeScan()
{
+ IndexingContext context = this.indexingContext;
+ if ( context == null )
+ {
+ try
+ {
+ context = getIndexingContext();
+ }
+ catch ( ConsumerException e )
+ {
+ log.warn( "failed to get an IndexingContext:{}", e.getMessage() );
+ return;
+ }
+ }
ArtifactIndexingTask task =
new ArtifactIndexingTask( repository, null, ArtifactIndexingTask.Action.FINISH, context );
try
@@ -205,7 +219,6 @@ public class NexusIndexerConsumer
{
log.error( "Error queueing task: " + task + ": " + e.getMessage(), e );
}
- context = null;
}
public void completeScan( boolean executeOnEntireRepo )
@@ -260,4 +273,23 @@ public class NexusIndexerConsumer
{
return includes;
}
+
+
+ private IndexingContext getIndexingContext()
+ throws ConsumerException
+ {
+
+ if ( this.indexingContext == null )
+ {
+ try
+ {
+ indexingContext = managedRepositoryAdmin.createIndexContext( repository );
+ }
+ catch ( RepositoryAdminException e )
+ {
+ throw new ConsumerException( e.getMessage(), e );
+ }
+ }
+ return indexingContext;
+ }
}