return false;
}
}
+
+ public void setFiletypes( FileTypes filetypes )
+ {
+ this.filetypes = filetypes;
+ }
}
*/
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.
*
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 );
throw new ProjectModelException( e.getMessage(), e );
}
}
-
}
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;
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");
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
{
assertContainsSameDependencies( "Dependencies", expectedModel.getDependencies(), effectiveModel
.getDependencies() );
assertContainsSameDependencies( "DependencyManagement", expectedModel.getDependencyManagement(), effectiveModel
- .getDependencyManagement() );
+ .getDependencyManagement() );
}
private void dumpDependencyList( String type, List<Dependency> deps )
--- /dev/null
+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;
+ }
+ }
+}
--- /dev/null
+<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>
\ No newline at end of file
--- /dev/null
+<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>
\ No newline at end of file
--- /dev/null
+<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>
\ No newline at end of file
--- /dev/null
+<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>
\ No newline at end of file
--- /dev/null
+<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>
\ No newline at end of file
--- /dev/null
+<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>
\ No newline at end of file
--- /dev/null
+<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>
\ No newline at end of file
--- /dev/null
+<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>
\ No newline at end of file