import org.apache.archiva.repository.content.BaseArtifactTypes;
import org.apache.archiva.repository.content.ItemSelector;
import org.apache.archiva.repository.content.Project;
-import org.apache.archiva.repository.content.Version;
import org.apache.archiva.repository.content.base.ArchivaItemSelector;
import org.apache.archiva.repository.maven.MavenManagedRepository;
import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
import javax.inject.Inject;
import javax.inject.Named;
-import javax.jcr.Item;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
.withNamespace( "javax.sql" )
.withProjectId( "jdbc" )
.withVersion( "2.0" ).build();
- Stream<? extends Artifact> stream = repoContent.newArtifactStream( selector );
- assertNotNull( stream );
- List<? extends Artifact> results = stream.collect( Collectors.toList( ) );
+ try(Stream<? extends Artifact> stream = repoContent.newArtifactStream( selector ))
+ {
+ assertNotNull( stream );
+ List<? extends Artifact> results = stream.collect( Collectors.toList( ) );
+ checkArtifactListWithVersionSelector1( results );
+ }
+ }
+
+ @Test
+ public void testGetArtifactListWithVersionSelector() {
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( "javax.sql" )
+ .withProjectId( "jdbc" )
+ .withVersion( "2.0" ).build();
+ List<? extends Artifact> results = repoContent.getArtifacts( selector );
+ checkArtifactListWithVersionSelector1( results );
+ }
+
+ private void checkArtifactListWithVersionSelector1( List<? extends Artifact> results )
+ {
+ assertNotNull( results );
assertEquals( 2, results.size( ) );
Artifact mainArtifact = results.stream( ).filter( a -> a.getFileName( ).equals( "jdbc-2.0.jar" ) ).findFirst( ).get( );
assertNotNull( mainArtifact );
assertNotNull( metaArtifact );
assertEquals( MavenTypes.REPOSITORY_METADATA, metaArtifact.getArtifactType( ) );
}
+
+ @Test
+ public void testGetArtifactStreamWithVersionSelector2() {
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( "org.apache.axis2" )
+ .withProjectId( "axis2" )
+ .withVersion( "1.3-SNAPSHOT" ).build();
+ try(Stream<? extends Artifact> stream = repoContent.newArtifactStream( selector ))
+ {
+ assertNotNull( stream );
+ List<? extends Artifact> results = stream.collect( Collectors.toList( ) );
+ checkArtifactListWithVersionSelector2( results );
+ }
+ }
+
+ @Test
+ public void testGetArtifactListWithVersionSelector2() {
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( "org.apache.axis2" )
+ .withProjectId( "axis2" )
+ .withVersion( "1.3-SNAPSHOT" ).build();
+ List<? extends Artifact> results = repoContent.getArtifacts( selector );
+ checkArtifactListWithVersionSelector2( results );
+ }
+
+ private void checkArtifactListWithVersionSelector2( List<? extends Artifact> results )
+ {
+ assertNotNull( results );
+ assertEquals( 39, results.size( ) );
+
+ Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equals( "axis2-1.3-20070725.210059-1.pom" ) )
+ .findFirst( ).get( );
+
+ assertNotNull( artifact );
+ assertEquals( "pom", artifact.getExtension( ) );
+ assertEquals( BaseArtifactTypes.MAIN, artifact.getArtifactType( ) );
+ assertEquals( "1.3-SNAPSHOT", artifact.getVersion( ).getVersion( ) );
+ assertEquals( "1.3-20070725.210059-1", artifact.getArtifactVersion( ) );
+ assertEquals( ".pom", artifact.getRemainder( ) );
+ assertEquals( "axis2", artifact.getId( ) );
+ assertEquals( "axis2", artifact.getVersion( ).getProject( ).getId( ) );
+ assertEquals( "org.apache.axis2", artifact.getVersion( ).getProject( ).getNamespace( ).getNamespace( ) );
+ assertEquals( "", artifact.getClassifier( ) );
+ assertEquals( "pom", artifact.getType( ) );
+
+ artifact = null;
+ artifact = results.stream( ).filter( a -> a.getFileName( ).equals( "axis2-1.3-20070725.210059-1.pom.md5" ) )
+ .findFirst( ).get( );
+
+ assertNotNull( artifact );
+ assertEquals( "md5", artifact.getExtension( ) );
+ assertEquals( BaseArtifactTypes.RELATED, artifact.getArtifactType( ) );
+ assertEquals( "1.3-SNAPSHOT", artifact.getVersion( ).getVersion( ) );
+ assertEquals( "1.3-20070725.210059-1", artifact.getArtifactVersion( ) );
+ assertEquals( ".pom.md5", artifact.getRemainder( ) );
+ assertEquals( "axis2", artifact.getId( ) );
+ assertEquals( "axis2", artifact.getVersion( ).getProject( ).getId( ) );
+ assertEquals( "org.apache.axis2", artifact.getVersion( ).getProject( ).getNamespace( ).getNamespace( ) );
+ assertEquals( "", artifact.getClassifier( ) );
+ assertEquals( "md5", artifact.getType( ) );
+
+
+ artifact = null;
+ artifact = results.stream( ).filter( a -> a.getFileName( ).equals( "maven-metadata.xml" ) )
+ .findFirst( ).get( );
+ assertNotNull( artifact );
+ assertEquals( BaseArtifactTypes.METADATA, artifact.getArtifactType( ) );
+ assertEquals( "1.3-SNAPSHOT", artifact.getVersion( ).getVersion( ) );
+ assertEquals( "xml", artifact.getExtension( ) );
+ }
+
+ @Test
+ public void testGetArtifactListWithArtifactSelector1() {
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( "org.apache.axis2" )
+ .withProjectId( "axis2" )
+ .withVersion( "1.3-SNAPSHOT" )
+ .withArtifactVersion( "1.3-20070731.113304-21" )
+ .withExtension( "pom" )
+ .build( );
+ List<? extends Artifact> results = repoContent.getArtifacts( selector );
+ checkArtifactListWithArtifactSelector1( results );
+ }
+
+ @Test
+ public void testGetArtifactStreamWithArtifactSelector1() {
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( "org.apache.axis2" )
+ .withProjectId( "axis2" )
+ .withVersion( "1.3-SNAPSHOT" )
+ .withArtifactVersion( "1.3-20070731.113304-21" )
+ .withExtension( "pom" )
+ .build( );
+ try(Stream<? extends Artifact> results = repoContent.newArtifactStream( selector ))
+ {
+ checkArtifactListWithArtifactSelector1( results.collect( Collectors.toList()) );
+ }
+ }
+
+ private void checkArtifactListWithArtifactSelector1( List<? extends Artifact> results )
+ {
+ assertNotNull( results );
+ assertEquals( 1, results.size( ) );
+ Artifact artifact = results.get( 0 );
+ assertEquals( "pom", artifact.getExtension( ) );
+ assertEquals( BaseArtifactTypes.MAIN, artifact.getArtifactType( ) );
+ }
+
+ @Test
+ public void testGetArtifactListWithArtifactSelector2() {
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( "org.apache.axis2" )
+ .withProjectId( "axis2" )
+ .withVersion( "1.3-SNAPSHOT" )
+ .withArtifactVersion( "1.3-20070731.113304-21" )
+ .withExtension( "pom" )
+ .includeRelatedArtifacts()
+ .build( );
+ List<? extends Artifact> results = repoContent.getArtifacts( selector );
+
+ checkArtifactListWithArtifactSelector2( results );
+
+ }
+
+ @Test
+ public void testGetArtifactStreamWithArtifactSelector2() {
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( "org.apache.axis2" )
+ .withProjectId( "axis2" )
+ .withVersion( "1.3-SNAPSHOT" )
+ .withArtifactVersion( "1.3-20070731.113304-21" )
+ .withExtension( "pom" )
+ .includeRelatedArtifacts()
+ .build( );
+ try(Stream<? extends Artifact> results = repoContent.newArtifactStream( selector ))
+ {
+ checkArtifactListWithArtifactSelector2( results.collect( Collectors.toList()) );
+ }
+ }
+
+ private void checkArtifactListWithArtifactSelector2( List<? extends Artifact> results )
+ {
+ assertNotNull( results );
+ assertEquals( 3, results.size( ) );
+ Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "axis2-1.3-20070731.113304-21.pom" ) )
+ .findFirst( ).get( );
+ assertNotNull( artifact );
+ assertEquals( "pom", artifact.getExtension( ) );
+ assertEquals( BaseArtifactTypes.MAIN, artifact.getArtifactType( ) );
+
+ artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "axis2-1.3-20070731.113304-21.pom.sha1" ) )
+ .findFirst( ).get( );
+ assertNotNull( artifact );
+ assertEquals( "sha1", artifact.getExtension( ) );
+ assertEquals( BaseArtifactTypes.RELATED, artifact.getArtifactType( ) );
+ }
+
+
+ @Test
+ public void testArtifactListWithProjectSelector1() {
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( "org.apache.maven.shared" )
+ .withProjectId( "maven-downloader" )
+ .build( );
+ List<? extends Artifact> results = repoContent.getArtifacts( selector );
+ checkArtifactListWithProjectSelector1( results );
+
+ }
+
+ @Test
+ public void testArtifactStreamWithProjectSelector1() {
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( "org.apache.maven.shared" )
+ .withProjectId( "maven-downloader" )
+ .build( );
+ Stream<? extends Artifact> results = repoContent.newArtifactStream( selector );
+ checkArtifactListWithProjectSelector1( results.collect( Collectors.toList()) );
+
+ }
+
+ private void checkArtifactListWithProjectSelector1( List<? extends Artifact> results )
+ {
+ assertNotNull( results );
+ assertEquals( 27, results.size( ) );
+
+ Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "maven-metadata.xml" ) )
+ .findFirst( ).get( );
+ assertNotNull( artifact );
+ assertEquals( "xml", artifact.getExtension( ) );
+ assertEquals( BaseArtifactTypes.METADATA, artifact.getArtifactType( ) );
+
+ artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "maven-downloader-1.0-sources.jar" ) )
+ .findFirst( ).get( );
+ assertNotNull( artifact );
+ assertEquals( BaseArtifactTypes.MAIN, artifact.getArtifactType( ) );
+ assertEquals( "sources", artifact.getClassifier( ) );
+ assertEquals( "java-source", artifact.getType( ) );
+
+ artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "maven-downloader-1.0-sources.jar.sha1" ) )
+ .findFirst( ).get( );
+ assertNotNull( artifact );
+ assertEquals( BaseArtifactTypes.RELATED, artifact.getArtifactType( ) );
+ assertEquals( "sources", artifact.getClassifier( ) );
+ assertEquals( "sha1", artifact.getType( ) );
+ assertEquals( ".jar.sha1", artifact.getRemainder( ) );
+ }
+
}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org</groupId>
+ <artifactId>multilevel</artifactId>
+ <name>Multilevel Test</name>
+ <version>1.0</version>
+ <packaging>pom</packaging>
+
+ <organization>
+ <name>Company</name>
+ <url>http://www.company.com/</url>
+ </organization>
+ <inceptionYear>2002</inceptionYear>
+
+ <modules>
+ <module>api</module>
+ <module>common</module>
+ <module>broker</module>
+ <module>endpoint</module>
+ </modules>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <dependencyManagement>
+ <dependencies>
+ <!-- common version strategy -->
+ <dependency>
+ <groupId>javax.activation</groupId>
+ <artifactId>activation</artifactId>
+ <version>1.0.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.jms</groupId>
+ <artifactId>jms</artifactId>
+ <version>1.0.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.ejb</groupId>
+ <artifactId>ejb</artifactId>
+ <version>2.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ <version>1.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ <version>2.0.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring</artifactId>
+ <version>2.0.7</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-mock</artifactId>
+ <version>2.0.7</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jdbc</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.8</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-discovery</groupId>
+ <artifactId>commons-discovery</artifactId>
+ <version>0.2</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-id</groupId>
+ <artifactId>commons-id</artifactId>
+ <version>0.1-dev</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.castor</groupId>
+ <artifactId>castor</artifactId>
+ <version>1.0.5-xml</version>
+ </dependency>
+ <dependency>
+ <groupId>xerces</groupId>
+ <artifactId>xerces</artifactId>
+ <version>2.4.0</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ <version>1.0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ <version>3.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>com.thoughtworks.xstream</groupId>
+ <artifactId>xstream</artifactId>
+ <version>1.2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.management</groupId>
+ <artifactId>jmxri</artifactId>
+ <version>1.2.1</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+</project>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.multilevel</groupId>
+ <artifactId>test</artifactId>
+ <name>Multilevel Test Sub 1</name>
+ <version>1.0</version>
+ <packaging>pom</packaging>
+
+ <organization>
+ <name>Company</name>
+ <url>http://www.company.com/</url>
+ </organization>
+ <inceptionYear>2002</inceptionYear>
+
+ <modules>
+ <module>api</module>
+ <module>common</module>
+ <module>broker</module>
+ <module>endpoint</module>
+ </modules>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <dependencyManagement>
+ <dependencies>
+ <!-- common version strategy -->
+ <dependency>
+ <groupId>javax.activation</groupId>
+ <artifactId>activation</artifactId>
+ <version>1.0.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.jms</groupId>
+ <artifactId>jms</artifactId>
+ <version>1.0.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.ejb</groupId>
+ <artifactId>ejb</artifactId>
+ <version>2.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ <version>1.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ <version>2.0.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring</artifactId>
+ <version>2.0.7</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-mock</artifactId>
+ <version>2.0.7</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jdbc</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.8</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-discovery</groupId>
+ <artifactId>commons-discovery</artifactId>
+ <version>0.2</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-id</groupId>
+ <artifactId>commons-id</artifactId>
+ <version>0.1-dev</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.castor</groupId>
+ <artifactId>castor</artifactId>
+ <version>1.0.5-xml</version>
+ </dependency>
+ <dependency>
+ <groupId>xerces</groupId>
+ <artifactId>xerces</artifactId>
+ <version>2.4.0</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ <version>1.0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ <version>3.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>com.thoughtworks.xstream</groupId>
+ <artifactId>xstream</artifactId>
+ <version>1.2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.management</groupId>
+ <artifactId>jmxri</artifactId>
+ <version>1.2.1</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+</project>