Skip to content

Commit

Permalink
fix: NPE because declared MavenSession field hides field of superclass
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom authored and slawekjaranowski committed Aug 11, 2024
1 parent a2b735f commit a8c4f94
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ This is the [exec-maven-plugin](http://www.mojohaus.org/exec-maven-plugin/).
[![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)
[![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)

## Running integration tests

Execute `mvn -P run-its clean verify`

## Releasing

* Make sure `gpg-agent` is running.
Expand Down
1 change: 1 addition & 0 deletions src/it/projects/mexec-439/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals = clean test
55 changes: 55 additions & 0 deletions src/it/projects/mexec-439/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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 https://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-439</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<includePluginDependencies>true</includePluginDependencies>
<executableDependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</executableDependency>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath />
<argument>org.junit.runner.JUnitCore</argument>
</arguments>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

</project>
12 changes: 4 additions & 8 deletions src/main/java/org/codehaus/mojo/exec/ExecMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,6 @@ public class ExecMojo extends AbstractExecMojo {
@Parameter
private File environmentScript = null;

/**
* The current build session instance. This is used for toolchain manager API calls.
*/
@Parameter(defaultValue = "${session}", readonly = true)
private MavenSession session;

/**
* Exit codes to be resolved as successful execution for non-compliant applications (applications not returning 0
* for success).
Expand Down Expand Up @@ -430,8 +424,9 @@ public void execute() throws MojoExecutionException {
// output as a log prefix, to enable easy tracing of program output when intermixed with other
// Maven log output. NOTE: The accept(..) methods are running in PumpStreamHandler thread,
// which is why we capture the thread name prefix here.
final String logPrefix =
session.isParallel() ? "[" + Thread.currentThread().getName() + "] " : "";
final String logPrefix = getSession().isParallel()
? "[" + Thread.currentThread().getName() + "] "
: "";
Consumer<String> mavenOutRedirect = logMessage -> {
if (quietLogs) {
getLog().debug(logPrefix + logMessage);
Expand Down Expand Up @@ -942,6 +937,7 @@ public int[] getSuccessCodes() {

private Toolchain getToolchain() {
// session and toolchainManager can be null in tests ...
MavenSession session = getSession();
if (session != null && toolchainManager != null) {
return toolchainManager.getToolchainFromBuildContext(toolchain, session);
}
Expand Down

0 comments on commit a8c4f94

Please sign in to comment.