Skip to content

Commit 2da1474

Browse files
authored
[MCLEAN-123] Switch to Maven 4 and the new api (#20)
1 parent 9073634 commit 2da1474

File tree

16 files changed

+411
-328
lines changed

16 files changed

+411
-328
lines changed

.github/workflows/maven-verify.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ jobs:
2626
name: Verify
2727
uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v4
2828
with:
29-
maven4-enabled: true
29+
ff-maven: "4.0.0-beta-3" # Maven version for fail-fast-build
30+
maven-matrix: '[ "4.0.0-beta-3" ]'
31+
jdk-matrix: '[ "17", "21" ]'

pom.xml

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ under the License.
2828
</parent>
2929

3030
<artifactId>maven-clean-plugin</artifactId>
31-
<version>3.4.1-SNAPSHOT</version>
31+
<version>4.0.0-SNAPSHOT</version>
3232
<packaging>maven-plugin</packaging>
3333

3434
<name>Apache Maven Clean Plugin</name>
@@ -61,46 +61,44 @@ under the License.
6161
</distributionManagement>
6262

6363
<properties>
64-
<mavenVersion>3.6.3</mavenVersion>
64+
<mavenVersion>4.0.0-beta-3</mavenVersion>
65+
<javaVersion>17</javaVersion>
66+
<version.maven-invoker-plugin>3.7.0</version.maven-invoker-plugin>
67+
<version.maven-plugin-testing>4.0.0-alpha-3-SNAPSHOT</version.maven-plugin-testing>
68+
<version.maven-plugin-tools>4.0.0-SNAPSHOT</version.maven-plugin-tools>
6569
<project.build.outputTimestamp>2024-06-16T10:25:11Z</project.build.outputTimestamp>
6670
</properties>
6771

6872
<dependencies>
6973
<dependency>
7074
<groupId>org.apache.maven</groupId>
71-
<artifactId>maven-plugin-api</artifactId>
75+
<artifactId>maven-api-core</artifactId>
7276
<version>${mavenVersion}</version>
7377
<scope>provided</scope>
7478
</dependency>
7579
<dependency>
7680
<groupId>org.apache.maven</groupId>
77-
<artifactId>maven-core</artifactId>
81+
<artifactId>maven-api-di</artifactId>
7882
<version>${mavenVersion}</version>
7983
<scope>provided</scope>
8084
</dependency>
8185
<dependency>
82-
<groupId>org.apache.maven.resolver</groupId>
83-
<artifactId>maven-resolver-api</artifactId>
84-
<version>1.1.1</version>
86+
<groupId>org.apache.maven</groupId>
87+
<artifactId>maven-api-meta</artifactId>
88+
<version>${mavenVersion}</version>
8589
<scope>provided</scope>
8690
</dependency>
91+
8792
<dependency>
8893
<groupId>org.codehaus.plexus</groupId>
8994
<artifactId>plexus-utils</artifactId>
9095
</dependency>
9196

92-
<!-- dependencies to annotations -->
93-
<dependency>
94-
<groupId>org.apache.maven.plugin-tools</groupId>
95-
<artifactId>maven-plugin-annotations</artifactId>
96-
<scope>provided</scope>
97-
</dependency>
98-
9997
<!-- Test -->
10098
<dependency>
10199
<groupId>org.apache.maven.plugin-testing</groupId>
102100
<artifactId>maven-plugin-testing-harness</artifactId>
103-
<version>4.0.0-alpha-2</version>
101+
<version>${version.maven-plugin-testing}</version>
104102
<scope>test</scope>
105103
</dependency>
106104
<dependency>
@@ -109,18 +107,42 @@ under the License.
109107
<scope>test</scope>
110108
</dependency>
111109
<dependency>
112-
<groupId>org.codehaus.plexus</groupId>
113-
<artifactId>plexus-testing</artifactId>
114-
<version>1.3.0</version>
110+
<groupId>org.apache.maven</groupId>
111+
<artifactId>maven-core</artifactId>
112+
<version>${mavenVersion}</version>
115113
<scope>test</scope>
116114
</dependency>
117115
<dependency>
118-
<groupId>org.codehaus.plexus</groupId>
119-
<artifactId>plexus-xml</artifactId>
116+
<groupId>com.google.inject</groupId>
117+
<artifactId>guice</artifactId>
118+
<version>6.0.0</version>
119+
<scope>test</scope>
120+
</dependency>
121+
<dependency>
122+
<groupId>org.slf4j</groupId>
123+
<artifactId>slf4j-simple</artifactId>
124+
<version>2.0.13</version>
120125
<scope>test</scope>
121126
</dependency>
122127
</dependencies>
123128

129+
<build>
130+
<plugins>
131+
<plugin>
132+
<groupId>org.apache.maven.plugins</groupId>
133+
<artifactId>maven-plugin-plugin</artifactId>
134+
<version>${version.maven-plugin-tools}</version>
135+
</plugin>
136+
<plugin>
137+
<groupId>org.apache.maven.plugins</groupId>
138+
<artifactId>maven-surefire-plugin</artifactId>
139+
<configuration>
140+
<redirectTestOutputToFile>true</redirectTestOutputToFile>
141+
</configuration>
142+
</plugin>
143+
</plugins>
144+
</build>
145+
124146
<profiles>
125147
<profile>
126148
<id>run-its</id>

src/it/settings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ under the License.
3232
<url>@localRepositoryUrl@</url>
3333
<releases>
3434
<enabled>true</enabled>
35+
<checksumPolicy>ignore</checksumPolicy>
3536
</releases>
3637
<snapshots>
3738
<enabled>true</enabled>
39+
<checksumPolicy>ignore</checksumPolicy>
3840
</snapshots>
3941
</repository>
4042
</repositories>
@@ -44,9 +46,11 @@ under the License.
4446
<url>@localRepositoryUrl@</url>
4547
<releases>
4648
<enabled>true</enabled>
49+
<checksumPolicy>ignore</checksumPolicy>
4750
</releases>
4851
<snapshots>
4952
<enabled>true</enabled>
53+
<checksumPolicy>ignore</checksumPolicy>
5054
</snapshots>
5155
</pluginRepository>
5256
</pluginRepositories>

src/main/java/org/apache/maven/plugins/clean/CleanMojo.java

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@
1818
*/
1919
package org.apache.maven.plugins.clean;
2020

21-
import java.io.File;
2221
import java.io.IOException;
22+
import java.nio.file.Path;
23+
import java.nio.file.Paths;
2324

24-
import org.apache.maven.execution.MavenSession;
25-
import org.apache.maven.plugin.AbstractMojo;
26-
import org.apache.maven.plugin.MojoExecutionException;
27-
import org.apache.maven.plugins.annotations.Mojo;
28-
import org.apache.maven.plugins.annotations.Parameter;
25+
import org.apache.maven.api.Session;
26+
import org.apache.maven.api.di.Inject;
27+
import org.apache.maven.api.plugin.Log;
28+
import org.apache.maven.api.plugin.MojoException;
29+
import org.apache.maven.api.plugin.annotations.Mojo;
30+
import org.apache.maven.api.plugin.annotations.Parameter;
2931

3032
/**
3133
* Goal which cleans the build.
@@ -43,40 +45,43 @@
4345
* @see org.apache.maven.plugins.clean.Fileset
4446
* @since 2.0
4547
*/
46-
@Mojo(name = "clean", threadSafe = true)
47-
public class CleanMojo extends AbstractMojo {
48+
@Mojo(name = "clean")
49+
public class CleanMojo implements org.apache.maven.api.plugin.Mojo {
4850

4951
public static final String FAST_MODE_BACKGROUND = "background";
5052

5153
public static final String FAST_MODE_AT_END = "at-end";
5254

5355
public static final String FAST_MODE_DEFER = "defer";
5456

57+
@Inject
58+
private Log logger;
59+
5560
/**
5661
* This is where build results go.
5762
*/
5863
@Parameter(defaultValue = "${project.build.directory}", readonly = true, required = true)
59-
private File directory;
64+
private Path directory;
6065

6166
/**
6267
* This is where compiled classes go.
6368
*/
6469
@Parameter(defaultValue = "${project.build.outputDirectory}", readonly = true, required = true)
65-
private File outputDirectory;
70+
private Path outputDirectory;
6671

6772
/**
6873
* This is where compiled test classes go.
6974
*/
7075
@Parameter(defaultValue = "${project.build.testOutputDirectory}", readonly = true, required = true)
71-
private File testOutputDirectory;
76+
private Path testOutputDirectory;
7277

7378
/**
7479
* This is where the site plugin generates its pages.
7580
*
7681
* @since 2.1.1
7782
*/
7883
@Parameter(defaultValue = "${project.build.outputDirectory}", readonly = true, required = true)
79-
private File reportDirectory;
84+
private Path reportDirectory;
8085

8186
/**
8287
* Sets whether the plugin runs in verbose mode. As of plugin version 2.3, the default value is derived from Maven's
@@ -186,11 +191,11 @@ public class CleanMojo extends AbstractMojo {
186191
* should usually reside on the same volume. The exact conditions are system dependant though, but if an atomic
187192
* move is not supported, the standard deletion mechanism will be used.
188193
*
189-
* @see #fast
190194
* @since 3.2
195+
* @see #fast
191196
*/
192197
@Parameter(property = "maven.clean.fastDir")
193-
private File fastDir;
198+
private Path fastDir;
194199

195200
/**
196201
* Mode to use when using fast clean. Values are: <code>background</code> to start deletion immediately and
@@ -199,35 +204,35 @@ public class CleanMojo extends AbstractMojo {
199204
* the actual file deletion should be started in the background when the session ends (this should only be used
200205
* when maven is embedded in a long running process).
201206
*
202-
* @see #fast
203207
* @since 3.2
208+
* @see #fast
204209
*/
205210
@Parameter(property = "maven.clean.fastMode", defaultValue = FAST_MODE_BACKGROUND)
206211
private String fastMode;
207212

208-
@Parameter(defaultValue = "${session}", readonly = true)
209-
private MavenSession session;
213+
@Inject
214+
private Session session;
210215

211216
/**
212217
* Deletes file-sets in the following project build directory order: (source) directory, output directory, test
213218
* directory, report directory, and then the additional file-sets.
214219
*
215-
* @throws MojoExecutionException When a directory failed to get deleted.
216-
* @see org.apache.maven.plugin.Mojo#execute()
220+
* @throws MojoException When a directory failed to get deleted.
221+
* @see org.apache.maven.api.plugin.Mojo#execute()
217222
*/
218-
public void execute() throws MojoExecutionException {
223+
public void execute() {
219224
if (skip) {
220225
getLog().info("Clean is skipped.");
221226
return;
222227
}
223228

224229
String multiModuleProjectDirectory =
225-
session != null ? session.getSystemProperties().getProperty("maven.multiModuleProjectDirectory") : null;
226-
File fastDir;
230+
session != null ? session.getSystemProperties().get("maven.multiModuleProjectDirectory") : null;
231+
Path fastDir;
227232
if (fast && this.fastDir != null) {
228233
fastDir = this.fastDir;
229234
} else if (fast && multiModuleProjectDirectory != null) {
230-
fastDir = new File(multiModuleProjectDirectory, "target/.clean");
235+
fastDir = Paths.get(multiModuleProjectDirectory, "target/.clean");
231236
} else {
232237
fastDir = null;
233238
if (fast) {
@@ -247,7 +252,7 @@ public void execute() throws MojoExecutionException {
247252
Cleaner cleaner = new Cleaner(session, getLog(), isVerbose(), fastDir, fastMode);
248253

249254
try {
250-
for (File directoryItem : getDirectories()) {
255+
for (Path directoryItem : getDirectories()) {
251256
if (directoryItem != null) {
252257
cleaner.delete(directoryItem, null, followSymLinks, failOnError, retryOnError);
253258
}
@@ -256,7 +261,7 @@ public void execute() throws MojoExecutionException {
256261
if (filesets != null) {
257262
for (Fileset fileset : filesets) {
258263
if (fileset.getDirectory() == null) {
259-
throw new MojoExecutionException("Missing base directory for " + fileset);
264+
throw new MojoException("Missing base directory for " + fileset);
260265
}
261266
final String[] includes = fileset.getIncludes();
262267
final String[] excludes = fileset.getExcludes();
@@ -273,8 +278,9 @@ public void execute() throws MojoExecutionException {
273278
fileset.getDirectory(), selector, fileset.isFollowSymlinks(), failOnError, retryOnError);
274279
}
275280
}
281+
276282
} catch (IOException e) {
277-
throw new MojoExecutionException("Failed to clean project: " + e.getMessage(), e);
283+
throw new MojoException("Failed to clean project: " + e.getMessage(), e);
278284
}
279285
}
280286

@@ -292,13 +298,17 @@ private boolean isVerbose() {
292298
*
293299
* @return The directories to clean or an empty array if none, never <code>null</code>.
294300
*/
295-
private File[] getDirectories() {
296-
File[] directories;
301+
private Path[] getDirectories() {
302+
Path[] directories;
297303
if (excludeDefaultDirectories) {
298-
directories = new File[0];
304+
directories = new Path[0];
299305
} else {
300-
directories = new File[] {directory, outputDirectory, testOutputDirectory, reportDirectory};
306+
directories = new Path[] {directory, outputDirectory, testOutputDirectory, reportDirectory};
301307
}
302308
return directories;
303309
}
310+
311+
private Log getLog() {
312+
return logger;
313+
}
304314
}

0 commit comments

Comments
 (0)