Browse Source

[MRM-1411] project information is missing if a POM could not be read correctly

o for snapshot artifacts, get the timestamp and build number first from the metadata in the remote repo before proxying the actual parent pom 
o added unit tests, removed checksums and other test files that are not necessarily used


git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1136424 13f79535-47bb-0310-9956-ffa450edef68
tags/archiva-1.4-M1
Maria Odea B. Ching 13 years ago
parent
commit
969e7fb37f
18 changed files with 243 additions and 20 deletions
  1. 5
    0
      archiva-modules/archiva-base/archiva-configuration/pom.xml
  2. 5
    0
      archiva-modules/archiva-base/archiva-repository-scanner/pom.xml
  3. 44
    0
      archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-security/pom.xml
  4. 5
    0
      archiva-modules/plugins/maven2-repository/pom.xml
  5. 38
    2
      archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java
  6. 76
    10
      archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java
  7. BIN
      archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-artifact-module-a/1.0/test-artifact-module-a-1.0.jar
  8. 0
    1
      archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-artifact-module-a/1.0/test-artifact-module-a-1.0.jar.md5
  9. 0
    1
      archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-artifact-module-a/1.0/test-artifact-module-a-1.0.jar.sha1
  10. 0
    1
      archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-artifact-module-a/1.0/test-artifact-module-a-1.0.pom.md5
  11. 0
    1
      archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-artifact-module-a/1.0/test-artifact-module-a-1.0.pom.sha1
  12. 0
    1
      archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-artifact-parent/1/test-artifact-parent-1.pom.md5
  13. 0
    1
      archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-artifact-parent/1/test-artifact-parent-1.pom.sha1
  14. 0
    1
      archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-artifact-root/1.0/test-artifact-root-1.0.pom.md5
  15. 0
    1
      archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-artifact-root/1.0/test-artifact-root-1.0.pom.sha1
  16. 18
    0
      archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-snapshot-artifact-module-a/1.1-SNAPSHOT/test-snapshot-artifact-module-a-1.1-SNAPSHOT.pom
  17. 13
    0
      archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-snapshot-artifact-root/1.1-SNAPSHOT/maven-metadata.xml
  18. 39
    0
      archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-snapshot-artifact-root/1.1-SNAPSHOT/test-snapshot-artifact-root-1.1-20100310.014828-2.pom

+ 5
- 0
archiva-modules/archiva-base/archiva-configuration/pom.xml View File

@@ -91,6 +91,11 @@
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-policies</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>

+ 5
- 0
archiva-modules/archiva-base/archiva-repository-scanner/pom.xml View File

@@ -45,5 +45,10 @@
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

+ 44
- 0
archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-security/pom.xml View File

@@ -41,6 +41,36 @@
<dependency>
<groupId>org.codehaus.redback</groupId>
<artifactId>redback-system</artifactId>
<exclusions>
<exclusion>
<groupId>org.codehaus.redback</groupId>
<artifactId>plexus-spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.plexus.registry</groupId>
<artifactId>plexus-registry-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.plexus.registry</groupId>
<artifactId>plexus-registry-commons</artifactId>
</exclusion>
<exclusion>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.plexus.cache</groupId>
<artifactId>plexus-cache-ehcache</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.plexus.cache</groupId>
<artifactId>plexus-cache-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
@@ -59,6 +89,20 @@
<groupId>org.codehaus.redback</groupId>
<artifactId>redback-authorization-rbac</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.plexus.cache</groupId>
<artifactId>plexus-cache-ehcache</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.plexus.cache</groupId>
<artifactId>plexus-cache-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.redback</groupId>

+ 5
- 0
archiva-modules/plugins/maven2-repository/pom.xml View File

@@ -96,6 +96,11 @@
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<!-- TODO: aim to remove this dependency -->
<dependency>
<groupId>org.apache.archiva</groupId>

+ 38
- 2
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java View File

@@ -29,8 +29,10 @@ import org.apache.archiva.proxy.common.WagonFactory;
import org.apache.archiva.proxy.common.WagonFactoryException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
import org.apache.maven.archiva.xml.XMLException;
import org.apache.maven.model.Repository;
import org.apache.maven.model.building.FileModelSource;
import org.apache.maven.model.building.ModelSource;
@@ -63,6 +65,8 @@ public class RepositoryModelResolver

private static final Logger log = LoggerFactory.getLogger( RepositoryModelResolver.class );

private static final String METADATA_FILENAME = "maven-metadata.xml";

// key/value: remote repo ID/network proxy
Map<String, ProxyInfo> networkProxyMap;

