diff --git a/archiva-modules/plugins/maven2-repository/pom.xml b/archiva-modules/plugins/maven2-repository/pom.xml
index c77e2ff65..cd65a89c4 100644
--- a/archiva-modules/plugins/maven2-repository/pom.xml
+++ b/archiva-modules/plugins/maven2-repository/pom.xml
@@ -304,6 +304,8 @@
src/test/resources/m1-repo-filelist.txt
src/test/repositories/**
src/test/expected-poms/**
+ src/test/resources/resolver-status.properties
+ src/test/resources/test01.properties
diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java
index 58a4dee56..efdb46087 100644
--- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java
+++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java
@@ -148,6 +148,9 @@ public class Maven2RepositoryStorage
private static final String METADATA_FILENAME = METADATA_FILENAME_START + ".xml";
+ // This array must be lexically sorted
+ private static final String[] IGNORED_FILES = { METADATA_FILENAME, "resolver-status.properties" };
+
private static final MavenXpp3Reader MAVEN_XPP_3_READER = new MavenXpp3Reader();
@@ -615,13 +618,25 @@ public class Maven2RepositoryStorage
List artifacts = new ArrayList<>();
if ( files != null )
{
+ int errorCount=0;
for ( File file : files )
{
- ArtifactMetadata metadata =
- getArtifactFromFile( readMetadataRequest.getRepositoryId(), readMetadataRequest.getNamespace(),
- readMetadataRequest.getProjectId(), readMetadataRequest.getProjectVersion(),
- file );
- artifacts.add( metadata );
+ try {
+ ArtifactMetadata metadata =
+ getArtifactFromFile(readMetadataRequest.getRepositoryId(), readMetadataRequest.getNamespace(),
+ readMetadataRequest.getProjectId(), readMetadataRequest.getProjectVersion(),
+ file);
+ artifacts.add(metadata);
+ } catch (Exception ex) {
+ LOGGER.error("Error while retrieving metadata of file {} (Project: {}, Repository: {}): {}",
+ file.getName(), readMetadataRequest.getProjectId(), readMetadataRequest.getRepositoryId(),
+ ex.getMessage());
+ errorCount++;
+ }
+ }
+ // We throw only an error, if the number of errors equals the number of files
+ if (errorCount>0 && errorCount==files.length) {
+ throw new RepositoryStorageRuntimeException(readMetadataRequest.getRepositoryId(), "Could not retrieve metadata of the files");
}
}
return artifacts;
@@ -1016,7 +1031,7 @@ public class Maven2RepositoryStorage
{
return false;
}
- else if ( name.equals( METADATA_FILENAME ) )
+ else if ( Arrays.binarySearch(IGNORED_FILES, name)>=0 )
{
return false;
}
diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTestMaven3.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTestMaven3.java
index c277434d8..93f6bc7fb 100644
--- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTestMaven3.java
+++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/dependency/tree/maven2/DependencyTreeBuilderTestMaven3.java
@@ -101,11 +101,14 @@ public class DependencyTreeBuilderTestMaven3
builder.buildDependencyTree( Collections.singletonList( TEST_REPO_ID ), TEST_GROUP_ID, TEST_ARTIFACT_ID,
TEST_VERSION );
- assertThat( treeEntries ).isNotNull().isNotEmpty().contains(
- new TreeEntry( new Artifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, "", "" ) ) );
+ Artifact artifact = new Artifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, "", "" );
+ artifact.setFileExtension("jar");
+ assertThat( treeEntries ).isNotNull().isNotEmpty().contains(new TreeEntry(artifact) );
+ artifact = new Artifact( "commons-lang", "commons-lang", "2.2", "compile", "" );
+ artifact.setFileExtension("jar");
assertThat( treeEntries.get( 0 ).getChilds() ).isNotNull().isNotEmpty().contains(
- new TreeEntry( new Artifact( "commons-lang", "commons-lang", "2.2", "compile", "" ) ) );
+ new TreeEntry(artifact) );
}
diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java
index 3f3b8e2dc..24e9b2609 100644
--- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java
+++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java
@@ -52,6 +52,12 @@ import javax.inject.Inject;
import javax.inject.Named;
import java.io.File;
import java.io.IOException;
+import java.net.URL;
+import java.nio.file.CopyOption;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -324,6 +330,90 @@ public class Maven2RepositoryMetadataResolverTest
assertEquals( "pom", facet.getType() );
}
+ @Test
+ public void testGetArtifactMetadataSnapshotsMRM1859()
+ throws Exception
+ {
+ Path repoDir = Paths.get("target/test-repository/com/example/test/test-artifact/1.0-SNAPSHOT");
+ URL url = Thread.currentThread().getContextClassLoader().getResource("resolver-status.properties");
+ Path resFile = Paths.get(url.toURI());
+ Path destFile = repoDir.resolve(resFile.getFileName());
+ Files.copy(resFile, destFile, StandardCopyOption.REPLACE_EXISTING);
+ URL url2 = Thread.currentThread().getContextClassLoader().getResource("test01.properties");
+ Path resFile2 = Paths.get(url2.toURI());
+ Path destFile2 = repoDir.resolve(resFile2.getFileName());
+ Files.copy(resFile2, destFile2, StandardCopyOption.REPLACE_EXISTING);
+
+ try {
+
+
+ Collection testArtifacts = storage.readArtifactsMetadata(
+ new ReadMetadataRequest(TEST_REPO_ID, "com.example.test", "test-artifact", "1.0-SNAPSHOT", ALL));
+ List artifacts = new ArrayList<>(testArtifacts);
+ Collections.sort(artifacts, new Comparator() {
+ @Override
+ public int compare(ArtifactMetadata o1, ArtifactMetadata o2) {
+ return o1.getId().compareTo(o2.getId());
+ }
+ });
+
+ assertEquals(6, artifacts.size());
+
+ ArtifactMetadata artifactMetadata = artifacts.get(0);
+ assertEquals("test-artifact-1.0-20100308.230825-1.jar", artifactMetadata.getId());
+ MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
+ assertEquals(1, facet.getBuildNumber());
+ assertEquals("20100308.230825", facet.getTimestamp());
+ assertNull(facet.getClassifier());
+ assertEquals("jar", facet.getType());
+
+ artifactMetadata = artifacts.get(1);
+ assertEquals("test-artifact-1.0-20100308.230825-1.pom", artifactMetadata.getId());
+ facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
+ assertEquals(1, facet.getBuildNumber());
+ assertEquals("20100308.230825", facet.getTimestamp());
+ assertNull(facet.getClassifier());
+ assertEquals("pom", facet.getType());
+
+ artifactMetadata = artifacts.get(2);
+ assertEquals("test-artifact-1.0-20100310.014828-2-javadoc.jar", artifactMetadata.getId());
+ facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
+ assertEquals(2, facet.getBuildNumber());
+ assertEquals("20100310.014828", facet.getTimestamp());
+ assertEquals("javadoc", facet.getClassifier());
+ assertEquals("javadoc", facet.getType());
+
+ artifactMetadata = artifacts.get(3);
+ assertEquals("test-artifact-1.0-20100310.014828-2-sources.jar", artifactMetadata.getId());
+ facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
+ assertEquals(2, facet.getBuildNumber());
+ assertEquals("20100310.014828", facet.getTimestamp());
+ assertEquals("sources", facet.getClassifier());
+ assertEquals("java-source", facet.getType());
+
+ artifactMetadata = artifacts.get(4);
+ assertEquals("test-artifact-1.0-20100310.014828-2.jar", artifactMetadata.getId());
+ facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
+ assertEquals(2, facet.getBuildNumber());
+ assertEquals("20100310.014828", facet.getTimestamp());
+ assertNull(facet.getClassifier());
+ assertEquals("jar", facet.getType());
+
+ artifactMetadata = artifacts.get(5);
+ assertEquals("test-artifact-1.0-20100310.014828-2.pom", artifactMetadata.getId());
+ facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
+ assertEquals(2, facet.getBuildNumber());
+ assertEquals("20100310.014828", facet.getTimestamp());
+ assertNull(facet.getClassifier());
+ assertEquals("pom", facet.getType());
+
+ } finally {
+ Files.delete(destFile);
+ Files.delete(destFile2);
+ }
+
+ }
+
private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
{
assertDependency( dependency, groupId, artifactId, version, "compile" );
diff --git a/archiva-modules/plugins/maven2-repository/src/test/resources/resolver-status.properties b/archiva-modules/plugins/maven2-repository/src/test/resources/resolver-status.properties
new file mode 100644
index 000000000..e69de29bb
diff --git a/archiva-modules/plugins/maven2-repository/src/test/resources/test01.properties b/archiva-modules/plugins/maven2-repository/src/test/resources/test01.properties
new file mode 100644
index 000000000..e69de29bb