From d150a6ed98445bdaa6fa1ac8e511658193a02057 Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Fri, 7 Aug 2009 11:00:03 +0000 Subject: [PATCH] [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 --- .../ManagedDefaultRepositoryContent.java | 5 + .../ManagedRepositoryProjectResolver.java | 35 ++++- .../EffectiveProjectModelFilterTest.java | 47 +++++- .../ManagedRepositoryProjectResolverTest.java | 138 ++++++++++++++++++ .../sample-parent-2.1-20090807.095532-1.pom | 23 +++ .../sample-parent-2.1-20090808.085535-2.pom | 23 +++ .../sample-project-2.1-SNAPSHOT.pom | 47 ++++++ .../generic-version-1.0-SNAPSHOT.pom | 9 ++ .../1.0/released-version-1.0.pom | 9 ++ .../unique-version-1.0-20090807.070903-1.pom | 9 ++ .../unique-version-1.0-20090808.051902-2.pom | 9 ++ .../unique-version-1.0-20090808.081025-3.pom | 9 ++ 12 files changed, 358 insertions(+), 5 deletions(-) create mode 100644 archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/resolvers/ManagedRepositoryProjectResolverTest.java create mode 100644 archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/archiva/sample-parent/2.1-SNAPSHOT/sample-parent-2.1-20090807.095532-1.pom create mode 100644 archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/archiva/sample-parent/2.1-SNAPSHOT/sample-parent-2.1-20090808.085535-2.pom create mode 100644 archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/archiva/sample-project/2.1-SNAPSHOT/sample-project-2.1-SNAPSHOT.pom create mode 100644 archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/test-repo/org/apache/archiva/generic-version/1.0-SNAPSHOT/generic-version-1.0-SNAPSHOT.pom create mode 100644 archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/test-repo/org/apache/archiva/released-version/1.0/released-version-1.0.pom create mode 100644 archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/test-repo/org/apache/archiva/unique-version/1.0-SNAPSHOT/unique-version-1.0-20090807.070903-1.pom create mode 100644 archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/test-repo/org/apache/archiva/unique-version/1.0-SNAPSHOT/unique-version-1.0-20090808.051902-2.pom create mode 100644 archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/test-repo/org/apache/archiva/unique-version/1.0-SNAPSHOT/unique-version-1.0-20090808.081025-3.pom diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java index 242d1413a..54f9b44aa 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java @@ -420,4 +420,9 @@ public class ManagedDefaultRepositoryContent return false; } } + + public void setFiletypes( FileTypes filetypes ) + { + this.filetypes = filetypes; + } } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/resolvers/ManagedRepositoryProjectResolver.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/resolvers/ManagedRepositoryProjectResolver.java index 91e71d6d9..12d177fba 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/resolvers/ManagedRepositoryProjectResolver.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/resolvers/ManagedRepositoryProjectResolver.java @@ -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 versions = new ArrayList( 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 ); } } - } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilterTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilterTest.java index fae996e6f..e5990f774 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilterTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilterTest.java @@ -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 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 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 deps ) diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/resolvers/ManagedRepositoryProjectResolverTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/resolvers/ManagedRepositoryProjectResolverTest.java new file mode 100644 index 000000000..51048beff --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/resolvers/ManagedRepositoryProjectResolverTest.java @@ -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; + } + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/archiva/sample-parent/2.1-SNAPSHOT/sample-parent-2.1-20090807.095532-1.pom b/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/archiva/sample-parent/2.1-SNAPSHOT/sample-parent-2.1-20090807.095532-1.pom new file mode 100644 index 000000000..55fdf5d28 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/archiva/sample-parent/2.1-SNAPSHOT/sample-parent-2.1-20090807.095532-1.pom @@ -0,0 +1,23 @@ + + 4.0.0 + org.apache.archiva + sample-parent + pom + 2.1-SNAPSHOT + sample-parent Build 1 + + + + + org.codehaus.mojo + build-helper-maven-plugin + ${build-helper-maven-plugin.version} + + + + + + 1.0 + + \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/archiva/sample-parent/2.1-SNAPSHOT/sample-parent-2.1-20090808.085535-2.pom b/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/archiva/sample-parent/2.1-SNAPSHOT/sample-parent-2.1-20090808.085535-2.pom new file mode 100644 index 000000000..ffc575bbc --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/archiva/sample-parent/2.1-SNAPSHOT/sample-parent-2.1-20090808.085535-2.pom @@ -0,0 +1,23 @@ + + 4.0.0 + org.apache.archiva + sample-parent + pom + 2.1-SNAPSHOT + sample-parent Build 2 + + + + + org.codehaus.mojo + build-helper-maven-plugin + ${build-helper-maven-plugin.version} + + + + + + 1.0 + + \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/archiva/sample-project/2.1-SNAPSHOT/sample-project-2.1-SNAPSHOT.pom b/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/archiva/sample-project/2.1-SNAPSHOT/sample-project-2.1-SNAPSHOT.pom new file mode 100644 index 000000000..b9e7e38a1 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/default-repository/org/apache/archiva/sample-project/2.1-SNAPSHOT/sample-project-2.1-SNAPSHOT.pom @@ -0,0 +1,47 @@ + + 4.0.0 + + org.apache.archiva + sample-parent + 2.1-SNAPSHOT + + sample-project + jar + sample-project + http://maven.apache.org + + + junit + junit + 3.8.2 + test + + + + + + org.codehaus.mojo + build-helper-maven-plugin + ${build-helper-maven-plugin.version} + true + + + add-source + generate-sources + + add-source + + + + ${basedir}/java-gen + ${basedir}/java-src + ${basedir}/java-test + + + + + + + + \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/test-repo/org/apache/archiva/generic-version/1.0-SNAPSHOT/generic-version-1.0-SNAPSHOT.pom b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/test-repo/org/apache/archiva/generic-version/1.0-SNAPSHOT/generic-version-1.0-SNAPSHOT.pom new file mode 100644 index 000000000..64ddc4d74 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/test-repo/org/apache/archiva/generic-version/1.0-SNAPSHOT/generic-version-1.0-SNAPSHOT.pom @@ -0,0 +1,9 @@ + + 4.0.0 + org.apache.archiva + generic-version + 1.0-SNAPSHOT + Generic Snapshot Version + pom + \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/test-repo/org/apache/archiva/released-version/1.0/released-version-1.0.pom b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/test-repo/org/apache/archiva/released-version/1.0/released-version-1.0.pom new file mode 100644 index 000000000..1a7f85e65 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/test-repo/org/apache/archiva/released-version/1.0/released-version-1.0.pom @@ -0,0 +1,9 @@ + + 4.0.0 + org.apache.archiva + released-version + 1.0 + Released Version + pom + \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/test-repo/org/apache/archiva/unique-version/1.0-SNAPSHOT/unique-version-1.0-20090807.070903-1.pom b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/test-repo/org/apache/archiva/unique-version/1.0-SNAPSHOT/unique-version-1.0-20090807.070903-1.pom new file mode 100644 index 000000000..4ccc67759 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/test-repo/org/apache/archiva/unique-version/1.0-SNAPSHOT/unique-version-1.0-20090807.070903-1.pom @@ -0,0 +1,9 @@ + + 4.0.0 + org.apache.archiva + unique-version + 1.0-SNAPSHOT + Unique Version Snapshot - Build 1 + pom + \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/test-repo/org/apache/archiva/unique-version/1.0-SNAPSHOT/unique-version-1.0-20090808.051902-2.pom b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/test-repo/org/apache/archiva/unique-version/1.0-SNAPSHOT/unique-version-1.0-20090808.051902-2.pom new file mode 100644 index 000000000..2662a0ea8 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/test-repo/org/apache/archiva/unique-version/1.0-SNAPSHOT/unique-version-1.0-20090808.051902-2.pom @@ -0,0 +1,9 @@ + + 4.0.0 + org.apache.archiva + unique-version + 1.0-SNAPSHOT + Unique Version Snapshot - Build 2 + pom + \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/test-repo/org/apache/archiva/unique-version/1.0-SNAPSHOT/unique-version-1.0-20090808.081025-3.pom b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/test-repo/org/apache/archiva/unique-version/1.0-SNAPSHOT/unique-version-1.0-20090808.081025-3.pom new file mode 100644 index 000000000..597e65408 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/test-repo/org/apache/archiva/unique-version/1.0-SNAPSHOT/unique-version-1.0-20090808.081025-3.pom @@ -0,0 +1,9 @@ + + 4.0.0 + org.apache.archiva + unique-version + 1.0-SNAPSHOT + Unique Version Snapshot - Build 3 + pom + \ No newline at end of file -- 2.39.5