Skip to content

Commit f6dbf0f

Browse files
committed
Upgrade to Maven 4.0.0-alpha-9
1 parent 347d946 commit f6dbf0f

22 files changed

+358
-243
lines changed

pom.xml

+5-28
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ under the License.
6969

7070
<properties>
7171
<javaVersion>8</javaVersion>
72-
<mavenVersion>4.0.0-alpha-8</mavenVersion>
72+
<mavenVersion>4.0.0-alpha-9-SNAPSHOT</mavenVersion>
7373
<!-- Keep in sync with resolver used in maven above -->
7474
<slf4jVersion>1.7.5</slf4jVersion>
7575
<!-- Keep in sync with resolver used in maven above -->
@@ -84,7 +84,8 @@ under the License.
8484
<mavenInstallPluginVersion>3.1.0</mavenInstallPluginVersion>
8585
<mavenJarPluginVersion>3.3.0</mavenJarPluginVersion>
8686
<mavenJavadocPluginVersion>3.4.1</mavenJavadocPluginVersion>
87-
<mavenPluginToolsVersion>3.9.0</mavenPluginToolsVersion>
87+
<mavenPluginPluginVersion>3.10.3-SNAPSHOT</mavenPluginPluginVersion>
88+
<mavenPluginTestingHarnessVersion>4.0.0-alpha-3-SNAPSHOT</mavenPluginTestingHarnessVersion>
8889
<mavenResourcesPluginVersion>3.3.0</mavenResourcesPluginVersion>
8990
<mavenSourcePluginVersion>3.2.1</mavenSourcePluginVersion>
9091
<mavenSurefirePluginVersion>${surefire.version}</mavenSurefirePluginVersion>
@@ -107,7 +108,7 @@ under the License.
107108
<dependency>
108109
<groupId>org.apache.maven.plugin-testing</groupId>
109110
<artifactId>maven-plugin-testing-harness</artifactId>
110-
<version>4.0.0-alpha-2</version>
111+
<version>${mavenPluginTestingHarnessVersion}</version>
111112
<scope>test</scope>
112113
</dependency>
113114
<dependency>
@@ -123,30 +124,6 @@ under the License.
123124
<version>${mavenVersion}</version>
124125
<scope>test</scope>
125126
</dependency>
126-
<!-- <dependency>-->
127-
<!-- <groupId>org.apache.maven.resolver</groupId>-->
128-
<!-- <artifactId>maven-resolver-connector-basic</artifactId>-->
129-
<!-- <version>${resolverVersion}</version>-->
130-
<!-- <scope>test</scope>-->
131-
<!-- </dependency>-->
132-
<!-- <dependency>-->
133-
<!-- <groupId>org.apache.maven.resolver</groupId>-->
134-
<!-- <artifactId>maven-resolver-transport-file</artifactId>-->
135-
<!-- <version>${resolverVersion}</version>-->
136-
<!-- <scope>test</scope>-->
137-
<!-- </dependency>-->
138-
<!-- <dependency>-->
139-
<!-- <groupId>org.apache.maven.resolver</groupId>-->
140-
<!-- <artifactId>maven-resolver-transport-http</artifactId>-->
141-
<!-- <version>${resolverVersion}</version>-->
142-
<!-- <scope>test</scope>-->
143-
<!-- </dependency>-->
144-
<!-- <dependency>-->
145-
<!-- <groupId>org.mockito</groupId>-->
146-
<!-- <artifactId>mockito-core</artifactId>-->
147-
<!-- <version>2.28.2</version>-->
148-
<!-- <scope>test</scope>-->
149-
<!-- </dependency>-->
150127
<dependency>
151128
<groupId>org.mockito</groupId>
152129
<artifactId>mockito-junit-jupiter</artifactId>
@@ -167,7 +144,7 @@ under the License.
167144
<plugin>
168145
<groupId>org.apache.maven.plugins</groupId>
169146
<artifactId>maven-plugin-plugin</artifactId>
170-
<version>${mavenPluginToolsVersion}</version>
147+
<version>${mavenPluginPluginVersion}</version>
171148
</plugin>
172149
<plugin>
173150
<groupId>com.diffplug.spotless</groupId>

