Author: olamy
Date: Fri Jun 23 08:43:56 2017
New Revision: 1799652

URL: http://svn.apache.org/viewvc?rev=1799652&view=rev
Log:
[MINVOKER-223] postBuildHookScript must be executed even if the maven build fail

Signed-off-by: olivier lamy <ol...@apache.org>

Added:
    maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/
    
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/invoker.properties
   (with props)
    maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/pom.xml  
 (with props)
    maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/
    maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/
    
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/
    
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/pom.xml
   (with props)
    
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/postbuild.bsh
   (with props)
    
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/src/
    
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/src/main/
    
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/src/main/java/
    
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/src/main/java/Foo.java
   (with props)
    
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/verify.bsh   
(with props)
Modified:
    
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/invoker.properties
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/invoker.properties?rev=1799652&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/invoker.properties
 (added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/invoker.properties
 Fri Jun 23 08:43:56 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.buildResult = failure
\ No newline at end of file

Propchange: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/invoker.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/invoker.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/pom.xml?rev=1799652&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/pom.xml 
(added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/pom.xml 
Fri Jun 23 08:43:56 2017
@@ -0,0 +1,65 @@
+<?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.plugins.invoker</groupId>
+  <artifactId>fail-run-postbuild</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <description>Test to check in case of failure the post-build hook is 
running.</description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-invoker-plugin</artifactId>
+        <version>@pom.version@</version>
+        <configuration>
+          <debug>true</debug>
+          <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
+          <pomIncludes>
+            <pomInclude>*/pom.xml</pomInclude>
+          </pomIncludes>
+          <goals>
+            <goal>package</goal>
+          </goals>
+        </configuration>
+        <executions>
+          <execution>
+            <id>integration-test</id>
+            <phase>initialize</phase>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Propchange: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/pom.xml?rev=1799652&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/pom.xml
 (added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/pom.xml
 Fri Jun 23 08:43:56 2017
@@ -0,0 +1,32 @@
+<?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>test</groupId>
+  <artifactId>fail-run-postbuild</artifactId>
+  <version>0.1-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+</project>

Propchange: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/postbuild.bsh
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/postbuild.bsh?rev=1799652&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/postbuild.bsh
 (added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/postbuild.bsh
 Fri Jun 23 08:43:56 2017
@@ -0,0 +1,24 @@
+/*
+ * 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.*;
+
+// marker for parent build that this sub build was indeed run
+File touchFile = new File( basedir, "touch.txt" );
+touchFile.createNewFile();

Propchange: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/postbuild.bsh
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/postbuild.bsh
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/src/main/java/Foo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/src/main/java/Foo.java?rev=1799652&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/src/main/java/Foo.java
 (added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/src/main/java/Foo.java
 Fri Jun 23 08:43:56 2017
@@ -0,0 +1,24 @@
+package org.apache.maven.plugins.invoker;
+
+/*
+ * 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.
+ */
+
+
+
+Foo beer Maven rocks
\ No newline at end of file

Propchange: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/src/main/java/Foo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/src/it/project/src/main/java/Foo.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/verify.bsh
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/verify.bsh?rev=1799652&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/verify.bsh 
(added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/verify.bsh 
Fri Jun 23 08:43:56 2017
@@ -0,0 +1,41 @@
+/*
+ * 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.*;
+import java.util.*;
+import java.util.regex.*;
+
+try
+{
+    // make sure the Invoker Plugin was indeed run and the build didn't fail 
somewhere else
+    File touchFile = new File( basedir, "target/it/project/touch.txt" );
+    System.out.println( "Checking for existence of touch file: " + touchFile );
+    if ( !touchFile.exists() )
+    {
+        System.out.println( "FAILED!" );
+        return false;
+    }
+}
+catch( Throwable t )
+{
+    t.printStackTrace();
+    return false;
+}
+
+return true;

Propchange: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/verify.bsh
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-run-postbuild/verify.bsh
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java?rev=1799652&r1=1799651&r2=1799652&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
 Fri Jun 23 08:43:56 2017
@@ -1860,12 +1860,9 @@ public abstract class AbstractInvokerMoj
                     throw new RunFailureException( "Maven invocation failed. " 
+ e.getMessage(),
                                                    
BuildJob.Result.FAILURE_BUILD );
                 }
-
+                runPostBuildHook( basedir, context, logger );
                 verify( result, invocationIndex, invokerProperties, logger );
             }
-
-            scriptRunner.run( "post-build script", basedir, 
postBuildHookScript, context, logger,
-                              BuildJob.Result.FAILURE_POST_HOOK, true );
         }
         catch ( IOException e )
         {
@@ -1881,6 +1878,19 @@ public abstract class AbstractInvokerMoj
         return true;
     }
 
+    private void runPostBuildHook( File basedir, Map<String, Object> context, 
FileLogger logger )
+        throws MojoExecutionException, RunFailureException
+    {
+        try
+        {
+            scriptRunner.run( "post-build script", basedir, 
postBuildHookScript, context, logger,
+                              BuildJob.Result.FAILURE_POST_HOOK, true );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( e.getMessage(), e );
+        }
+    }
     private void setupLoggerForBuildJob( FileLogger logger, final 
InvocationRequest request )
     {
         if ( logger != null )


Reply via email to