Skip to content

Commit

Permalink
Transitive dependency projects are not discovered with --also-make
Browse files Browse the repository at this point in the history
Currently it can happen that if one selects a project with -pl / -am
this project has initially not any maven dependencies but then later on
tycho adds one as a dependency and then the one declared in the pom are
not found.

This now adds an additional step each time a project is added as a
dependency to look if that project also has maven dependencies that map
to reactor projects.
  • Loading branch information
laeubi committed Mar 29, 2024
1 parent c6b6479 commit c657bfe
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ForkJoinPool;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.apache.maven.execution.MavenExecutionRequest;
Expand All @@ -38,6 +39,7 @@
import org.apache.maven.graph.DefaultGraphBuilder;
import org.apache.maven.graph.DefaultProjectDependencyGraph;
import org.apache.maven.graph.GraphBuilder;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.building.DefaultModelProblem;
import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.model.building.ModelProblem.Severity;
Expand Down Expand Up @@ -142,6 +144,8 @@ public Result<ProjectDependencyGraph> build(MavenSession session) {
}
ProjectDependencyGraph graph = graphResult.get();
List<MavenProject> projects = graph.getAllProjects();
Map<String, MavenProject> projectIdMap = projects.stream()
.collect(Collectors.toMap(p -> getProjectKey(p), Function.identity()));
int degreeOfConcurrency = request.getDegreeOfConcurrency();
Optional<ExecutorService> executor;
if (degreeOfConcurrency > 1) {
Expand Down Expand Up @@ -201,6 +205,22 @@ public Result<ProjectDependencyGraph> build(MavenSession session) {
// we also need to add the dependencies of the dependency project
queue.add(new ProjectRequest(project, false, true, projectRequest));
});
// special case: a (transitive) Tycho project might have declared a dependency
// to another project in the reactor but this can not be discovered by maven
// before we add it here...
List<Dependency> dependencies = projectRequest.mavenProject.getDependencies();
for (Dependency dependency : dependencies) {
MavenProject reactorMavenProjectDependency = projectIdMap.get(getProjectKey(dependency));
if (reactorMavenProjectDependency != null) {
if (DEBUG) {
log.info(" + add (maven) dependency project '"
+ reactorMavenProjectDependency.getId() + "' of project '"
+ projectRequest.mavenProject.getId() + "'");
}
queue.add(
new ProjectRequest(reactorMavenProjectDependency, false, true, projectRequest));
}
}
}
if (projectRequest.addRequires) {
dependencyClosure.dependencies(always -> List.of())//
Expand Down Expand Up @@ -248,6 +268,14 @@ public Result<ProjectDependencyGraph> build(MavenSession session) {
}
}

private String getProjectKey(Dependency project) {
return project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion();
}

private String getProjectKey(MavenProject project) {
return project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion();
}

private List<ModelProblem> toProblems(IStatus status, List<ModelProblem> problems) {
int severity = status.getSeverity();
if (severity == IStatus.OK || severity == IStatus.INFO) {
Expand Down

0 comments on commit c657bfe

Please sign in to comment.