src/it/deploy-attached-sources/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ under the License.
7777
<version>@project.version@</version>
7878
<configuration>
7979
<!-- Deployments will be written to ${basedir}/target -->
80-
<altDeploymentRepository>mine::default::file://${basedir}/target</altDeploymentRepository>
80+
<altDeploymentRepository>mine::default::file://${project.basedir}/target</altDeploymentRepository>
8181
</configuration>
8282
</plugin>
8383
</plugins>

src/it/deploy-attached-sources/test.properties

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
# under the License.
1717

1818
# Properties passed to invocations of the deploy plugin
19-
pomFile = ${basedir}/pom.xml
19+
pomFile = ${project.basedir}/pom.xml
2020

21-
file = ${basedir}/target/${project.artifactId}-${project.version}.jar
22-
sources = ${basedir}/target/${project.artifactId}-${project.version}-sources.jar
23-
javadoc = ${basedir}/target/${project.artifactId}-${project.version}-javadoc.jar
21+
file = ${project.basedir}/target/${project.artifactId}-${project.version}.jar
22+
sources = ${project.basedir}/target/${project.artifactId}-${project.version}-sources.jar
23+
javadoc = ${project.basedir}/target/${project.artifactId}-${project.version}-javadoc.jar
2424

25-
url = file://${basedir}/target/repo
25+
url = file://${project.basedir}/target/repo

src/it/deploy-default-packaging/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ under the License.
7777
<version>@project.version@</version>
7878
<configuration>
7979
<!-- Deployments will be written to ${basedir}/target -->
80-
<altDeploymentRepository>mine::default::file://${basedir}/target</altDeploymentRepository>
80+
<altDeploymentRepository>mine::default::file://${project.basedir}/target</altDeploymentRepository>
8181
</configuration>
8282
</plugin>
8383
</plugins>

src/it/deploy-default-packaging/test.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
groupId = org.apache.maven.test
2020
artifactId = test
2121
version = 1.1
22-
file = ${basedir}/lib/test-1.1.jar
23-
url = file://${basedir}/target/repo
22+
file = ${project.basedir}/lib/test-1.1.jar
23+
url = file://${project.basedir}/target/repo

src/it/setup-mock-phase-maven-plugin/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ under the License.
4545
<plugin>
4646
<groupId>org.apache.maven.plugins</groupId>
4747
<artifactId>maven-plugin-plugin</artifactId>
48-
<version>@mavenPluginToolsVersion@</version>
48+
<version>@mavenPluginPluginVersion@</version>
4949
<configuration>
5050
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
5151
</configuration>

src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
*/
1919
package org.apache.maven.plugins.deploy;
2020

21+
import jakarta.inject.Inject;
2122
import org.apache.maven.api.RemoteRepository;
2223
import org.apache.maven.api.Session;
2324
import org.apache.maven.api.Version;
2425
import org.apache.maven.api.plugin.Log;
2526
import org.apache.maven.api.plugin.Mojo;
2627
import org.apache.maven.api.plugin.MojoException;
27-
import org.apache.maven.api.plugin.annotations.Component;
2828
import org.apache.maven.api.plugin.annotations.Parameter;
2929
import org.apache.maven.api.services.VersionParser;
3030

