Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -532,28 +532,30 @@ protected List<MavenProject> getProjects() {
getLog().debug("PROJECTS: " + artifacts);

for (Artifact artifact : artifacts) {
if (artifact.isSnapshot()) {
artifact.setVersion(artifact.getBaseVersion());
}
MavenProject p = findReactorProject(artifact, mavenSession);
if (p == null) {
if (artifact.isSnapshot()) {
artifact.setVersion(artifact.getBaseVersion());
}

getLog().debug("Building project for " + artifact);
MavenProject p;
try {
ProjectBuildingRequest req = new DefaultProjectBuildingRequest()
.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL)
.setProcessPlugins(false)
.setRepositorySession(mavenSession.getRepositorySession())
.setSystemProperties(mavenSession.getSystemProperties())
.setUserProperties(mavenSession.getUserProperties())
.setLocalRepository(mavenSession.getLocalRepository())
.setRemoteRepositories(project.getRemoteArtifactRepositories());
ProjectBuildingResult res = projectBuilder.build(artifact, req);
p = res.getProject();
} catch (ProjectBuildingException e) {
getLog().warn("Invalid project model for artifact [" + artifact.getGroupId() + ":"
+ artifact.getArtifactId() + ":" + artifact.getVersion() + "]. "
+ "It will be ignored by the remote resources Mojo.");
continue;
getLog().debug("Building project for " + artifact);
try {
ProjectBuildingRequest req = new DefaultProjectBuildingRequest()
.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL)
.setProcessPlugins(false)
.setRepositorySession(mavenSession.getRepositorySession())
.setSystemProperties(mavenSession.getSystemProperties())
.setUserProperties(mavenSession.getUserProperties())
.setLocalRepository(mavenSession.getLocalRepository())
.setRemoteRepositories(project.getRemoteArtifactRepositories());
ProjectBuildingResult res = projectBuilder.build(artifact, req);
p = res.getProject();
} catch (ProjectBuildingException e) {
getLog().warn("Invalid project model for artifact [" + artifact.getGroupId() + ":"
+ artifact.getArtifactId() + ":" + artifact.getVersion() + "]. "
+ "It will be ignored by the remote resources Mojo.");
continue;
}
}

String supplementKey = generateSupplementMapKey(
Expand All @@ -575,6 +577,31 @@ protected List<MavenProject> getProjects() {
return projects;
}

private static MavenProject findReactorProject(Artifact artifact, MavenSession session) {
if (session == null) {
return null;
}
return findReactorProject(artifact, session.getProjects());
}

static MavenProject findReactorProject(Artifact artifact, List<MavenProject> reactorProjects) {
for (MavenProject reactorProject : reactorProjects) {
if (!artifact.getGroupId().equals(reactorProject.getGroupId())
|| !artifact.getArtifactId().equals(reactorProject.getArtifactId())
|| !artifactVersionMatches(artifact, reactorProject)) {
continue;
}
return reactorProject;
}
return null;
}

private static boolean artifactVersionMatches(Artifact artifact, MavenProject reactorProject) {
String projectVersion = reactorProject.getVersion();
return artifact.getVersion().equals(projectVersion)
|| (artifact.getBaseVersion() != null && artifact.getBaseVersion().equals(projectVersion));
}

/**
* Returns all the transitive hull of all the involved maven projects.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,36 @@ public void testNoBundles() throws Exception {
mojo.execute();
}

public void testReactorProjectIsReusedWithoutBuildingItsModel() throws Exception {
MavenProject reactorProject = new MavenProject(new org.apache.maven.model.Model());
reactorProject.setGroupId("com.example");
reactorProject.setArtifactId("reactor-project");
reactorProject.setVersion("1.0-SNAPSHOT");

Artifact artifact = new DefaultArtifact(
"com.example",
"reactor-project",
VersionRange.createFromVersion("1.0-20260926.120000-1"),
null,
"jar",
"",
new DefaultArtifactHandler());

assertSame(reactorProject, AbstractProcessRemoteResourcesMojo.findReactorProject(
artifact, Collections.singletonList(reactorProject)));

Artifact externalArtifact = new DefaultArtifact(
"com.example",
"external-project",
VersionRange.createFromVersion("1.0"),
null,
"jar",
"",
new DefaultArtifactHandler());
assertNull(AbstractProcessRemoteResourcesMojo.findReactorProject(
externalArtifact, Collections.singletonList(reactorProject)));
}

public void testConfigureLocatorRequiresProjectFile() throws Exception {
final MavenProjectResourcesStub project = createTestProject("default-null-pom");
final ProcessRemoteResourcesMojo mojo = lookupProcessMojoWithDefaultSettings(project);
Expand Down