Skip to content

Commit 0134866

Browse files
Fix #401 - Maven v4 compatibility
1 parent 198c289 commit 0134866

File tree

13 files changed

+151
-110
lines changed

13 files changed

+151
-110
lines changed

.github/workflows/maven.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,5 @@ jobs:
2424
name: Verify
2525
uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v3
2626
with:
27-
jdk-matrix: '[ "8", "17", "21" ]'
28-
ff-maven: "3.9.5" # Maven version for fail-fast-build
29-
maven-matrix: '[ "3.6.3", "3.8.8", "3.9.5" ]' # Maven versions matrix for verify builds
27+
ff-maven: "3.9.6" # Maven version for fail-fast-build
28+
maven-matrix: '[ "3.6.3", "3.9.6", "4.0.0-alpha-12" ]' # Maven versions matrix for verify builds

pom.xml

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,6 @@
181181
<scope>provided</scope>
182182
</dependency>
183183

184-
<dependency>
185-
<groupId>org.codehaus.plexus</groupId>
186-
<artifactId>plexus-component-annotations</artifactId>
187-
<version>2.2.0</version>
188-
<optional>true</optional>
189-
</dependency>
190-
191184
<dependency>
192185
<groupId>org.apache.commons</groupId>
193186
<artifactId>commons-exec</artifactId>
@@ -261,6 +254,9 @@
261254
<plugin>
262255
<groupId>org.apache.maven.plugins</groupId>
263256
<artifactId>maven-compiler-plugin</artifactId>
257+
<configuration>
258+
<proc>none</proc>
259+
</configuration>
264260
<executions>
265261
<execution>
266262
<id>default-testCompile</id>
@@ -296,18 +292,6 @@
296292
</execution>
297293
</executions>
298294
</plugin>
299-
<plugin>
300-
<groupId>org.codehaus.plexus</groupId>
301-
<artifactId>plexus-component-metadata</artifactId>
302-
<version>2.2.0</version>
303-
<executions>
304-
<execution>
305-
<goals>
306-
<goal>generate-metadata</goal>
307-
</goals>
308-
</execution>
309-
</executions>
310-
</plugin>
311295
<plugin>
312296
<groupId>org.apache.maven.plugins</groupId>
313297
<artifactId>maven-dependency-plugin</artifactId>
@@ -352,6 +336,10 @@
352336
</execution>
353337
</executions>
354338
</plugin>
339+
<plugin>
340+
<groupId>org.eclipse.sisu</groupId>
341+
<artifactId>sisu-maven-plugin</artifactId>
342+
</plugin>
355343
</plugins>
356344
</build>
357345

src/it/projects/mexec-gh-389-block-exit-non-zero/verify.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ assert buildLogLines[infoMessageLineNumber - 1] == "[one, two, three]"
2424
// Verify that subsequent lines contain the beginning of the thrown SystemExitException stack trace
2525
assert buildLogLines[infoMessageLineNumber + 1].startsWith("[WARNING]")
2626
assert buildLogLines[infoMessageLineNumber + 2].contains("SystemExitException: System::exit was called with return code 123")
27-
assert buildLogLines[infoMessageLineNumber + 3].contains("SystemExitManager.exit (SystemExitManager.java")
27+
assert buildLogLines[infoMessageLineNumber + 3].matches(".*SystemExitManager.exit ?\\(SystemExitManager.java.*")

