only pass tru NexusIndexer to create IndexingContext, this entry point take care of lucene locks : still some changes to do in junit to prevent lock

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1140035 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-06-27 07:45:16 +00:00
parent e9e681546a
commit 23d74d0956
6 changed files with 67 additions and 17 deletions

View File

@ -26,6 +26,8 @@ import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
import org.apache.archiva.scheduler.ArchivaTaskScheduler; import org.apache.archiva.scheduler.ArchivaTaskScheduler;
import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask; import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask;
import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ArchivaConfiguration;
@ -35,6 +37,7 @@ import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
import org.apache.maven.archiva.consumers.ConsumerException; import org.apache.maven.archiva.consumers.ConsumerException;
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.maven.index.NexusIndexer;
import org.apache.maven.index.context.IndexingContext; import org.apache.maven.index.context.IndexingContext;
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
@ -64,16 +67,20 @@ public class NexusIndexerConsumer
private IndexingContext context; private IndexingContext context;
private NexusIndexer nexusIndexer;
private List<String> includes = new ArrayList<String>(); private List<String> includes = new ArrayList<String>();
private ManagedRepositoryConfiguration repository; private ManagedRepositoryConfiguration repository;
public NexusIndexerConsumer( ArchivaTaskScheduler<ArtifactIndexingTask> scheduler, public NexusIndexerConsumer( ArchivaTaskScheduler<ArtifactIndexingTask> scheduler,
ArchivaConfiguration configuration, FileTypes filetypes ) ArchivaConfiguration configuration, FileTypes filetypes, PlexusSisuBridge plexusSisuBridge )
throws PlexusSisuBridgeException
{ {
this.configuration = configuration; this.configuration = configuration;
this.filetypes = filetypes; this.filetypes = filetypes;
this.scheduler = scheduler; this.scheduler = scheduler;
this.nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );
} }
public String getDescription() public String getDescription()
@ -100,7 +107,7 @@ public class NexusIndexerConsumer
try try
{ {
log.info( "Creating indexing context for repo : " + repository.getId() ); log.info( "Creating indexing context for repo : " + repository.getId() );
context = ArtifactIndexingTask.createContext( repository ); context = ArtifactIndexingTask.createContext( repository, nexusIndexer );
} }
catch ( IOException e ) catch ( IOException e )
{ {

View File

@ -28,9 +28,10 @@
default-lazy-init="true"> default-lazy-init="true">
<bean id="indexerConsumer" class="org.apache.archiva.consumers.lucene.NexusIndexerConsumer" lazy-init="true"> <bean id="indexerConsumer" class="org.apache.archiva.consumers.lucene.NexusIndexerConsumer" lazy-init="true">
<constructor-arg ref="archivaTaskScheduler#indexing"/> <constructor-arg ref="archivaTaskScheduler#indexing"/>
<constructor-arg ref="archivaConfiguration"/> <constructor-arg ref="archivaConfiguration"/>
<constructor-arg ref="fileTypes"/> <constructor-arg ref="fileTypes"/>
<constructor-arg ref="plexusSisuBridge"/>
</bean> </bean>
<bean id="logger" class="org.apache.maven.archiva.common.utils.Slf4JPlexusLogger"> <bean id="logger" class="org.apache.maven.archiva.common.utils.Slf4JPlexusLogger">

View File

@ -28,6 +28,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.archiva.scheduler.ArchivaTaskScheduler; import org.apache.archiva.scheduler.ArchivaTaskScheduler;
import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask; import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
@ -35,6 +36,7 @@ import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.FileTypes; import org.apache.maven.archiva.configuration.FileTypes;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.maven.index.NexusIndexer;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.taskqueue.TaskQueueException; import org.codehaus.plexus.taskqueue.TaskQueueException;
import org.junit.After; import org.junit.After;
@ -94,6 +96,9 @@ public class NexusIndexerConsumerTest
@Inject @Inject
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@Inject
private PlexusSisuBridge plexusSisuBridge;
@Override @Override
@Before @Before
@ -108,7 +113,7 @@ public class NexusIndexerConsumerTest
FileTypes filetypes = applicationContext.getBean( FileTypes.class ); FileTypes filetypes = applicationContext.getBean( FileTypes.class );
nexusIndexerConsumer = new NexusIndexerConsumer( scheduler, configuration, filetypes ); nexusIndexerConsumer = new NexusIndexerConsumer( scheduler, configuration, filetypes, plexusSisuBridge );
// initialize to set the file types to be processed // initialize to set the file types to be processed
( (Initializable) nexusIndexerConsumer ).initialize(); ( (Initializable) nexusIndexerConsumer ).initialize();

View File

@ -31,6 +31,7 @@ import org.apache.maven.index.ArtifactContextProducer;
import org.apache.maven.index.ArtifactInfo; import org.apache.maven.index.ArtifactInfo;
import org.apache.maven.index.DefaultArtifactContextProducer; import org.apache.maven.index.DefaultArtifactContextProducer;
import org.apache.maven.index.IndexerEngine; import org.apache.maven.index.IndexerEngine;
import org.apache.maven.index.NexusIndexer;
import org.apache.maven.index.artifact.IllegalArtifactCoordinateException; import org.apache.maven.index.artifact.IllegalArtifactCoordinateException;
import org.apache.maven.index.context.IndexingContext; import org.apache.maven.index.context.IndexingContext;
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
@ -77,6 +78,8 @@ public class ArchivaIndexingTaskExecutor
@Inject @Inject
private PlexusSisuBridge plexusSisuBridge; private PlexusSisuBridge plexusSisuBridge;
private NexusIndexer nexusIndexer;
@PostConstruct @PostConstruct
public void initialize() public void initialize()
throws PlexusSisuBridgeException throws PlexusSisuBridgeException
@ -115,7 +118,7 @@ public class ArchivaIndexingTaskExecutor
{ {
log.debug( log.debug(
"Creating indexing context on resource: {}", indexingTask.getResourceFile().getPath() ); "Creating indexing context on resource: {}", indexingTask.getResourceFile().getPath() );
context = ArtifactIndexingTask.createContext( repository ); context = ArtifactIndexingTask.createContext( repository, nexusIndexer );
} }
catch ( IOException e ) catch ( IOException e )
{ {

View File

@ -19,22 +19,25 @@ package org.apache.archiva.scheduler.indexing;
* under the License. * under the License.
*/ */
import java.io.File;
import java.io.IOException;
import org.apache.maven.archiva.common.utils.ArchivaNexusIndexerUtil; import org.apache.maven.archiva.common.utils.ArchivaNexusIndexerUtil;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.index.context.DefaultIndexingContext; import org.apache.maven.index.NexusIndexer;
import org.apache.maven.index.context.IndexingContext; import org.apache.maven.index.context.IndexingContext;
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
import org.codehaus.plexus.taskqueue.Task; import org.codehaus.plexus.taskqueue.Task;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
public class ArtifactIndexingTask public class ArtifactIndexingTask
implements Task implements Task
{ {
public enum Action public enum Action
{ {
ADD, DELETE, FINISH ADD,
DELETE,
FINISH
} }
private final ManagedRepositoryConfiguration repository; private final ManagedRepositoryConfiguration repository;
@ -120,27 +123,41 @@ public class ArtifactIndexingTask
public boolean equals( Object obj ) public boolean equals( Object obj )
{ {
if ( this == obj ) if ( this == obj )
{
return true; return true;
}
if ( obj == null ) if ( obj == null )
{
return false; return false;
}
if ( getClass() != obj.getClass() ) if ( getClass() != obj.getClass() )
{
return false; return false;
}
ArtifactIndexingTask other = (ArtifactIndexingTask) obj; ArtifactIndexingTask other = (ArtifactIndexingTask) obj;
if ( !action.equals( other.action ) ) if ( !action.equals( other.action ) )
{
return false; return false;
}
if ( !repository.getId().equals( other.repository.getId() ) ) if ( !repository.getId().equals( other.repository.getId() ) )
{
return false; return false;
}
if ( resourceFile == null ) if ( resourceFile == null )
{ {
if ( other.resourceFile != null ) if ( other.resourceFile != null )
{
return false; return false;
}
} }
else if ( !resourceFile.equals( other.resourceFile ) ) else if ( !resourceFile.equals( other.resourceFile ) )
{
return false; return false;
}
return true; return true;
} }
public static IndexingContext createContext( ManagedRepositoryConfiguration repository ) public static IndexingContext createContext( ManagedRepositoryConfiguration repository, NexusIndexer indexer )
throws IOException, UnsupportedExistingLuceneIndexException throws IOException, UnsupportedExistingLuceneIndexException
{ {
String indexDir = repository.getIndexDir(); String indexDir = repository.getIndexDir();
@ -156,9 +173,20 @@ public class ArtifactIndexingTask
indexDirectory = new File( managedRepository, ".indexer" ); indexDirectory = new File( managedRepository, ".indexer" );
} }
if ( indexer.getIndexingContexts().containsKey( repository.getId() ) )
{
LoggerFactory.getLogger( ArtifactIndexingTask.class ).warn(
"skip adding repository with id {} as already exists", repository.getId() );
}
IndexingContext context = IndexingContext context =
new DefaultIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory, indexer.addIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory,
null, null, ArchivaNexusIndexerUtil.FULL_INDEX, false ); 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() ); context.setSearchable( repository.isScanned() );
return context; return context;
} }

View File

@ -81,6 +81,8 @@ public class ArchivaIndexingTaskExecutorTest
private IndexingContext context; private IndexingContext context;
private NexusIndexer nexusIndexer;
@Inject @Inject
PlexusSisuBridge plexusSisuBridge; PlexusSisuBridge plexusSisuBridge;
@ -113,7 +115,11 @@ public class ArchivaIndexingTaskExecutorTest
indexingExecutor.setIndexerEngine( indexerEngine ); indexingExecutor.setIndexerEngine( indexerEngine );
indexingExecutor.setIndexPacker( indexPacker ); indexingExecutor.setIndexPacker( indexPacker );
context = ArtifactIndexingTask.createContext( repositoryConfig ); nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );
context = ArtifactIndexingTask.createContext( repositoryConfig, nexusIndexer );
} }
@After @After
@ -245,7 +251,7 @@ public class ArchivaIndexingTaskExecutorTest
searcher.close(); searcher.close();
context = ArtifactIndexingTask.createContext( repositoryConfig ); context = ArtifactIndexingTask.createContext( repositoryConfig, nexusIndexer );
// remove added artifact from index // remove added artifact from index
task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.DELETE, context ); task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.DELETE, context );