mirror of
https://github.com/apache/archiva.git
synced 2025-02-09 19:45:57 +00:00
[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:
parent
77f294d87f
commit
cfd8ca2ffb
@ -43,6 +43,12 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
|
||||
this.count = 0;
|
||||
}
|
||||
|
||||
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
|
||||
throws ConsumerException
|
||||
{
|
||||
beginScan( repository, whenGathered );
|
||||
}
|
||||
|
||||
public void processFile( String path )
|
||||
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()
|
||||
{
|
||||
System.out.println( "Final Count of Artifacts processed by " + getId() + ": " + count );
|
||||
}
|
||||
|
||||
public void completeScan( boolean executeOnEntireRepo )
|
||||
{
|
||||
completeScan();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -61,6 +61,22 @@ public interface RepositoryContentConsumer extends Consumer
|
||||
*/
|
||||
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>
|
||||
* Event indicating a file is to be processed by this consumer.
|
||||
@ -76,6 +92,14 @@ public interface RepositoryContentConsumer extends Consumer
|
||||
* @throws ConsumerException if there was a problem processing this file.
|
||||
*/
|
||||
public void processFile( String path ) throws ConsumerException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param path
|
||||
* @param executeOnEntireRepo
|
||||
* @throws Exception
|
||||
*/
|
||||
public void processFile( String path, boolean executeOnEntireRepo ) throws Exception;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -89,6 +113,13 @@ public interface RepositoryContentConsumer extends Consumer
|
||||
*/
|
||||
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
|
||||
* method.
|
||||
|
@ -99,11 +99,22 @@ public void beginScan( ManagedRepositoryConfiguration repo, Date whenGathered )
|
||||
this.repositoryDir = new File( repo.getLocation() );
|
||||
}
|
||||
|
||||
public void beginScan( ManagedRepositoryConfiguration repo, Date whenGathered, boolean executeOnEntireRepo )
|
||||
throws ConsumerException
|
||||
{
|
||||
beginScan( repo, whenGathered );
|
||||
}
|
||||
|
||||
public void completeScan()
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
public void completeScan( boolean executeOnEntireRepo )
|
||||
{
|
||||
completeScan();
|
||||
}
|
||||
|
||||
public List<String> getExcludes()
|
||||
{
|
||||
return getDefaultArtifactExclusions();
|
||||
@ -120,6 +131,12 @@ public void processFile( String path )
|
||||
createFixChecksum( path, new ChecksumAlgorithm[] { ChecksumAlgorithm.SHA1 } );
|
||||
createFixChecksum( path, new ChecksumAlgorithm[] { ChecksumAlgorithm.MD5 } );
|
||||
}
|
||||
|
||||
public void processFile( String path, boolean executeOnEntireRepo )
|
||||
throws ConsumerException
|
||||
{
|
||||
processFile( path );
|
||||
}
|
||||
|
||||
private void createFixChecksum( String path, ChecksumAlgorithm checksumAlgorithm[] )
|
||||
{
|
||||
|
@ -95,11 +95,22 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
|
||||
this.repositoryDir = new File( repository.getLocation() );
|
||||
}
|
||||
|
||||
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
|
||||
throws ConsumerException
|
||||
{
|
||||
beginScan( repository, whenGathered );
|
||||
}
|
||||
|
||||
public void completeScan()
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
public void completeScan( boolean executeOnEntireRepo )
|
||||
{
|
||||
completeScan();
|
||||
}
|
||||
|
||||
public List<String> getExcludes()
|
||||
{
|
||||
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 )
|
||||
{
|
||||
if ( ConfigurationNames.isRepositoryScanning( propertyName ) )
|
||||
|
@ -96,11 +96,22 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
|
||||
this.repositoryDir = new File( repository.getLocation() );
|
||||
}
|
||||
|
||||
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
|
||||
throws ConsumerException
|
||||
{
|
||||
beginScan( repository, whenGathered );
|
||||
}
|
||||
|
||||
public void completeScan()
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
public void completeScan( boolean executeOnEntireRepo )
|
||||
{
|
||||
completeScan();
|
||||
}
|
||||
|
||||
public List<String> getExcludes()
|
||||
{
|
||||
return null;
|
||||
@ -143,4 +154,10 @@ public void processFile( String path )
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public void processFile( String path, boolean executeOnEntireRepo )
|
||||
throws ConsumerException
|
||||
{
|
||||
processFile( path );
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
{
|
||||
/* do nothing here */
|
||||
}
|
||||
|
||||
public void completeScan( boolean executeOnEntireRepo )
|
||||
{
|
||||
completeScan();
|
||||
}
|
||||
|
||||
public List<String> getExcludes()
|
||||
{
|
||||
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 )
|
||||
{
|
||||
ProjectReference projectRef = new ProjectReference();
|
||||
|
@ -102,11 +102,22 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
|
||||
this.repositoryDir = new File( repository.getLocation() );
|
||||
}
|
||||
|
||||
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
|
||||
throws ConsumerException
|
||||
{
|
||||
beginScan( repository, whenGathered );
|
||||
}
|
||||
|
||||
public void completeScan()
|
||||
{
|
||||
/* nothing to do */
|
||||
}
|
||||
|
||||
public void completeScan( boolean executeOnEntireRepo )
|
||||
{
|
||||
completeScan();
|
||||
}
|
||||
|
||||
public List<String> getExcludes()
|
||||
{
|
||||
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()
|
||||
throws InitializationException
|
||||
{
|
||||
|
@ -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 )
|
||||
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()
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
public void completeScan( boolean executeOnEntireRepo )
|
||||
{
|
||||
completeScan();
|
||||
}
|
||||
|
||||
public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
|
||||
{
|
||||
if ( ConfigurationNames.isRepositoryScanning( propertyName ) )
|
||||
|
@ -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 )
|
||||
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.
|
||||
* <p/>
|
||||
@ -248,6 +260,11 @@ public void completeScan()
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
public void completeScan( boolean executeOnEntireRepo )
|
||||
{
|
||||
completeScan();
|
||||
}
|
||||
|
||||
public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
|
||||
{
|
||||
if ( ConfigurationNames.isRepositoryScanning( propertyName ) )
|
||||
|
@ -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( boolean executeOnEntireRepo )
|
||||
{
|
||||
completeScan();
|
||||
}
|
||||
|
||||
public List<String> getExcludes()
|
||||
{
|
||||
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 )
|
||||
{
|
||||
try
|
||||
|
@ -64,6 +64,10 @@
|
||||
<artifactId>bcel</artifactId>
|
||||
<version>5.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
|
@ -70,6 +70,8 @@ public class NexusIndexerConsumer
|
||||
|
||||
private List<String> includes = new ArrayList<String>();
|
||||
|
||||
private ManagedRepositoryConfiguration repository;
|
||||
|
||||
public NexusIndexerConsumer( ArchivaTaskScheduler scheduler, ArchivaConfiguration configuration, FileTypes filetypes )
|
||||
{
|
||||
this.configuration = configuration;
|
||||
@ -102,6 +104,7 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
|
||||
|
||||
try
|
||||
{
|
||||
log.info( "Creating indexing context for repo : " + repository.getId() );
|
||||
context = TaskCreator.createContext( repository );
|
||||
}
|
||||
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 )
|
||||
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()
|
||||
{
|
||||
ArtifactIndexingTask task =
|
||||
@ -150,6 +193,16 @@ public void completeScan()
|
||||
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()
|
||||
{
|
||||
return Collections.emptyList();
|
||||
|
@ -13,4 +13,8 @@
|
||||
<constructor-arg ref="repositoryContentFactory"/>
|
||||
<constructor-arg ref="archivaTaskScheduler"/>
|
||||
</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>
|
@ -88,11 +88,22 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
|
||||
this.managedRepository.setRepository( repository );
|
||||
}
|
||||
|
||||
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
|
||||
throws ConsumerException
|
||||
{
|
||||
beginScan( repository, whenGathered );
|
||||
}
|
||||
|
||||
public void completeScan()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void completeScan( boolean executeOnEntireRepo )
|
||||
{
|
||||
completeScan();
|
||||
}
|
||||
|
||||
public List<String> getExcludes()
|
||||
{
|
||||
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()
|
||||
{
|
||||
return "Legacy Artifact to Default Artifact Converter";
|
||||
|
@ -37,6 +37,7 @@
|
||||
import org.sonatype.nexus.index.FlatSearchRequest;
|
||||
import org.sonatype.nexus.index.FlatSearchResponse;
|
||||
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.UnsupportedExistingLuceneIndexException;
|
||||
|
||||
|
@ -7,6 +7,10 @@
|
||||
<constructor-arg ref="nexusIndexer"/>
|
||||
<constructor-arg ref="archivaConfiguration"/>
|
||||
</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"/> -->
|
||||
</beans>
|
@ -35,17 +35,25 @@ public class TriggerScanCompletedClosure
|
||||
|
||||
private final ManagedRepositoryConfiguration repository;
|
||||
|
||||
private boolean executeOnEntireRepo = true;
|
||||
|
||||
public TriggerScanCompletedClosure( ManagedRepositoryConfiguration repository )
|
||||
{
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
public TriggerScanCompletedClosure( ManagedRepositoryConfiguration repository, boolean executeOnEntireRepo )
|
||||
{
|
||||
this( repository );
|
||||
this.executeOnEntireRepo = executeOnEntireRepo;
|
||||
}
|
||||
|
||||
public void execute( Object input )
|
||||
{
|
||||
if ( input instanceof RepositoryContentConsumer )
|
||||
{
|
||||
RepositoryContentConsumer consumer = (RepositoryContentConsumer) input;
|
||||
consumer.completeScan();
|
||||
consumer.completeScan( executeOnEntireRepo );
|
||||
log.debug( "Consumer [" + consumer.getId() + "] completed for repository [" + repository.getId() + "]" );
|
||||
}
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ public void executeConsumers( ManagedRepositoryConfiguration repository, File lo
|
||||
// Run the repository consumers
|
||||
try
|
||||
{
|
||||
Closure triggerBeginScan = new TriggerBeginScanClosure( repository, getStartTime() );
|
||||
Closure triggerBeginScan = new TriggerBeginScanClosure( repository, getStartTime(), false );
|
||||
|
||||
List<KnownRepositoryContentConsumer> selectedKnownConsumers = getSelectedKnownConsumers();
|
||||
|
||||
@ -266,9 +266,12 @@ public void executeConsumers( ManagedRepositoryConfiguration repository, File lo
|
||||
BaseFile baseFile = new BaseFile( repository.getLocation(), localFile );
|
||||
ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
|
||||
predicate.setBasefile( baseFile );
|
||||
predicate.setCaseSensitive( false );
|
||||
|
||||
ConsumerProcessFileClosure closure = new ConsumerProcessFileClosure();
|
||||
closure.setBasefile( baseFile );
|
||||
predicate.setCaseSensitive( false );
|
||||
closure.setExecuteOnEntireRepo( false );
|
||||
|
||||
Closure processIfWanted = IfClosure.getInstance( predicate, closure );
|
||||
|
||||
CollectionUtils.forAllDo( selectedKnownConsumers, processIfWanted );
|
||||
@ -279,7 +282,7 @@ public void executeConsumers( ManagedRepositoryConfiguration repository, File lo
|
||||
CollectionUtils.forAllDo( selectedInvalidConsumers, closure );
|
||||
}
|
||||
|
||||
TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure( repository );
|
||||
TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure( repository, false );
|
||||
|
||||
CollectionUtils.forAllDo( selectedKnownConsumers, scanCompletedClosure );
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ public RepositoryScannerInstance( ManagedRepositoryConfiguration repository,
|
||||
stats = new RepositoryScanStatistics();
|
||||
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( invalidConsumerList, triggerBeginScan );
|
||||
@ -131,6 +131,7 @@ public void directoryWalkStep( int percentage, File file )
|
||||
}
|
||||
|
||||
consumerProcessFile.setBasefile( basefile );
|
||||
consumerProcessFile.setExecuteOnEntireRepo( true );
|
||||
consumerWantsFile.setBasefile( basefile );
|
||||
|
||||
Closure processIfWanted = IfClosure.getInstance( consumerWantsFile, consumerProcessFile );
|
||||
@ -145,7 +146,7 @@ public void directoryWalkStep( int percentage, File file )
|
||||
|
||||
public void directoryWalkFinished()
|
||||
{
|
||||
TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure(repository);
|
||||
TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure( repository, true );
|
||||
|
||||
CollectionUtils.forAllDo( knownConsumers, scanCompletedClosure );
|
||||
CollectionUtils.forAllDo( invalidConsumers, scanCompletedClosure );
|
||||
|
@ -37,6 +37,8 @@ public class ConsumerProcessFileClosure
|
||||
|
||||
private BaseFile basefile;
|
||||
|
||||
private boolean executeOnEntireRepo;
|
||||
|
||||
public void execute( Object input )
|
||||
{
|
||||
if ( input instanceof RepositoryContentConsumer )
|
||||
@ -47,7 +49,7 @@ public void execute( Object input )
|
||||
{
|
||||
log.debug( "Sending to consumer: " + consumer.getId() );
|
||||
|
||||
consumer.processFile( basefile.getRelativePath() );
|
||||
consumer.processFile( basefile.getRelativePath(), executeOnEntireRepo );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
@ -70,6 +72,16 @@ public void setBasefile( BaseFile basefile )
|
||||
this.basefile = basefile;
|
||||
}
|
||||
|
||||
public boolean isExecuteOnEntireRepo()
|
||||
{
|
||||
return executeOnEntireRepo;
|
||||
}
|
||||
|
||||
public void setExecuteOnEntireRepo( boolean executeOnEntireRepo )
|
||||
{
|
||||
this.executeOnEntireRepo = executeOnEntireRepo;
|
||||
}
|
||||
|
||||
public Logger getLogger()
|
||||
{
|
||||
return log;
|
||||
|
@ -42,6 +42,8 @@ public class TriggerBeginScanClosure
|
||||
|
||||
private Date whenGathered;
|
||||
|
||||
private boolean executeOnEntireRepo = true;
|
||||
|
||||
public TriggerBeginScanClosure( ManagedRepositoryConfiguration repository )
|
||||
{
|
||||
this.repository = repository;
|
||||
@ -53,6 +55,12 @@ public TriggerBeginScanClosure( ManagedRepositoryConfiguration repository, Date
|
||||
this.whenGathered = whenGathered;
|
||||
}
|
||||
|
||||
public TriggerBeginScanClosure( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
|
||||
{
|
||||
this( repository, whenGathered );
|
||||
this.executeOnEntireRepo = executeOnEntireRepo;
|
||||
}
|
||||
|
||||
public void execute( Object input )
|
||||
{
|
||||
if ( input instanceof RepositoryContentConsumer )
|
||||
@ -61,7 +69,7 @@ public void execute( Object input )
|
||||
|
||||
try
|
||||
{
|
||||
consumer.beginScan( repository, whenGathered );
|
||||
consumer.beginScan( repository, whenGathered, executeOnEntireRepo );
|
||||
}
|
||||
catch ( ConsumerException e )
|
||||
{
|
||||
|
@ -49,11 +49,22 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
|
||||
throws ConsumerException
|
||||
{
|
||||
beginScan( repository, whenGathered );
|
||||
}
|
||||
|
||||
public void completeScan()
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
public void completeScan( boolean executeOnEntireRepo )
|
||||
{
|
||||
completeScan();
|
||||
}
|
||||
|
||||
public List<String> getExcludes()
|
||||
{
|
||||
return null;
|
||||
@ -70,6 +81,12 @@ public void processFile( String path )
|
||||
processCount++;
|
||||
}
|
||||
|
||||
public void processFile( String path, boolean executeOnEntireRepo )
|
||||
throws ConsumerException
|
||||
{
|
||||
processFile( path );
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return "Bad Content Scan Consumer (for testing)";
|
||||
|
@ -76,17 +76,34 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
|
||||
throws ConsumerException
|
||||
{
|
||||
beginScan( repository, whenGathered );
|
||||
}
|
||||
|
||||
public void processFile( String path )
|
||||
throws ConsumerException
|
||||
{
|
||||
this.processCount++;
|
||||
}
|
||||
|
||||
public void processFile( String path, boolean executeOnEntireRepo )
|
||||
throws Exception
|
||||
{
|
||||
processFile( path );
|
||||
}
|
||||
|
||||
public void completeScan()
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
public void completeScan( boolean executeOnEntireRepo )
|
||||
{
|
||||
completeScan();
|
||||
}
|
||||
|
||||
public int getProcessCount()
|
||||
{
|
||||
return processCount;
|
||||
|
@ -241,16 +241,16 @@ public void testExecution()
|
||||
Date startTime = new Date( System.currentTimeMillis() );
|
||||
startTime.setTime( 12345678 );
|
||||
|
||||
selectedKnownConsumer.beginScan( repo, startTime );
|
||||
selectedKnownConsumer.beginScan( repo, startTime, false );
|
||||
selectedKnownConsumer.getExcludes();
|
||||
knownControl.setReturnValue( Collections.EMPTY_LIST );
|
||||
selectedKnownConsumer.getIncludes();
|
||||
knownControl.setReturnValue( Collections.singletonList( "**/*.txt" ) );
|
||||
selectedKnownConsumer.processFile( _OS( "path/to/test-file.txt" ) );
|
||||
selectedKnownConsumer.processFile( _OS( "path/to/test-file.txt" ), false );
|
||||
// knownConsumer.completeScan();
|
||||
knownControl.replay();
|
||||
|
||||
selectedInvalidConsumer.beginScan( repo, startTime );
|
||||
selectedInvalidConsumer.beginScan( repo, startTime, false );
|
||||
// invalidConsumer.completeScan();
|
||||
invalidControl.replay();
|
||||
|
||||
@ -264,7 +264,7 @@ public void testExecution()
|
||||
|
||||
File notIncludedTestFile = getTestFile( "target/test-repo/path/to/test-file.xml" );
|
||||
|
||||
selectedKnownConsumer.beginScan( repo, startTime );
|
||||
selectedKnownConsumer.beginScan( repo, startTime, false );
|
||||
selectedKnownConsumer.getExcludes();
|
||||
knownControl.setReturnValue( Collections.EMPTY_LIST );
|
||||
selectedKnownConsumer.getIncludes();
|
||||
@ -272,8 +272,8 @@ public void testExecution()
|
||||
// knownConsumer.completeScan();
|
||||
knownControl.replay();
|
||||
|
||||
selectedInvalidConsumer.beginScan( repo, startTime );
|
||||
selectedInvalidConsumer.processFile( _OS( "path/to/test-file.xml" ) );
|
||||
selectedInvalidConsumer.beginScan( repo, startTime, false );
|
||||
selectedInvalidConsumer.processFile( _OS( "path/to/test-file.xml" ), false );
|
||||
selectedInvalidConsumer.getId();
|
||||
invalidControl.setReturnValue( "invalid" );
|
||||
// invalidConsumer.completeScan();
|
||||
@ -289,14 +289,14 @@ public void testExecution()
|
||||
|
||||
File excludedTestFile = getTestFile( "target/test-repo/path/to/test-file.txt" );
|
||||
|
||||
selectedKnownConsumer.beginScan( repo, startTime );
|
||||
selectedKnownConsumer.beginScan( repo, startTime, false );
|
||||
selectedKnownConsumer.getExcludes();
|
||||
knownControl.setReturnValue( Collections.singletonList( "**/test-file.txt" ) );
|
||||
// knownConsumer.completeScan();
|
||||
knownControl.replay();
|
||||
|
||||
selectedInvalidConsumer.beginScan( repo, startTime );
|
||||
selectedInvalidConsumer.processFile( _OS( "path/to/test-file.txt" ) );
|
||||
selectedInvalidConsumer.beginScan( repo, startTime, false );
|
||||
selectedInvalidConsumer.processFile( _OS( "path/to/test-file.txt" ), false );
|
||||
selectedInvalidConsumer.getId();
|
||||
invalidControl.setReturnValue( "invalid" );
|
||||
// invalidConsumer.completeScan();
|
||||
|
@ -50,11 +50,22 @@ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathe
|
||||
/* nothing to do */
|
||||
}
|
||||
|
||||
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
|
||||
throws ConsumerException
|
||||
{
|
||||
beginScan( repository, whenGathered );
|
||||
}
|
||||
|
||||
public void completeScan()
|
||||
{
|
||||
/* nothing to do */
|
||||
}
|
||||
|
||||
public void completeScan( boolean executeOnEntireRepo )
|
||||
{
|
||||
completeScan();
|
||||
}
|
||||
|
||||
public List<String> getExcludes()
|
||||
{
|
||||
return null;
|
||||
@ -71,6 +82,12 @@ public void processFile( String path )
|
||||
/* nothing to do */
|
||||
}
|
||||
|
||||
public void processFile( String path, boolean executeOnEntireRepo )
|
||||
throws Exception
|
||||
{
|
||||
processFile( path );
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return "Sample Known Consumer";
|
||||
|
@ -21,11 +21,13 @@
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
||||
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.InitializationException;
|
||||
import org.codehaus.plexus.taskqueue.Task;
|
||||
@ -38,7 +40,9 @@
|
||||
import org.sonatype.nexus.index.ArtifactInfo;
|
||||
import org.sonatype.nexus.index.DefaultArtifactContextProducer;
|
||||
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.UnsupportedExistingLuceneIndexException;
|
||||
import org.sonatype.nexus.index.packer.IndexPacker;
|
||||
import org.sonatype.nexus.index.packer.IndexPackingRequest;
|
||||
|
||||
@ -78,44 +82,35 @@ public void executeTask( Task task )
|
||||
ManagedRepositoryConfiguration repository = indexingTask.getRepository();
|
||||
IndexingContext context = indexingTask.getContext();
|
||||
|
||||
if ( ArtifactIndexingTask.Action.FINISH.equals( indexingTask.getAction() ) )
|
||||
if ( ArtifactIndexingTask.Action.FINISH.equals( indexingTask.getAction() )
|
||||
&& indexingTask.isExecuteOnEntireRepo() )
|
||||
{
|
||||
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() );
|
||||
}
|
||||
}
|
||||
}
|
||||
log.debug( "Finishing indexing task on repo: " + repository.getId() );
|
||||
finishIndexingTask( indexingTask, repository, context );
|
||||
}
|
||||
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" );
|
||||
}
|
||||
@ -157,6 +152,13 @@ public void executeTask( Task task )
|
||||
indexerEngine.update( context, ac );
|
||||
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
|
||||
{
|
||||
@ -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()
|
||||
throws InitializationException
|
||||
{
|
||||
|
@ -41,6 +41,8 @@ public enum Action
|
||||
|
||||
private final IndexingContext context;
|
||||
|
||||
private boolean executeOnEntireRepo = true;
|
||||
|
||||
public ArtifactIndexingTask( ManagedRepositoryConfiguration repository, File resourceFile, Action action,
|
||||
IndexingContext context )
|
||||
{
|
||||
@ -50,6 +52,23 @@ public ArtifactIndexingTask( ManagedRepositoryConfiguration repository, File res
|
||||
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()
|
||||
{
|
||||
return 0;
|
||||
|
@ -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>
|
@ -26,6 +26,8 @@
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
@ -45,6 +47,7 @@
|
||||
import org.sonatype.nexus.index.FlatSearchResponse;
|
||||
import org.sonatype.nexus.index.IndexerEngine;
|
||||
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.packer.IndexPacker;
|
||||
|
||||
|
@ -188,6 +188,12 @@
|
||||
<lifecycle-handler>basic</lifecycle-handler>
|
||||
</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.
|
||||
-->
|
||||
|
4
pom.xml
4
pom.xml
@ -557,12 +557,12 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.lucene</groupId>
|
||||
<artifactId>lucene-core</artifactId>
|
||||
<version>2.4.0</version>
|
||||
<version>2.4.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.lucene</groupId>
|
||||
<artifactId>lucene-queries</artifactId>
|
||||
<version>2.4.0</version>
|
||||
<version>2.4.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.mail</groupId>
|
||||
|
Loading…
x
Reference in New Issue
Block a user