[MRM-1194] Archiva doesn't cope with versions in a pom.xml that are properties

o get latest timestamped file if no -SNAPSHOT exists when resolving the pom
o added tests


git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@801946 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Maria Odea B. Ching 2009-08-07 11:00:03 +00:00
parent 06ac3284ec
commit d150a6ed98
12 changed files with 358 additions and 5 deletions

View File

@ -420,4 +420,9 @@ public class ManagedDefaultRepositoryContent
return false;
}
}
public void setFiletypes( FileTypes filetypes )
{
this.filetypes = filetypes;
}
}

View File

@ -20,16 +20,23 @@ package org.apache.maven.archiva.repository.project.resolvers;
*/
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.maven.archiva.common.utils.VersionComparator;
import org.apache.maven.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.apache.maven.archiva.model.VersionedReference;
import org.apache.maven.archiva.repository.ContentNotFoundException;
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.apache.maven.archiva.repository.project.ProjectModelException;
import org.apache.maven.archiva.repository.project.ProjectModelReader;
import org.apache.maven.archiva.repository.project.ProjectModelResolver;
import org.apache.maven.archiva.xml.XMLException;
/**
* Resolve Project from managed repository.
*
@ -50,12 +57,33 @@ public class ManagedRepositoryProjectResolver
public ArchivaProjectModel resolveProjectModel( VersionedReference reference )
throws ProjectModelException
{
{
ArchivaArtifact artifact = new ArchivaArtifact( reference.getGroupId(), reference.getArtifactId(), reference
.getVersion(), "", "pom", repository.getId() );
File repoFile = repository.toFile( artifact );
// MRM-1194
if( !repoFile.exists() && VersionUtil.isGenericSnapshot( reference.getVersion() ) )
{
// check if a timestamped version exists, get the latest if true
try
{
List<String> versions = new ArrayList<String>( repository.getVersions( reference ) );
Collections.sort( versions, VersionComparator.getInstance() );
String latestSnapshot = versions.get( versions.size() - 1 );
artifact =
new ArchivaArtifact( reference.getGroupId(), reference.getArtifactId(), latestSnapshot, "", "pom",
repository.getId() );
repoFile = repository.toFile( artifact );
}
catch( ContentNotFoundException e )
{
throw new ProjectModelException( e.getMessage(), e );
}
}
try
{
return reader.read( repoFile );
@ -65,5 +93,4 @@ public class ManagedRepositoryProjectResolver
throw new ProjectModelException( e.getMessage(), e );
}
}
}

View File

@ -21,6 +21,7 @@ package org.apache.maven.archiva.repository.project.filters;
import org.apache.maven.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.model.Dependency;
import org.apache.maven.archiva.model.Individual;
import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase;
@ -84,6 +85,7 @@ public class EffectiveProjectModelFilterTest
assertEffectiveProject(
"/org/apache/maven/archiva/archiva-model/1.0-SNAPSHOT/archiva-model-1.0-SNAPSHOT.pom",
"/archiva-model-effective.pom");
assertEffectiveProject(
"/test-project/test-project-endpoint-ejb/2.4.4/test-project-endpoint-ejb-2.4.4.pom",
"/test-project-model-effective.pom");
@ -220,6 +222,49 @@ public class EffectiveProjectModelFilterTest
assertTrue( passedWagonVersionChecking );
}
// MRM-1194
public void testEffectiveProjectPropertyExistingParentHasUniqueSnapshotVersion()
throws Exception
{
initTestResolverFactory();
EffectiveProjectModelFilter filter = lookupEffective();
String pomFile = "/org/apache/archiva/sample-project/2.1-SNAPSHOT/sample-project-2.1-SNAPSHOT.pom";
ArchivaProjectModel startModel = createArchivaProjectModel( DEFAULT_REPOSITORY + pomFile );
String buildHelperPluginVersion = "1.0";
boolean passedBuildHelperVersionChecking = false;
List<ArtifactReference> startPlugins = startModel.getPlugins();
for( ArtifactReference plugin : startPlugins )
{
if( "build-helper-maven-plugin".equals( plugin.getArtifactId() ) )
{
assertEquals( "${build-helper-maven-plugin.version}", plugin.getVersion() );
}
}
ArchivaProjectModel effectiveModel = filter.filter( startModel );
List<ArtifactReference> effectivePlugins = effectiveModel.getPlugins();
for( ArtifactReference plugin : effectivePlugins )
{
if( "build-helper-maven-plugin".equals( plugin.getArtifactId() ) )
{
assertEquals( buildHelperPluginVersion, plugin.getVersion() );
if ( !passedBuildHelperVersionChecking )
{
passedBuildHelperVersionChecking = true;
}
}
}
assertTrue( passedBuildHelperVersionChecking );
}
private ProjectModelResolverFactory initTestResolverFactory()
throws Exception
{
@ -241,7 +286,7 @@ public class EffectiveProjectModelFilterTest
assertContainsSameDependencies( "Dependencies", expectedModel.getDependencies(), effectiveModel
.getDependencies() );
assertContainsSameDependencies( "DependencyManagement", expectedModel.getDependencyManagement(), effectiveModel
.getDependencyManagement() );
.getDependencyManagement() );
}
private void dumpDependencyList( String type, List<Dependency> deps )

View File

@ -0,0 +1,138 @@
package org.apache.maven.archiva.repository.project.resolvers;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.File;
import org.apache.maven.archiva.configuration.FileTypes;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.apache.maven.archiva.model.VersionedReference;
import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
import org.apache.maven.archiva.repository.project.readers.ProjectModel400Reader;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
public class ManagedRepositoryProjectResolverTest
extends PlexusInSpringTestCase
{
private ManagedRepositoryProjectResolver resolver;
public void setUp() throws Exception
{
super.setUp();
FileTypes fileTypes = new MockFileTypes();
ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
repoConfig.setId( "test-repo" );
repoConfig.setLocation( new File( getBasedir(), "target/test-classes/test-repo" ).getPath() );
repoConfig.setName( "Test Repository" );
ManagedDefaultRepositoryContent repository = new ManagedDefaultRepositoryContent();
repository.setRepository( repoConfig );
repository.setFiletypes( fileTypes );
resolver = new ManagedRepositoryProjectResolver( repository, new ProjectModel400Reader() );
}
public void testResolveSnapshotUniqueVersionPresent()
throws Exception
{
VersionedReference ref = new VersionedReference();
ref.setGroupId( "org.apache.archiva" );
ref.setArtifactId( "unique-version" );
ref.setVersion( "1.0-SNAPSHOT" );
try
{
ArchivaProjectModel model = resolver.resolveProjectModel( ref );
assertNotNull( model );
assertEquals( "org.apache.archiva", model.getGroupId() );
assertEquals( "unique-version", model.getArtifactId() );
assertEquals( "1.0-SNAPSHOT", model.getVersion() );
assertEquals( "Unique Version Snapshot - Build 3", model.getName() );
}
catch ( Exception e )
{
fail( "The latest timestamp should have been found!" );
}
}
public void testResolveSnapshotGenericVersionPresent()
throws Exception
{
VersionedReference ref = new VersionedReference();
ref.setGroupId( "org.apache.archiva" );
ref.setArtifactId( "generic-version" );
ref.setVersion( "1.0-SNAPSHOT" );
ArchivaProjectModel model = resolver.resolveProjectModel( ref );
assertNotNull( model );
assertEquals( "org.apache.archiva", model.getGroupId() );
assertEquals( "generic-version", model.getArtifactId() );
assertEquals( "1.0-SNAPSHOT", model.getVersion() );
}
public void testResolveSuccessful()
throws Exception
{
VersionedReference ref = new VersionedReference();
ref.setGroupId( "org.apache.archiva" );
ref.setArtifactId( "released-version" );
ref.setVersion( "1.0" );
ArchivaProjectModel model = resolver.resolveProjectModel( ref );
assertNotNull( model );
assertEquals( "org.apache.archiva", model.getGroupId() );
assertEquals( "released-version", model.getArtifactId() );
assertEquals( "1.0", model.getVersion() );
}
public void testResolveNotFound()
throws Exception
{
VersionedReference ref = new VersionedReference();
ref.setGroupId( "org.apache.archiva" );
ref.setArtifactId( "non-existant" );
ref.setVersion( "2.0" );
try
{
resolver.resolveProjectModel( ref );
fail( "An exception should have been thrown." );
}
catch( Exception e )
{
assertTrue( true );
}
}
class MockFileTypes
extends FileTypes
{
public boolean matchesArtifactPattern( String relativePath )
{
return true;
}
}
}

View File

@ -0,0 +1,23 @@
<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>
<groupId>org.apache.archiva</groupId>
<artifactId>sample-parent</artifactId>
<packaging>pom</packaging>
<version>2.1-SNAPSHOT</version>
<name>sample-parent Build 1</name>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<properties>
<build-helper-maven-plugin.version>1.0</build-helper-maven-plugin.version>
</properties>
</project>

View File

@ -0,0 +1,23 @@
<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>
<groupId>org.apache.archiva</groupId>
<artifactId>sample-parent</artifactId>
<packaging>pom</packaging>
<version>2.1-SNAPSHOT</version>
<name>sample-parent Build 2</name>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<properties>
<build-helper-maven-plugin.version>1.0</build-helper-maven-plugin.version>
</properties>
</project>

View File

@ -0,0 +1,47 @@
<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>org.apache.archiva</groupId>
<artifactId>sample-parent</artifactId>
<version>2.1-SNAPSHOT</version>
</parent>
<artifactId>sample-project</artifactId>
<packaging>jar</packaging>
<name>sample-project</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
<inherited>true</inherited>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/java-gen</source>
<source>${basedir}/java-src</source>
<source>${basedir}/java-test</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,9 @@
<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>
<groupId>org.apache.archiva</groupId>
<artifactId>generic-version</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Generic Snapshot Version</name>
<packaging>pom</packaging>
</project>

View File

@ -0,0 +1,9 @@
<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>
<groupId>org.apache.archiva</groupId>
<artifactId>released-version</artifactId>
<version>1.0</version>
<name>Released Version</name>
<packaging>pom</packaging>
</project>

View File

@ -0,0 +1,9 @@
<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>
<groupId>org.apache.archiva</groupId>
<artifactId>unique-version</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Unique Version Snapshot - Build 1</name>
<packaging>pom</packaging>
</project>

View File

@ -0,0 +1,9 @@
<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>
<groupId>org.apache.archiva</groupId>
<artifactId>unique-version</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Unique Version Snapshot - Build 2</name>
<packaging>pom</packaging>
</project>

View File

@ -0,0 +1,9 @@
<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>
<groupId>org.apache.archiva</groupId>
<artifactId>unique-version</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Unique Version Snapshot - Build 3</name>
<packaging>pom</packaging>
</project>