-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#389] Add option 'blockSystemExit' to 'java' mojo
This new option enables users to stop programs called by 'exec:java' from calling System::exit, terminating not just the mojo but the whole Maven JVM. Closes #389. Relates to #388.
- Loading branch information
Showing
16 changed files
with
451 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/it/projects/mexec-gh-389-block-exit-non-zero/invoker.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
invoker.goals = clean process-classes | ||
invoker.buildResult = failure | ||
invoker.debug = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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> | ||
|
||
<parent> | ||
<groupId>org.codehaus.mojo.exec.it</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>0.1</version> | ||
</parent> | ||
|
||
<artifactId>mexec-gh-389</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>@project.version@</version> | ||
<executions> | ||
<execution> | ||
<phase>process-classes</phase> | ||
<goals> | ||
<goal>java</goal> | ||
</goals> | ||
<configuration> | ||
<mainClass>Main</mainClass> | ||
<blockSystemExit>true</blockSystemExit> | ||
<systemProperties> | ||
<systemProperty> | ||
<key>exitBehaviour</key> | ||
<value>system-exit-error</value> | ||
</systemProperty> | ||
</systemProperties> | ||
<arguments> | ||
<argument>one</argument> | ||
<argument>two</argument> | ||
<argument>three</argument> | ||
</arguments> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
19 changes: 19 additions & 0 deletions
19
src/it/projects/mexec-gh-389-block-exit-non-zero/src/main/java/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import java.util.Arrays; | ||
|
||
public class Main | ||
{ | ||
public static void main( String[] args ) | ||
{ | ||
System.out.println( Arrays.toString( args ) ); | ||
switch ( System.getProperty( "exitBehaviour", "ok" ) ) | ||
{ | ||
case "throw-exception": | ||
throw new RuntimeException( "uh-oh" ); | ||
case "system-exit-ok": | ||
System.exit( 0 ); | ||
case "system-exit-error": | ||
System.exit( 123 ); | ||
} | ||
System.out.println( "OK" ); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/it/projects/mexec-gh-389-block-exit-non-zero/verify.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright MojoHaus and Contributors | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
def buildLogLines = new File( basedir, "build.log" ).readLines() | ||
|
||
// Find "System::exit was called" line index | ||
def infoMessageLineNumber = buildLogLines.indexOf("[INFO] System::exit was called with return code 123") | ||
assert infoMessageLineNumber > 0 | ||
// Verify that preceding line is program output | ||
assert buildLogLines[infoMessageLineNumber - 1] == "[one, two, three]" | ||
// Verify that subsequent lines contain the beginning of the thrown SystemExitException stack trace | ||
assert buildLogLines[infoMessageLineNumber + 1].startsWith("[WARNING]") | ||
assert buildLogLines[infoMessageLineNumber + 2].contains("SystemExitException: System::exit was called with return code 123") | ||
assert buildLogLines[infoMessageLineNumber + 3].contains("SystemExitManager.checkExit (SystemExitManager.java") |
3 changes: 3 additions & 0 deletions
3
src/it/projects/mexec-gh-389-block-exit-zero/invoker.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
invoker.goals = clean process-classes | ||
invoker.buildResult = success | ||
invoker.debug = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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> | ||
|
||
<parent> | ||
<groupId>org.codehaus.mojo.exec.it</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>0.1</version> | ||
</parent> | ||
|
||
<artifactId>mexec-gh-389</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>@project.version@</version> | ||
<executions> | ||
<execution> | ||
<phase>process-classes</phase> | ||
<goals> | ||
<goal>java</goal> | ||
</goals> | ||
<configuration> | ||
<mainClass>Main</mainClass> | ||
<blockSystemExit>true</blockSystemExit> | ||
<systemProperties> | ||
<systemProperty> | ||
<key>exitBehaviour</key> | ||
<value>system-exit-ok</value> | ||
</systemProperty> | ||
</systemProperties> | ||
<arguments> | ||
<argument>one</argument> | ||
<argument>two</argument> | ||
<argument>three</argument> | ||
</arguments> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
19 changes: 19 additions & 0 deletions
19
src/it/projects/mexec-gh-389-block-exit-zero/src/main/java/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import java.util.Arrays; | ||
|
||
public class Main | ||
{ | ||
public static void main( String[] args ) | ||
{ | ||
System.out.println( Arrays.toString( args ) ); | ||
switch ( System.getProperty( "exitBehaviour", "ok" ) ) | ||
{ | ||
case "throw-exception": | ||
throw new RuntimeException( "uh-oh" ); | ||
case "system-exit-ok": | ||
System.exit( 0 ); | ||
case "system-exit-error": | ||
System.exit( 123 ); | ||
} | ||
System.out.println( "OK" ); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/it/projects/mexec-gh-389-block-exit-zero/verify.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright MojoHaus and Contributors | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
def buildLogLines = new File( basedir, "build.log" ).readLines() | ||
|
||
// Find "System::exit was called" line index | ||
def infoMessageLineNumber = buildLogLines.indexOf("[INFO] System::exit was called with return code 0") | ||
assert infoMessageLineNumber > 0 | ||
// Verify that preceding line is program output | ||
assert buildLogLines[infoMessageLineNumber - 1] == "[one, two, three]" |
4 changes: 4 additions & 0 deletions
4
src/it/projects/mexec-gh-389-default-permit-exit/invoker.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
invoker.goals = clean process-classes | ||
# Cannot not check result, because build terminates unexpectedly | ||
# invoker.buildResult = failure | ||
invoker.debug = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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> | ||
|
||
<parent> | ||
<groupId>org.codehaus.mojo.exec.it</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>0.1</version> | ||
</parent> | ||
|
||
<artifactId>mexec-gh-389</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>@project.version@</version> | ||
<executions> | ||
<execution> | ||
<phase>process-classes</phase> | ||
<goals> | ||
<goal>java</goal> | ||
</goals> | ||
<configuration> | ||
<mainClass>Main</mainClass> | ||
<!-- This is the default, no need to specify it --> | ||
<!--<blockSystemExit>false</blockSystemExit>--> | ||
<systemProperties> | ||
<systemProperty> | ||
<key>exitBehaviour</key> | ||
<!-- System.exit with any return code will terminate the JVM and the whole Maven process --> | ||
<value>system-exit-ok</value> | ||
</systemProperty> | ||
</systemProperties> | ||
<arguments> | ||
<argument>one</argument> | ||
<argument>two</argument> | ||
<argument>three</argument> | ||
</arguments> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
19 changes: 19 additions & 0 deletions
19
src/it/projects/mexec-gh-389-default-permit-exit/src/main/java/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import java.util.Arrays; | ||
|
||
public class Main | ||
{ | ||
public static void main( String[] args ) | ||
{ | ||
System.out.println( Arrays.toString( args ) ); | ||
switch ( System.getProperty( "exitBehaviour", "ok" ) ) | ||
{ | ||
case "throw-exception": | ||
throw new RuntimeException( "uh-oh" ); | ||
case "system-exit-ok": | ||
System.exit( 0 ); | ||
case "system-exit-error": | ||
System.exit( 123 ); | ||
} | ||
System.out.println( "OK" ); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/it/projects/mexec-gh-389-default-permit-exit/verify.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright MojoHaus and Contributors | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
def buildLogLines = new File( basedir, "build.log" ).readLines() | ||
|
||
// Second-last line is the last line the called program prints before exiting the JVM with System.exit. | ||
// Last line is "Running post-build script: ...", i.e. we need to disregard it. | ||
assert buildLogLines[-2] == "[one, two, three]" |
Oops, something went wrong.