From: Martin Stockhammer Date: Sat, 14 Mar 2020 11:51:04 +0000 (+0100) Subject: Adding additional tests X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2e477224ffec5e5247ae014c8dfee83769adf938;p=archiva.git Adding additional tests --- diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java index ef4ec97d8..a69ab4a20 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java @@ -444,6 +444,12 @@ public class ManagedDefaultRepositoryContent } } 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 = ""; @@ -464,6 +470,11 @@ public class ManagedDefaultRepositoryContent 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 = ""; @@ -627,6 +638,15 @@ public class ManagedDefaultRepositoryContent 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_\\-.]+" ); @@ -637,7 +657,7 @@ public class ManagedDefaultRepositoryContent { if ( "*".equals( classifier ) ) { - fileNamePattern.append( "-[A-Za-z0-9]+\\." ); + fileNamePattern.append( "(-[A-Za-z0-9]+)?\\." ); } else { @@ -677,8 +697,13 @@ public class ManagedDefaultRepositoryContent * namespace and project are returned. *
  • If a namespace and a project id or artifact id and a version is given, the artifacts of the given * version are returned
  • + *
  • 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).
  • * * + * 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. diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java index 4f1d936b2..d32d0f732 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java @@ -714,6 +714,21 @@ public class ManagedDefaultRepositoryContentTest .recurse() .build( ); List results = repoContent.getArtifacts( selector ); + checkArtifactListWithNamespaceSelectorRecursive( results ); + } + + @Test + public void testArtifactStreamWithNamespaceSelectorRecursive() { + ItemSelector selector = ArchivaItemSelector.builder( ) + .withNamespace( "org.multilevel" ) + .recurse() + .build( ); + Stream results = repoContent.newArtifactStream( selector ); + checkArtifactListWithNamespaceSelectorRecursive( results.collect( Collectors.toList()) ); + } + + private void checkArtifactListWithNamespaceSelectorRecursive( List results ) + { assertNotNull( results ); assertEquals( 6, results.size( ) ); @@ -726,6 +741,114 @@ public class ManagedDefaultRepositoryContentTest .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 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 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 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 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( ) ); }