Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MDEPLOY-313] Update to parent 41, cleanup #47

Merged
merged 8 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 44 additions & 28 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ under the License.
<parent>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugins</artifactId>
<version>39</version>
<version>41</version>
<relativePath />
</parent>

Expand All @@ -43,7 +43,7 @@ under the License.
</contributors>

<prerequisites>
<maven>${mavenVersion}</maven>
<maven>3.2.5</maven>
</prerequisites>

<scm>
Expand All @@ -69,24 +69,24 @@ under the License.

<properties>
<javaVersion>8</javaVersion>
<mavenVersion>3.2.5</mavenVersion>
<mavenVersion>3.9.6</mavenVersion>
<!-- Keep in sync with resolver used in maven above -->
<slf4jVersion>1.7.5</slf4jVersion>
<slf4jVersion>1.7.36</slf4jVersion>
<!-- Keep in sync with resolver used in maven above -->
<resolverVersion>1.0.0.v20140518</resolverVersion>
<resolverVersion>1.9.18</resolverVersion>

<!-- plugins version used in IT tests -->
<mavenAntrunPluginVersion>3.1.0</mavenAntrunPluginVersion>
<mavenCompilerPluginVersion>3.10.1</mavenCompilerPluginVersion>
<mavenEnforcerPluginVersion>3.1.0</mavenEnforcerPluginVersion>
<mavenInstallPluginVersion>3.1.0</mavenInstallPluginVersion>
<mavenJarPluginVersion>3.3.0</mavenJarPluginVersion>
<mavenJavadocPluginVersion>3.4.1</mavenJavadocPluginVersion>
<mavenPluginToolsVersion>${maven.plugin.tools.version}</mavenPluginToolsVersion>
<mavenResourcesPluginVersion>3.3.0</mavenResourcesPluginVersion>
<mavenSourcePluginVersion>3.2.1</mavenSourcePluginVersion>
<mavenSurefirePluginVersion>${surefire.version}</mavenSurefirePluginVersion>
<mavenWarPluginVersion>3.3.2</mavenWarPluginVersion>
<mavenAntrunPluginVersion>${version.maven-antrun-plugin}</mavenAntrunPluginVersion>
<mavenCompilerPluginVersion>${version.maven-compiler-plugin}</mavenCompilerPluginVersion>
<mavenEnforcerPluginVersion>${version.maven-enforcer-plugin}</mavenEnforcerPluginVersion>
<mavenInstallPluginVersion>${version.maven-install-plugin}</mavenInstallPluginVersion>
<mavenJarPluginVersion>${version.maven-jar-plugin}</mavenJarPluginVersion>
<mavenJavadocPluginVersion>${version.maven-javadoc-plugin}</mavenJavadocPluginVersion>
<mavenPluginToolsVersion>${version.maven-plugin-tools}</mavenPluginToolsVersion>
<mavenResourcesPluginVersion>${version.maven-resources-plugin}</mavenResourcesPluginVersion>
<mavenSourcePluginVersion>${version.maven-source-plugin}</mavenSourcePluginVersion>
<mavenSurefirePluginVersion>${version.maven-surefire}</mavenSurefirePluginVersion>
<mavenWarPluginVersion>${version.maven-war-plugin}</mavenWarPluginVersion>