@@ -36,10 +36,10 @@ public abstract class AbstractDeployMojo implements Mojo {
3636

3737
private static final String FIXED_MAVEN_VERSION = "3.9.0";
3838

39-
@Component
39+
@Inject
4040
protected Log logger;
4141

42-
@Component
42+
@Inject
4343
protected Session session;
4444

4545
/**

src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
*
5353
* @author <a href="mailto:[email protected]">Allan Ramirez</a>
5454
*/
55-
@Mojo(name = "deploy-file", requiresProject = false)
55+
@Mojo(name = "deploy-file", projectRequired = false)
5656
@SuppressWarnings("unused")
5757
public class DeployFileMojo extends AbstractDeployMojo {
5858
private static final String TAR = "tar.";

src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.regex.Matcher;
2626
import java.util.regex.Pattern;
2727

28+
import jakarta.inject.Inject;
2829
import org.apache.maven.api.Artifact;
2930
import org.apache.maven.api.MojoExecution;
3031
import org.apache.maven.api.Project;
@@ -33,7 +34,6 @@
3334
import org.apache.maven.api.model.Plugin;
3435
import org.apache.maven.api.model.PluginExecution;
3536
import org.apache.maven.api.plugin.MojoException;
36-
import org.apache.maven.api.plugin.annotations.Component;
3737
import org.apache.maven.api.plugin.annotations.LifecyclePhase;
3838
import org.apache.maven.api.plugin.annotations.Mojo;
3939
import org.apache.maven.api.plugin.annotations.Parameter;
@@ -55,10 +55,10 @@ public class DeployMojo extends AbstractDeployMojo {
5555

5656
private static final Pattern ALT_REPO_SYNTAX_PATTERN = Pattern.compile("(.+?)::(.+)");
5757

58-
@Component
58+
@Inject
5959
private Project project;
6060

61-
@Component
61+
@Inject
6262
private MojoExecution mojoExecution;
6363

6464
/**
@@ -194,7 +194,7 @@ private boolean allProjectsMarked() {
194194
}
195195

196196
private boolean hasDeployExecution(Project p) {
197-
String key = mojoExecution.getPlugin().getKey();
197+
String key = mojoExecution.getPlugin().getModel().getKey();
198198
Plugin plugin = p.getBuild().getPluginsAsMap().get(key);
199199
if (plugin != null) {
200200
for (PluginExecution execution : plugin.getExecutions()) {

src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java

+58-14
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.File;
2222
import java.nio.file.Files;
2323
import java.nio.file.Path;
24+
import java.nio.file.Paths;
2425
import java.util.ArrayList;
2526
import java.util.List;
2627
import java.util.concurrent.atomic.AtomicReference;
@@ -33,6 +34,9 @@
3334
import org.apache.maven.api.Session;
3435
import org.apache.maven.api.model.Model;
3536
import org.apache.maven.api.plugin.testing.InjectMojo;
37+
import org.apache.maven.api.plugin.testing.MojoExtension;
38+
import org.apache.maven.api.plugin.testing.MojoParameter;
39+
import org.apache.maven.api.plugin.testing.MojoParameters;
3640
import org.apache.maven.api.plugin.testing.MojoTest;
3741
import org.apache.maven.api.plugin.testing.stubs.ArtifactStub;
3842
import org.apache.maven.api.plugin.testing.stubs.SessionStub;
@@ -41,6 +45,7 @@
4145
import org.apache.maven.api.services.ArtifactManager;
4246
import org.apache.maven.api.services.ProjectBuilder;
4347
import org.apache.maven.api.services.ProjectManager;
48+
import org.apache.maven.internal.impl.InternalSession;
4449
import org.junit.jupiter.api.Test;
4550

4651
import static org.apache.maven.api.plugin.testing.MojoExtension.getVariableValueFromObject;
@@ -50,6 +55,7 @@
5055
import static org.junit.jupiter.api.Assertions.assertTrue;
5156
import static org.mockito.ArgumentMatchers.any;
5257
import static org.mockito.Mockito.doAnswer;
58+
import static org.mockito.Mockito.when;
5359

5460
/**
5561
* @author <a href="mailto:[email protected]">Allan Ramirez</a>
@@ -71,13 +77,27 @@ public class DeployFileMojoTest {
7177
private ArtifactManager artifactManager;
7278

7379
@Test
74-
@InjectMojo(goal = "deploy-file", pom = "classpath:/unit/deploy-file/plugin-config-test.xml")
80+
@InjectMojo(goal = "deploy-file")
7581
public void testDeployTestEnvironment(DeployFileMojo mojo) {
7682
assertNotNull(mojo);
7783
}
7884

7985
@Test
80-
@InjectMojo(goal = "deploy-file", pom = "classpath:/unit/deploy-file/plugin-config-test.xml")
86+
@InjectMojo(goal = "deploy-file")
87+
@MojoParameters({
88+
@MojoParameter(name = "groupId", value = "org.apache.maven.test"),
89+
@MojoParameter(name = "artifactId", value = "maven-deploy-file-test"),
90+
@MojoParameter(name = "version", value = "1.0"),
91+
@MojoParameter(name = "packaging", value = "jar"),
92+
@MojoParameter(
93+
name = "file",
94+
value = "${session.topDirectory}/src/test/resources/unit/maven-deploy-test-1.0-SNAPSHOT.jar"),
95+
@MojoParameter(name = "repositoryId", value = "deploy-test"),
96+
@MojoParameter(name = "url", value = "file://${session.topDirectory}/target/remote-repo/deploy-file"),
97+
@MojoParameter(name = "description", value = "POM was created from deploy:deploy-file"),
98+
@MojoParameter(name = "generatePom", value = "true"),
99+
@MojoParameter(name = "skip", value = "snapshots")
100+
})
81101
public void testBasicDeployFile(DeployFileMojo mojo) throws Exception {
82102
assertNotNull(mojo);
83103

@@ -93,9 +113,9 @@ public void testBasicDeployFile(DeployFileMojo mojo) throws Exception {
93113
assertEquals("maven-deploy-file-test", artifactId);
94114
assertEquals("1.0", version);
95115
assertEquals("jar", packaging);
96-
assertTrue(Files.exists(file));
116+
assertTrue(Files.exists(file), file.toString());
97117
assertEquals("deploy-test", repositoryId);
98-
assertEquals("file://" + getBasedir() + "/target/remote-repo/deploy-file-test", url);
118+
assertEquals("file://" + getBasedir() + "/target/remote-repo/deploy-file", url);
99119

100120
execute(mojo, request -> {
101121
assertNotNull(request);
@@ -128,7 +148,20 @@ public void testBasicDeployFile(DeployFileMojo mojo) throws Exception {
128148
}
129149

130150
@Test
131-
@InjectMojo(goal = "deploy-file", pom = "classpath:/unit/deploy-file/plugin-config-classifier.xml")
151+
@InjectMojo(goal = "deploy-file")
152+
@MojoParameters({
153+
@MojoParameter(name = "groupId", value = "org.apache.maven.test"),
154+
@MojoParameter(name = "artifactId", value = "maven-deploy-file-test"),
155+
@MojoParameter(name = "version", value = "1.0"),
156+
@MojoParameter(name = "packaging", value = "jar"),
157+
@MojoParameter(
158+
name = "file",
159+
value = "${session.topDirectory}/src/test/resources/unit/maven-deploy-test-1.0-SNAPSHOT.jar"),
160+
@MojoParameter(name = "repositoryId", value = "deploy-test"),
161+
@MojoParameter(name = "url", value = "file://${session.topDirectory}/target/remote-repo/deploy-file"),
162+
@MojoParameter(name = "classifier", value = "bin"),
163+
@MojoParameter(name = "generatePom", value = "true")
164+
})
132165
public void testDeployIfClassifierIsSet(DeployFileMojo mojo) throws Exception {
133166
assertNotNull(mojo);
134167

@@ -149,7 +182,7 @@ public void testDeployIfClassifierIsSet(DeployFileMojo mojo) throws Exception {
149182
assertEquals(new ArtifactStub(groupId, artifactId, "bin", version, "jar"), a1);
150183
Path p1 = artifactManager.getPath(a1).orElse(null);
151184
assertNotNull(p1);
152-
assertTrue(p1.toString().endsWith("deploy-test-file-1.0-SNAPSHOT.jar"));
185+
assertTrue(p1.toString().endsWith("maven-deploy-test-1.0-SNAPSHOT.jar"));
153186
// second artifact
154187
Artifact a2 = artifacts.get(1);
155188
assertEquals(new ArtifactStub(groupId, artifactId, "", version, "pom"), a2);
@@ -162,7 +195,16 @@ public void testDeployIfClassifierIsSet(DeployFileMojo mojo) throws Exception {
162195
}
163196

164197
@Test
165-
@InjectMojo(goal = "deploy-file", pom = "classpath:/unit/deploy-file/plugin-config-artifact-not-jar.xml")
198+
@InjectMojo(goal = "deploy-file")
199+
@MojoParameters({
200+
@MojoParameter(name = "groupId", value = "org.apache.maven.test"),
201+
@MojoParameter(name = "artifactId", value = "maven-deploy-file-test"),
202+
@MojoParameter(name = "version", value = "1.0"),
203+
@MojoParameter(name = "file", value = "${session.topDirectory}/src/test/resources/unit/maven-deploy-test.zip"),
204+
@MojoParameter(name = "repositoryId", value = "deploy-test"),
205+
@MojoParameter(name = "url", value = "file://${session.topDirectory}/target/remote-repo/deploy-file"),
206+
@MojoParameter(name = "generatePom", value = "true")
207+
})
166208
public void testDeployIfArtifactIsNotJar(DeployFileMojo mojo) throws Exception {
167209
assertNotNull(mojo);
168210

@@ -183,7 +225,7 @@ public void testDeployIfArtifactIsNotJar(DeployFileMojo mojo) throws Exception {
183225
Path p1 = artifactManager.getPath(a1).orElse(null);
184226
Path p2 = artifactManager.getPath(a2).orElse(null);
185227
assertNotNull(p1);
186-
assertTrue(p1.toString().endsWith("deploy-test-file.zip"));
228+
assertTrue(p1.toString().endsWith("maven-deploy-test.zip"));
187229
assertNotNull(p2);
188230
assertTrue(p2.toString().endsWith(".pom"));
189231

@@ -213,31 +255,33 @@ private void execute(DeployFileMojo mojo, Consumer<ArtifactDeployerRequest> cons
213255
@Provides
214256
@Singleton
215257
@SuppressWarnings("unused")
216-
private Session getMockSession() {
217-
return SessionStub.getMockSession(LOCAL_REPO);
258+
private InternalSession createSession() {
259+
InternalSession session = SessionStub.getMockSession(LOCAL_REPO);
260+
when(session.getTopDirectory()).thenReturn(Paths.get(MojoExtension.getBasedir()));
261+
return session;
218262
}
219263

220264
@Provides
221265
@SuppressWarnings("unused")
222-
private ArtifactDeployer getMockArtifactDeployer(Session session) {
266+
private ArtifactDeployer createArtifactDeployer(Session session) {
223267
return session.getService(ArtifactDeployer.class);
224268
}
225269

226270
@Provides
227271
@SuppressWarnings("unused")
228-
private ArtifactManager getMockArtifactManager(Session session) {
272+
private ArtifactManager createArtifactManager(Session session) {
229273
return session.getService(ArtifactManager.class);
230274
}
231275

232276
@Provides
233277
@SuppressWarnings("unused")
234-
private ProjectManager getMockProjectManager(Session session) {
278+
private ProjectManager createProjectManager(Session session) {
235279
return session.getService(ProjectManager.class);
236280
}
237281

238282
@Provides
239283
@SuppressWarnings("unused")
240-
private ProjectBuilder getMockProjectBuilder(Session session) {
284+
private ProjectBuilder createProjectBuilder(Session session) {
241285
return session.getService(ProjectBuilder.class);
242286
}
243287
}

0 commit comments

Comments
 (0)