Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit cc9ae77

Browse files
committed
[MINVOKER-223] postBuildHookScript must be executed even if the maven build fail
Signed-off-by: olivier lamy <[email protected]> git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1799652 13f79535-47bb-0310-9956-ffa450edef68
1 parent a458664 commit cc9ae77

File tree

7 files changed

+218
-4
lines changed

7 files changed

+218
-4
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
invoker.buildResult = failure
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
-->
21+
22+
<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">
23+
<modelVersion>4.0.0</modelVersion>
24+
25+
<groupId>org.apache.maven.plugins.invoker</groupId>
26+
<artifactId>fail-run-postbuild</artifactId>
27+
<version>1.0-SNAPSHOT</version>
28+
<packaging>pom</packaging>
29+
30+
<description>Test to check in case of failure the post-build hook is running.</description>
31+
32+
<properties>
33+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34+
</properties>
35+
36+
<build>
37+
<plugins>
38+
<plugin>
39+
<groupId>org.apache.maven.plugins</groupId>
40+
<artifactId>maven-invoker-plugin</artifactId>
41+
<version>@pom.version@</version>
42+
<configuration>
43+
<debug>true</debug>
44+
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
45+
<pomIncludes>
46+
<pomInclude>*/pom.xml</pomInclude>
47+
</pomIncludes>
48+
<goals>
49+
<goal>package</goal>
50+
</goals>
51+
</configuration>
52+
<executions>
53+
<execution>
54+
<id>integration-test</id>
55+
<phase>initialize</phase>
56+
<goals>
57+
<goal>run</goal>
58+
</goals>
59+
</execution>
60+
</executions>
61+
</plugin>
62+
</plugins>
63+
</build>
64+
65+
</project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
-->
21+
22+
<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">
23+
<modelVersion>4.0.0</modelVersion>
24+
<groupId>test</groupId>
25+
<artifactId>fail-run-postbuild</artifactId>
26+
<version>0.1-SNAPSHOT</version>
27+
<packaging>jar</packaging>
28+
29+
<properties>
30+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
31+
</properties>
32+
</project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import java.io.*;
21+
22+
// marker for parent build that this sub build was indeed run
23+
File touchFile = new File( basedir, "touch.txt" );
24+
touchFile.createNewFile();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.apache.maven.plugins.invoker;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
23+
24+
Foo beer Maven rocks
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import java.io.*;
21+
import java.util.*;
22+
import java.util.regex.*;
23+
24+
try
25+
{
26+
// make sure the Invoker Plugin was indeed run and the build didn't fail somewhere else
27+
File touchFile = new File( basedir, "target/it/project/touch.txt" );
28+
System.out.println( "Checking for existence of touch file: " + touchFile );
29+
if ( !touchFile.exists() )
30+
{
31+
System.out.println( "FAILED!" );
32+
return false;
33+
}
34+
}
35+
catch( Throwable t )
36+
{
37+
t.printStackTrace();
38+
return false;
39+
}
40+
41+
return true;

maven-invoker-plugin/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,12 +1860,9 @@ private boolean runBuild( File basedir, File pomFile, File settingsFile, File ac
18601860
throw new RunFailureException( "Maven invocation failed. " + e.getMessage(),
18611861
BuildJob.Result.FAILURE_BUILD );
18621862
}
1863-
1863+
runPostBuildHook( basedir, context, logger );
18641864
verify( result, invocationIndex, invokerProperties, logger );
18651865
}
1866-
1867-
scriptRunner.run( "post-build script", basedir, postBuildHookScript, context, logger,
1868-
BuildJob.Result.FAILURE_POST_HOOK, true );
18691866
}
18701867
catch ( IOException e )
18711868
{
@@ -1881,6 +1878,19 @@ private boolean runBuild( File basedir, File pomFile, File settingsFile, File ac
18811878
return true;
18821879
}
18831880

1881+
private void runPostBuildHook( File basedir, Map<String, Object> context, FileLogger logger )
1882+
throws MojoExecutionException, RunFailureException
1883+
{
1884+
try
1885+
{
1886+
scriptRunner.run( "post-build script", basedir, postBuildHookScript, context, logger,
1887+
BuildJob.Result.FAILURE_POST_HOOK, true );
1888+
}
1889+
catch ( IOException e )
1890+
{
1891+
throw new MojoExecutionException( e.getMessage(), e );
1892+
}
1893+
}
18841894
private void setupLoggerForBuildJob( FileLogger logger, final InvocationRequest request )
18851895
{
18861896
if ( logger != null )

0 commit comments

Comments
 (0)