<project.build.outputTimestamp>2023-03-21T14:38:01Z</project.build.outputTimestamp>
</properties>
Expand Down Expand Up @@ -128,14 +128,18 @@ under the License.
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-api</artifactId>
<version>${resolverVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-util</artifactId>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-util</artifactId>
<version>${resolverVersion}</version>
<!-- To work in Maven versions older than 3.9.0 -->
<scope>compile</scope>
Expand Down Expand Up @@ -164,25 +168,25 @@ under the License.
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-aether-provider</artifactId>
<artifactId>maven-resolver-provider</artifactId>
<version>${mavenVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-basic</artifactId>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-connector-basic</artifactId>
<version>${resolverVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-file</artifactId>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-file</artifactId>
<version>${resolverVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-http</artifactId>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-http</artifactId>
<version>${resolverVersion}</version>
<scope>test</scope>
</dependency>
Expand All @@ -204,9 +208,21 @@ under the License.
<version>${slf4jVersion}</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<proc>none</proc>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>run-its</id>
Expand Down
4 changes: 2 additions & 2 deletions src/it/MDEPLOY-178_deployfile-with-embedded-pom/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ File buildLog = new File( basedir, 'build.log' )
assert buildLog.exists()
assert buildLog.text.contains( "[DEBUG] Using META-INF/maven/org.apache.maven.plugins.deploy.its/mdeploy178/pom.xml as pomFile" )

def pomProject = new XmlSlurper().parse( deployedPom )
assert "https://issues.apache.org/jira/browse/MDEPLOY-178".equals( pomProject.url.text() )
def pomProject = new groovy.xml.XmlParser().parse( deployedPom )
assert "https://issues.apache.org/jira/browse/MDEPLOY-178".equals( pomProject.get("url").text() )
27 changes: 7 additions & 20 deletions src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.WriterFactory;
import org.codehaus.plexus.util.xml.ReaderFactory;
import org.codehaus.plexus.util.xml.WriterFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
Expand Down Expand Up @@ -429,21 +429,14 @@ private void processModel(Model model) {
* @throws MojoExecutionException If the file doesn't exist or cannot be read.
*/
Model readModel(File pomFile) throws MojoExecutionException {
Reader reader = null;
try {
reader = ReaderFactory.newXmlReader(pomFile);
final Model model = new MavenXpp3Reader().read(reader);
reader.close();
reader = null;
return model;
try (Reader reader = ReaderFactory.newXmlReader(pomFile)) {
return new MavenXpp3Reader().read(reader);
} catch (FileNotFoundException e) {
throw new MojoExecutionException("POM not found " + pomFile, e);
} catch (IOException e) {
throw new MojoExecutionException("Error reading POM " + pomFile, e);
} catch (XmlPullParserException e) {
throw new MojoExecutionException("Error parsing POM " + pomFile, e);
} finally {
IOUtil.close(reader);
}
}

Expand All @@ -456,23 +449,17 @@ Model readModel(File pomFile) throws MojoExecutionException {
private File generatePomFile() throws MojoExecutionException {
Model model = generateModel();

Writer fw = null;
try {
File tempFile = File.createTempFile("mvndeploy", ".pom");
tempFile.deleteOnExit();

fw = WriterFactory.newXmlWriter(tempFile);

new MavenXpp3Writer().write(fw, model);

fw.close();
fw = null;
try (Writer fw = WriterFactory.newXmlWriter(tempFile)) {
new MavenXpp3Writer().write(fw, model);
}

return tempFile;
} catch (IOException e) {
throw new MojoExecutionException("Error writing temporary pom file: " + e.getMessage(), e);
} finally {
IOUtil.close(fw);
}
}

Expand Down
32 changes: 26 additions & 6 deletions src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.ProjectArtifact;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.deployment.DeployRequest;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.util.artifact.ArtifactIdUtils;

/**
* Deploys an artifact to remote repository.
Expand Down Expand Up @@ -285,17 +287,35 @@ private boolean hasExecution(Plugin plugin) {
}

private void processProject(final MavenProject project, DeployRequest request) throws MojoExecutionException {
// always exists, as project exists
Artifact pomArtifact = RepositoryUtils.toArtifact(new ProjectArtifact(project));
// always exists, but at "init" is w/o file (packaging plugin assigns file to this when packaged)
Artifact projectArtifact = RepositoryUtils.toArtifact(project.getArtifact());

// pom project: pomArtifact and projectArtifact are SAME
// jar project: pomArtifact and projectArtifact are DIFFERENT
// incomplete project: is not pom project and projectArtifact has no file

// we must compare coordinates ONLY (as projectArtifact may not have file, and Artifact.equals factors it in)
// BUT if projectArtifact has file set, use that one
if (ArtifactIdUtils.equalsId(pomArtifact, projectArtifact)) {
if (isFile(projectArtifact.getFile())) {
pomArtifact = projectArtifact;
}
projectArtifact = null;
}

if (isFile(project.getFile())) {
request.addArtifact(RepositoryUtils.toArtifact(new ProjectArtifact(project)));
if (isFile(pomArtifact.getFile())) {
request.addArtifact(pomArtifact);
} else {
throw new MojoExecutionException("The project POM could not be attached");
}

if (!"pom".equals(project.getPackaging())) {
org.apache.maven.artifact.Artifact mavenMainArtifact = project.getArtifact();
if (isFile(mavenMainArtifact.getFile())) {
request.addArtifact(RepositoryUtils.toArtifact(mavenMainArtifact));
// is not packaged, is "incomplete"
boolean isIncomplete = projectArtifact != null && !isFile(projectArtifact.getFile());
if (projectArtifact != null) {
if (!isIncomplete) {
request.addArtifact(projectArtifact);
} else if (!project.getAttachedArtifacts().isEmpty()) {
if (allowIncompleteProjects) {
getLog().warn("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.project.ProjectBuildingRequest;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.internal.impl.DefaultLocalPathComposer;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.repository.LocalRepository;
import org.mockito.InjectMocks;
Expand Down Expand Up @@ -86,8 +87,9 @@ public void testBasicDeployFile() throws Exception {
when(buildingRequest.getRepositoryMerging()).thenReturn(ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT);
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
repositorySession.setLocalRepositoryManager(
new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer())
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
when(session.getRepositorySession()).thenReturn(repositorySession);

Expand Down Expand Up @@ -194,8 +196,9 @@ public void testDeployIfClassifierIsSet() throws Exception {
when(buildingRequest.getRepositoryMerging()).thenReturn(ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT);
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
repositorySession.setLocalRepositoryManager(
new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer())
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
when(session.getRepositorySession()).thenReturn(repositorySession);

Expand Down Expand Up @@ -248,8 +251,9 @@ public void testDeployIfArtifactIsNotJar() throws Exception {
when(buildingRequest.getRepositoryMerging()).thenReturn(ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT);
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
repositorySession.setLocalRepositoryManager(
new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer())
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
when(session.getRepositorySession()).thenReturn(repositorySession);

Expand Down
Loading