forked from mojohaus/exec-maven-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mojohaus#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 mojohaus#389. Relates to mojohaus#388.
- Loading branch information
Showing
15 changed files
with
456 additions
and
0 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
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,6 @@ | ||
invoker.goals = clean process-classes | ||
invoker.buildResult = failure | ||
invoker.debug = false | ||
# Since JDK 17, this option is necessary to avoid | ||
# "UnsupportedOperationException: The Security Manager is deprecated and will be removed in a future release" | ||
invoker.mavenOpts = -Djava.security.manager=allow |
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" ); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
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,30 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
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") |
6 changes: 6 additions & 0 deletions
6
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,6 @@ | ||
invoker.goals = clean process-classes | ||
invoker.buildResult = success | ||
invoker.debug = false | ||
# Since JDK 17, this option is necessary to avoid | ||
# "UnsupportedOperationException: The Security Manager is deprecated and will be removed in a future release" | ||
invoker.mavenOpts = -Djava.security.manager=allow |
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" ); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
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,26 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
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" ); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
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,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. | ||
*/ | ||
|
||
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]" |
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
Oops, something went wrong.