mirror of https://github.com/apache/archiva.git
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:
parent
e9e681546a
commit
23d74d0956
|
@ -26,6 +26,8 @@ import java.util.Collections;
|
|||
import java.util.Date;
|
||||
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.indexing.ArtifactIndexingTask;
|
||||
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.ConsumerException;
|
||||
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.UnsupportedExistingLuceneIndexException;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
||||
|
@ -64,16 +67,20 @@ public class NexusIndexerConsumer
|
|||
|
||||
private IndexingContext context;
|
||||
|
||||
private NexusIndexer nexusIndexer;
|
||||
|
||||
private List<String> includes = new ArrayList<String>();
|
||||
|
||||
private ManagedRepositoryConfiguration repository;
|
||||
|
||||
public NexusIndexerConsumer( ArchivaTaskScheduler<ArtifactIndexingTask> scheduler,
|
||||
ArchivaConfiguration configuration, FileTypes filetypes )
|
||||
ArchivaConfiguration configuration, FileTypes filetypes, PlexusSisuBridge plexusSisuBridge )
|
||||
throws PlexusSisuBridgeException
|
||||
{
|
||||
this.configuration = configuration;
|
||||
this.filetypes = filetypes;
|
||||
this.scheduler = scheduler;
|
||||
this.nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
|
@ -100,7 +107,7 @@ public class NexusIndexerConsumer
|
|||
try
|
||||
{
|
||||
log.info( "Creating indexing context for repo : " + repository.getId() );
|
||||
context = ArtifactIndexingTask.createContext( repository );
|
||||
context = ArtifactIndexingTask.createContext( repository, nexusIndexer );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
|
|
|
@ -28,9 +28,10 @@
|
|||
default-lazy-init="true">
|
||||
|
||||
<bean id="indexerConsumer" class="org.apache.archiva.consumers.lucene.NexusIndexerConsumer" lazy-init="true">
|
||||
<constructor-arg ref="archivaTaskScheduler#indexing"/>
|
||||
<constructor-arg ref="archivaConfiguration"/>
|
||||
<constructor-arg ref="fileTypes"/>
|
||||
<constructor-arg ref="archivaTaskScheduler#indexing"/>
|
||||
<constructor-arg ref="archivaConfiguration"/>
|
||||
<constructor-arg ref="fileTypes"/>
|
||||
<constructor-arg ref="plexusSisuBridge"/>
|
||||
</bean>
|
||||
|
||||
<bean id="logger" class="org.apache.maven.archiva.common.utils.Slf4JPlexusLogger">
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
|
||||
import org.apache.archiva.scheduler.ArchivaTaskScheduler;
|
||||
import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask;
|
||||
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.ManagedRepositoryConfiguration;
|
||||
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.taskqueue.TaskQueueException;
|
||||
import org.junit.After;
|
||||
|
@ -94,6 +96,9 @@ public class NexusIndexerConsumerTest
|
|||
@Inject
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Inject
|
||||
private PlexusSisuBridge plexusSisuBridge;
|
||||
|
||||
|
||||
@Override
|
||||
@Before
|
||||
|
@ -108,7 +113,7 @@ public class NexusIndexerConsumerTest
|
|||
|
||||
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
|
||||
( (Initializable) nexusIndexerConsumer ).initialize();
|
||||
|
|
|
@ -31,6 +31,7 @@ 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.NexusIndexer;
|
||||
import org.apache.maven.index.artifact.IllegalArtifactCoordinateException;
|
||||
import org.apache.maven.index.context.IndexingContext;
|
||||
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
|
||||
|
@ -77,6 +78,8 @@ public class ArchivaIndexingTaskExecutor
|
|||
@Inject
|
||||
private PlexusSisuBridge plexusSisuBridge;
|
||||
|
||||
private NexusIndexer nexusIndexer;
|
||||
|
||||
@PostConstruct
|
||||
public void initialize()
|
||||
throws PlexusSisuBridgeException
|
||||
|
@ -115,7 +118,7 @@ public class ArchivaIndexingTaskExecutor
|
|||
{
|
||||
log.debug(
|
||||
"Creating indexing context on resource: {}", indexingTask.getResourceFile().getPath() );
|
||||
context = ArtifactIndexingTask.createContext( repository );
|
||||
context = ArtifactIndexingTask.createContext( repository, nexusIndexer );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
|
|
|
@ -19,22 +19,25 @@ package org.apache.archiva.scheduler.indexing;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.maven.archiva.common.utils.ArchivaNexusIndexerUtil;
|
||||
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.UnsupportedExistingLuceneIndexException;
|
||||
import org.codehaus.plexus.taskqueue.Task;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ArtifactIndexingTask
|
||||
implements Task
|
||||
{
|
||||
public enum Action
|
||||
{
|
||||
ADD, DELETE, FINISH
|
||||
ADD,
|
||||
DELETE,
|
||||
FINISH
|
||||
}
|
||||
|
||||
private final ManagedRepositoryConfiguration repository;
|
||||
|
@ -120,27 +123,41 @@ public class ArtifactIndexingTask
|
|||
public boolean equals( Object obj )
|
||||
{
|
||||
if ( this == obj )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if ( obj == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( getClass() != obj.getClass() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ArtifactIndexingTask other = (ArtifactIndexingTask) obj;
|
||||
if ( !action.equals( other.action ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( !repository.getId().equals( other.repository.getId() ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( resourceFile == null )
|
||||
{
|
||||
if ( other.resourceFile != null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if ( !resourceFile.equals( other.resourceFile ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static IndexingContext createContext( ManagedRepositoryConfiguration repository )
|
||||
public static IndexingContext createContext( ManagedRepositoryConfiguration repository, NexusIndexer indexer )
|
||||
throws IOException, UnsupportedExistingLuceneIndexException
|
||||
{
|
||||
String indexDir = repository.getIndexDir();
|
||||
|
@ -156,9 +173,20 @@ public class ArtifactIndexingTask
|
|||
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 =
|
||||
new DefaultIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory,
|
||||
null, null, ArchivaNexusIndexerUtil.FULL_INDEX, false );
|
||||
indexer.addIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory,
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -81,6 +81,8 @@ public class ArchivaIndexingTaskExecutorTest
|
|||
|
||||
private IndexingContext context;
|
||||
|
||||
private NexusIndexer nexusIndexer;
|
||||
|
||||
@Inject
|
||||
PlexusSisuBridge plexusSisuBridge;
|
||||
|
||||
|
@ -113,7 +115,11 @@ public class ArchivaIndexingTaskExecutorTest
|
|||
indexingExecutor.setIndexerEngine( indexerEngine );
|
||||
indexingExecutor.setIndexPacker( indexPacker );
|
||||
|
||||
context = ArtifactIndexingTask.createContext( repositoryConfig );
|
||||
nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );
|
||||
|
||||
context = ArtifactIndexingTask.createContext( repositoryConfig, nexusIndexer );
|
||||
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
|
@ -245,7 +251,7 @@ public class ArchivaIndexingTaskExecutorTest
|
|||
|
||||
searcher.close();
|
||||
|
||||
context = ArtifactIndexingTask.createContext( repositoryConfig );
|
||||
context = ArtifactIndexingTask.createContext( repositoryConfig, nexusIndexer );
|
||||
|
||||
// remove added artifact from index
|
||||
task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.DELETE, context );
|
||||
|
|
Loading…
Reference in New Issue