src/it/projects/setup-parent/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@
8686
<artifactId>maven-resources-plugin</artifactId>
8787
<version>@maven-resources-plugin.version@</version>
8888
</plugin>
89+
<plugin>
90+
<groupId>org.apache.maven.plugins</groupId>
91+
<artifactId>maven-toolchains-plugin</artifactId>
92+
<version>3.1.0</version>
93+
</plugin>
8994
</plugins>
9095
</pluginManagement>
9196
</build>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.goals = --toolchains toolchains.xml validate
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<project
2+
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 http://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>toolchains-paths</artifactId>
14+
<version>0.0.1-SNAPSHOT</version>
15+
<packaging>pom</packaging>
16+
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.apache.maven.plugins</groupId>
21+
<artifactId>maven-toolchains-plugin</artifactId>
22+
<configuration>
23+
<toolchains>
24+
<paths>
25+
<id>my-paths</id>
26+
</paths>
27+
</toolchains>
28+
</configuration>
29+
<executions>
30+
<execution>
31+
<goals>
32+
<goal>toolchain</goal>
33+
</goals>
34+
</execution>
35+
</executions>
36+
</plugin>
37+
<plugin>
38+
<groupId>org.codehaus.mojo</groupId>
39+
<artifactId>exec-maven-plugin</artifactId>
40+
<version>@project.version@</version>
41+
<extensions>true</extensions>
42+
<configuration>
43+
<executable>test</executable>
44+
<toolchain>paths</toolchain>
45+
</configuration>
46+
<executions>
47+
<execution>
48+
<id>execution</id>
49+
<goals>
50+
<goal>exec</goal>
51+
</goals>
52+
<phase>validate</phase>
53+
</execution>
54+
</executions>
55+
</plugin>
56+
</plugins>
57+
</build>
58+
</project>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#! /bin/sh
2+
echo Hello from exec-maven-plugin
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo Hello from exec-maven-plugin
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF8"?>
2+
<toolchains>
3+
<toolchain>
4+
<type>paths</type>
5+
<provides>
6+
<id>my-paths</id>
7+
</provides>
8+
<configuration>
9+
<paths>
10+
<path>scripts</path>
11+
</paths>
12+
</configuration>
13+
</toolchain>
14+
</toolchains>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
File log = new File(basedir, 'build.log')
2+
3+
assert log.exists()
4+
assert log.getText().contains( "[INFO] Toolchain in exec-maven-plugin: Paths[scripts]" )
5+
assert log.getText().contains( "Hello from exec-maven-plugin" )

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@
5959
import org.apache.maven.artifact.resolver.filter.IncludesArtifactFilter;
6060
import org.apache.maven.execution.MavenSession;
6161
import org.apache.maven.plugin.MojoExecutionException;
62+
import org.apache.maven.plugins.annotations.Component;
6263
import org.apache.maven.plugins.annotations.Mojo;
6364
import org.apache.maven.plugins.annotations.Parameter;
6465
import org.apache.maven.plugins.annotations.ResolutionScope;
6566
import org.apache.maven.project.MavenProject;
6667
import org.apache.maven.toolchain.Toolchain;
6768
import org.apache.maven.toolchain.ToolchainManager;
68-
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
6969
import org.codehaus.plexus.util.StringUtils;
7070
import org.codehaus.plexus.util.cli.CommandLineException;
7171
import org.codehaus.plexus.util.cli.CommandLineUtils;
@@ -344,6 +344,9 @@ public class ExecMojo extends AbstractExecMojo {
344344
@Parameter(property = "exec.asyncDestroyOnShutdown", defaultValue = "true")
345345
private boolean asyncDestroyOnShutdown = true;
346346

347+
@Component
348+
private ToolchainManager toolchainManager;
349+
347350
public static final String CLASSPATH_TOKEN = "%classpath";
348351

349352
public static final String MODULEPATH_TOKEN = "%modulepath";
@@ -936,22 +939,11 @@ public int[] getSuccessCodes() {
936939
}
937940

938941
private Toolchain getToolchain() {
939-
Toolchain tc = null;
940-
941-
try {
942-
if (session != null) // session is null in tests..
943-
{
944-
ToolchainManager toolchainManager =
945-
(ToolchainManager) session.getContainer().lookup(ToolchainManager.ROLE);
946-
947-
if (toolchainManager != null) {
948-
tc = toolchainManager.getToolchainFromBuildContext(toolchain, session);
949-
}
950-
}
951-
} catch (ComponentLookupException componentLookupException) {
952-
// just ignore, could happen in pre-2.0.9 builds..
942+
// session and toolchainManager can be null in tests ...
943+
if (session != null && toolchainManager != null) {
944+
return toolchainManager.getToolchainFromBuildContext(toolchain, session);
953945
}
954-
return tc;
946+
return null;
955947
}
956948

957949
/**

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

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,59 @@
1919
* under the License.
2020
*/
2121

22+
import java.util.Collections;
2223
import java.util.List;
24+
import java.util.Map;
25+
import java.util.Objects;
2326

24-
import org.apache.maven.toolchain.DefaultToolchain;
27+
import org.apache.maven.toolchain.ToolchainPrivate;
2528
import org.apache.maven.toolchain.model.ToolchainModel;
26-
import org.codehaus.plexus.logging.Logger;
2729

2830
/**
2931
* Searches a list of configured paths for the requested tool.
3032
*
3133
* @author Markus KARG ([email protected])
3234
*/
33-
class PathsToolchain extends DefaultToolchain {
35+
class PathsToolchain implements ToolchainPrivate {
36+
private final ToolchainModel model;
37+
3438
private List<String> paths;
3539

36-
public PathsToolchain(final ToolchainModel model, final Logger logger) {
37-
super(model, "paths", logger); // NOI18N
40+
public PathsToolchain(ToolchainModel model) {
41+
this.model = model;
42+
}
43+
44+
@Override
45+
public ToolchainModel getModel() {
46+
return model;
3847
}
3948

40-
public List<String> getPaths() {
41-
return this.paths;
49+
@Override
50+
public String getType() {
51+
return model.getType();
4252
}
4353

44-
public void setPaths(final List<String> paths) {
54+
public void setPaths(List<String> paths) {
4555
this.paths = paths;
4656
}
4757

48-
@Override
49-
public String toString() {
50-
return "Paths" + this.getPaths(); // NOI18N
58+
private List<String> getPaths() {
59+
return paths != null ? paths : Collections.emptyList();
5160
}
5261

62+
@Override
5363
public String findTool(final String toolName) {
54-
return ExecMojo.findExecutable(toolName, this.paths);
64+
return ExecMojo.findExecutable(toolName, getPaths());
65+
}
66+
67+
@Override
68+
public boolean matchesRequirements(Map<String, String> requirements) {
69+
return requirements.entrySet().stream()
70+
.anyMatch(entry -> Objects.equals(model.getProvides().get(entry.getKey()), entry.getValue()));
71+
}
72+
73+
@Override
74+
public String toString() {
75+
return "Paths" + getPaths(); // NOI18N
5576
}
5677
}

0 commit comments

Comments
 (0)