[MRM-1097] for deployments/proxied artifacts, create and close indexing context when indexing task is executed as compared to the original behavior where the indexing context is created before it is queued (so as the indexing task queue builds up, more indexing contexts are being opened/created which might be causing the too many open files problem)

Updated unit tests with changes made
Did not update the indexer as it would impact the API more significantly
Merged from: r1039004


git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-1.3.x@1041824 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2010-12-03 14:11:05 +00:00
parent 77f294d87f
commit cfd8ca2ffb
31 changed files with 481 additions and 54 deletions

View File

@ -43,6 +43,12 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
this.count = 0; this.count = 0;
} }
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
throws ConsumerException
{
beginScan( repository, whenGathered );
}
public void processFile( String path ) public void processFile( String path )
throws ConsumerException throws ConsumerException
{ {
@ -54,9 +60,20 @@ public void processFile( String path )
} }
public void processFile( String path, boolean executeOnEntireRepo )
throws ConsumerException
{
processFile( path );
}
public void completeScan() public void completeScan()
{ {
System.out.println( "Final Count of Artifacts processed by " + getId() + ": " + count ); System.out.println( "Final Count of Artifacts processed by " + getId() + ": " + count );
} }
public void completeScan( boolean executeOnEntireRepo )
{
completeScan();
}
} }

View File

@ -61,6 +61,22 @@ public interface RepositoryContentConsumer extends Consumer
*/ */
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered ) throws ConsumerException; public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered ) throws ConsumerException;
/**
* <p>
* Event that triggers at the beginning of a scan, where you can also indicate whether the consumers will be
* executed on an entire repository or on a specific resource.
* </p>
*
* @see RepositoryContentConsumer#beginScan(org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration, java.util.Date )
*
* @param repository the repository that this consumer is being used for.
* @param whenGathered the start of the repository scan
* @param executeOnEntireRepo flags whether the consumer will be executed on an entire repository or just on a specific resource
* @throws ConsumerException if there was a problem with using the provided repository with the consumer.
*/
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
throws ConsumerException;
/** /**
* <p> * <p>
* Event indicating a file is to be processed by this consumer. * Event indicating a file is to be processed by this consumer.
@ -77,6 +93,14 @@ public interface RepositoryContentConsumer extends Consumer
*/ */
public void processFile( String path ) throws ConsumerException; public void processFile( String path ) throws ConsumerException;
/**
*
* @param path
* @param executeOnEntireRepo
* @throws Exception
*/
public void processFile( String path, boolean executeOnEntireRepo ) throws Exception;
/** /**
* <p> * <p>
* Event that triggers on the completion of a scan. * Event that triggers on the completion of a scan.
@ -89,6 +113,13 @@ public interface RepositoryContentConsumer extends Consumer
*/ */
public void completeScan(); public void completeScan();
/**
*
* @param executeOnEntireRepo
* @throws Exception
*/
public void completeScan( boolean executeOnEntireRepo );
/** /**
* Whether the consumer should process files that have not been modified since the time passed in to the scan * Whether the consumer should process files that have not been modified since the time passed in to the scan
* method. * method.

View File

@ -99,11 +99,22 @@ public void beginScan( ManagedRepositoryConfiguration repo, Date whenGathered )
this.repositoryDir = new File( repo.getLocation() ); this.repositoryDir = new File( repo.getLocation() );
} }
public void beginScan( ManagedRepositoryConfiguration repo, Date whenGathered, boolean executeOnEntireRepo )
throws ConsumerException
{
beginScan( repo, whenGathered );
}
public void completeScan() public void completeScan()
{ {
/* do nothing */ /* do nothing */
} }
public void completeScan( boolean executeOnEntireRepo )
{
completeScan();
}
public List<String> getExcludes() public List<String> getExcludes()
{ {
return getDefaultArtifactExclusions(); return getDefaultArtifactExclusions();
@ -121,6 +132,12 @@ public void processFile( String path )
createFixChecksum( path, new ChecksumAlgorithm[] { ChecksumAlgorithm.MD5 } ); createFixChecksum( path, new ChecksumAlgorithm[] { ChecksumAlgorithm.MD5 } );
} }
public void processFile( String path, boolean executeOnEntireRepo )
throws ConsumerException
{
processFile( path );
}
private void createFixChecksum( String path, ChecksumAlgorithm checksumAlgorithm[] ) private void createFixChecksum( String path, ChecksumAlgorithm checksumAlgorithm[] )
{ {
File artifactFile = new File( this.repositoryDir, path ); File artifactFile = new File( this.repositoryDir, path );

View File

@ -95,11 +95,22 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
this.repositoryDir = new File( repository.getLocation() ); this.repositoryDir = new File( repository.getLocation() );
} }
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
throws ConsumerException
{
beginScan( repository, whenGathered );
}
public void completeScan() public void completeScan()
{ {
/* do nothing */ /* do nothing */
} }
public void completeScan( boolean executeOnEntireRepo )
{
completeScan();
}
public List<String> getExcludes() public List<String> getExcludes()
{ {
return null; return null;
@ -121,6 +132,12 @@ public void processFile( String path )
} }
} }
public void processFile( String path, boolean executeOnEntireRepo )
throws ConsumerException
{
processFile( path );
}
public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
{ {
if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) if ( ConfigurationNames.isRepositoryScanning( propertyName ) )

View File

@ -96,11 +96,22 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
this.repositoryDir = new File( repository.getLocation() ); this.repositoryDir = new File( repository.getLocation() );
} }
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
throws ConsumerException
{
beginScan( repository, whenGathered );
}
public void completeScan() public void completeScan()
{ {
/* do nothing */ /* do nothing */
} }
public void completeScan( boolean executeOnEntireRepo )
{
completeScan();
}
public List<String> getExcludes() public List<String> getExcludes()
{ {
return null; return null;
@ -143,4 +154,10 @@ public void processFile( String path )
file.delete(); file.delete();
} }
} }
public void processFile( String path, boolean executeOnEntireRepo )
throws ConsumerException
{
processFile( path );
}
} }

