From 42c53bc5e881515453d207b5c450cea6a5168491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Thu, 7 Mar 2024 09:36:38 +0100 Subject: [PATCH] Use all maven session project to resolve project loc If the build is run with a limited set of projects the resolving of project-loc does not work if the referenced project is not selected. This now uses all projects of the reactor even if they are currently not selected to resolve the variable. --- ...faultTargetDefinitionVariableResolver.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/DefaultTargetDefinitionVariableResolver.java b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/DefaultTargetDefinitionVariableResolver.java index 7e2c480071..b784e14bae 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/DefaultTargetDefinitionVariableResolver.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/DefaultTargetDefinitionVariableResolver.java @@ -16,13 +16,19 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.inject.Inject; + +import org.apache.maven.SessionScoped; +import org.apache.maven.execution.MavenSession; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; import org.eclipse.tycho.ReactorProject; +import org.eclipse.tycho.core.osgitools.DefaultReactorProject; import org.eclipse.tycho.core.shared.MavenContext; @Component(role = TargetDefinitionVariableResolver.class) +@SessionScoped public class DefaultTargetDefinitionVariableResolver implements TargetDefinitionVariableResolver { private static final Pattern SYSTEM_PROPERTY_PATTERN = createVariablePatternArgument("system_property"); @@ -33,8 +39,11 @@ public class DefaultTargetDefinitionVariableResolver implements TargetDefinition private MavenContext mavenContext; @Requirement private Logger logger; + private MavenSession mavenSession; - public DefaultTargetDefinitionVariableResolver() { + @Inject + public DefaultTargetDefinitionVariableResolver(MavenSession mavenSession) { + this.mavenSession = mavenSession; } /** for tests */ @@ -59,21 +68,22 @@ private String findProjectLocation(String projectName) { projectName = projectName.substring(1); } logger.debug("Find project location for project " + projectName); - for (ReactorProject project : projects()) { + Iterable projects = projects(); + for (ReactorProject project : projects) { String name = project.getName(); logger.debug("check reactor project name: " + name); if (name.equals(projectName)) { return project.getBasedir().getAbsolutePath(); } } - for (ReactorProject project : projects()) { + for (ReactorProject project : projects) { String artifactId = project.getArtifactId(); logger.debug("check reactor project artifact id: " + artifactId); if (artifactId.equals(projectName)) { return project.getBasedir().getAbsolutePath(); } } - for (ReactorProject project : projects()) { + for (ReactorProject project : projects) { String name = project.getBasedir().getName(); logger.debug("check reactor project base directory: " + name); if (name.equals(projectName)) { @@ -91,6 +101,9 @@ private String property(String key, String defaultValue) { } private Iterable projects() { + if (mavenSession != null) { + return mavenSession.getAllProjects().stream().map(DefaultReactorProject::adapt).toList(); + } return mavenContext.getProjects(); }