mirror of https://github.com/apache/archiva.git
[MRM-528] run consumers as artifacts arrive via proxy
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@580187 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
15e551e983
commit
bc5df1bd8a
|
@ -72,12 +72,6 @@
|
|||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-container-default</artifactId>
|
||||
</dependency>
|
||||
<!-- Test Deps -->
|
||||
<dependency>
|
||||
<groupId>easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -113,6 +113,8 @@ public abstract class AbstractRepositoryPurge
|
|||
artifact.getType() );
|
||||
|
||||
artifactDao.deleteArtifact( queriedArtifact );
|
||||
|
||||
// TODO [MRM-37]: re-run the database consumers to clean up
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -80,11 +80,6 @@
|
|||
<artifactId>plexus-registry-commons</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -60,11 +60,6 @@
|
|||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -44,11 +44,6 @@
|
|||
<groupId>org.codehaus.plexus.cache</groupId>
|
||||
<artifactId>plexus-cache-ehcache</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-slf4j-logging</artifactId>
|
||||
|
|
|
@ -76,11 +76,6 @@
|
|||
<artifactId>xmlunit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-slf4j-logging</artifactId>
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutF
|
|||
import org.apache.maven.archiva.repository.layout.LayoutException;
|
||||
import org.apache.maven.archiva.repository.metadata.MetadataTools;
|
||||
import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException;
|
||||
import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers;
|
||||
import org.apache.maven.wagon.ConnectionException;
|
||||
import org.apache.maven.wagon.ResourceDoesNotExistException;
|
||||
import org.apache.maven.wagon.Wagon;
|
||||
|
@ -115,6 +116,11 @@ public class DefaultRepositoryProxyConnectors
|
|||
|
||||
private Map networkProxyMap = new HashMap();
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private RepositoryContentConsumers consumers;
|
||||
|
||||
/**
|
||||
* Fetch an artifact from a remote repository.
|
||||
*
|
||||
|
@ -475,6 +481,9 @@ public class DefaultRepositoryProxyConnectors
|
|||
return null;
|
||||
}
|
||||
|
||||
// Just-in-time update of the index and database by executing the consumers for this artifact
|
||||
consumers.executeConsumers( connector.getSourceRepository(), localFile );
|
||||
|
||||
// Everything passes.
|
||||
return localFile;
|
||||
}
|
||||
|
|
|
@ -61,6 +61,10 @@
|
|||
<role-hint>default</role-hint>
|
||||
<field-name>urlFailureCache</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
|
||||
<field-name>consumers</field-name>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
|
||||
|
|
|
@ -61,6 +61,10 @@
|
|||
<role-hint>default</role-hint>
|
||||
<field-name>urlFailureCache</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
|
||||
<field-name>consumers</field-name>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
|
||||
|
|
|
@ -61,6 +61,10 @@
|
|||
<role-hint>default</role-hint>
|
||||
<field-name>urlFailureCache</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
|
||||
<field-name>consumers</field-name>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
|
||||
|
|
|
@ -61,6 +61,10 @@
|
|||
<role-hint>default</role-hint>
|
||||
<field-name>urlFailureCache</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
|
||||
<field-name>consumers</field-name>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
|
||||
|
|
|
@ -87,6 +87,10 @@
|
|||
<role-hint>default</role-hint>
|
||||
<field-name>urlFailureCache</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
|
||||
<field-name>consumers</field-name>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
|
||||
|
|
|
@ -65,6 +65,10 @@
|
|||
<role-hint>default</role-hint>
|
||||
<field-name>urlFailureCache</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
|
||||
<field-name>consumers</field-name>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
|
||||
|
|
|
@ -61,6 +61,10 @@
|
|||
<role-hint>default</role-hint>
|
||||
<field-name>urlFailureCache</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
|
||||
<field-name>consumers</field-name>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
|
||||
|
|
|
@ -88,11 +88,6 @@
|
|||
<artifactId>plexus-registry-commons</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-slf4j-logging</artifactId>
|
||||
|
|
|
@ -24,16 +24,20 @@ import org.apache.commons.collections.CollectionUtils;
|
|||
import org.apache.commons.collections.Predicate;
|
||||
import org.apache.commons.collections.functors.IfClosure;
|
||||
import org.apache.commons.collections.functors.OrPredicate;
|
||||
import org.apache.maven.archiva.common.utils.PathUtil;
|
||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||
import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
|
||||
import org.apache.maven.archiva.consumers.ConsumerException;
|
||||
import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
|
||||
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
|
||||
import org.apache.maven.archiva.consumers.RepositoryContentConsumer;
|
||||
import org.apache.maven.archiva.consumers.functors.PermanentConsumerPredicate;
|
||||
import org.apache.maven.archiva.model.ArchivaRepository;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -59,12 +63,12 @@ public class RepositoryContentConsumers
|
|||
/**
|
||||
* @plexus.requirement role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
|
||||
*/
|
||||
private List availableKnownConsumers;
|
||||
private List<KnownRepositoryContentConsumer> availableKnownConsumers;
|
||||
|
||||
/**
|
||||
* @plexus.requirement role="org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer"
|
||||
*/
|
||||
private List availableInvalidConsumers;
|
||||
private List<InvalidRepositoryContentConsumer> availableInvalidConsumers;
|
||||
|
||||
private Predicate selectedKnownPredicate;
|
||||
|
||||
|
@ -186,13 +190,55 @@ public class RepositoryContentConsumers
|
|||
return ret;
|
||||
}
|
||||
|
||||
public List getAvailableKnownConsumers()
|
||||
public List<KnownRepositoryContentConsumer> getAvailableKnownConsumers()
|
||||
{
|
||||
return availableKnownConsumers;
|
||||
}
|
||||
|
||||
public List getAvailableInvalidConsumers()
|
||||
public List<InvalidRepositoryContentConsumer> getAvailableInvalidConsumers()
|
||||
{
|
||||
return availableInvalidConsumers;
|
||||
}
|
||||
|
||||
public void setAvailableKnownConsumers( List<KnownRepositoryContentConsumer> availableKnownConsumers )
|
||||
{
|
||||
this.availableKnownConsumers = availableKnownConsumers;
|
||||
}
|
||||
|
||||
public void setAvailableInvalidConsumers( List<InvalidRepositoryContentConsumer> availableInvalidConsumers )
|
||||
{
|
||||
this.availableInvalidConsumers = availableInvalidConsumers;
|
||||
}
|
||||
|
||||
public void executeConsumers( ArchivaRepository repository, File localFile )
|
||||
{
|
||||
// Run the repository consumers
|
||||
for ( RepositoryContentConsumer consumer : availableKnownConsumers )
|
||||
{
|
||||
consumeFile( consumer, repository, localFile );
|
||||
}
|
||||
|
||||
for ( RepositoryContentConsumer consumer : availableInvalidConsumers )
|
||||
{
|
||||
consumeFile( consumer, repository, localFile );
|
||||
}
|
||||
}
|
||||
|
||||
private void consumeFile( RepositoryContentConsumer consumer, ArchivaRepository repository, File localFile )
|
||||
{
|
||||
try
|
||||
{
|
||||
consumer.beginScan( repository );
|
||||
consumer.processFile( PathUtil.getRelative( repository.getUrl().getPath(), localFile ) );
|
||||
}
|
||||
catch ( ConsumerException e )
|
||||
{
|
||||
getLogger().error( "Error processing file: " + localFile, e );
|
||||
// ignore, let next repo scan handle it
|
||||
}
|
||||
finally
|
||||
{
|
||||
consumer.completeScan();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,15 +19,20 @@ package org.apache.maven.archiva.repository.scanner;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
|
||||
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
|
||||
import org.apache.maven.archiva.consumers.RepositoryContentConsumer;
|
||||
import org.apache.maven.archiva.model.ArchivaRepository;
|
||||
import org.codehaus.plexus.PlexusTestCase;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* RepositoryContentConsumerUtilTest
|
||||
* RepositoryContentConsumerUtilTest
|
||||
*
|
||||
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
|
@ -71,7 +76,7 @@ public class RepositoryContentConsumerUtilTest
|
|||
assertNotNull( "Known[sample-known] should not be null.", o );
|
||||
assertInstanceof( "Known[sample-known]", RepositoryContentConsumer.class, o );
|
||||
assertInstanceof( "Known[sample-known]", KnownRepositoryContentConsumer.class, o );
|
||||
|
||||
|
||||
Map invalidConsumerMap = consumerutil.getSelectedInvalidConsumersMap();
|
||||
assertNotNull( "Invalid Consumer Map should not be null", invalidConsumerMap );
|
||||
assertEquals( "Invalid Consumer Map.size", 0, invalidConsumerMap.size() );
|
||||
|
@ -81,8 +86,8 @@ public class RepositoryContentConsumerUtilTest
|
|||
{
|
||||
if ( clazz.isInstance( o ) == false )
|
||||
{
|
||||
fail( msg + ": Object [" + o.getClass().getName() + "] should have been an instanceof [" + clazz.getName()
|
||||
+ "]" );
|
||||
fail( msg + ": Object [" + o.getClass().getName() + "] should have been an instanceof [" + clazz.getName() +
|
||||
"]" );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,4 +105,36 @@ public class RepositoryContentConsumerUtilTest
|
|||
assertNotNull( "invalid consumers should not be null.", invalidConsumers );
|
||||
assertEquals( "invalid consumers", 0, invalidConsumers.size() );
|
||||
}
|
||||
|
||||
public void testExecution()
|
||||
throws Exception
|
||||
{
|
||||
MockControl knownControl = MockControl.createControl( KnownRepositoryContentConsumer.class );
|
||||
RepositoryContentConsumers consumers = lookupRepositoryConsumerUtil();
|
||||
KnownRepositoryContentConsumer knownConsumer = (KnownRepositoryContentConsumer) knownControl.getMock();
|
||||
consumers.setAvailableKnownConsumers( Collections.singletonList( knownConsumer ) );
|
||||
|
||||
MockControl invalidControl = MockControl.createControl( InvalidRepositoryContentConsumer.class );
|
||||
InvalidRepositoryContentConsumer invalidConsumer = (InvalidRepositoryContentConsumer) invalidControl.getMock();
|
||||
consumers.setAvailableInvalidConsumers( Collections.singletonList( invalidConsumer ) );
|
||||
|
||||
ArchivaRepository repo =
|
||||
new ArchivaRepository( "id", "name", getTestFile( "target/test-repo" ).toURL().toExternalForm() );
|
||||
File testFile = getTestFile( "target/test-repo/path/to/test-file.txt" );
|
||||
|
||||
knownConsumer.beginScan( repo );
|
||||
knownConsumer.processFile( "path/to/test-file.txt" );
|
||||
knownConsumer.completeScan();
|
||||
knownControl.replay();
|
||||
|
||||
invalidConsumer.beginScan( repo );
|
||||
invalidConsumer.processFile( "path/to/test-file.txt" );
|
||||
invalidConsumer.completeScan();
|
||||
invalidControl.replay();
|
||||
|
||||
consumers.executeConsumers( repo, testFile );
|
||||
|
||||
knownControl.verify();
|
||||
invalidControl.verify();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,11 +58,6 @@
|
|||
<artifactId>hsqldb</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-slf4j-logging</artifactId>
|
||||
|
|
|
@ -235,12 +235,6 @@
|
|||
<version>${redback.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- Test Deps -->
|
||||
<dependency>
|
||||
<groupId>easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package org.apache.maven.archiva.web.repository;
|
||||
|
||||
import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers;
|
||||
|
||||
public class StubRepositoryContentConsumers
|
||||
extends RepositoryContentConsumers
|
||||
{
|
||||
}
|
|
@ -38,6 +38,13 @@
|
|||
</configuration>
|
||||
</component>
|
||||
|
||||
<!-- Don't drag in the world just to test this -->
|
||||
<component>
|
||||
<role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
|
||||
<role-hint>default</role-hint>
|
||||
<implementation>org.apache.maven.archiva.web.repository.StubRepositoryContentConsumers</implementation>
|
||||
</component>
|
||||
|
||||
<!-- TODO: shouldn't need so many components just to use in-memory - is flaky since these are auto-generated -->
|
||||
<component>
|
||||
<role>org.codehaus.plexus.redback.system.SecuritySystem</role>
|
||||
|
|
11
pom.xml
11
pom.xml
|
@ -190,6 +190,12 @@
|
|||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<version>1.2_Java1.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
|
@ -370,11 +376,6 @@
|
|||
<artifactId>dom4j</artifactId>
|
||||
<version>1.6.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<version>1.2_Java1.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>hsqldb</groupId>
|
||||
<artifactId>hsqldb</artifactId>
|
||||
|
|
Loading…
Reference in New Issue