Selaa lähdekoodia

[MRM-1547] release an archetype to create consumer



git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1195071 13f79535-47bb-0310-9956-ffa450edef68
tags/archiva-1.4-M2
Olivier Lamy 12 vuotta sitten
vanhempi
commit
54f0882529

+ 62
- 0
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/pom.xml Näytä tiedosto

@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-parent</artifactId>
<version>7</version>
</parent>

<groupId>org.apache.archiva</groupId>
<artifactId>archiva-consumer-archetype</artifactId>
<version>1.4-SNAPSHOT</version>
<packaging>maven-archetype</packaging>
<name>Archiva Consumers :: Consumers Archetype</name>
<description>Simple archetype to create archiva consumers</description>
<properties>
<archivaVersion>1.4-M2-SNAPSHOT</archivaVersion>
</properties>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<extensions>
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
<version>2.1</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<version>2.1</version>
</plugin>
</plugins>
</build>

</project>

+ 16
- 0
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml Näytä tiedosto

@@ -0,0 +1,16 @@
<archetype-descriptor xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
name="archiva-consumer-archetype" partial="false">

<fileSets>
<fileSet filtered="true" packaged="true">
<directory>src/main/java</directory>
</fileSet>
<fileSet filtered="true" packaged="true">
<directory>src/test/java</directory>
</fileSet>
<fileSet filtered="true" packaged="false">
<directory>src/test/resources</directory>
</fileSet>
</fileSets>
</archetype-descriptor>

+ 85
- 0
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/pom.xml Näytä tiedosto

@@ -0,0 +1,85 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
<packaging>jar</packaging>
<name>Simple Archiva Consumer</name>
<url>http://maven.apache.org</url>
<description>
This is a simple consumer component which demonstrates how a
component can be plugged in Archiva.
</description>
<properties>
<archiva.version>${archivaVersion}</archiva.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-consumer-api</artifactId>
<version>${archiva.version}</version>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-configuration</artifactId>
<version>${archiva.version}</version>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-layer</artifactId>
<version>${archiva.version}</version>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-indexer</artifactId>
<version>${archiva.version}</version>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>package</id>
<phase>package</phase>
<configuration>
<tasks>
<echo>
Remember to add the the following to the knownconsumers section in ~/.m2/archiva.xml
&lt;knownContentConsumer>simple-artifact-consumer&lt;/knownContentConsumer>
</echo>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

+ 185
- 0
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/main/java/SimpleArtifactConsumer.java Näytä tiedosto

@@ -0,0 +1,185 @@
package $package;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.FileTypes;
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.archiva.consumers.AbstractMonitoredConsumer;
import org.apache.archiva.consumers.ConsumerException;
import org.apache.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;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.apache.archiva.admin.model.beans.ManagedRepository;

import javax.annotation.PostConstruct;

/**
* <code>SimpleArtifactConsumer</code>
*
*/
@Service("knownRepositoryContentConsumer#simple")
@Scope("prototype")
public class SimpleArtifactConsumer
extends AbstractMonitoredConsumer
implements KnownRepositoryContentConsumer, RegistryListener, Initializable
{

private Logger log = LoggerFactory.getLogger( SimpleArtifactConsumer.class );

/**
* default-value="simple-artifact-consumer"
*/
private String id = "simple-artifact-consumer";

/**
*
*/
private String description = "Simple consumer to illustrate how to consume the contents of a repository.";

/**
*
*/
@Inject
private FileTypes filetypes;

/**
*
*/
@Inject
private ArchivaConfiguration configuration;

private List propertyNameTriggers = new ArrayList();

private List includes = new ArrayList();

/** current repository being scanned */
private ManagedRepository repository;

public void beginScan( ManagedRepository repository )
throws ConsumerException
{
this.repository = repository;
log.info( "Beginning scan of repository [" + this.repository.getId() + "]" );
}

public void beginScan( ManagedRepository repository, Date whenGathered )
throws ConsumerException
{
this.repository = repository;
log.info( "Beginning scan of repository [" + this.repository.getId() + "]" );
}

public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
throws ConsumerException
{
this.repository = repository;
log.info( "Beginning scan of repository [" + this.repository.getId() + "]" );
}

public void processFile( String path )
throws ConsumerException
{
log.info( "Processing entry [" + path + "] from repository [" + this.repository.getId() + "]" );
}

public void processFile( String path, boolean executeOnEntireRepo )
throws ConsumerException
{
log.info( "Processing entry [" + path + "] from repository [" + this.repository.getId() + "]" );
}

public void completeScan()
{
log.info( "Finished scan of repository [" + this.repository.getId() + "]" );
}

public void completeScan( boolean executeOnEntireRepo )
{
log.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 ) );
}

@PostConstruct
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;
}
}

+ 100
- 0
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/SimpleArtifactConsumerTest.java Näytä tiedosto

@@ -0,0 +1,100 @@
package $package;

/*
* 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.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
import org.easymock.EasyMock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import junit.framework.TestCase;

/**
* <code>SimpleArtifactConsumerTest</code>
*/
@RunWith( SpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} )
public class SimpleArtifactConsumerTest
extends TestCase
{
@Inject
private SimpleArtifactConsumer consumer;

private File repoDir;

private ManagedRepository testRepository;

private Logger log = LoggerFactory.getLogger( SimpleArtifactConsumer.class );

@Before
public void setUp()
throws Exception
{
super.setUp();
String consumerRole = KnownRepositoryContentConsumer.class.getName();

setUpMockRepository();

}



private void setUpMockRepository()
{
repoDir = new java.io.File( "target/test-consumer-repo" );
repoDir.mkdirs();
repoDir.deleteOnExit();

testRepository = new ManagedRepository();
testRepository.setName( "Test-Consumer-Repository" );
testRepository.setId( "test-consumer-repository" );
testRepository.setLocation( repoDir.getAbsolutePath() );
}

@Test
public void testBeginScan()
throws Exception
{
log.info( "Beginning scan of repository [test-consumer-repository]" );

consumer.beginScan( testRepository );

}

@Test
public void testProcessFile()
throws Exception
{
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" );
}

}

+ 34
- 0
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/resources/spring-context.xml Näytä tiedosto

@@ -0,0 +1,34 @@
<?xml version="1.0"?>

<!--
~ 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
default-lazy-init="true">
<context:annotation-config/>
<context:component-scan base-package="$package"/>



</beans>

+ 4
- 0
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/test/resources/projects/compile/archetype.properties Näytä tiedosto

@@ -0,0 +1,4 @@
groupId=org.apache.archiva.consumer.its.compile
artifactId=simple-consumer-compile
version=1.0-SNAPSHOT
package=org.apache.archiva.consumer.its

+ 1
- 0
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/test/resources/projects/compile/goal.txt Näytä tiedosto

@@ -0,0 +1 @@
verify

Loading…
Peruuta
Tallenna