Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get some feedback from Maven core #402

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
</contributors>

<prerequisites>
<maven>${mavenVersion}</maven>
<maven>${mavenMinVersion}</maven>
</prerequisites>

<scm>
Expand All @@ -122,7 +122,8 @@
</scm>

<properties>
<mavenVersion>3.6.3</mavenVersion>
<mavenMinVersion>3.6.3</mavenMinVersion>
<mavenVersion>3.9.6</mavenVersion>
Comment on lines +125 to +126
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it good idea.
After it we will can use newer methods from API ... and we will have an exception in runtime on older Maven.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this is wrong, but if we will run tests with 3.6.3 we should sooner or later catch it

<recommendedJavaBuildVersion>11</recommendedJavaBuildVersion>
<slf4j.version>1.7.36</slf4j.version>
<invoker.parallelThreads>1C</invoker.parallelThreads>
Expand Down Expand Up @@ -159,8 +160,7 @@
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-util</artifactId>
<!-- bound version with used Maven -->
<version>1.4.1</version>
<version>1.9.18</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -242,6 +242,16 @@
<detectOfflineLinks>false</detectOfflineLinks>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<proc>none</proc>
<compilerArgs>
<compilerArg>-Xlint:deprecation</compilerArg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</pluginManagement>

Expand Down
37 changes: 18 additions & 19 deletions src/main/java/org/codehaus/mojo/exec/ExecMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* under the License.
*/

import javax.inject.Inject;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -65,13 +67,13 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.toolchain.Toolchain;
import org.apache.maven.toolchain.ToolchainManager;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.codehaus.plexus.util.cli.Commandline;
import org.codehaus.plexus.util.cli.DefaultConsumer;
import org.codehaus.plexus.util.cli.StreamConsumer;
import org.eclipse.sisu.Nullable;

/**
* A Plugin for executing external programs.
Expand Down Expand Up @@ -285,12 +287,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 @@ -348,11 +344,22 @@ public class ExecMojo extends AbstractExecMojo {

public static final String MODULEPATH_TOKEN = "%modulepath";

/**
* The current build session instance. This is used for toolchain manager API calls.
*/
@Inject
private MavenSession session;

@Inject
@Nullable
private ToolchainManager toolchainManager;

/**
* priority in the execute method will be to use System properties arguments over the pom specification.
*
* @throws MojoExecutionException if a failure happens
*/
@Override
public void execute() throws MojoExecutionException {
if (executable == null) {
if (executableDependency == null) {
Expand Down Expand Up @@ -937,19 +944,11 @@ public int[] getSuccessCodes() {

private Toolchain getToolchain() {
Toolchain tc = null;

try {
if (session != null) // session is null in tests..
{
ToolchainManager toolchainManager =
(ToolchainManager) session.getContainer().lookup(ToolchainManager.ROLE);

if (toolchainManager != null) {
tc = toolchainManager.getToolchainFromBuildContext(toolchain, session);
}
if (session != null) // session is null in tests..
{
if (toolchainManager != null) {
tc = toolchainManager.getToolchainFromBuildContext(toolchain, session);
}
} catch (ComponentLookupException componentLookupException) {
// just ignore, could happen in pre-2.0.9 builds..
}
return tc;
}
Expand Down