@@ -139,7 +143,8 @@ public class RepositoryModelResolver
// because it's causing a cyclic dependency
private boolean getModelFromProxy( RemoteRepositoryConfiguration remoteRepository, String groupId,
String artifactId, String version, String filename )
throws AuthorizationException, TransferFailedException, ResourceDoesNotExistException, WagonFactoryException
throws AuthorizationException, TransferFailedException, ResourceDoesNotExistException, WagonFactoryException,
XMLException
{
boolean success = false;
File tmpMd5 = null;
@@ -167,8 +172,39 @@ public class RepositoryModelResolver
{
tmpResource = new File( workingDirectory, filename );

if ( VersionUtil.isSnapshot( version ) )
{
// get the metadata first!
File tmpMetadataResource = new File( workingDirectory, METADATA_FILENAME );

String metadataPath = StringUtils.substringBeforeLast( artifactPath, "/" ) + "/" + METADATA_FILENAME;

wagon.get( metadataPath, tmpMetadataResource );

log.debug( "Successfully downloaded metadata." );

MavenRepositoryMetadata metadata = MavenRepositoryMetadataReader.read( tmpMetadataResource );

// re-adjust to timestamp if present, otherwise retain the original -SNAPSHOT filename
MavenRepositoryMetadata.Snapshot snapshotVersion = metadata.getSnapshotVersion();
String timestampVersion = version;
if ( snapshotVersion != null )
{
timestampVersion =
timestampVersion.substring( 0, timestampVersion.length() - 8 ); // remove SNAPSHOT from end
timestampVersion =
timestampVersion + snapshotVersion.getTimestamp() + "-" + snapshotVersion.getBuildNumber();

filename = artifactId + "-" + timestampVersion + ".pom";

artifactPath = pathTranslator.toPath( groupId, artifactId, version, filename );

log.debug( "New artifactPath : " + artifactPath );
}
}

log.info( "Retrieving " + artifactPath + " from " + remoteRepository.getName() );
wagon.get( artifactPath, tmpResource );

log.debug( "Downloaded successfully." );

+ 76
- 10
archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java View File

@@ -450,7 +450,8 @@ public class Maven2RepositoryMetadataResolverTest
public void testGetProjectVersionMetadataWithParentSuccessful()
throws Exception
{
copyTestArtifactWithParent();
copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
"target/test-repository/com/example/test/test-artifact-module-a" );

ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test",
"test-artifact-module-a", "1.0" );
@@ -480,7 +481,12 @@ public class Maven2RepositoryMetadataResolverTest
assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );

deleteTestArtifactWithParent();
List<String> paths = new ArrayList<String>();
paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
paths.add( "target/test-repository/com/example/test/test-artifact-root" );

deleteTestArtifactWithParent( paths );
}

@Test
@@ -494,7 +500,8 @@ public class Maven2RepositoryMetadataResolverTest

configuration.save( config );

copyTestArtifactWithParent();
copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
"target/test-repository/com/example/test/test-artifact-module-a" );

ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test",
"test-artifact-module-a", "1.0" );
@@ -506,14 +513,20 @@ public class Maven2RepositoryMetadataResolverTest
assertEquals( "test-artifact-module-a", facet.getArtifactId() );
assertEquals( "jar", facet.getPackaging() );

deleteTestArtifactWithParent();
List<String> paths = new ArrayList<String>();
paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
paths.add( "target/test-repository/com/example/test/test-artifact-root" );

deleteTestArtifactWithParent( paths );
}

@Test
public void testGetProjectVersionMetadataWithParentNotInAnyRemoteRepo()
throws Exception
{
copyTestArtifactWithParent();
copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
"target/test-repository/com/example/test/test-artifact-module-a" );

ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-parent", "1.1" );

@@ -525,7 +538,53 @@ public class Maven2RepositoryMetadataResolverTest
assertEquals( "missing-parent", facet.getArtifactId() );
assertEquals( "jar", facet.getPackaging() );

deleteTestArtifactWithParent();
List<String> paths = new ArrayList<String>();
paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
paths.add( "target/test-repository/com/example/test/test-artifact-root" );

deleteTestArtifactWithParent( paths );
}

@Test
public void testGetProjectVersionMetadataWithParentSnapshotVersion()
throws Exception
{
copyTestArtifactWithParent( "target/test-classes/com/example/test/test-snapshot-artifact-module-a",
"target/test-repository/com/example/test/test-snapshot-artifact-module-a" );

ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test",
"test-snapshot-artifact-module-a", "1.1-SNAPSHOT" );

MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
assertEquals( "jar", facet.getPackaging() );
assertEquals( "com.example.test", facet.getParent().getGroupId() );
assertEquals( "test-snapshot-artifact-root", facet.getParent().getArtifactId() );
assertEquals( "1.1-SNAPSHOT", facet.getParent().getVersion() );
assertEquals( "test-snapshot-artifact-module-a", facet.getArtifactId() );
assertEquals( "com.example.test", facet.getGroupId() );
assertNull( metadata.getCiManagement() );
assertNotNull( metadata.getDescription() );

checkApacheLicense( metadata );

assertEquals( "1.1-SNAPSHOT", metadata.getId() );
assertEquals( "Test Snapshot Artifact :: Module A", metadata.getName() );
String path = "test-snapshot-artifact/trunk/test-snapshot-artifact-module-a";
assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );

List<Dependency> dependencies = metadata.getDependencies();
assertEquals( 2, dependencies.size() );
assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );

List<String> paths = new ArrayList<String>();
paths.add( "target/test-repository/com/example/test/test-snapshot-artifact-module-a" );
paths.add( "target/test-repository/com/example/test/test-snapshot-artifact-root" );

