Skip to content

Commit a8c4f94

Browse files
sebthomslawekjaranowski
authored andcommitted
fix: NPE because declared MavenSession field hides field of superclass
1 parent a2b735f commit a8c4f94

File tree

4 files changed

+64
-8
lines changed

4 files changed

+64
-8
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ This is the [exec-maven-plugin](http://www.mojohaus.org/exec-maven-plugin/).
66
[![Maven Central](https://img.shields.io/maven-central/v/org.codehaus.mojo/exec-maven-plugin.svg?label=Maven%20Central)](https://search.maven.org/artifact/org.codehaus.mojo/exec-maven-plugin)
77
[![GitHub CI](https://github.com/mojohaus/exec-maven-plugin/actions/workflows/maven.yml/badge.svg)](https://github.com/mojohaus/exec-maven-plugin/actions/workflows/maven.yml)
88

9+
## Running integration tests
10+
11+
Execute `mvn -P run-its clean verify`
12+
913
## Releasing
1014

1115
* Make sure `gpg-agent` is running.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.goals = clean test

src/it/projects/mexec-439/pom.xml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>org.codehaus.mojo.exec.it</groupId>
9+
<artifactId>parent</artifactId>
10+
<version>0.1</version>
11+
</parent>
12+
13+
<artifactId>mexec-439</artifactId>
14+
<version>0.0.1-SNAPSHOT</version>
15+
<packaging>pom</packaging>
16+
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.codehaus.mojo</groupId>
21+
<artifactId>exec-maven-plugin</artifactId>
22+
<version>@project.version@</version>
23+
<executions>
24+
<execution>
25+
<phase>test</phase>
26+
<goals>
27+
<goal>exec</goal>
28+
</goals>
29+
<configuration>
30+
<includePluginDependencies>true</includePluginDependencies>
31+
<executableDependency>
32+
<groupId>junit</groupId>
33+
<artifactId>junit</artifactId>
34+
</executableDependency>
35+
<executable>java</executable>
36+
<arguments>
37+
<argument>-classpath</argument>
38+
<classpath />
39+
<argument>org.junit.runner.JUnitCore</argument>
40+
</arguments>
41+
</configuration>
42+
</execution>
43+
</executions>
44+
<dependencies>
45+
<dependency>
46+
<groupId>junit</groupId>
47+
<artifactId>junit</artifactId>
48+
<version>4.13.2</version>
49+
</dependency>
50+
</dependencies>
51+
</plugin>
52+
</plugins>
53+
</build>
54+
55+
</project>

src/main/java/org/codehaus/mojo/exec/ExecMojo.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,6 @@ public class ExecMojo extends AbstractExecMojo {
284284
@Parameter
285285
private File environmentScript = null;
286286

287-
/**
288-
* The current build session instance. This is used for toolchain manager API calls.
289-
*/
290-
@Parameter(defaultValue = "${session}", readonly = true)
291-
private MavenSession session;
292-
293287
/**
294288
* Exit codes to be resolved as successful execution for non-compliant applications (applications not returning 0
295289
* for success).
@@ -430,8 +424,9 @@ public void execute() throws MojoExecutionException {
430424
// output as a log prefix, to enable easy tracing of program output when intermixed with other
431425
// Maven log output. NOTE: The accept(..) methods are running in PumpStreamHandler thread,
432426
// which is why we capture the thread name prefix here.
433-
final String logPrefix =
434-
session.isParallel() ? "[" + Thread.currentThread().getName() + "] " : "";
427+
final String logPrefix = getSession().isParallel()
428+
? "[" + Thread.currentThread().getName() + "] "
429+
: "";
435430
Consumer<String> mavenOutRedirect = logMessage -> {
436431
if (quietLogs) {
437432
getLog().debug(logPrefix + logMessage);
@@ -942,6 +937,7 @@ public int[] getSuccessCodes() {
942937

943938
private Toolchain getToolchain() {
944939
// session and toolchainManager can be null in tests ...
940+
MavenSession session = getSession();
945941
if (session != null && toolchainManager != null) {
946942
return toolchainManager.getToolchainFromBuildContext(toolchain, session);
947943
}

0 commit comments

Comments
 (0)