[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
This commit is contained in:
Maria Odea B. Ching 2011-06-16 13:12:22 +00:00
parent ea6a0644af
commit 969e7fb37f
18 changed files with 243 additions and 20 deletions

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>

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>

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>

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>

View File

@ -29,8 +29,10 @@
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 ModelResolver newCopy()
// 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 @@ private boolean getModelFromProxy( RemoteRepositoryConfiguration remoteRepositor
{
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." );

View File

@ -450,7 +450,8 @@ public void testGetProjectVersionMetadataForMissingPom()
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 void testGetProjectVersionMetadataWithParentSuccessful()
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 void testGetProjectVersionMetadataWithParentNoRemoteReposConfigured()
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 void testGetProjectVersionMetadataWithParentNoRemoteReposConfigured()
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 void testGetProjectVersionMetadataWithParentNotInAnyRemoteRepo()
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 @@ private void checkOrganizationApache( ProjectVersionMetadata metadata )
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 @@ private void deleteTestArtifactWithParent()
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() );

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>

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>

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>