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();
List<ArtifactMetadata> 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;
{
return false;
}
- else if ( name.equals( METADATA_FILENAME ) )
+ else if ( Arrays.binarySearch(IGNORED_FILES, name)>=0 )
{
return false;
}
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;
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<ArtifactMetadata> testArtifacts = storage.readArtifactsMetadata(
+ new ReadMetadataRequest(TEST_REPO_ID, "com.example.test", "test-artifact", "1.0-SNAPSHOT", ALL));
+ List<ArtifactMetadata> artifacts = new ArrayList<>(testArtifacts);
+ Collections.sort(artifacts, new Comparator<ArtifactMetadata>() {
+ @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" );