You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gb...@apache.org on 2017/05/29 18:43:25 UTC
svn commit: r1796671 - in /maven/plugins/trunk/maven-antrun-plugin/src:
it/attach-artifact-from-ant-task/ main/java/org/apache/maven/plugin/antrun/
Author: gboue
Date: Mon May 29 18:43:25 2017
New Revision: 1796671
URL: http://svn.apache.org/viewvc?rev=1796671&view=rev
Log:
[MANTRUN-181] AttachArtifact task does not work in external Ant build file
When the run goal executes an Ant task that calls an external Ant build file, Ant creates a sub-project of the main Ant project that was created for the (parent) Ant task. However, the project's references are not passed to the sub-project, meaning that whatever Maven added as a reference to the main project is lost when calling the external build file. This notably includes the "maven.project" and "maven.project.helper" references that are needed for the 'attachartifact' built-in task to work.
This is resolved by overriding the way of creating sub-projects, so that references added to an Ant project by Maven are passed to any sub-projects.
Added:
maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/
maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/build.xml (with props)
maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/invoker.properties (with props)
maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/pom.xml (with props)
maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/test.txt (with props)
maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/verify.bsh (with props)
maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/MavenAntRunProject.java (with props)
Modified:
maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java
Added: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/build.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/build.xml?rev=1796671&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/build.xml (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/build.xml Mon May 29 18:43:25 2017
@@ -0,0 +1,26 @@
+<?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 name="External Build" default="mytarget">
+ <target name="mytarget">
+ <attachartifact file="test.txt" classifier="from-build" />
+ </target>
+</project>
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/build.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/build.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/invoker.properties?rev=1796671&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/invoker.properties (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/invoker.properties Mon May 29 18:43:25 2017
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.goals=clean install
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/invoker.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/invoker.properties
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/pom.xml?rev=1796671&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/pom.xml (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/pom.xml Mon May 29 18:43:25 2017
@@ -0,0 +1,57 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.plugins.antrun</groupId>
+ <artifactId>attach-artifact-from-ant-task</artifactId>
+ <version>1.0</version>
+ <packaging>pom</packaging>
+ <url>https://issues.apache.org/jira/browse/MANTRUN-181</url>
+ <description>
+ Checks that the attachartifact built-in task works correctly when invoked from an external Ant build through the
+ ant task.
+ </description>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>@pom.version@</version>
+ <executions>
+ <execution>
+ <id>call-build</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <target>
+ <ant antfile="build.xml" target="mytarget" />
+ <attachartifact file="test.txt" classifier="from-pom" />
+ </target>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/test.txt
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/test.txt?rev=1796671&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/test.txt (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/test.txt Mon May 29 18:43:25 2017
@@ -0,0 +1,16 @@
+# 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.
\ No newline at end of file
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/test.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/test.txt
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/verify.bsh?rev=1796671&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/verify.bsh (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/verify.bsh Mon May 29 18:43:25 2017
@@ -0,0 +1,37 @@
+
+/*
+ * 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.*;
+
+String[] expectedFiles = {
+ "org/apache/maven/plugins/antrun/attach-artifact-from-ant-task/1.0/attach-artifact-from-ant-task-1.0.pom",
+ "org/apache/maven/plugins/antrun/attach-artifact-from-ant-task/1.0/attach-artifact-from-ant-task-1.0-from-pom.txt",
+ "org/apache/maven/plugins/antrun/attach-artifact-from-ant-task/1.0/attach-artifact-from-ant-task-1.0-from-build.txt"
+};
+
+for ( String expectedFile : expectedFiles )
+{
+ File file = new File( localRepositoryPath, expectedFile );
+ System.out.println( "Checking for existence of " + file );
+ if ( !file.isFile() )
+ {
+ throw new Exception( "Missing file " + file );
+ }
+}
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/verify.bsh
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-from-ant-task/verify.bsh
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java?rev=1796671&r1=1796670&r2=1796671&view=diff
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java (original)
+++ maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java Mon May 29 18:43:25 2017
@@ -68,15 +68,21 @@ import org.codehaus.plexus.util.StringUt
public class AntRunMojo
extends AbstractMojo
{
+
+ /**
+ * The prefix of all refid used by the plugin.
+ */
+ public static final String MAVEN_REFID_PREFIX = "maven.";
+
/**
* The refid used to store the Maven project object in the Ant build.
*/
- public static final String DEFAULT_MAVEN_PROJECT_REFID = "maven.project";
+ public static final String DEFAULT_MAVEN_PROJECT_REFID = MAVEN_REFID_PREFIX + "project";
/**
* The refid used to store the Maven project object in the Ant build.
*/
- public static final String DEFAULT_MAVEN_PROJECT_HELPER_REFID = "maven.project.helper";
+ public static final String DEFAULT_MAVEN_PROJECT_HELPER_REFID = MAVEN_REFID_PREFIX + "project.helper";
/**
* The default target name.
@@ -245,7 +251,7 @@ public class AntRunMojo
try
{
- Project antProject = new Project();
+ Project antProject = new MavenAntRunProject();
File antBuildFile = this.writeTargetToProjectFile();
ProjectHelper.configureProject( antProject, antBuildFile );
antProject.init();
@@ -280,23 +286,24 @@ public class AntRunMojo
p.setPath( StringUtils.join( mavenProject.getCompileClasspathElements().iterator(), File.pathSeparator ) );
/* maven.dependency.classpath it's deprecated as it's equal to maven.compile.classpath */
- antProject.addReference( "maven.dependency.classpath", p );
- antProject.addReference( "maven.compile.classpath", p );
+ antProject.addReference( MAVEN_REFID_PREFIX + "dependency.classpath", p );
+ antProject.addReference( MAVEN_REFID_PREFIX + "compile.classpath", p );
p = new Path( antProject );
p.setPath( StringUtils.join( mavenProject.getRuntimeClasspathElements().iterator(), File.pathSeparator ) );
- antProject.addReference( "maven.runtime.classpath", p );
+ antProject.addReference( MAVEN_REFID_PREFIX + "runtime.classpath", p );
p = new Path( antProject );
p.setPath( StringUtils.join( mavenProject.getTestClasspathElements().iterator(), File.pathSeparator ) );
- antProject.addReference( "maven.test.classpath", p );
+ antProject.addReference( MAVEN_REFID_PREFIX + "test.classpath", p );
/* set maven.plugin.classpath with plugin dependencies */
- antProject.addReference( "maven.plugin.classpath", getPathFromArtifacts( pluginArtifacts, antProject ) );
+ antProject.addReference( MAVEN_REFID_PREFIX + "plugin.classpath",
+ getPathFromArtifacts( pluginArtifacts, antProject ) );
antProject.addReference( DEFAULT_MAVEN_PROJECT_REFID, getMavenProject() );
antProject.addReference( DEFAULT_MAVEN_PROJECT_HELPER_REFID, projectHelper );
- antProject.addReference( "maven.local.repository", localRepository );
+ antProject.addReference( MAVEN_REFID_PREFIX + "local.repository", localRepository );
initMavenTasks( antProject );
// The Ant project needs actual properties vs. using expression evaluator when calling an external build
Added: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/MavenAntRunProject.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/MavenAntRunProject.java?rev=1796671&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/MavenAntRunProject.java (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/MavenAntRunProject.java Mon May 29 18:43:25 2017
@@ -0,0 +1,54 @@
+package org.apache.maven.plugin.antrun;
+
+/*
+ * 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.util.Map;
+
+import org.apache.tools.ant.Project;
+
+/**
+ * Extension of the Ant's Project representation, where all sub-projects created from this project also share the same
+ * Maven references.
+ * <p>
+ * When Ant is performing some tasks (e.g. invoking the <code>ant</code> taskdef), it works from a temporary sub-project
+ * created from the main project. Since Maven is adding references to the main project, they need to be copied to any
+ * sub-projects so that built-in antrun tasks still work correctly, even in a sub-project. An example of this is using
+ * the <code>attachartifact</code> task in an external Ant <code>build.xml</code> called from the plugin.
+ *
+ * @author gboue
+ */
+class MavenAntRunProject
+ extends Project
+{
+
+ @Override
+ public void initSubProject( Project subProject )
+ {
+ super.initSubProject( subProject );
+ for ( Map.Entry<String, Object> entry : getCopyOfReferences().entrySet() )
+ {
+ if ( entry.getKey().startsWith( AntRunMojo.MAVEN_REFID_PREFIX ) )
+ {
+ subProject.addReference( entry.getKey(), entry.getValue() );
+ }
+ }
+ }
+
+}
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/MavenAntRunProject.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/MavenAntRunProject.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision