Repository: maven-archetype
Updated Branches:
  refs/heads/master 0f614ecf4 -> 2e5611a2d


[ARCHETYPE-517] Maven doesn't fail if invocation goals fail


Project: http://git-wip-us.apache.org/repos/asf/maven-archetype/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-archetype/commit/2e5611a2
Tree: http://git-wip-us.apache.org/repos/asf/maven-archetype/tree/2e5611a2
Diff: http://git-wip-us.apache.org/repos/asf/maven-archetype/diff/2e5611a2

Branch: refs/heads/master
Commit: 2e5611a2d4d99eddee096b43b45c9b3e252dee9e
Parents: 0f614ec
Author: rfscholte <rfscho...@apache.org>
Authored: Tue Feb 7 22:01:44 2017 +0100
Committer: rfscholte <rfscho...@apache.org>
Committed: Tue Feb 7 22:01:44 2017 +0100

----------------------------------------------------------------------
 .../invoker.properties                          | 18 +++++++++++++
 .../it/ARCHETYPE-517_failing-goals/setup.groovy | 23 +++++++++++++++++
 .../ARCHETYPE-517_failing-goals/test.properties | 27 ++++++++++++++++++++
 .../ARCHETYPE-517_failing-goals/verify.groovy   | 21 +++++++++++++++
 .../mojos/CreateProjectFromArchetypeMojo.java   |  9 ++++++-
 5 files changed, 97 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/2e5611a2/maven-archetype-plugin/src/it/ARCHETYPE-517_failing-goals/invoker.properties
----------------------------------------------------------------------
diff --git 
a/maven-archetype-plugin/src/it/ARCHETYPE-517_failing-goals/invoker.properties 
b/maven-archetype-plugin/src/it/ARCHETYPE-517_failing-goals/invoker.properties
new file mode 100644
index 0000000..04b8f23
--- /dev/null
+++ 
b/maven-archetype-plugin/src/it/ARCHETYPE-517_failing-goals/invoker.properties
@@ -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 = 
org.apache.maven.plugins:maven-archetype-plugin:${project.version}:generate
+invoker.buildResult=failure
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/2e5611a2/maven-archetype-plugin/src/it/ARCHETYPE-517_failing-goals/setup.groovy
----------------------------------------------------------------------
diff --git 
a/maven-archetype-plugin/src/it/ARCHETYPE-517_failing-goals/setup.groovy 
b/maven-archetype-plugin/src/it/ARCHETYPE-517_failing-goals/setup.groovy
new file mode 100644
index 0000000..09bbaf8
--- /dev/null
+++ b/maven-archetype-plugin/src/it/ARCHETYPE-517_failing-goals/setup.groovy
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+// We can't run "mvn clean" as there is no pom. So we need to remove any 
already
+// created project before executing.
+directory = new File( basedir, "project" )
+directory.deleteDir()

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/2e5611a2/maven-archetype-plugin/src/it/ARCHETYPE-517_failing-goals/test.properties
----------------------------------------------------------------------
diff --git 
a/maven-archetype-plugin/src/it/ARCHETYPE-517_failing-goals/test.properties 
b/maven-archetype-plugin/src/it/ARCHETYPE-517_failing-goals/test.properties
new file mode 100644
index 0000000..9d9daee
--- /dev/null
+++ b/maven-archetype-plugin/src/it/ARCHETYPE-517_failing-goals/test.properties
@@ -0,0 +1,27 @@
+# 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.
+
+archetypeGroupId=org.apache.maven.archetypes
+archetypeArtifactId=maven-archetype-quickstart
+archetypeVersion=1.1
+
+groupId=com.company
+artifactId=project
+version=1.0-SNAPSHOT
+package=com.company.project
+
+goals=UNKNOWNPHASE
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/2e5611a2/maven-archetype-plugin/src/it/ARCHETYPE-517_failing-goals/verify.groovy
----------------------------------------------------------------------
diff --git 
a/maven-archetype-plugin/src/it/ARCHETYPE-517_failing-goals/verify.groovy 
b/maven-archetype-plugin/src/it/ARCHETYPE-517_failing-goals/verify.groovy
new file mode 100644
index 0000000..05a9053
--- /dev/null
+++ b/maven-archetype-plugin/src/it/ARCHETYPE-517_failing-goals/verify.groovy
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+buildLog = new File( basedir, "build.log" )
+assert buildLog.text.contains( "Failed to invoke goals" )
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/2e5611a2/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateProjectFromArchetypeMojo.java
----------------------------------------------------------------------
diff --git 
a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateProjectFromArchetypeMojo.java
 
b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateProjectFromArchetypeMojo.java
index b13fe9e..f109185 100644
--- 
a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateProjectFromArchetypeMojo.java
+++ 
b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateProjectFromArchetypeMojo.java
@@ -38,6 +38,7 @@ import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.shared.invoker.DefaultInvocationRequest;
 import org.apache.maven.shared.invoker.InvocationRequest;
+import org.apache.maven.shared.invoker.InvocationResult;
 import org.apache.maven.shared.invoker.Invoker;
 import org.apache.maven.shared.invoker.MavenInvocationException;
 
@@ -229,7 +230,13 @@ public class CreateProjectFromArchetypeMojo
 
             try
             {
-                invoker.execute( request );
+                InvocationResult result = invoker.execute( request );
+                
+                if ( result.getExitCode() != 0 )
+                {
+                    throw new MojoExecutionException( "Failed to invoke goals",
+                                                      
result.getExecutionException() );
+                }
             }
             catch ( MavenInvocationException e )
             {

Reply via email to