Skip to content

Commit

Permalink
Upgrade to Maven 4.0.0-alpha-9
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Nov 29, 2023
1 parent 347d946 commit f6dbf0f
Show file tree
Hide file tree
Showing 22 changed files with 358 additions and 243 deletions.
33 changes: 5 additions & 28 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ under the License.

<properties>
<javaVersion>8</javaVersion>
<mavenVersion>4.0.0-alpha-8</mavenVersion>
<mavenVersion>4.0.0-alpha-9-SNAPSHOT</mavenVersion>
<!-- Keep in sync with resolver used in maven above -->
<slf4jVersion>1.7.5</slf4jVersion>
<!-- Keep in sync with resolver used in maven above -->
Expand All @@ -84,7 +84,8 @@ under the License.
<mavenInstallPluginVersion>3.1.0</mavenInstallPluginVersion>
<mavenJarPluginVersion>3.3.0</mavenJarPluginVersion>
<mavenJavadocPluginVersion>3.4.1</mavenJavadocPluginVersion>
<mavenPluginToolsVersion>3.9.0</mavenPluginToolsVersion>
<mavenPluginPluginVersion>3.10.3-SNAPSHOT</mavenPluginPluginVersion>
<mavenPluginTestingHarnessVersion>4.0.0-alpha-3-SNAPSHOT</mavenPluginTestingHarnessVersion>
<mavenResourcesPluginVersion>3.3.0</mavenResourcesPluginVersion>
<mavenSourcePluginVersion>3.2.1</mavenSourcePluginVersion>
<mavenSurefirePluginVersion>${surefire.version}</mavenSurefirePluginVersion>
Expand All @@ -107,7 +108,7 @@ under the License.
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>4.0.0-alpha-2</version>
<version>${mavenPluginTestingHarnessVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -123,30 +124,6 @@ under the License.
<version>${mavenVersion}</version>
<scope>test</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.apache.maven.resolver</groupId>-->
<!-- <artifactId>maven-resolver-connector-basic</artifactId>-->
<!-- <version>${resolverVersion}</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.apache.maven.resolver</groupId>-->
<!-- <artifactId>maven-resolver-transport-file</artifactId>-->
<!-- <version>${resolverVersion}</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.apache.maven.resolver</groupId>-->
<!-- <artifactId>maven-resolver-transport-http</artifactId>-->
<!-- <version>${resolverVersion}</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.mockito</groupId>-->
<!-- <artifactId>mockito-core</artifactId>-->
<!-- <version>2.28.2</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
Expand All @@ -167,7 +144,7 @@ under the License.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>${mavenPluginToolsVersion}</version>
<version>${mavenPluginPluginVersion}</version>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
Expand Down
2 changes: 1 addition & 1 deletion src/it/deploy-attached-sources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ under the License.
<version>@project.version@</version>
<configuration>
<!-- Deployments will be written to ${basedir}/target -->
<altDeploymentRepository>mine::default::file://${basedir}/target</altDeploymentRepository>
<altDeploymentRepository>mine::default::file://${project.basedir}/target</altDeploymentRepository>
</configuration>
</plugin>
</plugins>
Expand Down
10 changes: 5 additions & 5 deletions src/it/deploy-attached-sources/test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
# under the License.

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

file = ${basedir}/target/${project.artifactId}-${project.version}.jar
sources = ${basedir}/target/${project.artifactId}-${project.version}-sources.jar
javadoc = ${basedir}/target/${project.artifactId}-${project.version}-javadoc.jar
file = ${project.basedir}/target/${project.artifactId}-${project.version}.jar
sources = ${project.basedir}/target/${project.artifactId}-${project.version}-sources.jar
javadoc = ${project.basedir}/target/${project.artifactId}-${project.version}-javadoc.jar

url = file://${basedir}/target/repo
url = file://${project.basedir}/target/repo
2 changes: 1 addition & 1 deletion src/it/deploy-default-packaging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ under the License.
<version>@project.version@</version>
<configuration>
<!-- Deployments will be written to ${basedir}/target -->
<altDeploymentRepository>mine::default::file://${basedir}/target</altDeploymentRepository>
<altDeploymentRepository>mine::default::file://${project.basedir}/target</altDeploymentRepository>
</configuration>
</plugin>
</plugins>
Expand Down
4 changes: 2 additions & 2 deletions src/it/deploy-default-packaging/test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
groupId = org.apache.maven.test
artifactId = test
version = 1.1
file = ${basedir}/lib/test-1.1.jar
url = file://${basedir}/target/repo
file = ${project.basedir}/lib/test-1.1.jar
url = file://${project.basedir}/target/repo
2 changes: 1 addition & 1 deletion src/it/setup-mock-phase-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ under the License.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>@mavenPluginToolsVersion@</version>
<version>@mavenPluginPluginVersion@</version>
<configuration>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
*/
package org.apache.maven.plugins.deploy;

import jakarta.inject.Inject;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Session;
import org.apache.maven.api.Version;
import org.apache.maven.api.plugin.Log;
import org.apache.maven.api.plugin.Mojo;
import org.apache.maven.api.plugin.MojoException;
import org.apache.maven.api.plugin.annotations.Component;
import org.apache.maven.api.plugin.annotations.Parameter;
import org.apache.maven.api.services.VersionParser;

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

private static final String FIXED_MAVEN_VERSION = "3.9.0";

@Component
@Inject
protected Log logger;

@Component
@Inject
protected Session session;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
*
* @author <a href="mailto:aramirez@apache.org">Allan Ramirez</a>
*/
@Mojo(name = "deploy-file", requiresProject = false)
@Mojo(name = "deploy-file", projectRequired = false)
@SuppressWarnings("unused")
public class DeployFileMojo extends AbstractDeployMojo {
private static final String TAR = "tar.";
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import jakarta.inject.Inject;
import org.apache.maven.api.Artifact;
import org.apache.maven.api.MojoExecution;
import org.apache.maven.api.Project;
Expand All @@ -33,7 +34,6 @@
import org.apache.maven.api.model.Plugin;
import org.apache.maven.api.model.PluginExecution;
import org.apache.maven.api.plugin.MojoException;
import org.apache.maven.api.plugin.annotations.Component;
import org.apache.maven.api.plugin.annotations.LifecyclePhase;
import org.apache.maven.api.plugin.annotations.Mojo;
import org.apache.maven.api.plugin.annotations.Parameter;
Expand All @@ -55,10 +55,10 @@ public class DeployMojo extends AbstractDeployMojo {

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

@Component
@Inject
private Project project;

@Component
@Inject
private MojoExecution mojoExecution;

/**
Expand Down Expand Up @@ -194,7 +194,7 @@ private boolean allProjectsMarked() {
}

private boolean hasDeployExecution(Project p) {
String key = mojoExecution.getPlugin().getKey();
String key = mojoExecution.getPlugin().getModel().getKey();
Plugin plugin = p.getBuild().getPluginsAsMap().get(key);
if (plugin != null) {
for (PluginExecution execution : plugin.getExecutions()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
Expand All @@ -33,6 +34,9 @@
import org.apache.maven.api.Session;
import org.apache.maven.api.model.Model;
import org.apache.maven.api.plugin.testing.InjectMojo;
import org.apache.maven.api.plugin.testing.MojoExtension;
import org.apache.maven.api.plugin.testing.MojoParameter;
import org.apache.maven.api.plugin.testing.MojoParameters;
import org.apache.maven.api.plugin.testing.MojoTest;
import org.apache.maven.api.plugin.testing.stubs.ArtifactStub;
import org.apache.maven.api.plugin.testing.stubs.SessionStub;
Expand All @@ -41,6 +45,7 @@
import org.apache.maven.api.services.ArtifactManager;
import org.apache.maven.api.services.ProjectBuilder;
import org.apache.maven.api.services.ProjectManager;
import org.apache.maven.internal.impl.InternalSession;
import org.junit.jupiter.api.Test;

import static org.apache.maven.api.plugin.testing.MojoExtension.getVariableValueFromObject;
Expand All @@ -50,6 +55,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.when;

/**
* @author <a href="mailto:aramirez@apache.org">Allan Ramirez</a>
Expand All @@ -71,13 +77,27 @@ public class DeployFileMojoTest {
private ArtifactManager artifactManager;

@Test
@InjectMojo(goal = "deploy-file", pom = "classpath:/unit/deploy-file/plugin-config-test.xml")
@InjectMojo(goal = "deploy-file")
public void testDeployTestEnvironment(DeployFileMojo mojo) {
assertNotNull(mojo);
}

@Test
@InjectMojo(goal = "deploy-file", pom = "classpath:/unit/deploy-file/plugin-config-test.xml")
@InjectMojo(goal = "deploy-file")
@MojoParameters({
@MojoParameter(name = "groupId", value = "org.apache.maven.test"),
@MojoParameter(name = "artifactId", value = "maven-deploy-file-test"),
@MojoParameter(name = "version", value = "1.0"),
@MojoParameter(name = "packaging", value = "jar"),
@MojoParameter(
name = "file",
value = "${session.topDirectory}/src/test/resources/unit/maven-deploy-test-1.0-SNAPSHOT.jar"),
@MojoParameter(name = "repositoryId", value = "deploy-test"),
@MojoParameter(name = "url", value = "file://${session.topDirectory}/target/remote-repo/deploy-file"),
@MojoParameter(name = "description", value = "POM was created from deploy:deploy-file"),
@MojoParameter(name = "generatePom", value = "true"),
@MojoParameter(name = "skip", value = "snapshots")
})
public void testBasicDeployFile(DeployFileMojo mojo) throws Exception {
assertNotNull(mojo);

Expand All @@ -93,9 +113,9 @@ public void testBasicDeployFile(DeployFileMojo mojo) throws Exception {
assertEquals("maven-deploy-file-test", artifactId);
assertEquals("1.0", version);
assertEquals("jar", packaging);
assertTrue(Files.exists(file));
assertTrue(Files.exists(file), file.toString());
assertEquals("deploy-test", repositoryId);
assertEquals("file://" + getBasedir() + "/target/remote-repo/deploy-file-test", url);
assertEquals("file://" + getBasedir() + "/target/remote-repo/deploy-file", url);

execute(mojo, request -> {
assertNotNull(request);
Expand Down Expand Up @@ -128,7 +148,20 @@ public void testBasicDeployFile(DeployFileMojo mojo) throws Exception {
}

@Test
@InjectMojo(goal = "deploy-file", pom = "classpath:/unit/deploy-file/plugin-config-classifier.xml")
@InjectMojo(goal = "deploy-file")
@MojoParameters({
@MojoParameter(name = "groupId", value = "org.apache.maven.test"),
@MojoParameter(name = "artifactId", value = "maven-deploy-file-test"),
@MojoParameter(name = "version", value = "1.0"),
@MojoParameter(name = "packaging", value = "jar"),
@MojoParameter(
name = "file",
value = "${session.topDirectory}/src/test/resources/unit/maven-deploy-test-1.0-SNAPSHOT.jar"),
@MojoParameter(name = "repositoryId", value = "deploy-test"),
@MojoParameter(name = "url", value = "file://${session.topDirectory}/target/remote-repo/deploy-file"),
@MojoParameter(name = "classifier", value = "bin"),
@MojoParameter(name = "generatePom", value = "true")
})
public void testDeployIfClassifierIsSet(DeployFileMojo mojo) throws Exception {
assertNotNull(mojo);

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

@Test
@InjectMojo(goal = "deploy-file", pom = "classpath:/unit/deploy-file/plugin-config-artifact-not-jar.xml")
@InjectMojo(goal = "deploy-file")
@MojoParameters({
@MojoParameter(name = "groupId", value = "org.apache.maven.test"),
@MojoParameter(name = "artifactId", value = "maven-deploy-file-test"),
@MojoParameter(name = "version", value = "1.0"),
@MojoParameter(name = "file", value = "${session.topDirectory}/src/test/resources/unit/maven-deploy-test.zip"),
@MojoParameter(name = "repositoryId", value = "deploy-test"),
@MojoParameter(name = "url", value = "file://${session.topDirectory}/target/remote-repo/deploy-file"),
@MojoParameter(name = "generatePom", value = "true")
})
public void testDeployIfArtifactIsNotJar(DeployFileMojo mojo) throws Exception {
assertNotNull(mojo);

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

Expand Down Expand Up @@ -213,31 +255,33 @@ private void execute(DeployFileMojo mojo, Consumer<ArtifactDeployerRequest> cons
@Provides
@Singleton
@SuppressWarnings("unused")
private Session getMockSession() {
return SessionStub.getMockSession(LOCAL_REPO);
private InternalSession createSession() {
InternalSession session = SessionStub.getMockSession(LOCAL_REPO);
when(session.getTopDirectory()).thenReturn(Paths.get(MojoExtension.getBasedir()));
return session;
}

@Provides
@SuppressWarnings("unused")
private ArtifactDeployer getMockArtifactDeployer(Session session) {
private ArtifactDeployer createArtifactDeployer(Session session) {
return session.getService(ArtifactDeployer.class);
}

@Provides
@SuppressWarnings("unused")
private ArtifactManager getMockArtifactManager(Session session) {
private ArtifactManager createArtifactManager(Session session) {
return session.getService(ArtifactManager.class);
}

@Provides
@SuppressWarnings("unused")
private ProjectManager getMockProjectManager(Session session) {
private ProjectManager createProjectManager(Session session) {
return session.getService(ProjectManager.class);
}

@Provides
@SuppressWarnings("unused")
private ProjectBuilder getMockProjectBuilder(Session session) {
private ProjectBuilder createProjectBuilder(Session session) {
return session.getService(ProjectBuilder.class);
}
}

0 comments on commit f6dbf0f

Please sign in to comment.