mirror of https://github.com/apache/archiva.git
[MRM-1859] Improve handling of invalid artifacts
Throws only exception if all artifacts are invalid. Ignores resolver-status.properties
This commit is contained in:
parent
e162e0a8db
commit
94e8342ec0
|
@ -304,6 +304,8 @@
|
|||
<exclude>src/test/resources/m1-repo-filelist.txt</exclude>
|
||||
<exclude>src/test/repositories/**</exclude>
|
||||
<exclude>src/test/expected-poms/**</exclude>
|
||||
<exclude>src/test/resources/resolver-status.properties</exclude>
|
||||
<exclude>src/test/resources/test01.properties</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
|
|
@ -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<ArtifactMetadata> artifacts = new ArrayList<>();
|
||||
if ( files != null )
|
||||
{
|
||||
int errorCount=0;
|
||||
for ( File file : files )
|
||||
{
|
||||
try {
|
||||
ArtifactMetadata metadata =
|
||||
getArtifactFromFile( readMetadataRequest.getRepositoryId(), readMetadataRequest.getNamespace(),
|
||||
getArtifactFromFile(readMetadataRequest.getRepositoryId(), readMetadataRequest.getNamespace(),
|
||||
readMetadataRequest.getProjectId(), readMetadataRequest.getProjectVersion(),
|
||||
file );
|
||||
artifacts.add( metadata );
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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) );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<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" );
|
||||
|
|
Loading…
Reference in New Issue