Index: archiva-consumer-plugin-archetype/src/main/resources/META-INF/maven/archetype.xml =================================================================== --- archiva-consumer-plugin-archetype/src/main/resources/META-INF/maven/archetype.xml (revision 0) +++ archiva-consumer-plugin-archetype/src/main/resources/META-INF/maven/archetype.xml (revision 0) @@ -0,0 +1,12 @@ + + archiva-consumer-plugin-archetype + + src/main/java/org/example/consumer/SimpleArtifactConsumer.java + + + src/test/java/org/example/consumer/SimpleArtifactConsumerTest.java + + + src/test/resources/org/example/consumer/SimpleArtifactConsumerTest.xml + + Index: archiva-consumer-plugin-archetype/src/main/resources/archetype-resources/src/test/java/org/example/consumer/SimpleArtifactConsumerTest.java =================================================================== --- archiva-consumer-plugin-archetype/src/main/resources/archetype-resources/src/test/java/org/example/consumer/SimpleArtifactConsumerTest.java (revision 0) +++ archiva-consumer-plugin-archetype/src/main/resources/archetype-resources/src/test/java/org/example/consumer/SimpleArtifactConsumerTest.java (revision 0) @@ -0,0 +1,104 @@ +package org.example.consumer; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.File; + +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.logging.Logger; +import org.easymock.EasyMock; + +/** + * SimpleArtifactConsumerTest + */ +public class SimpleArtifactConsumerTest + extends PlexusTestCase +{ + private SimpleArtifactConsumer consumer; + + private File repoDir; + + private ManagedRepositoryConfiguration testRepository; + + private Logger mockLogger; + + protected void setUp() + throws Exception + { + super.setUp(); + String consumerRole = KnownRepositoryContentConsumer.class.getName(); + consumer = (SimpleArtifactConsumer) lookup( consumerRole, "simple-artifact-consumer" ); + + setUpMockRepository(); + setupMockLogger(); + } + + private void setupMockLogger() + { + mockLogger = (Logger) EasyMock.createNiceMock(Logger.class); + consumer.enableLogging( mockLogger ); + } + + private void setUpMockRepository() + { + repoDir = new java.io.File( getBasedir(), "/target/test-consumer-repo" ); + repoDir.mkdirs(); + repoDir.deleteOnExit(); + + testRepository = new ManagedRepositoryConfiguration(); + testRepository.setName( "Test-Consumer-Repository" ); + testRepository.setId( "test-consumer-repository" ); + testRepository.setLocation( repoDir.getAbsolutePath() ); + } + + public void testBeginScan() + throws Exception + { + mockLogger.info( "Beginning scan of repository [test-consumer-repository]" ); + EasyMock.expectLastCall(); + EasyMock.replay(mockLogger); + + consumer.beginScan( testRepository ); + + EasyMock.verify(); + } + + public void testProcessFile() + throws Exception + { + mockLogger.info( "Beginning scan of repository [test-consumer-repository]" ); + EasyMock.expectLastCall(); + mockLogger.info( "Processing entry [org/simple/test/testartifact/testartifact/1.0/testartifact-1.0.pom]" + + " from repository [test-consumer-repository]" ); + EasyMock.expectLastCall(); + mockLogger.info( "Processing entry [org/simple/test/testartifact/testartifact/1.1/testartifact-1.1.pom]" + + " from repository [test-consumer-repository]" ); + EasyMock.expectLastCall(); + EasyMock.replay(mockLogger); + + consumer.beginScan( testRepository ); + consumer.processFile( "org/simple/test/testartifact/testartifact/1.0/testartifact-1.0.pom" ); + consumer.processFile( "org/simple/test/testartifact/testartifact/1.1/testartifact-1.1.pom" ); + EasyMock.verify(mockLogger); + } + +} Index: archiva-consumer-plugin-archetype/src/main/resources/archetype-resources/src/main/java/org/example/consumer/SimpleArtifactConsumer.java =================================================================== --- archiva-consumer-plugin-archetype/src/main/resources/archetype-resources/src/main/java/org/example/consumer/SimpleArtifactConsumer.java (revision 0) +++ archiva-consumer-plugin-archetype/src/main/resources/archetype-resources/src/main/java/org/example/consumer/SimpleArtifactConsumer.java (revision 0) @@ -0,0 +1,142 @@ +package org.example.consumer; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.FileTypes; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; +import org.apache.maven.archiva.consumers.ConsumerException; +import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; +import org.codehaus.plexus.registry.Registry; +import org.codehaus.plexus.registry.RegistryListener; + +/** + * SimpleArtifactConsumer + * + * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer" + * role-hint="simple-artifact-consumer" instantiation-strategy="per-lookup" + */ +public class SimpleArtifactConsumer + extends AbstractMonitoredConsumer + implements KnownRepositoryContentConsumer, RegistryListener, Initializable +{ + /** + * @plexus.configuration default-value="simple-artifact-consumer" + */ + private String id; + + /** + * @plexus.configuration default-value="Simple consumer to illustrate how to consume the contents of a repository." + */ + private String description; + + /** + * @plexus.requirement + */ + private FileTypes filetypes; + + /** + * @plexus.requirement + */ + private ArchivaConfiguration configuration; + + private List propertyNameTriggers = new ArrayList(); + + private List includes = new ArrayList(); + + /** current repository being scanned */ + private ManagedRepositoryConfiguration repository; + + public void beginScan( ManagedRepositoryConfiguration repository ) + throws ConsumerException + { + this.repository = repository; + getLogger().info( "Beginning scan of repository [" + this.repository.getId() + "]" ); + } + + public void processFile( String path ) + throws ConsumerException + { + getLogger().info( "Processing entry [" + path + "] from repository [" + this.repository.getId() + "]" ); + } + + public void completeScan() + { + getLogger().info( "Finished scan of repository [" + this.repository.getId() + "]" ); + } + + /** + * Used by archiva to determine if the consumer wishes to process all of a repository's entries or just those that + * have been modified since the last scan. + * + * @return boolean true if the consumer wishes to process all entries on each scan, false for only those modified + * since the last scan + */ + public boolean isProcessUnmodified() + { + return super.isProcessUnmodified(); + } + + public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) + { + if ( propertyNameTriggers.contains( propertyName ) ) + { + initIncludes(); + } + } + + public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue ) + { + /* do nothing */ + } + + private void initIncludes() + { + includes.clear(); + includes.addAll( filetypes.getFileTypePatterns( FileTypes.INDEXABLE_CONTENT ) ); + } + + public void initialize() + throws InitializationException + { + propertyNameTriggers = new ArrayList(); + propertyNameTriggers.add( "repositoryScanning" ); + propertyNameTriggers.add( "fileTypes" ); + propertyNameTriggers.add( "fileType" ); + propertyNameTriggers.add( "patterns" ); + propertyNameTriggers.add( "pattern" ); + + configuration.addChangeListener( this ); + + initIncludes(); + } + + public String getId() + { + return this.id; + } + + public String getDescription() + { + return this.description; + } + + public List getExcludes() + { + return null; + } + + public List getIncludes() + { + return this.includes; + } + + public boolean isPermanent() + { + return false; + } +} Index: archiva-consumer-plugin-archetype/src/main/resources/archetype-resources/pom.xml =================================================================== --- archiva-consumer-plugin-archetype/src/main/resources/archetype-resources/pom.xml (revision 0) +++ archiva-consumer-plugin-archetype/src/main/resources/archetype-resources/pom.xml (revision 0) @@ -0,0 +1,92 @@ + + 4.0.0 + ${groupId} + ${artifactId} + 1.0-SNAPSHOT + jar + Simple Archiva Consumer + http://maven.apache.org + + This is a simple consumer component which demonstrates how a + component can be plugged in Archiva. + + + + org.apache.maven.archiva + archiva-consumer-api + 1.1-SNAPSHOT + + + org.apache.maven.archiva + archiva-configuration + 1.1-SNAPSHOT + + + org.apache.maven.archiva + archiva-repository-layer + 1.1-SNAPSHOT + + + org.apache.maven.archiva + archiva-indexer + 1.1-SNAPSHOT + + + org.easymock + easymock + 2.2 + test + + + + + + + org.codehaus.plexus + plexus-maven-plugin + 1.3.5 + + + generate + + descriptor + + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + package + package + + + + Remember to add the the following to the knownconsumers section in ~/.m2/archiva.xml + <knownContentConsumer>simple-artifact-consumer</knownContentConsumer> + + + + + run + + + + + + maven-compiler-plugin + + 1.5 + 1.5 + + + + + Index: archiva-consumer-plugin-archetype/pom.xml =================================================================== --- archiva-consumer-plugin-archetype/pom.xml (revision 0) +++ archiva-consumer-plugin-archetype/pom.xml (revision 0) @@ -0,0 +1,9 @@ + + 4.0.0 + org.apache.maven.archiva + archiva-consumer-plugin-archetype + 1.1-SNAPSHOT + Archiva Consumers :: Consumers Plugin Archetype + Simple archetype to create archiva consumers +