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 Dec 13, 2023
1 parent 347d946 commit bf1ed68
Show file tree
Hide file tree
Showing 22 changed files with 362 additions and 305 deletions.
70 changes: 34 additions & 36 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</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 @@ -100,14 +101,23 @@ under the License.
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-core</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-model</artifactId>
<version>${mavenVersion}</version>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<version>2.0.1</version>
</dependency>

<!-- Test -->
<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 @@ -118,47 +128,35 @@ under the License.
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-resolver-provider</artifactId>
<version>${mavenVersion}</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>4.11.0</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>
<version>2.28.2</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4jVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4jVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<scope>none</scope>
</dependency>

</dependencies>

Expand All @@ -167,7 +165,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,15 +18,14 @@
*/
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;

/**
* Abstract class for Deploy mojo's.
Expand All @@ -36,10 +35,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 Expand Up @@ -74,9 +73,8 @@ public int getRetryFailedDeploymentCount() {
*/
protected void warnIfAffectedPackagingAndMaven(final String packaging) {
if (AFFECTED_MAVEN_PACKAGING.equals(packaging)) {
VersionParser parser = session.getService(VersionParser.class);
Version fixedMavenVersion = parser.parseVersion(FIXED_MAVEN_VERSION);
Version currentMavenVersion = parser.parseVersion(session.getMavenVersion());
Version fixedMavenVersion = session.parseVersion(FIXED_MAVEN_VERSION);
Version currentMavenVersion = session.parseVersion(session.getMavenVersion());
if (fixedMavenVersion.compareTo(currentMavenVersion) > 0) {
getLog().warn("");
getLog().warn("You are about to deploy a maven-plugin using Maven " + currentMavenVersion + ".");
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.jar.JarFile;
import java.util.regex.Pattern;

import jakarta.inject.Inject;
import org.apache.maven.api.Artifact;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.model.Model;
Expand All @@ -52,7 +53,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 Expand Up @@ -180,6 +181,15 @@ public class DeployFileMojo extends AbstractDeployMojo {
@Parameter(property = "maven.deploy.file.skip", defaultValue = "false")
private String skip = Boolean.FALSE.toString();

@Inject
private ArtifactManager artifactManager;

@Inject
private ArtifactDeployer artifactDeployer;

@Inject
private ModelXmlFactory modelXmlFactory;

void initProperties() throws MojoException {
Path deployedPom;
if (pomFile != null) {
Expand Down Expand Up @@ -284,7 +294,6 @@ public void execute() throws MojoException {
throw new MojoException("Cannot deploy artifact from the local repository: " + file);
}

ArtifactManager artifactManager = session.getService(ArtifactManager.class);
artifactManager.setPath(artifact, file);
deployables.add(artifact);

Expand Down Expand Up @@ -393,7 +402,7 @@ public void execute() throws MojoException {
.retryFailedDeploymentCount(Math.max(1, Math.min(10, getRetryFailedDeploymentCount())))
.build();

session.getService(ArtifactDeployer.class).deploy(deployRequest);
artifactDeployer.deploy(deployRequest);
} catch (ArtifactDeployerException e) {
throw new MojoException(e.getMessage(), e);
} finally {
Expand Down Expand Up @@ -452,7 +461,7 @@ private void processModel(Model model) {
*/
Model readModel(Path pomFile) throws MojoException {
try (InputStream is = Files.newInputStream(pomFile)) {
return session.getService(ModelXmlFactory.class).read(is);
return modelXmlFactory.read(is);
} catch (FileNotFoundException e) {
throw new MojoException("POM not found " + pomFile, e);
} catch (IOException e) {
Expand All @@ -473,7 +482,7 @@ private Path generatePomFile() throws MojoException {
try {
Path pomFile = File.createTempFile("mvndeploy", ".pom").toPath();
try (Writer writer = Files.newBufferedWriter(pomFile)) {
session.getService(ModelXmlFactory.class).write(model, writer);
modelXmlFactory.write(model, writer);
}
return pomFile;
} catch (IOException e) {
Expand Down
29 changes: 18 additions & 11 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,15 +34,13 @@
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;
import org.apache.maven.api.services.ArtifactDeployer;
import org.apache.maven.api.services.ArtifactDeployerRequest;
import org.apache.maven.api.services.ArtifactManager;
import org.apache.maven.api.services.ProjectManager;
import org.apache.maven.api.services.RepositoryFactory;

/**
* Deploys an artifact to remote repository.
Expand All @@ -55,10 +54,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 @@ -138,12 +137,23 @@ public class DeployMojo extends AbstractDeployMojo {
@Parameter(defaultValue = "false", property = "allowIncompleteProjects")
private boolean allowIncompleteProjects;

@Inject
private ArtifactDeployer artifactDeployer;

@Inject
private ArtifactManager artifactManager;

@Inject
private ProjectManager projectManager;

private enum State {
SKIPPED,
DEPLOYED,
TO_BE_DEPLOYED
}

public DeployMojo() {}

private void putState(State state) {
session.getPluginContext(project).put(State.class.getName(), state);
}
Expand Down Expand Up @@ -194,7 +204,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 Expand Up @@ -238,8 +248,7 @@ private void deployAllAtOnce() {

private void deploy(ArtifactDeployerRequest request) {
try {
ArtifactDeployer artifactInstaller = session.getService(ArtifactDeployer.class);
artifactInstaller.deploy(request);
artifactDeployer.deploy(request);
} catch (MojoException e) {
throw e;
} catch (Exception e) {
Expand All @@ -248,8 +257,6 @@ private void deploy(ArtifactDeployerRequest request) {
}

private ArtifactDeployerRequest createDeployerRequest() {
ArtifactManager artifactManager = session.getService(ArtifactManager.class);
ProjectManager projectManager = session.getService(ProjectManager.class);
Predicate<Artifact> isValidPath =
a -> artifactManager.getPath(a).filter(Files::isRegularFile).isPresent();

Expand Down Expand Up @@ -369,11 +376,11 @@ RemoteRepository getDeploymentRepository(boolean isSnapshot) throws MojoExceptio
&& dm.getSnapshotRepository() != null
&& isNotEmpty(dm.getSnapshotRepository().getId())
&& isNotEmpty(dm.getSnapshotRepository().getUrl())) {
repo = getSession().getService(RepositoryFactory.class).createRemote(dm.getSnapshotRepository());
repo = session.createRemoteRepository(dm.getSnapshotRepository());
} else if (dm.getRepository() != null
&& isNotEmpty(dm.getRepository().getId())
&& isNotEmpty(dm.getRepository().getUrl())) {
repo = getSession().getService(RepositoryFactory.class).createRemote(dm.getRepository());
repo = session.createRemoteRepository(dm.getRepository());
}
}
}
Expand Down

0 comments on commit bf1ed68

Please sign in to comment.