deleteTestArtifactWithParent( paths );
}

// Tests for MRM-1411 - END
@@ -735,9 +794,16 @@ public class Maven2RepositoryMetadataResolverTest
assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );
}

private void deleteTestArtifactWithParent()
private void deleteTestArtifactWithParent( List<String> pathsToBeDeleted )
throws IOException
{
for( String path : pathsToBeDeleted )
{
File dir = new File( FileUtil.getBasedir(), path );
FileUtils.deleteDirectory( dir );

assertFalse( dir.exists() );
}
File dest = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" );
File parentPom = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" );
File rootPom = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" );
@@ -751,11 +817,11 @@ public class Maven2RepositoryMetadataResolverTest
assertFalse( rootPom.exists() );
}

private File copyTestArtifactWithParent()
private File copyTestArtifactWithParent( String srcPath, String destPath )
throws IOException
{
File src = new File( FileUtil.getBasedir(), "target/test-classes/com/example/test/test-artifact-module-a" );
File dest = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" );
File src = new File( FileUtil.getBasedir(), srcPath );
File dest = new File( FileUtil.getBasedir(), destPath );

FileUtils.copyDirectory( src, dest );
assertTrue( dest.exists() );

BIN
archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-artifact-module-a/1.0/test-artifact-module-a-1.0.jar View File


+ 0
- 1
archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-artifact-module-a/1.0/test-artifact-module-a-1.0.jar.md5 View File

@@ -1 +0,0 @@
37786de9e272ed6db8541855e0e2d5dc

+ 0
- 1
archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-artifact-module-a/1.0/test-artifact-module-a-1.0.jar.sha1 View File

@@ -1 +0,0 @@
bb1ca7834422926d0cb79ef303b715bc17f41661

+ 0
- 1
archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-artifact-module-a/1.0/test-artifact-module-a-1.0.pom.md5 View File

@@ -1 +0,0 @@
61a4d030260fc6bee0681cf99ba54674

+ 0
- 1
archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-artifact-module-a/1.0/test-artifact-module-a-1.0.pom.sha1 View File

@@ -1 +0,0 @@
6f54bc4223bc39d7880420f66baa3a24d7f9c181

+ 0
- 1
archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-artifact-parent/1/test-artifact-parent-1.pom.md5 View File

@@ -1 +0,0 @@
92c60efe85e23fe5afd8a854cea87209

+ 0
- 1
archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-artifact-parent/1/test-artifact-parent-1.pom.sha1 View File

@@ -1 +0,0 @@
6eca3509acf66023c29e2bc17f73e79d1d1a341a

+ 0
- 1
archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-artifact-root/1.0/test-artifact-root-1.0.pom.md5 View File

@@ -1 +0,0 @@
034449f8696981edce2485b841a02a47

+ 0
- 1
archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-artifact-root/1.0/test-artifact-root-1.0.pom.sha1 View File

@@ -1 +0,0 @@
bef26aec1a0714cec7fa56cdbb7ebcdb452295eb

+ 18
- 0
archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-snapshot-artifact-module-a/1.1-SNAPSHOT/test-snapshot-artifact-module-a-1.1-SNAPSHOT.pom View File

@@ -0,0 +1,18 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example.test</groupId>
<artifactId>test-snapshot-artifact-root</artifactId>
<version>1.1-SNAPSHOT</version>
</parent>
<artifactId>test-snapshot-artifact-module-a</artifactId>
<packaging>jar</packaging>
<name>Test Snapshot Artifact :: Module A</name>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
</dependencies>
</project>

+ 13
- 0
archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-snapshot-artifact-root/1.1-SNAPSHOT/maven-metadata.xml View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.example.test</groupId>
<artifactId>test-snapshot-artifact-root</artifactId>
<version>1.1-SNAPSHOT</version>
<versioning>
<snapshot>
<timestamp>20100310.014828</timestamp>
<buildNumber>2</buildNumber>
</snapshot>
<lastUpdated>20100310014828</lastUpdated>
</versioning>
</metadata>

+ 39
- 0
archiva-modules/plugins/maven2-repository/src/test/resources/com/example/test/test-snapshot-artifact-root/1.1-SNAPSHOT/test-snapshot-artifact-root-1.1-20100310.014828-2.pom View File

@@ -0,0 +1,39 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example.test</groupId>
<artifactId>test-artifact-parent</artifactId>
<version>1</version>
</parent>
<artifactId>test-snapshot-artifact-root</artifactId>
<version>1.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Test Snapshot Artifact :: Root</name>
<description>This is the Test project.</description>
<modules>
<module>test-snapshot-artifact-module-a</module>
</modules>
<scm>
<connection>scm:svn:http://svn.example.com/repos/test-snapshot-artifact/trunk</connection>
<developerConnection>scm:svn:https://svn.example.com/repos/test-snapshot-artifact/trunk</developerConnection>
<url>http://svn.example.com/repos/test-snapshot-artifact/trunk</url>
</scm>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

Loading…
Cancel
Save