View File

@ -142,11 +142,22 @@ public void beginScan( ManagedRepositoryConfiguration repoConfig, Date whenGathe
} }
} }
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
throws ConsumerException
{
beginScan( repository, whenGathered );
}
public void completeScan() public void completeScan()
{ {
/* do nothing here */ /* do nothing here */
} }
public void completeScan( boolean executeOnEntireRepo )
{
completeScan();
}
public List<String> getExcludes() public List<String> getExcludes()
{ {
return getDefaultArtifactExclusions(); return getDefaultArtifactExclusions();
@ -176,6 +187,12 @@ public void processFile( String path )
} }
} }
public void processFile( String path, boolean executeOnEntireRepo )
throws Exception
{
processFile( path );
}
private void updateProjectMetadata( ArtifactReference artifact, String path ) private void updateProjectMetadata( ArtifactReference artifact, String path )
{ {
ProjectReference projectRef = new ProjectReference(); ProjectReference projectRef = new ProjectReference();

View File

@ -102,11 +102,22 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
this.repositoryDir = new File( repository.getLocation() ); this.repositoryDir = new File( repository.getLocation() );
} }
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
throws ConsumerException
{
beginScan( repository, whenGathered );
}
public void completeScan() public void completeScan()
{ {
/* nothing to do */ /* nothing to do */
} }
public void completeScan( boolean executeOnEntireRepo )
{
completeScan();
}
public List<String> getExcludes() public List<String> getExcludes()
{ {
return null; return null;
@ -143,6 +154,12 @@ public void processFile( String path )
} }
} }
public void processFile( String path, boolean executeOnEntireRepo )
throws Exception
{
processFile( path );
}
public void initialize() public void initialize()
throws InitializationException throws InitializationException
{ {

View File

@ -157,6 +157,12 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
} }
} }
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
throws ConsumerException
{
beginScan( repository, whenGathered );
}
public void processFile( String path ) public void processFile( String path )
throws ConsumerException throws ConsumerException
{ {
@ -175,11 +181,22 @@ public void processFile( String path )
} }
} }
public void processFile( String path, boolean executeOnEntireRepo )
throws Exception
{
processFile( path );
}
public void completeScan() public void completeScan()
{ {
/* do nothing */ /* do nothing */
} }
public void completeScan( boolean executeOnEntireRepo )
{
completeScan();
}
public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
{ {
if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) if ( ConfigurationNames.isRepositoryScanning( propertyName ) )

View File

@ -152,6 +152,12 @@ public void beginScan( ManagedRepositoryConfiguration repo, Date whenGathered )
} }
} }
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
throws ConsumerException
{
beginScan( repository, whenGathered );
}
public void processFile( String path ) public void processFile( String path )
throws ConsumerException throws ConsumerException
{ {
@ -210,6 +216,12 @@ public void processFile( String path )
} }
} }
public void processFile( String path, boolean executeOnEntireRepo )
throws Exception
{
processFile( path );
}
/** /**
* Get a Live Artifact from a Path. * Get a Live Artifact from a Path.
* <p/> * <p/>
@ -248,6 +260,11 @@ public void completeScan()
/* do nothing */ /* do nothing */
} }
public void completeScan( boolean executeOnEntireRepo )
{
completeScan();
}
public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
{ {
if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) if ( ConfigurationNames.isRepositoryScanning( propertyName ) )

View File

@ -155,10 +155,21 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
} }
} }
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
throws ConsumerException
{
beginScan( repository, whenGathered );
}
public void completeScan() public void completeScan()
{ {
} }
public void completeScan( boolean executeOnEntireRepo )
{
completeScan();
}
public List<String> getExcludes() public List<String> getExcludes()
{ {
return null; return null;
@ -246,6 +257,12 @@ public void processFile( String path )
} }
} }
public void processFile( String path, boolean executeOnEntireRepo )
throws ConsumerException
{
processFile( path );
}
private void flushProjectCache( MavenProjectBuilder projectBuilder ) private void flushProjectCache( MavenProjectBuilder projectBuilder )
{ {
try try

View File

@ -64,6 +64,10 @@
<artifactId>bcel</artifactId> <artifactId>bcel</artifactId>
<version>5.2</version> <version>5.2</version>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId> <artifactId>slf4j-simple</artifactId>

View File

@ -70,6 +70,8 @@ public class NexusIndexerConsumer
private List<String> includes = new ArrayList<String>(); private List<String> includes = new ArrayList<String>();
private ManagedRepositoryConfiguration repository;
public NexusIndexerConsumer( ArchivaTaskScheduler scheduler, ArchivaConfiguration configuration, FileTypes filetypes ) public NexusIndexerConsumer( ArchivaTaskScheduler scheduler, ArchivaConfiguration configuration, FileTypes filetypes )
{ {
this.configuration = configuration; this.configuration = configuration;
@ -102,6 +104,7 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
try try
{ {
log.info( "Creating indexing context for repo : " + repository.getId() );
context = TaskCreator.createContext( repository ); context = TaskCreator.createContext( repository );
} }
catch ( IOException e ) catch ( IOException e )
@ -114,6 +117,20 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
} }
} }
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
throws ConsumerException
{
if( executeOnEntireRepo )
{
beginScan( repository, whenGathered );
}
else
{
this.repository = repository;
managedRepository = new File( repository.getLocation() );
}
}
public void processFile( String path ) public void processFile( String path )
throws ConsumerException throws ConsumerException
{ {
@ -133,6 +150,32 @@ public void processFile( String path )
} }
} }
public void processFile( String path, boolean executeOnEntireRepo )
throws Exception
{
if( executeOnEntireRepo )
{
processFile( path );
}
else
{
File artifactFile = new File( managedRepository, path );
// specify in indexing task that this is not a repo scan request!
ArtifactIndexingTask task =
new ArtifactIndexingTask( repository, artifactFile, ArtifactIndexingTask.Action.ADD, context, false );
try
{
log.debug( "Queueing indexing task + '" + task + "' to add or update the artifact in the index." );
scheduler.queueIndexingTask( task );
}
catch ( TaskQueueException e )
{
throw new ConsumerException( e.getMessage(), e );
}
}
}
public void completeScan() public void completeScan()
{ {
ArtifactIndexingTask task = ArtifactIndexingTask task =
@ -150,6 +193,16 @@ public void completeScan()
context = null; context = null;
} }
public void completeScan( boolean executeOnEntireRepo )
{
if( executeOnEntireRepo )
{
completeScan();
}
// else, do nothing as the context will be closed when indexing task is executed if not a repo scan request!
}
public List<String> getExcludes() public List<String> getExcludes()
{ {
return Collections.emptyList(); return Collections.emptyList();

View File

@ -13,4 +13,8 @@
<constructor-arg ref="repositoryContentFactory"/> <constructor-arg ref="repositoryContentFactory"/>
<constructor-arg ref="archivaTaskScheduler"/> <constructor-arg ref="archivaTaskScheduler"/>
</bean> </bean>
<bean id="logger" class="org.apache.maven.archiva.common.utils.Slf4JPlexusLogger">
<constructor-arg type="java.lang.Class"><value>org.sonatype.nexus.index.DefaultNexusIndexer</value></constructor-arg>
</bean>
</beans> </beans>

View File

@ -88,11 +88,22 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
this.managedRepository.setRepository( repository ); this.managedRepository.setRepository( repository );
} }
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
throws ConsumerException
{
beginScan( repository, whenGathered );
}
public void completeScan() public void completeScan()
{ {
} }
public void completeScan( boolean executeOnEntireRepo )
{
completeScan();
}
public List<String> getExcludes() public List<String> getExcludes()
{ {
return excludes; return excludes;
@ -124,6 +135,12 @@ public void processFile( String path )
} }
} }
public void processFile( String path, boolean executeOnEntireRepo )
throws Exception
{
processFile( path );
}
public String getDescription() public String getDescription()
{ {
return "Legacy Artifact to Default Artifact Converter"; return "Legacy Artifact to Default Artifact Converter";

View File

@ -37,6 +37,7 @@
import org.sonatype.nexus.index.FlatSearchRequest; import org.sonatype.nexus.index.FlatSearchRequest;
import org.sonatype.nexus.index.FlatSearchResponse; import org.sonatype.nexus.index.FlatSearchResponse;
import org.sonatype.nexus.index.NexusIndexer; import org.sonatype.nexus.index.NexusIndexer;
import org.sonatype.nexus.index.context.IndexCreator;
import org.sonatype.nexus.index.context.IndexingContext; import org.sonatype.nexus.index.context.IndexingContext;
import org.sonatype.nexus.index.context.UnsupportedExistingLuceneIndexException; import org.sonatype.nexus.index.context.UnsupportedExistingLuceneIndexException;

View File

@ -8,5 +8,9 @@
<constructor-arg ref="archivaConfiguration"/> <constructor-arg ref="archivaConfiguration"/>
</bean> </bean>
<bean id="logger" class="org.apache.maven.archiva.common.utils.Slf4JPlexusLogger">
<constructor-arg type="java.lang.Class"><value>org.sonatype.nexus.index.DefaultNexusIndexer</value></constructor-arg>
</bean>
<!-- <bean id="indexingContextMap" class="org.apache.archiva.indexer.IndexingContextMap"/> --> <!-- <bean id="indexingContextMap" class="org.apache.archiva.indexer.IndexingContextMap"/> -->
</beans> </beans>

View File

@ -35,17 +35,25 @@ public class TriggerScanCompletedClosure
private final ManagedRepositoryConfiguration repository; private final ManagedRepositoryConfiguration repository;
private boolean executeOnEntireRepo = true;
public TriggerScanCompletedClosure( ManagedRepositoryConfiguration repository ) public TriggerScanCompletedClosure( ManagedRepositoryConfiguration repository )
{ {
this.repository = repository; this.repository = repository;
} }
public TriggerScanCompletedClosure( ManagedRepositoryConfiguration repository, boolean executeOnEntireRepo )
{
this( repository );
this.executeOnEntireRepo = executeOnEntireRepo;
}
public void execute( Object input ) public void execute( Object input )
{ {
if ( input instanceof RepositoryContentConsumer ) if ( input instanceof RepositoryContentConsumer )
{ {
RepositoryContentConsumer consumer = (RepositoryContentConsumer) input; RepositoryContentConsumer consumer = (RepositoryContentConsumer) input;
consumer.completeScan(); consumer.completeScan( executeOnEntireRepo );
log.debug( "Consumer [" + consumer.getId() + "] completed for repository [" + repository.getId() + "]" ); log.debug( "Consumer [" + consumer.getId() + "] completed for repository [" + repository.getId() + "]" );
} }
} }

View File

@ -236,7 +236,7 @@ public void executeConsumers( ManagedRepositoryConfiguration repository, File lo
// Run the repository consumers // Run the repository consumers
try try
{ {
Closure triggerBeginScan = new TriggerBeginScanClosure( repository, getStartTime() ); Closure triggerBeginScan = new TriggerBeginScanClosure( repository, getStartTime(), false );
List<KnownRepositoryContentConsumer> selectedKnownConsumers = getSelectedKnownConsumers(); List<KnownRepositoryContentConsumer> selectedKnownConsumers = getSelectedKnownConsumers();
@ -266,9 +266,12 @@ public void executeConsumers( ManagedRepositoryConfiguration repository, File lo
BaseFile baseFile = new BaseFile( repository.getLocation(), localFile ); BaseFile baseFile = new BaseFile( repository.getLocation(), localFile );
ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate(); ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
predicate.setBasefile( baseFile ); predicate.setBasefile( baseFile );
predicate.setCaseSensitive( false );
ConsumerProcessFileClosure closure = new ConsumerProcessFileClosure(); ConsumerProcessFileClosure closure = new ConsumerProcessFileClosure();
closure.setBasefile( baseFile ); closure.setBasefile( baseFile );
predicate.setCaseSensitive( false ); closure.setExecuteOnEntireRepo( false );
Closure processIfWanted = IfClosure.getInstance( predicate, closure ); Closure processIfWanted = IfClosure.getInstance( predicate, closure );
CollectionUtils.forAllDo( selectedKnownConsumers, processIfWanted ); CollectionUtils.forAllDo( selectedKnownConsumers, processIfWanted );
@ -279,7 +282,7 @@ public void executeConsumers( ManagedRepositoryConfiguration repository, File lo
CollectionUtils.forAllDo( selectedInvalidConsumers, closure ); CollectionUtils.forAllDo( selectedInvalidConsumers, closure );
} }
TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure( repository ); TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure( repository, false );
CollectionUtils.forAllDo( selectedKnownConsumers, scanCompletedClosure ); CollectionUtils.forAllDo( selectedKnownConsumers, scanCompletedClosure );
} }

View File

@ -82,7 +82,7 @@ public RepositoryScannerInstance( ManagedRepositoryConfiguration repository,
stats = new RepositoryScanStatistics(); stats = new RepositoryScanStatistics();
stats.setRepositoryId( repository.getId() ); stats.setRepositoryId( repository.getId() );
Closure triggerBeginScan = new TriggerBeginScanClosure( repository, new Date( System.currentTimeMillis() ) ); Closure triggerBeginScan = new TriggerBeginScanClosure( repository, new Date( System.currentTimeMillis() ), true );
CollectionUtils.forAllDo( knownConsumerList, triggerBeginScan ); CollectionUtils.forAllDo( knownConsumerList, triggerBeginScan );
CollectionUtils.forAllDo( invalidConsumerList, triggerBeginScan ); CollectionUtils.forAllDo( invalidConsumerList, triggerBeginScan );
@ -131,6 +131,7 @@ public void directoryWalkStep( int percentage, File file )
} }
consumerProcessFile.setBasefile( basefile ); consumerProcessFile.setBasefile( basefile );
consumerProcessFile.setExecuteOnEntireRepo( true );
consumerWantsFile.setBasefile( basefile ); consumerWantsFile.setBasefile( basefile );
Closure processIfWanted = IfClosure.getInstance( consumerWantsFile, consumerProcessFile ); Closure processIfWanted = IfClosure.getInstance( consumerWantsFile, consumerProcessFile );
@ -145,7 +146,7 @@ public void directoryWalkStep( int percentage, File file )
public void directoryWalkFinished() public void directoryWalkFinished()
{ {
TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure(repository); TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure( repository, true );
CollectionUtils.forAllDo( knownConsumers, scanCompletedClosure ); CollectionUtils.forAllDo( knownConsumers, scanCompletedClosure );
CollectionUtils.forAllDo( invalidConsumers, scanCompletedClosure ); CollectionUtils.forAllDo( invalidConsumers, scanCompletedClosure );

View File

@ -37,6 +37,8 @@ public class ConsumerProcessFileClosure
private BaseFile basefile; private BaseFile basefile;
private boolean executeOnEntireRepo;
public void execute( Object input ) public void execute( Object input )
{ {
if ( input instanceof RepositoryContentConsumer ) if ( input instanceof RepositoryContentConsumer )
@ -47,7 +49,7 @@ public void execute( Object input )
{ {
log.debug( "Sending to consumer: " + consumer.getId() ); log.debug( "Sending to consumer: " + consumer.getId() );
consumer.processFile( basefile.getRelativePath() ); consumer.processFile( basefile.getRelativePath(), executeOnEntireRepo );
} }
catch ( Exception e ) catch ( Exception e )
{ {
@ -70,6 +72,16 @@ public void setBasefile( BaseFile basefile )
this.basefile = basefile; this.basefile = basefile;
} }
public boolean isExecuteOnEntireRepo()
{
return executeOnEntireRepo;
}
public void setExecuteOnEntireRepo( boolean executeOnEntireRepo )
{
this.executeOnEntireRepo = executeOnEntireRepo;
}
public Logger getLogger() public Logger getLogger()
{ {
return log; return log;

View File

@ -42,6 +42,8 @@ public class TriggerBeginScanClosure
private Date whenGathered; private Date whenGathered;
private boolean executeOnEntireRepo = true;
public TriggerBeginScanClosure( ManagedRepositoryConfiguration repository ) public TriggerBeginScanClosure( ManagedRepositoryConfiguration repository )
{ {
this.repository = repository; this.repository = repository;
@ -53,6 +55,12 @@ public TriggerBeginScanClosure( ManagedRepositoryConfiguration repository, Date
this.whenGathered = whenGathered; this.whenGathered = whenGathered;
} }
public TriggerBeginScanClosure( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
{
this( repository, whenGathered );
this.executeOnEntireRepo = executeOnEntireRepo;
}
public void execute( Object input ) public void execute( Object input )
{ {
if ( input instanceof RepositoryContentConsumer ) if ( input instanceof RepositoryContentConsumer )
@ -61,7 +69,7 @@ public void execute( Object input )
try try
{ {
consumer.beginScan( repository, whenGathered ); consumer.beginScan( repository, whenGathered, executeOnEntireRepo );
} }
catch ( ConsumerException e ) catch ( ConsumerException e )
{ {

View File

@ -49,11 +49,22 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
/* do nothing */ /* do nothing */
} }
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
throws ConsumerException
{
beginScan( repository, whenGathered );
}
public void completeScan() public void completeScan()
{ {
/* do nothing */ /* do nothing */
} }
public void completeScan( boolean executeOnEntireRepo )
{
completeScan();
}
public List<String> getExcludes() public List<String> getExcludes()
{ {
return null; return null;
@ -70,6 +81,12 @@ public void processFile( String path )
processCount++; processCount++;
} }
public void processFile( String path, boolean executeOnEntireRepo )
throws ConsumerException
{
processFile( path );
}
public String getDescription() public String getDescription()
{ {
return "Bad Content Scan Consumer (for testing)"; return "Bad Content Scan Consumer (for testing)";

View File

@ -76,17 +76,34 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
/* do nothing */ /* do nothing */
} }
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
throws ConsumerException
{
beginScan( repository, whenGathered );
}
public void processFile( String path ) public void processFile( String path )
throws ConsumerException throws ConsumerException
{ {
this.processCount++; this.processCount++;
} }
public void processFile( String path, boolean executeOnEntireRepo )
throws Exception
{
processFile( path );
}
public void completeScan() public void completeScan()
{ {
/* do nothing */ /* do nothing */
} }
public void completeScan( boolean executeOnEntireRepo )
{
completeScan();
}
public int getProcessCount() public int getProcessCount()
{ {
return processCount; return processCount;

View File

@ -241,16 +241,16 @@ public void testExecution()
Date startTime = new Date( System.currentTimeMillis() ); Date startTime = new Date( System.currentTimeMillis() );
startTime.setTime( 12345678 ); startTime.setTime( 12345678 );
selectedKnownConsumer.beginScan( repo, startTime ); selectedKnownConsumer.beginScan( repo, startTime, false );
selectedKnownConsumer.getExcludes(); selectedKnownConsumer.getExcludes();
knownControl.setReturnValue( Collections.EMPTY_LIST ); knownControl.setReturnValue( Collections.EMPTY_LIST );
selectedKnownConsumer.getIncludes(); selectedKnownConsumer.getIncludes();
knownControl.setReturnValue( Collections.singletonList( "**/*.txt" ) ); knownControl.setReturnValue( Collections.singletonList( "**/*.txt" ) );
selectedKnownConsumer.processFile( _OS( "path/to/test-file.txt" ) ); selectedKnownConsumer.processFile( _OS( "path/to/test-file.txt" ), false );
// knownConsumer.completeScan(); // knownConsumer.completeScan();
knownControl.replay(); knownControl.replay();
selectedInvalidConsumer.beginScan( repo, startTime ); selectedInvalidConsumer.beginScan( repo, startTime, false );
// invalidConsumer.completeScan(); // invalidConsumer.completeScan();
invalidControl.replay(); invalidControl.replay();
@ -264,7 +264,7 @@ public void testExecution()
File notIncludedTestFile = getTestFile( "target/test-repo/path/to/test-file.xml" ); File notIncludedTestFile = getTestFile( "target/test-repo/path/to/test-file.xml" );
selectedKnownConsumer.beginScan( repo, startTime ); selectedKnownConsumer.beginScan( repo, startTime, false );
selectedKnownConsumer.getExcludes(); selectedKnownConsumer.getExcludes();
knownControl.setReturnValue( Collections.EMPTY_LIST ); knownControl.setReturnValue( Collections.EMPTY_LIST );
selectedKnownConsumer.getIncludes(); selectedKnownConsumer.getIncludes();
@ -272,8 +272,8 @@ public void testExecution()
// knownConsumer.completeScan(); // knownConsumer.completeScan();
knownControl.replay(); knownControl.replay();
selectedInvalidConsumer.beginScan( repo, startTime ); selectedInvalidConsumer.beginScan( repo, startTime, false );
selectedInvalidConsumer.processFile( _OS( "path/to/test-file.xml" ) ); selectedInvalidConsumer.processFile( _OS( "path/to/test-file.xml" ), false );
selectedInvalidConsumer.getId(); selectedInvalidConsumer.getId();
invalidControl.setReturnValue( "invalid" ); invalidControl.setReturnValue( "invalid" );
// invalidConsumer.completeScan(); // invalidConsumer.completeScan();
@ -289,14 +289,14 @@ public void testExecution()
File excludedTestFile = getTestFile( "target/test-repo/path/to/test-file.txt" ); File excludedTestFile = getTestFile( "target/test-repo/path/to/test-file.txt" );
selectedKnownConsumer.beginScan( repo, startTime ); selectedKnownConsumer.beginScan( repo, startTime, false );
selectedKnownConsumer.getExcludes(); selectedKnownConsumer.getExcludes();
knownControl.setReturnValue( Collections.singletonList( "**/test-file.txt" ) ); knownControl.setReturnValue( Collections.singletonList( "**/test-file.txt" ) );
// knownConsumer.completeScan(); // knownConsumer.completeScan();
knownControl.replay(); knownControl.replay();
selectedInvalidConsumer.beginScan( repo, startTime ); selectedInvalidConsumer.beginScan( repo, startTime, false );
selectedInvalidConsumer.processFile( _OS( "path/to/test-file.txt" ) ); selectedInvalidConsumer.processFile( _OS( "path/to/test-file.txt" ), false );
selectedInvalidConsumer.getId(); selectedInvalidConsumer.getId();
invalidControl.setReturnValue( "invalid" ); invalidControl.setReturnValue( "invalid" );
// invalidConsumer.completeScan(); // invalidConsumer.completeScan();

View File

@ -50,11 +50,22 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
/* nothing to do */ /* nothing to do */
} }
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
throws ConsumerException
{
beginScan( repository, whenGathered );
}
public void completeScan() public void completeScan()
{ {
/* nothing to do */ /* nothing to do */
} }
public void completeScan( boolean executeOnEntireRepo )
{
completeScan();
}
public List<String> getExcludes() public List<String> getExcludes()
{ {
return null; return null;
@ -71,6 +82,12 @@ public void processFile( String path )
/* nothing to do */ /* nothing to do */
} }
public void processFile( String path, boolean executeOnEntireRepo )
throws Exception
{
processFile( path );
}
public String getDescription() public String getDescription()
{ {
return "Sample Known Consumer"; return "Sample Known Consumer";

View File

@ -21,11 +21,13 @@
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import org.apache.lucene.document.Document; import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.scheduled.tasks.ArtifactIndexingTask; import org.apache.maven.archiva.scheduled.tasks.ArtifactIndexingTask;
import org.apache.maven.archiva.scheduled.tasks.TaskCreator;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.codehaus.plexus.taskqueue.Task; import org.codehaus.plexus.taskqueue.Task;
@ -38,7 +40,9 @@
import org.sonatype.nexus.index.ArtifactInfo; import org.sonatype.nexus.index.ArtifactInfo;
import org.sonatype.nexus.index.DefaultArtifactContextProducer; import org.sonatype.nexus.index.DefaultArtifactContextProducer;
import org.sonatype.nexus.index.IndexerEngine; import org.sonatype.nexus.index.IndexerEngine;
import org.sonatype.nexus.index.context.IndexCreator;
import org.sonatype.nexus.index.context.IndexingContext; import org.sonatype.nexus.index.context.IndexingContext;
import org.sonatype.nexus.index.context.UnsupportedExistingLuceneIndexException;
import org.sonatype.nexus.index.packer.IndexPacker; import org.sonatype.nexus.index.packer.IndexPacker;
import org.sonatype.nexus.index.packer.IndexPackingRequest; import org.sonatype.nexus.index.packer.IndexPackingRequest;
@ -78,44 +82,35 @@ public void executeTask( Task task )
ManagedRepositoryConfiguration repository = indexingTask.getRepository(); ManagedRepositoryConfiguration repository = indexingTask.getRepository();
IndexingContext context = indexingTask.getContext(); IndexingContext context = indexingTask.getContext();
if ( ArtifactIndexingTask.Action.FINISH.equals( indexingTask.getAction() ) ) if ( ArtifactIndexingTask.Action.FINISH.equals( indexingTask.getAction() )
&& indexingTask.isExecuteOnEntireRepo() )
{ {
try log.debug( "Finishing indexing task on repo: " + repository.getId() );
{ finishIndexingTask( indexingTask, repository, context );
context.optimize();
File managedRepository = new File( repository.getLocation() );
final File indexLocation = new File( managedRepository, ".index" );
IndexPackingRequest request = new IndexPackingRequest( context, indexLocation );
indexPacker.packIndex( request );
log.debug( "Index file packaged at '" + indexLocation.getPath() + "'." );
}
catch ( IOException e )
{
log.error( "Error occurred while executing indexing task '" + indexingTask + "': " + e.getMessage() );
throw new TaskExecutionException( "Error occurred while executing indexing task '" + indexingTask
+ "'", e );
}
finally
{
if ( context != null )
{
try
{
context.close( false );
}
catch ( IOException e )
{
log.error( "Error occurred while closing context: " + e.getMessage() );
throw new TaskExecutionException( "Error occurred while closing context: " + e.getMessage() );
}
}
}
} }
else else
{ {
if ( context.getIndexDirectory() == null ) // create context if not a repo scan request
if( !indexingTask.isExecuteOnEntireRepo() )
{
try
{
log.debug( "Creating indexing context on resource: " + indexingTask.getResourceFile().getPath() );
context = TaskCreator.createContext( repository );
}
catch( IOException e )
{
log.error( "Error occurred while creating context: " + e.getMessage() );
throw new TaskExecutionException( "Error occurred while creating context: " + e.getMessage() );
}
catch( UnsupportedExistingLuceneIndexException e )
{
log.error( "Error occurred while creating context: " + e.getMessage() );
throw new TaskExecutionException( "Error occurred while creating context: " + e.getMessage() );
}
}
if ( context == null || context.getIndexDirectory() == null )
{ {
throw new TaskExecutionException( "Trying to index an artifact but the context is already closed" ); throw new TaskExecutionException( "Trying to index an artifact but the context is already closed" );
} }
@ -157,6 +152,13 @@ public void executeTask( Task task )
indexerEngine.update( context, ac ); indexerEngine.update( context, ac );
context.getIndexWriter().commit(); context.getIndexWriter().commit();
} }
// close the context if not a repo scan request
if( !indexingTask.isExecuteOnEntireRepo() )
{
log.debug( "Finishing indexing task on resource file : " + indexingTask.getResourceFile().getPath() );
finishIndexingTask( indexingTask, repository, context );
}
} }
else else
{ {
@ -176,6 +178,44 @@ public void executeTask( Task task )
} }
} }
private void finishIndexingTask( ArtifactIndexingTask indexingTask, ManagedRepositoryConfiguration repository,
IndexingContext context )
throws TaskExecutionException
{
try
{
context.optimize();
File managedRepository = new File( repository.getLocation() );
final File indexLocation = new File( managedRepository, ".index" );
IndexPackingRequest request = new IndexPackingRequest( context, indexLocation );
indexPacker.packIndex( request );
log.debug( "Index file packaged at '" + indexLocation.getPath() + "'." );
}
catch ( IOException e )
{
log.error( "Error occurred while executing indexing task '" + indexingTask + "': " + e.getMessage() );
throw new TaskExecutionException( "Error occurred while executing indexing task '" + indexingTask
+ "'", e );
}
finally
{
if ( context != null )
{
try
{
context.close( false );
}
catch ( IOException e )
{
log.error( "Error occurred while closing context: " + e.getMessage() );
throw new TaskExecutionException( "Error occurred while closing context: " + e.getMessage() );
}
}
}
}
public void initialize() public void initialize()
throws InitializationException throws InitializationException
{ {

View File

@ -41,6 +41,8 @@ public enum Action
private final IndexingContext context; private final IndexingContext context;
private boolean executeOnEntireRepo = true;
public ArtifactIndexingTask( ManagedRepositoryConfiguration repository, File resourceFile, Action action, public ArtifactIndexingTask( ManagedRepositoryConfiguration repository, File resourceFile, Action action,
IndexingContext context ) IndexingContext context )
{ {
@ -50,6 +52,23 @@ public ArtifactIndexingTask( ManagedRepositoryConfiguration repository, File res
this.context = context; this.context = context;
} }
public ArtifactIndexingTask( ManagedRepositoryConfiguration repository, File resourceFile, Action action,
IndexingContext context, boolean executeOnEntireRepo )
{
this( repository, resourceFile, action, context );
this.executeOnEntireRepo = executeOnEntireRepo;
}
public boolean isExecuteOnEntireRepo()
{
return executeOnEntireRepo;
}
public void setExecuteOnEntireRepo( boolean executeOnEntireRepo )
{
this.executeOnEntireRepo = executeOnEntireRepo;
}
public long getMaxExecutionTime() public long getMaxExecutionTime()
{ {
return 0; return 0;

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="logger" class="org.apache.maven.archiva.common.utils.Slf4JPlexusLogger">
<constructor-arg type="java.lang.Class"><value>org.sonatype.nexus.index.DefaultNexusIndexer</value></constructor-arg>
</bean>
</beans>

View File

@ -26,6 +26,8 @@
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
@ -45,6 +47,7 @@
import org.sonatype.nexus.index.FlatSearchResponse; import org.sonatype.nexus.index.FlatSearchResponse;
import org.sonatype.nexus.index.IndexerEngine; import org.sonatype.nexus.index.IndexerEngine;
import org.sonatype.nexus.index.NexusIndexer; import org.sonatype.nexus.index.NexusIndexer;
import org.sonatype.nexus.index.context.IndexCreator;
import org.sonatype.nexus.index.context.IndexingContext; import org.sonatype.nexus.index.context.IndexingContext;
import org.sonatype.nexus.index.packer.IndexPacker; import org.sonatype.nexus.index.packer.IndexPacker;

View File

@ -188,6 +188,12 @@
<lifecycle-handler>basic</lifecycle-handler> <lifecycle-handler>basic</lifecycle-handler>
</component> </component>
<component>
<role>org.codehaus.plexus.logging.Logger</role>
<implementation>org.apache.maven.archiva.common.utils.Slf4JPlexusLogger</implementation>
<role-hint>logger</role-hint>
</component>
<!-- <!--
PLXREDBACK-81 bad role hint, redefining here until redback alpha-2 is released. PLXREDBACK-81 bad role hint, redefining here until redback alpha-2 is released.
--> -->

View File

@ -557,12 +557,12 @@
<dependency> <dependency>
<groupId>org.apache.lucene</groupId> <groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId> <artifactId>lucene-core</artifactId>
<version>2.4.0</version> <version>2.4.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.lucene</groupId> <groupId>org.apache.lucene</groupId>
<artifactId>lucene-queries</artifactId> <artifactId>lucene-queries</artifactId>
<version>2.4.0</version> <version>2.4.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.mail</groupId> <groupId>javax.mail</groupId>