Skip to content

Commit 390e610

Browse files
authored
[MDEPLOY-313] Update to parent 41, cleanup (#47)
In general perform a cleanup of plugin, apply updates where needed. The plugin now builds against 3.9.x latest, and minimum is left as is (3.2.5). A notable change along that above is removal of "baked in" packaging, now plugin relies completely and only on what project and artifact tells, there is no "if this is POM" check anymore. The new "BOM UT" shows this in action. Has to be noted though, that the UT tests ONLY the plugin, to use BOM packaging you need Maven that knows what it is (Maven 3 w/ extension or Maven 4 that has it OOTB). --- https://issues.apache.org/jira/browse/MDEPLOY-313
1 parent 29f3c81 commit 390e610

File tree

11 files changed

+321
-139
lines changed

11 files changed

+321
-139
lines changed

pom.xml

+44-28
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ under the License.
2323
<parent>
2424
<groupId>org.apache.maven.plugins</groupId>
2525
<artifactId>maven-plugins</artifactId>
26-
<version>39</version>
26+
<version>41</version>
2727
<relativePath />
2828
</parent>
2929

@@ -43,7 +43,7 @@ under the License.
4343
</contributors>
4444

4545
<prerequisites>
46-
<maven>${mavenVersion}</maven>
46+
<maven>3.2.5</maven>
4747
</prerequisites>
4848

4949
<scm>
@@ -69,24 +69,24 @@ under the License.
6969

7070
<properties>
7171
<javaVersion>8</javaVersion>
72-
<mavenVersion>3.2.5</mavenVersion>
72+
<mavenVersion>3.9.6</mavenVersion>
7373
<!-- Keep in sync with resolver used in maven above -->
74-
<slf4jVersion>1.7.5</slf4jVersion>
74+
<slf4jVersion>1.7.36</slf4jVersion>
7575
<!-- Keep in sync with resolver used in maven above -->
76-
<resolverVersion>1.0.0.v20140518</resolverVersion>
76+
<resolverVersion>1.9.18</resolverVersion>
7777

7878
<!-- plugins version used in IT tests -->
79-
<mavenAntrunPluginVersion>3.1.0</mavenAntrunPluginVersion>
80-
<mavenCompilerPluginVersion>3.10.1</mavenCompilerPluginVersion>
81-
<mavenEnforcerPluginVersion>3.1.0</mavenEnforcerPluginVersion>
82-
<mavenInstallPluginVersion>3.1.0</mavenInstallPluginVersion>
83-
<mavenJarPluginVersion>3.3.0</mavenJarPluginVersion>
84-
<mavenJavadocPluginVersion>3.4.1</mavenJavadocPluginVersion>
85-
<mavenPluginToolsVersion>${maven.plugin.tools.version}</mavenPluginToolsVersion>
86-
<mavenResourcesPluginVersion>3.3.0</mavenResourcesPluginVersion>
87-
<mavenSourcePluginVersion>3.2.1</mavenSourcePluginVersion>
88-
<mavenSurefirePluginVersion>${surefire.version}</mavenSurefirePluginVersion>
89-
<mavenWarPluginVersion>3.3.2</mavenWarPluginVersion>
79+
<mavenAntrunPluginVersion>${version.maven-antrun-plugin}</mavenAntrunPluginVersion>
80+
<mavenCompilerPluginVersion>${version.maven-compiler-plugin}</mavenCompilerPluginVersion>
81+
<mavenEnforcerPluginVersion>${version.maven-enforcer-plugin}</mavenEnforcerPluginVersion>
82+
<mavenInstallPluginVersion>${version.maven-install-plugin}</mavenInstallPluginVersion>
83+
<mavenJarPluginVersion>${version.maven-jar-plugin}</mavenJarPluginVersion>
84+
<mavenJavadocPluginVersion>${version.maven-javadoc-plugin}</mavenJavadocPluginVersion>
85+
<mavenPluginToolsVersion>${version.maven-plugin-tools}</mavenPluginToolsVersion>
86+
<mavenResourcesPluginVersion>${version.maven-resources-plugin}</mavenResourcesPluginVersion>
87+
<mavenSourcePluginVersion>${version.maven-source-plugin}</mavenSourcePluginVersion>
88+
<mavenSurefirePluginVersion>${version.maven-surefire}</mavenSurefirePluginVersion>
89+
<mavenWarPluginVersion>${version.maven-war-plugin}</mavenWarPluginVersion>
9090

9191
<project.build.outputTimestamp>2023-03-21T14:38:01Z</project.build.outputTimestamp>
9292
</properties>
@@ -128,14 +128,18 @@ under the License.
128128
<artifactId>plexus-utils</artifactId>
129129
</dependency>
130130
<dependency>
131-
<groupId>org.eclipse.aether</groupId>
132-
<artifactId>aether-api</artifactId>
131+
<groupId>org.codehaus.plexus</groupId>
132+
<artifactId>plexus-xml</artifactId>
133+
</dependency>
134+
<dependency>
135+
<groupId>org.apache.maven.resolver</groupId>
136+
<artifactId>maven-resolver-api</artifactId>
133137
<version>${resolverVersion}</version>
134138
<scope>provided</scope>
135139
</dependency>
136140
<dependency>
137-
<groupId>org.eclipse.aether</groupId>
138-
<artifactId>aether-util</artifactId>
141+
<groupId>org.apache.maven.resolver</groupId>
142+
<artifactId>maven-resolver-util</artifactId>
139143
<version>${resolverVersion}</version>
140144
<!-- To work in Maven versions older than 3.9.0 -->
141145
<scope>compile</scope>
@@ -164,25 +168,25 @@ under the License.
164168
</dependency>
165169
<dependency>
166170
<groupId>org.apache.maven</groupId>
167-
<artifactId>maven-aether-provider</artifactId>
171+
<artifactId>maven-resolver-provider</artifactId>
168172
<version>${mavenVersion}</version>
169173
<scope>test</scope>
170174
</dependency>
171175
<dependency>
172-
<groupId>org.eclipse.aether</groupId>
173-
<artifactId>aether-connector-basic</artifactId>
176+
<groupId>org.apache.maven.resolver</groupId>
177+
<artifactId>maven-resolver-connector-basic</artifactId>
174178
<version>${resolverVersion}</version>
175179
<scope>test</scope>
176180
</dependency>
177181
<dependency>
178-
<groupId>org.eclipse.aether</groupId>
179-
<artifactId>aether-transport-file</artifactId>
182+
<groupId>org.apache.maven.resolver</groupId>
183+
<artifactId>maven-resolver-transport-file</artifactId>
180184
<version>${resolverVersion}</version>
181185
<scope>test</scope>
182186
</dependency>
183187
<dependency>
184-
<groupId>org.eclipse.aether</groupId>
185-
<artifactId>aether-transport-http</artifactId>
188+
<groupId>org.apache.maven.resolver</groupId>
189+
<artifactId>maven-resolver-transport-http</artifactId>
186190
<version>${resolverVersion}</version>
187191
<scope>test</scope>
188192
</dependency>
@@ -204,9 +208,21 @@ under the License.
204208
<version>${slf4jVersion}</version>
205209
<scope>test</scope>
206210
</dependency>
207-
208211
</dependencies>
209212

213+
<build>
214+
<plugins>
215+
<plugin>
216+
<groupId>org.apache.maven.plugins</groupId>
217+
<artifactId>maven-compiler-plugin</artifactId>
218+
<configuration>
219+
<proc>none</proc>
220+
<showDeprecation>true</showDeprecation>
221+
</configuration>
222+
</plugin>
223+
</plugins>
224+
</build>
225+
210226
<profiles>
211227
<profile>
212228
<id>run-its</id>

src/it/MDEPLOY-178_deployfile-with-embedded-pom/verify.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ File buildLog = new File( basedir, 'build.log' )
2525
assert buildLog.exists()
2626
assert buildLog.text.contains( "[DEBUG] Using META-INF/maven/org.apache.maven.plugins.deploy.its/mdeploy178/pom.xml as pomFile" )
2727

28-
def pomProject = new XmlSlurper().parse( deployedPom )
29-
assert "https://issues.apache.org/jira/browse/MDEPLOY-178".equals( pomProject.url.text() )
28+
def pomProject = new groovy.xml.XmlParser().parse( deployedPom )
29+
assert "https://issues.apache.org/jira/browse/MDEPLOY-178".equals( pomProject.get("url").text() )

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

+7-20
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
import org.apache.maven.plugins.annotations.Parameter;
4444
import org.codehaus.plexus.util.FileUtils;
4545
import org.codehaus.plexus.util.IOUtil;
46-
import org.codehaus.plexus.util.ReaderFactory;
4746
import org.codehaus.plexus.util.StringUtils;
48-
import org.codehaus.plexus.util.WriterFactory;
47+
import org.codehaus.plexus.util.xml.ReaderFactory;
48+
import org.codehaus.plexus.util.xml.WriterFactory;
4949
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
5050
import org.eclipse.aether.RepositorySystemSession;
5151
import org.eclipse.aether.artifact.Artifact;
@@ -429,21 +429,14 @@ private void processModel(Model model) {
429429
* @throws MojoExecutionException If the file doesn't exist or cannot be read.
430430
*/
431431
Model readModel(File pomFile) throws MojoExecutionException {
432-
Reader reader = null;
433-
try {
434-
reader = ReaderFactory.newXmlReader(pomFile);
435-
final Model model = new MavenXpp3Reader().read(reader);
436-
reader.close();
437-
reader = null;
438-
return model;
432+
try (Reader reader = ReaderFactory.newXmlReader(pomFile)) {
433+
return new MavenXpp3Reader().read(reader);
439434
} catch (FileNotFoundException e) {
440435
throw new MojoExecutionException("POM not found " + pomFile, e);
441436
} catch (IOException e) {
442437
throw new MojoExecutionException("Error reading POM " + pomFile, e);
443438
} catch (XmlPullParserException e) {
444439
throw new MojoExecutionException("Error parsing POM " + pomFile, e);
445-
} finally {
446-
IOUtil.close(reader);
447440
}
448441
}
449442

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

459-
Writer fw = null;
460452
try {
461453
File tempFile = File.createTempFile("mvndeploy", ".pom");
462454
tempFile.deleteOnExit();
463455

464-
fw = WriterFactory.newXmlWriter(tempFile);
465-
466-
new MavenXpp3Writer().write(fw, model);
467-
468-
fw.close();
469-
fw = null;
456+
try (Writer fw = WriterFactory.newXmlWriter(tempFile)) {
457+
new MavenXpp3Writer().write(fw, model);
458+
}
470459

471460
return tempFile;
472461
} catch (IOException e) {
473462
throw new MojoExecutionException("Error writing temporary pom file: " + e.getMessage(), e);
474-
} finally {
475-
IOUtil.close(fw);
476463
}
477464
}
478465

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

+26-6
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
import org.apache.maven.plugins.annotations.Parameter;
3939
import org.apache.maven.project.MavenProject;
4040
import org.apache.maven.project.artifact.ProjectArtifact;
41+
import org.eclipse.aether.artifact.Artifact;
4142
import org.eclipse.aether.deployment.DeployRequest;
4243
import org.eclipse.aether.repository.RemoteRepository;
44+
import org.eclipse.aether.util.artifact.ArtifactIdUtils;
4345

4446
/**
4547
* Deploys an artifact to remote repository.
@@ -285,17 +287,35 @@ private boolean hasExecution(Plugin plugin) {
285287
}
286288

287289
private void processProject(final MavenProject project, DeployRequest request) throws MojoExecutionException {
290+
// always exists, as project exists
291+
Artifact pomArtifact = RepositoryUtils.toArtifact(new ProjectArtifact(project));
292+
// always exists, but at "init" is w/o file (packaging plugin assigns file to this when packaged)
293+
Artifact projectArtifact = RepositoryUtils.toArtifact(project.getArtifact());
294+
295+
// pom project: pomArtifact and projectArtifact are SAME
296+
// jar project: pomArtifact and projectArtifact are DIFFERENT
297+
// incomplete project: is not pom project and projectArtifact has no file
298+
299+
// we must compare coordinates ONLY (as projectArtifact may not have file, and Artifact.equals factors it in)
300+
// BUT if projectArtifact has file set, use that one
301+
if (ArtifactIdUtils.equalsId(pomArtifact, projectArtifact)) {
302+
if (isFile(projectArtifact.getFile())) {
303+
pomArtifact = projectArtifact;
304+
}
305+
projectArtifact = null;
306+
}
288307

289-
if (isFile(project.getFile())) {
290-
request.addArtifact(RepositoryUtils.toArtifact(new ProjectArtifact(project)));
308+
if (isFile(pomArtifact.getFile())) {
309+
request.addArtifact(pomArtifact);
291310
} else {
292311
throw new MojoExecutionException("The project POM could not be attached");
293312
}
294313

295-
if (!"pom".equals(project.getPackaging())) {
296-
org.apache.maven.artifact.Artifact mavenMainArtifact = project.getArtifact();
297-
if (isFile(mavenMainArtifact.getFile())) {
298-
request.addArtifact(RepositoryUtils.toArtifact(mavenMainArtifact));
314+
// is not packaged, is "incomplete"
315+
boolean isIncomplete = projectArtifact != null && !isFile(projectArtifact.getFile());
316+
if (projectArtifact != null) {
317+
if (!isIncomplete) {
318+
request.addArtifact(projectArtifact);
299319
} else if (!project.getAttachedArtifacts().isEmpty()) {
300320
if (allowIncompleteProjects) {
301321
getLog().warn("");

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

+10-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
2929
import org.apache.maven.project.ProjectBuildingRequest;
3030
import org.eclipse.aether.DefaultRepositorySystemSession;
31+
import org.eclipse.aether.internal.impl.DefaultLocalPathComposer;
3132
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
3233
import org.eclipse.aether.repository.LocalRepository;
3334
import org.mockito.InjectMocks;
@@ -86,8 +87,9 @@ public void testBasicDeployFile() throws Exception {
8687
when(buildingRequest.getRepositoryMerging()).thenReturn(ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT);
8788
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
8889
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
89-
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
90-
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
90+
repositorySession.setLocalRepositoryManager(
91+
new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer())
92+
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
9193
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
9294
when(session.getRepositorySession()).thenReturn(repositorySession);
9395

@@ -194,8 +196,9 @@ public void testDeployIfClassifierIsSet() throws Exception {
194196
when(buildingRequest.getRepositoryMerging()).thenReturn(ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT);
195197
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
196198
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
197-
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
198-
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
199+
repositorySession.setLocalRepositoryManager(
200+
new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer())
201+
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
199202
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
200203
when(session.getRepositorySession()).thenReturn(repositorySession);
201204

@@ -248,8 +251,9 @@ public void testDeployIfArtifactIsNotJar() throws Exception {
248251
when(buildingRequest.getRepositoryMerging()).thenReturn(ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT);
249252
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
250253
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
251-
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
252-
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
254+
repositorySession.setLocalRepositoryManager(
255+
new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer())
256+
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
253257
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
254258
when(session.getRepositorySession()).thenReturn(repositorySession);
255259

0 commit comments

Comments
 (0)