You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by st...@apache.org on 2011/07/05 14:54:20 UTC
svn commit: r1143035 - in /maven/plugins/trunk/maven-dependency-plugin/src:
it/copy-from-reactor/ it/copy-from-reactor/child-a/
it/copy-from-reactor/child-a/src/ it/copy-from-reactor/child-a/src/main/
it/copy-from-reactor/child-a/src/main/resources/ it...
Author: stephenc
Date: Tue Jul 5 12:54:20 2011
New Revision: 1143035
URL: http://svn.apache.org/viewvc?rev=1143035&view=rev
Log:
[MDEP-316] dependency:copy and dependency:unpack behave differently with M2 and M3 (should always search the reactor for artifacts)
o With this patch all copy and unpack will not resolve from the reactor always (both M2 and M3)
Added:
maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/
maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/child-a/
maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/child-a/pom.xml
maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/child-a/src/
maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/child-a/src/main/
maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/child-a/src/main/resources/
maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/child-a/src/main/resources/DoNotDelete.xml
maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/child-b/
maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/child-b/pom.xml
maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/invoker.properties
maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/pom.xml
maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/validate.bsh
Modified:
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
maven/plugins/trunk/maven-dependency-plugin/src/site/apt/examples/copying-artifacts.apt.vm
maven/plugins/trunk/maven-dependency-plugin/src/site/apt/index.apt
Added: maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/child-a/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/child-a/pom.xml?rev=1143035&view=auto
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/child-a/pom.xml (added)
+++ maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/child-a/pom.xml Tue Jul 5 12:54:20 2011
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<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.maven.its.dependency</groupId>
+ <artifactId>test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>child-a</artifactId>
+ <packaging>jar</packaging>
+
+ <name>Copy from reactor source of dependency</name>
+ <description>
+ Test dependency:copy when searching the reactor
+ </description>
+
+</project>
Added: maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/child-a/src/main/resources/DoNotDelete.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/child-a/src/main/resources/DoNotDelete.xml?rev=1143035&view=auto
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/child-a/src/main/resources/DoNotDelete.xml (added)
+++ maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/child-a/src/main/resources/DoNotDelete.xml Tue Jul 5 12:54:20 2011
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ 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.
+ -->
+<root/>
Added: maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/child-b/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/child-b/pom.xml?rev=1143035&view=auto
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/child-b/pom.xml (added)
+++ maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/child-b/pom.xml Tue Jul 5 12:54:20 2011
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<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.maven.its.dependency</groupId>
+ <artifactId>test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>child-b</artifactId>
+ <packaging>pom</packaging>
+
+ <name>Copy from reactor</name>
+ <description>
+ Test dependency:copy when searching the reactor
+ </description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>child-a</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>test</id>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>child-a</artifactId>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/invoker.properties?rev=1143035&view=auto
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/invoker.properties (added)
+++ maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/invoker.properties Tue Jul 5 12:54:20 2011
@@ -0,0 +1 @@
+invoker.goals = clean package
Added: maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/pom.xml?rev=1143035&view=auto
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/pom.xml (added)
+++ maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/pom.xml Tue Jul 5 12:54:20 2011
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<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.maven.its.dependency</groupId>
+ <artifactId>test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>child-a</module>
+ <module>child-b</module>
+ </modules>
+
+ <name>Copy from reactor</name>
+ <description>
+ Test dependency:copy when searching the reactor
+ </description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>@project.version@</version>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/validate.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/validate.bsh?rev=1143035&view=auto
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/validate.bsh (added)
+++ maven/plugins/trunk/maven-dependency-plugin/src/it/copy-from-reactor/validate.bsh Tue Jul 5 12:54:20 2011
@@ -0,0 +1,19 @@
+import java.io.*;
+
+File libDir = new File( basedir, "child-b/target/dependency" );
+
+String[] expectedFiles = {
+ "child-a-1.0-SNAPSHOT.jar",
+};
+
+for ( String expectedFile : expectedFiles )
+{
+ File file = new File( libDir, expectedFile );
+ System.out.println( "Checking for existence of " + file );
+ if ( !file.isFile() )
+ {
+ throw new Exception( "Missing file " + file );
+ }
+}
+
+return true;
Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java?rev=1143035&r1=1143034&r2=1143035&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java Tue Jul 5 12:54:20 2011
@@ -20,9 +20,12 @@ package org.apache.maven.plugin.dependen
*/
import java.io.File;
+import java.util.Collections;
import java.util.List;
+import java.util.Set;
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
@@ -34,7 +37,9 @@ import org.apache.maven.plugin.MojoExecu
import org.apache.maven.plugin.dependency.AbstractDependencyMojo;
import org.apache.maven.plugin.dependency.utils.DependencyUtil;
import org.apache.maven.plugin.dependency.utils.filters.ArtifactItemFilter;
+import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
+import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;
/**
@@ -94,6 +99,15 @@ public abstract class AbstractFromConfig
private boolean overWriteIfNewer;
/**
+ * To search for artifacts within the reactor and ensure consistent behaviour between Maven 2 and Maven 3.
+ *
+ * @parameter expression="${reactorProjects}"
+ * @required
+ * @readonly
+ */
+ protected List<MavenProject> reactorProjects;
+
+ /**
* Collection of ArtifactItems to work on. (ArtifactItem contains groupId, artifactId, version, type, classifier,
* location, destFileName, markerFile and overwrite.) See <a href="./usage.html">Usage</a> for details.
*
@@ -237,6 +251,13 @@ public abstract class AbstractFromConfig
Artifact.SCOPE_COMPILE );
}
+ // Maven 3 will search the reactor for the artifact but Maven 2 does not
+ // to keep consistent behaviour, we search the reactor ourselves.
+ Artifact result = getArtifactFomReactor( artifact );
+ if ( result != null )
+ {
+ return result;
+ }
try
{
// mdep-50 - rolledback for now because it's breaking some functionality.
@@ -264,6 +285,71 @@ public abstract class AbstractFromConfig
}
/**
+ * Checks to see if the specified artifact is available from the reactor.
+ * @param artifact The artifact we are looking for.
+ * @return The resolved artifact that is the same as the one we were looking for or <code>null</code> if one could
+ * not be found.
+ */
+ private Artifact getArtifactFomReactor( Artifact artifact )
+ {
+ // check project dependencies first off
+ for ( Artifact a : (Set<Artifact>) project.getArtifacts() )
+ {
+ if ( equals( artifact, a ) && hasFile( a ) )
+ {
+ return a;
+ }
+ }
+ // check reactor projects
+ for ( MavenProject p : reactorProjects == null ? Collections.<MavenProject>emptyList() : reactorProjects )
+ {
+ // check the main artifact
+ if ( equals( artifact, p.getArtifact() ) && hasFile( p.getArtifact() ) )
+ {
+ return p.getArtifact();
+ }
+ // check any side artifacts
+ for ( Artifact a : (List<Artifact>) p.getAttachedArtifacts() )
+ {
+ if ( equals( artifact, a ) && hasFile( a ) )
+ {
+ return a;
+ }
+ }
+ }
+ // not available
+ return null;
+ }
+
+ /**
+ * Returns <code>true</code> if the artifact has a file.
+ * @param artifact the artifact (may be null)
+ * @return <code>true</code> if and only if the artifact is non-null and has a file.
+ */
+ private static boolean hasFile( Artifact artifact )
+ {
+ return artifact != null && artifact.getFile() != null && artifact.getFile().isFile();
+ }
+
+ /**
+ * Null-safe compare of two artifacts based on groupId, artifactId, version, type and classifier.
+ * @param a the first artifact.
+ * @param b the second artifact.
+ * @return <code>true</code> if and only if the two artifacts have the same groupId, artifactId, version,
+ * type and classifier.
+ */
+ private static boolean equals( Artifact a, Artifact b )
+ {
+ return a == b
+ || !( a == null || b == null )
+ && StringUtils.equals( a.getGroupId(), b.getGroupId() )
+ && StringUtils.equals( a.getArtifactId(), b.getArtifactId() )
+ && StringUtils.equals( a.getVersion(), b.getVersion() )
+ && StringUtils.equals( a.getType(), b.getType() )
+ && StringUtils.equals( a.getClassifier(), b.getClassifier() );
+ }
+
+ /**
* Tries to find missing version from dependency list and dependency management. If found, the artifact is updated
* with the correct version. It will first look for an exact match on artifactId/groupId/classifier/type and if it
* doesn't find a match, it will try again looking for artifactId and groupId only.
@@ -275,7 +361,9 @@ public abstract class AbstractFromConfig
throws MojoExecutionException
{
List<Dependency> deps = project.getDependencies();
- List<Dependency> depMngt = project.getDependencyManagement().getDependencies();
+ List<Dependency> depMngt = project.getDependencyManagement() == null
+ ? Collections.<Dependency>emptyList()
+ : project.getDependencyManagement().getDependencies();
if ( !findDependencyVersion( artifact, deps, false )
&& ( project.getDependencyManagement() == null || !findDependencyVersion( artifact, depMngt, false ) )
Modified: maven/plugins/trunk/maven-dependency-plugin/src/site/apt/examples/copying-artifacts.apt.vm
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/site/apt/examples/copying-artifacts.apt.vm?rev=1143035&r1=1143034&r2=1143035&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/site/apt/examples/copying-artifacts.apt.vm (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/site/apt/examples/copying-artifacts.apt.vm Tue Jul 5 12:54:20 2011
@@ -20,8 +20,9 @@
------
Allan Ramirez
Brian Fox
+ Stephen Connolly
------
- Mar 2007
+ Jul 2011
------
Copying specific artifacts
@@ -74,10 +75,74 @@ Copying specific artifacts
Then after executing <<<mvn package>>> the artifact (junit) is copied to the
given alternateLocation.
+ Artifacts are resolved from the following sources in order:
+
+ * The current reactor,
+
+ * The local repository,
+
+ * The configured remote repositories.
+
+ []
+
+ If the artifact cannot be resolved from the above sources then the build
+
+ If the artifact is also listed as a dependency, the <<<version>>> of the <<<artifactItem>>> will default to
+ the version from the <<<dependencies>>> or <<<dependencyManagement>>>, e.g.
+
++---+
+<project>
+ [...]
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ [...]
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>${project.version}</version>
+ <executions>
+ <execution>
+ <id>copy</id>
+ <phase>package</phase>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <overWrite>false</overWrite>
+ <outputDirectory>\${project.build.directory}/alternateLocation</outputDirectory>
+ <destFileName>optional-new-name.jar</destFileName>
+ </artifactItem>
+ </artifactItems>
+ <outputDirectory>\${project.build.directory}/wars</outputDirectory>
+ <overWriteReleases>false</overWriteReleases>
+ <overWriteSnapshots>true</overWriteSnapshots>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ [...]
+</project>
++---+
+
The <<<dependency:copy>>> goal can also be used to copy the just built
artifact to a custom location if desired. It must be bound after the
- install phase so that the artifact exists in the repository. The following
- configuration shows how:
+ to any phase after the package phase so that the artifact exists in the
+ repository. The following configuration shows how (binding to the
+ install phase in this case):
+---+
<project>
Modified: maven/plugins/trunk/maven-dependency-plugin/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/site/apt/index.apt?rev=1143035&r1=1143034&r2=1143035&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/site/apt/index.apt (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/site/apt/index.apt Tue Jul 5 12:54:20 2011
@@ -55,7 +55,7 @@ Maven Dependency Plugin
*{{{./copy-mojo.html}dependency:copy}} takes a list of artifacts defined in the plugin configuration section and
copies them to a specified location, renaming them or stripping the version if desired. This goal can resolve
- the artifacts from remote repositories if they don't exist in local.
+ the artifacts from remote repositories if they don't exist in either the local repository or the reactor.
*{{{./copy-dependencies-mojo.html}dependency:copy-dependencies}} takes the list of project direct dependencies and
optionally transitive dependencies and copies them to a specified location, stripping the version if desired.
@@ -83,8 +83,7 @@ Maven Dependency Plugin
*{{{./tree-mojo.html}dependency:tree}} displays the dependency tree for this project.
- *{{{./unpack-mojo.html}dependency:unpack}} removes the project dependencies from the local repository, and optionally
- re-resolve them.
+ *{{{./unpack-mojo.html}dependency:unpack}} like copy but unpacks.
*{{{./unpack-dependencies-mojo.html}dependency:unpack-dependencies}} like
copy-dependencies but unpacks.