}
} else {
log.debug( "Artifact does not match the maven name pattern: {}", path );
+ if ( fileName.contains( "-"+baseVersion ) )
+ {
+ info.id = StringUtils.substringBefore( fileName, "-"+baseVersion );
+ } else {
+ info.id = fileName;
+ }
info.artifactType = BaseArtifactTypes.UNKNOWN;
info.version = "";
info.classifier = "";
info.remainder = classPostfix;
}
} else {
+ if (fileName.contains( "-"+genericVersion )) {
+ info.id = StringUtils.substringBefore( fileName, "-"+genericVersion );
+ } else {
+ info.id = fileName;
+ }
log.debug( "Artifact does not match the version pattern {}", path );
info.artifactType = BaseArtifactTypes.UNKNOWN;
info.version = "";
fileNamePattern.append("[A-Za-z0-9_\\-.]+-");
}
if (selector.hasArtifactVersion()) {
+ if ( selector.getArtifactVersion( ).contains("*")) {
+ String[] tokens = StringUtils.splitPreserveAllTokens( selector.getArtifactVersion( ), "*" );
+ for (String currentToken : tokens) {
+ if (!currentToken.equals("")) {
+ fileNamePattern.append( Pattern.quote( currentToken ) );
+ }
+ fileNamePattern.append( "[A-Za-z0-9_\\-.]*" );
+ }
+ }
fileNamePattern.append( Pattern.quote(selector.getArtifactVersion( )) );
} else {
fileNamePattern.append( "[A-Za-z0-9_\\-.]+" );
{
if ( "*".equals( classifier ) )
{
- fileNamePattern.append( "-[A-Za-z0-9]+\\." );
+ fileNamePattern.append( "(-[A-Za-z0-9]+)?\\." );
}
else
{
* namespace and project are returned.</li>
* <li>If a namespace and a project id or artifact id and a version is given, the artifacts of the given
* version are returned</li>
+ * <li>If no artifact version or artifact id is given, it will return all "artifacts" found in the directory.
+ * To select only artifacts that match the layout you should add the artifact id and artifact version
+ * (can contain a '*' pattern).</li>
* </ul>
*
+ * The '*' pattern can be used in classifiers and artifact versions and match zero or more characters.
+ *
* There is no determinate order of the elements in the stream.
*
* Returned streams are auto closable and should be used in a try-with-resources statement.
.recurse()
.build( );
List<? extends Artifact> results = repoContent.getArtifacts( selector );
+ checkArtifactListWithNamespaceSelectorRecursive( results );
+ }
+
+ @Test
+ public void testArtifactStreamWithNamespaceSelectorRecursive() {
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( "org.multilevel" )
+ .recurse()
+ .build( );
+ Stream<? extends Artifact> results = repoContent.newArtifactStream( selector );
+ checkArtifactListWithNamespaceSelectorRecursive( results.collect( Collectors.toList()) );
+ }
+
+ private void checkArtifactListWithNamespaceSelectorRecursive( List<? extends Artifact> results )
+ {
assertNotNull( results );
assertEquals( 6, results.size( ) );
.findFirst( ).get( );
assertNotNull( artifact );
assertEquals( 5, artifact.getAsset( ).getParent( ).getPath( ).split( "/" ).length );
+ }
+
+
+ @Test
+ public void testArtifactListWithArtifactSelector1() {
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( "org.apache.maven" )
+ .withProjectId( "test" )
+ .withVersion( "1.0-SNAPSHOT" )
+ .withArtifactId( "test" )
+ .withArtifactVersion( "1.0-20050611.112233-1" )
+ .build( );
+
+ List<? extends Artifact> results = repoContent.getArtifacts( selector );
+
+ assertNotNull( results );
+ assertEquals( 1, results.size( ) );
+
+ Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "test-1.0-20050611.112233-1.jar" ) )
+ .findFirst().get();
+ assertNotNull( artifact );
+ assertEquals( "", artifact.getClassifier( ) );
+ }
+
+ @Test
+ public void testArtifactListWithArtifactSelector2() {
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( "org.apache.maven" )
+ .withProjectId( "test" )
+ .withVersion( "1.0-SNAPSHOT" )
+ .withClassifier( "*" )
+ .withArtifactId( "test" )
+ .withArtifactVersion( "1.0-20050611.112233-1" )
+ .build( );
+
+ List<? extends Artifact> results = repoContent.getArtifacts( selector );
+
+ assertNotNull( results );
+ assertEquals( 2, results.size( ) );
+
+ Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "test-1.0-20050611.112233-1-javadoc.jar" ) )
+ .findFirst().get();
+ assertNotNull( artifact );
+ assertEquals( "javadoc", artifact.getClassifier( ) );
+ assertEquals( "javadoc", artifact.getType( ) );
+ }
+
+ @Test
+ public void testArtifactListWithArtifactSelector3() {
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( "org.apache.maven" )
+ .withProjectId( "test" )
+ .withVersion( "1.0-SNAPSHOT" )
+ .withClassifier( "*" )
+ .withArtifactVersion( "1.0-20050611.112233-1" )
+ .build( );
+
+ List<? extends Artifact> results = repoContent.getArtifacts( selector );
+
+ assertNotNull( results );
+ assertEquals( 3, results.size( ) );
+
+ Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "test-1.0-20050611.112233-1-javadoc.jar" ) )
+ .findFirst().get();
+ assertNotNull( artifact );
+ assertEquals( "javadoc", artifact.getClassifier( ) );
+ assertEquals( "javadoc", artifact.getType( ) );
+
+ artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "wrong-artifactId-1.0-20050611.112233-1.jar" ) )
+ .findFirst().get();
+ assertNotNull( artifact );
+ assertEquals( "", artifact.getClassifier( ) );
+ assertEquals( "wrong-artifactId", artifact.getId( ) );
+ }
+
+ @Test
+ public void testArtifactListWithArtifactSelectorAndRelated() {
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( "org.apache.maven" )
+ .withProjectId( "samplejar" )
+ .withVersion( "1.0" )
+ .withArtifactVersion( "1.0" )
+ .withArtifactId( "samplejar" )
+ .withExtension( "jar" )
+ .includeRelatedArtifacts()
+ .build( );
+
+ List<? extends Artifact> results = repoContent.getArtifacts( selector );
+
+ assertNotNull( results );
+ assertEquals( 3, results.size( ) );
+
+ Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "samplejar-1.0.jar" ) )
+ .findFirst().get();
+ assertNotNull( artifact );
+ assertEquals( BaseArtifactTypes.MAIN, artifact.getArtifactType( ) );
+
+ artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "samplejar-1.0.jar.md5" ) )
+ .findFirst().get();
+ assertNotNull( artifact );
+ assertEquals( BaseArtifactTypes.RELATED, artifact.getArtifactType( ) );
+ assertEquals( "md5", artifact.getExtension( ) );
+
+ artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "samplejar-1.0.jar.sha1" ) )
+ .findFirst().get();
+ assertNotNull( artifact );
+ assertEquals( BaseArtifactTypes.RELATED, artifact.getArtifactType( ) );
+ assertEquals( "sha1", artifact.getExtension( ) );
}