Skip to content

Commit 3ebb448

Browse files
authored
[MINSTALL-197] Update to parent 41, cleanup (#61)
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/MINSTALL-197
1 parent 30d2b53 commit 3ebb448

File tree

10 files changed

+258
-56
lines changed

10 files changed

+258
-56
lines changed

pom.xml

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
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

@@ -46,7 +46,7 @@
4646
</contributors>
4747

4848
<prerequisites>
49-
<maven>${mavenVersion}</maven>
49+
<maven>3.2.5</maven>
5050
</prerequisites>
5151

5252
<scm>
@@ -72,21 +72,21 @@
7272

7373
<properties>
7474
<javaVersion>8</javaVersion>
75-
<mavenVersion>3.2.5</mavenVersion>
75+
<mavenVersion>3.9.6</mavenVersion>
7676
<!-- Maven bound -->
77-
<aetherVersion>1.0.0.v20140518</aetherVersion>
77+
<resolverVersion>1.9.18</resolverVersion>
7878
<!-- Maven bound -->
79-
<slf4jVersion>1.7.5</slf4jVersion>
79+
<slf4jVersion>1.7.36</slf4jVersion>
8080

8181
<!-- plugin versions used in IT tests -->
82-
<mavenAntrunPluginVersion>3.1.0</mavenAntrunPluginVersion>
83-
<mavenCompilerPluginVersion>3.10.1</mavenCompilerPluginVersion>
84-
<mavenEnforcerPluginVersion>3.1.0</mavenEnforcerPluginVersion>
85-
<mavenJarPluginVersion>3.3.0</mavenJarPluginVersion>
86-
<mavenPluginPluginVersion>3.7.0</mavenPluginPluginVersion>
87-
<mavenResourcesPluginVersion>3.3.0</mavenResourcesPluginVersion>
88-
<mavenSourcePluginVersion>3.2.1</mavenSourcePluginVersion>
89-
<mavenSurefirePluginVersion>3.0.0-M7</mavenSurefirePluginVersion>
82+
<mavenAntrunPluginVersion>${version.maven-antrun-plugin}</mavenAntrunPluginVersion>
83+
<mavenCompilerPluginVersion>${version.maven-compiler-plugin}</mavenCompilerPluginVersion>
84+
<mavenEnforcerPluginVersion>${version.maven-enforcer-plugin}</mavenEnforcerPluginVersion>
85+
<mavenJarPluginVersion>${version.maven-jar-plugin}</mavenJarPluginVersion>
86+
<mavenPluginPluginVersion>${version.maven-plugin-tools}</mavenPluginPluginVersion>
87+
<mavenResourcesPluginVersion>${version.maven-resources-plugin}</mavenResourcesPluginVersion>
88+
<mavenSourcePluginVersion>${version.maven-source-plugin}</mavenSourcePluginVersion>
89+
<mavenSurefirePluginVersion>${version.maven-surefire}</mavenSurefirePluginVersion>
9090

9191
<project.build.outputTimestamp>2023-03-21T14:31:18Z</project.build.outputTimestamp>
9292
</properties>
@@ -118,22 +118,26 @@
118118
<scope>provided</scope>
119119
</dependency>
120120
<dependency>
121-
<groupId>org.eclipse.aether</groupId>
122-
<artifactId>aether-api</artifactId>
123-
<version>${aetherVersion}</version>
121+
<groupId>org.apache.maven.resolver</groupId>
122+
<artifactId>maven-resolver-api</artifactId>
123+
<version>${resolverVersion}</version>
124124
<scope>provided</scope>
125125
</dependency>
126126
<dependency>
127-
<groupId>org.eclipse.aether</groupId>
128-
<artifactId>aether-util</artifactId>
129-
<version>${aetherVersion}</version>
127+
<groupId>org.apache.maven.resolver</groupId>
128+
<artifactId>maven-resolver-util</artifactId>
129+
<version>${resolverVersion}</version>
130130
<!-- To work in Maven versions older than 3.9.0 -->
131131
<scope>compile</scope>
132132
</dependency>
133133
<dependency>
134134
<groupId>org.codehaus.plexus</groupId>
135135
<artifactId>plexus-utils</artifactId>
136136
</dependency>
137+
<dependency>
138+
<groupId>org.codehaus.plexus</groupId>
139+
<artifactId>plexus-xml</artifactId>
140+
</dependency>
137141

138142
<!-- dependencies to annotations -->
139143
<dependency>
@@ -180,13 +184,26 @@
180184
<scope>test</scope>
181185
</dependency>
182186
<dependency>
183-
<groupId>org.eclipse.aether</groupId>
184-
<artifactId>aether-impl</artifactId>
185-
<version>${aetherVersion}</version>
187+
<groupId>org.apache.maven.resolver</groupId>
188+
<artifactId>maven-resolver-impl</artifactId>
189+
<version>${resolverVersion}</version>
186190
<scope>test</scope>
187191
</dependency>
188192
</dependencies>
189193

194+
<build>
195+
<plugins>
196+
<plugin>
197+
<groupId>org.apache.maven.plugins</groupId>
198+
<artifactId>maven-compiler-plugin</artifactId>
199+
<configuration>
200+
<proc>none</proc>
201+
<showDeprecation>true</showDeprecation>
202+
</configuration>
203+
</plugin>
204+
</plugins>
205+
</build>
206+
190207
<profiles>
191208
<profile>
192209
<id>run-its</id>

src/main/java/org/apache/maven/plugins/install/InstallFileMojo.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
*/
6868
@Mojo(name = "install-file", requiresProject = false, aggregator = true, threadSafe = true)
6969
public class InstallFileMojo extends AbstractMojo {
70-
private static final String LS = System.getProperty("line.separator");
70+
private static final String LS = System.lineSeparator();
7171

7272
@Component
7373
private RepositorySystem repositorySystem;
@@ -384,11 +384,11 @@ private Model generateModel() {
384384
private File generatePomFile() throws MojoExecutionException {
385385
Model model = generateModel();
386386
try {
387-
File tempPomFile = File.createTempFile("mvninstall", ".pom");
387+
Path tempPomFile = Files.createTempFile("mvninstall", ".pom");
388388

389-
try (OutputStream writer = Files.newOutputStream(tempPomFile.toPath())) {
389+
try (OutputStream writer = Files.newOutputStream(tempPomFile)) {
390390
new MavenXpp3Writer().write(writer, model);
391-
return tempPomFile;
391+
return tempPomFile.toFile();
392392
}
393393
} catch (IOException e) {
394394
throw new MojoExecutionException("Error writing temporary POM file: " + e.getMessage(), e);

src/main/java/org/apache/maven/plugins/install/InstallMojo.java

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
import org.apache.maven.project.MavenProject;
3939
import org.apache.maven.project.artifact.ProjectArtifact;
4040
import org.eclipse.aether.RepositorySystem;
41+
import org.eclipse.aether.artifact.Artifact;
4142
import org.eclipse.aether.installation.InstallRequest;
4243
import org.eclipse.aether.installation.InstallationException;
44+
import org.eclipse.aether.util.artifact.ArtifactIdUtils;
4345

4446
/**
4547
* Installs the project's main artifact, and any other artifacts attached by other plugins in the lifecycle, to the
@@ -58,9 +60,6 @@ public class InstallMojo extends AbstractMojo {
5860
@Parameter(defaultValue = "${project}", readonly = true, required = true)
5961
private MavenProject project;
6062

61-
@Parameter(defaultValue = "${reactorProjects}", required = true, readonly = true)
62-
private List<MavenProject> reactorProjects;
63-
6463
@Parameter(defaultValue = "${plugin}", required = true, readonly = true)
6564
private PluginDescriptor pluginDescriptor;
6665

@@ -157,7 +156,9 @@ private boolean allProjectsMarked(List<MavenProject> allProjectsUsingPlugin) {
157156
rp -> hasExecution(rp.getPlugin("org.apache.maven.plugins:maven-install-plugin"));
158157

159158
private List<MavenProject> getAllProjectsUsingPlugin() {
160-
return reactorProjects.stream().filter(hasMavenInstallPluginExecution).collect(Collectors.toList());
159+
return session.getProjects().stream()
160+
.filter(hasMavenInstallPluginExecution)
161+
.collect(Collectors.toList());
161162
}
162163

163164
private final Predicate<PluginExecution> havingGoals = pe -> !pe.getGoals().isEmpty();
@@ -185,16 +186,35 @@ private void installProject(InstallRequest request) throws MojoExecutionExceptio
185186
* @throws MojoExecutionException if project is badly set up.
186187
*/
187188
private void processProject(MavenProject project, InstallRequest request) throws MojoExecutionException {
188-
if (isFile(project.getFile())) {
189-
request.addArtifact(RepositoryUtils.toArtifact(new ProjectArtifact(project)));
189+
// always exists, as project exists
190+
Artifact pomArtifact = RepositoryUtils.toArtifact(new ProjectArtifact(project));
191+
// always exists, but at "init" is w/o file (packaging plugin assigns file to this when packaged)
192+
Artifact projectArtifact = RepositoryUtils.toArtifact(project.getArtifact());
193+
194+
// pom project: pomArtifact and projectArtifact are SAME
195+
// jar project: pomArtifact and projectArtifact are DIFFERENT
196+
// incomplete project: is not pom project and projectArtifact has no file
197+
198+
// we must compare coordinates ONLY (as projectArtifact may not have file, and Artifact.equals factors it in)
199+
// BUT if projectArtifact has file set, use that one
200+
if (ArtifactIdUtils.equalsId(pomArtifact, projectArtifact)) {
201+
if (isFile(projectArtifact.getFile())) {
202+
pomArtifact = projectArtifact;
203+
}
204+
projectArtifact = null;
205+
}
206+
207+
if (isFile(pomArtifact.getFile())) {
208+
request.addArtifact(pomArtifact);
190209
} else {
191210
throw new MojoExecutionException("The project POM could not be attached");
192211
}
193212

194-
if (!"pom".equals(project.getPackaging())) {
195-
org.apache.maven.artifact.Artifact mavenMainArtifact = project.getArtifact();
196-
if (isFile(mavenMainArtifact.getFile())) {
197-
request.addArtifact(RepositoryUtils.toArtifact(mavenMainArtifact));
213+
// is not packaged, is "incomplete"
214+
boolean isIncomplete = projectArtifact != null && !isFile(projectArtifact.getFile());
215+
if (projectArtifact != null) {
216+
if (!isIncomplete) {
217+
request.addArtifact(projectArtifact);
198218
} else if (!project.getAttachedArtifacts().isEmpty()) {
199219
if (allowIncompleteProjects) {
200220
getLog().warn("");

src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
import org.codehaus.plexus.util.FileUtils;
3131
import org.codehaus.plexus.util.xml.XmlStreamReader;
3232
import org.eclipse.aether.DefaultRepositorySystemSession;
33+
import org.eclipse.aether.internal.impl.DefaultLocalPathComposer;
34+
import org.eclipse.aether.internal.impl.DefaultLocalPathPrefixComposerFactory;
35+
import org.eclipse.aether.internal.impl.DefaultTrackingFileManager;
3336
import org.eclipse.aether.internal.impl.EnhancedLocalRepositoryManagerFactory;
3437
import org.eclipse.aether.repository.LocalRepository;
3538
import org.eclipse.aether.repository.NoLocalRepositoryManagerException;
@@ -341,7 +344,10 @@ private String dotToSlashReplacer(String parameter) {
341344
private MavenSession createMavenSession(String localRepositoryBaseDir) throws NoLocalRepositoryManagerException {
342345
MavenSession session = mock(MavenSession.class);
343346
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
344-
repositorySession.setLocalRepositoryManager(new EnhancedLocalRepositoryManagerFactory()
347+
repositorySession.setLocalRepositoryManager(new EnhancedLocalRepositoryManagerFactory(
348+
new DefaultLocalPathComposer(),
349+
new DefaultTrackingFileManager(),
350+
new DefaultLocalPathPrefixComposerFactory())
345351
.newInstance(repositorySession, new LocalRepository(localRepositoryBaseDir)));
346352
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
347353
buildingRequest.setRepositorySession(repositorySession);

src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
import org.codehaus.plexus.util.FileUtils;
4040
import org.eclipse.aether.DefaultRepositorySystemSession;
4141
import org.eclipse.aether.artifact.DefaultArtifact;
42+
import org.eclipse.aether.internal.impl.DefaultLocalPathComposer;
43+
import org.eclipse.aether.internal.impl.DefaultLocalPathPrefixComposerFactory;
44+
import org.eclipse.aether.internal.impl.DefaultTrackingFileManager;
4245
import org.eclipse.aether.internal.impl.EnhancedLocalRepositoryManagerFactory;
4346
import org.eclipse.aether.repository.LocalRepository;
4447
import org.eclipse.aether.repository.NoLocalRepositoryManagerException;
@@ -84,10 +87,11 @@ public void testBasicInstall() throws Exception {
8487
MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
8588
updateMavenProject(project);
8689

90+
MavenSession session = createMavenSession();
91+
session.setProjects(Collections.singletonList(project));
92+
setVariableValueToObject(mojo, "session", session);
8793
setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
8894
setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
89-
setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
90-
setVariableValueToObject(mojo, "session", createMavenSession());
9195

9296
artifact = (InstallArtifactStub) project.getArtifact();
9397

@@ -120,10 +124,11 @@ public void testBasicInstallWithAttachedArtifacts() throws Exception {
120124
MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
121125
updateMavenProject(project);
122126

127+
MavenSession session = createMavenSession();
128+
session.setProjects(Collections.singletonList(project));
129+
setVariableValueToObject(mojo, "session", session);
123130
setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
124131
setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
125-
setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
126-
setVariableValueToObject(mojo, "session", createMavenSession());
127132

128133
List<Artifact> attachedArtifacts = project.getAttachedArtifacts();
129134

@@ -164,10 +169,11 @@ public void testUpdateReleaseParamSetToTrue() throws Exception {
164169
MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
165170
updateMavenProject(project);
166171

172+
MavenSession session = createMavenSession();
173+
session.setProjects(Collections.singletonList(project));
174+
setVariableValueToObject(mojo, "session", session);
167175
setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
168176
setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
169-
setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
170-
setVariableValueToObject(mojo, "session", createMavenSession());
171177

172178
artifact = (InstallArtifactStub) project.getArtifact();
173179

@@ -190,10 +196,11 @@ public void testInstallIfArtifactFileIsNull() throws Exception {
190196
MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
191197
updateMavenProject(project);
192198

199+
MavenSession session = createMavenSession();
200+
session.setProjects(Collections.singletonList(project));
201+
setVariableValueToObject(mojo, "session", session);
193202
setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
194203
setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
195-
setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
196-
setVariableValueToObject(mojo, "session", createMavenSession());
197204

198205
artifact = (InstallArtifactStub) project.getArtifact();
199206

@@ -223,10 +230,11 @@ public void testInstallIfPackagingIsPom() throws Exception {
223230
MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
224231
updateMavenProject(project);
225232

233+
MavenSession session = createMavenSession();
234+
session.setProjects(Collections.singletonList(project));
235+
setVariableValueToObject(mojo, "session", session);
226236
setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
227237
setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
228-
setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
229-
setVariableValueToObject(mojo, "session", createMavenSession());
230238

231239
String packaging = project.getPackaging();
232240

@@ -248,6 +256,43 @@ public void testInstallIfPackagingIsPom() throws Exception {
248256
assertEquals(4, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
249257
}
250258

259+
public void testInstallIfPackagingIsBom() throws Exception {
260+
File testPom = new File(
261+
getBasedir(), "target/test-classes/unit/basic-install-test-packaging-bom/" + "plugin-config.xml");
262+
263+
AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);
264+
265+
assertNotNull(mojo);
266+
267+
MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
268+
updateMavenProject(project);
269+
270+
MavenSession session = createMavenSession();
271+
session.setProjects(Collections.singletonList(project));
272+
setVariableValueToObject(mojo, "session", session);
273+
setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
274+
setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
275+
276+
String packaging = project.getPackaging();
277+
278+
assertEquals("bom", packaging);
279+
280+
artifact = (InstallArtifactStub) project.getArtifact();
281+
282+
mojo.execute();
283+
284+
String groupId = dotToSlashReplacer(artifact.getGroupId());
285+
286+
File installedArtifact = new File(
287+
getBasedir(),
288+
LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/"
289+
+ artifact.getArtifactId() + "-" + artifact.getVersion() + "." + "pom");
290+
291+
assertTrue(installedArtifact.exists());
292+
293+
assertEquals(4, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
294+
}
295+
251296
public void testBasicInstallAndCreate() throws Exception {
252297
File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-checksum/plugin-config.xml");
253298

@@ -261,10 +306,11 @@ public void testBasicInstallAndCreate() throws Exception {
261306
MavenSession mavenSession = createMavenSession();
262307
updateMavenProject(project);
263308

309+
MavenSession session = createMavenSession();
310+
session.setProjects(Collections.singletonList(project));
311+
setVariableValueToObject(mojo, "session", session);
264312
setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
265313
setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
266-
setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
267-
setVariableValueToObject(mojo, "session", mavenSession);
268314

269315
artifact = (InstallArtifactStub) project.getArtifact();
270316

@@ -308,10 +354,11 @@ public void testSkip() throws Exception {
308354
MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
309355
updateMavenProject(project);
310356

357+
MavenSession session = createMavenSession();
358+
session.setProjects(Collections.singletonList(project));
359+
setVariableValueToObject(mojo, "session", session);
311360
setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
312361
setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
313-
setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
314-
setVariableValueToObject(mojo, "session", createMavenSession());
315362
setVariableValueToObject(mojo, "skip", Boolean.TRUE);
316363

317364
artifact = (InstallArtifactStub) project.getArtifact();
@@ -341,7 +388,10 @@ private String dotToSlashReplacer(String parameter) {
341388
private MavenSession createMavenSession() throws NoLocalRepositoryManagerException {
342389
MavenSession session = mock(MavenSession.class);
343390
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
344-
repositorySession.setLocalRepositoryManager(new EnhancedLocalRepositoryManagerFactory()
391+
repositorySession.setLocalRepositoryManager(new EnhancedLocalRepositoryManagerFactory(
392+
new DefaultLocalPathComposer(),
393+
new DefaultTrackingFileManager(),
394+
new DefaultLocalPathPrefixComposerFactory())
345395
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
346396
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
347397
buildingRequest.setRepositorySession(repositorySession);

0 commit comments

Comments
 (0)