<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>
<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>
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;
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;
// 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;
{
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." );
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" );
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
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" );
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" );
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
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" );
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() );