From 73cdda6af5b31b25cde10f53ace909d78db7faf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Tue, 10 Sep 2024 07:08:00 +0200 Subject: [PATCH] Convert TychoGraphBuilder to JSR330 and catch generic exception --- .../tycho/build/TychoGraphBuilder.java | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/tycho-build/src/main/java/org/eclipse/tycho/build/TychoGraphBuilder.java b/tycho-build/src/main/java/org/eclipse/tycho/build/TychoGraphBuilder.java index 1100f3ff40..b43b742b2e 100644 --- a/tycho-build/src/main/java/org/eclipse/tycho/build/TychoGraphBuilder.java +++ b/tycho-build/src/main/java/org/eclipse/tycho/build/TychoGraphBuilder.java @@ -33,6 +33,10 @@ import java.util.function.Function; import java.util.stream.Collectors; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.ProjectDependencyGraph; @@ -44,15 +48,12 @@ import org.apache.maven.model.building.ModelProblem; import org.apache.maven.model.building.ModelProblem.Severity; import org.apache.maven.model.building.Result; -import org.apache.maven.project.DuplicateProjectException; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; -import org.codehaus.plexus.util.dag.CycleDetectedException; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.sisu.Priority; import org.eclipse.tycho.PackagingType; import org.eclipse.tycho.TychoConstants; import org.eclipse.tycho.p2maven.MavenProjectDependencyProcessor; @@ -61,18 +62,26 @@ import org.eclipse.tycho.pomless.AbstractTychoMapping; import org.sonatype.maven.polyglot.mapping.Mapping; -@Component(role = GraphBuilder.class, hint = GraphBuilder.HINT) -public class TychoGraphBuilder extends DefaultGraphBuilder { +@Singleton +@Named(GraphBuilder.HINT) +@Priority(10) +public class TychoGraphBuilder implements GraphBuilder { private static final boolean DEBUG = Boolean.getBoolean("tycho.graphbuilder.debug"); - @Requirement + @Inject private Logger log; - @Requirement(role = Mapping.class) + @Inject private Map polyglotMappings; - @Requirement + @Inject private MavenProjectDependencyProcessor dependencyProcessor; + private DefaultGraphBuilder defaultGraphBuilder; + + @Inject + public TychoGraphBuilder(DefaultGraphBuilder defaultGraphBuilder) { + this.defaultGraphBuilder = defaultGraphBuilder; + } @Override public Result build(MavenSession session) { @@ -92,7 +101,7 @@ public Result build(MavenSession session) { } MavenExecutionRequest request = session.getRequest(); ProjectDependencyGraph dependencyGraph = session.getProjectDependencyGraph(); - Result graphResult = super.build(session); + Result graphResult = defaultGraphBuilder.build(session); if (dependencyGraph != null || graphResult.hasErrors()) { // on second pass nothing to do for tycho, or already error ... return graphResult; @@ -262,7 +271,11 @@ public Result build(MavenSession session) { .thenComparing(MavenProject::getArtifactId, String.CASE_INSENSITIVE_ORDER)) .forEachOrdered(p -> log.debug(p.getId())); return Result.success(new DefaultProjectDependencyGraph(projects, selectedProjects)); - } catch (DuplicateProjectException | CycleDetectedException e) { + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + // as the actual types thrown will change in later maven version we catch a + // generic exception here log.error("Cannot compute project's dependency graph", e); return Result.error(graph); }