From c4e5481b0d6a2d096c57002000edfbe578c60d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sun, 17 Dec 2023 06:08:01 +0100 Subject: [PATCH] Get rid of TychoProjectUtils entirely (cherry picked from commit 77acf50fe482a80a3b569b06e4c22f7da60226dc) --- .../tycho/core/osgitools/EquinoxResolver.java | 15 ++++- .../core/resolver/DefaultTychoResolver.java | 17 +++++ .../tycho/core/utils/TychoProjectUtils.java | 64 ------------------- .../core/test/DependencyComputerTest.java | 2 +- .../tycho/test/util}/MavenSessionUtils.java | 2 +- .../surefire/AbstractEclipseTestMojo.java | 10 ++- 6 files changed, 35 insertions(+), 75 deletions(-) delete mode 100644 tycho-core/src/main/java/org/eclipse/tycho/core/utils/TychoProjectUtils.java rename tycho-core/src/{main/java/org/eclipse/tycho/core/utils => test/java/org/eclipse/tycho/test/util}/MavenSessionUtils.java (97%) diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/EquinoxResolver.java b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/EquinoxResolver.java index c317116728..8ad5ec7973 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/EquinoxResolver.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/EquinoxResolver.java @@ -71,7 +71,6 @@ import org.eclipse.tycho.core.ee.ExecutionEnvironmentUtils; import org.eclipse.tycho.core.ee.StandardExecutionEnvironment; import org.eclipse.tycho.core.osgitools.DependencyComputer.DependencyEntry; -import org.eclipse.tycho.core.utils.TychoProjectUtils; import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; import org.osgi.framework.Constants; @@ -215,8 +214,7 @@ protected Properties getPlatformProperties(ReactorProject project, MavenSession //FIXME formally we should resolve the configuration for ALL declared environments! TargetEnvironment environment = configuration.getEnvironments().get(0); logger.debug("Using TargetEnvironment " + environment.toFilterExpression() + " to create resolver properties"); - Properties properties = new Properties(); - properties.putAll(TychoProjectUtils.getMergedProperties(project.adapt(MavenProject.class), mavenSession)); + Properties properties = computeMergedProperties(project.adapt(MavenProject.class), mavenSession); return getPlatformProperties(properties, mavenSession, environment, ee); } @@ -578,4 +576,15 @@ public List getBootClasspathExtraAccessRules() { }; } + public static Properties computeMergedProperties(MavenProject mavenProject, MavenSession mavenSession) { + Properties properties = new Properties(); + properties.putAll(mavenProject.getProperties()); + if (mavenSession != null) { + properties.putAll(mavenSession.getSystemProperties()); // session wins + properties.putAll(mavenSession.getUserProperties()); + } else { + properties.putAll(System.getProperties()); + } + return properties; + } } diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/DefaultTychoResolver.java b/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/DefaultTychoResolver.java index 7ace72ca2c..cd0716fbe1 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/DefaultTychoResolver.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/DefaultTychoResolver.java @@ -15,6 +15,7 @@ package org.eclipse.tycho.core.resolver; import java.util.Optional; +import java.util.Properties; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; @@ -23,6 +24,7 @@ import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; import org.eclipse.tycho.DependencyArtifacts; +import org.eclipse.tycho.PlatformPropertiesUtils; import org.eclipse.tycho.ReactorProject; import org.eclipse.tycho.core.DependencyResolver; import org.eclipse.tycho.core.TychoProject; @@ -30,6 +32,7 @@ import org.eclipse.tycho.core.osgitools.AbstractTychoProject; import org.eclipse.tycho.core.osgitools.DebugUtils; import org.eclipse.tycho.core.osgitools.DefaultReactorProject; +import org.eclipse.tycho.core.osgitools.EquinoxResolver; import org.eclipse.tycho.resolver.TychoResolver; @Component(role = TychoResolver.class) @@ -37,6 +40,9 @@ public class DefaultTychoResolver implements TychoResolver { private static final String SETUP_MARKER = "DefaultTychoResolver/Setup"; private static final String RESOLVE_MARKER = "DefaultTychoResolver/Resolve"; + private static final String TYCHO_ENV_OSGI_WS = "tycho.env.osgi.ws"; + private static final String TYCHO_ENV_OSGI_OS = "tycho.env.osgi.os"; + private static final String TYCHO_ENV_OSGI_ARCH = "tycho.env.osgi.arch"; @Requirement private Logger logger; @@ -58,6 +64,17 @@ public void setupProject(MavenSession session, MavenProject project) { return; } reactorProject.setContextValue(SETUP_MARKER, true); + + //enhance the current project properties with the currently used environment + Properties properties = EquinoxResolver.computeMergedProperties(project, session); + String arch = PlatformPropertiesUtils.getArch(properties); + String os = PlatformPropertiesUtils.getOS(properties); + String ws = PlatformPropertiesUtils.getWS(properties); + Properties projectProperties = project.getProperties(); + projectProperties.put(TYCHO_ENV_OSGI_WS, ws); + projectProperties.put(TYCHO_ENV_OSGI_OS, os); + projectProperties.put(TYCHO_ENV_OSGI_ARCH, arch); + //FIXME this should actually happen lazy on first access so we do not require more here than bootstrap the project with a session above dr.setupProject(session, project); dependencyResolver.setupProjects(session, project, reactorProject); diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/utils/TychoProjectUtils.java b/tycho-core/src/main/java/org/eclipse/tycho/core/utils/TychoProjectUtils.java deleted file mode 100644 index 313e3d4e55..0000000000 --- a/tycho-core/src/main/java/org/eclipse/tycho/core/utils/TychoProjectUtils.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2014 SAP SE and others. - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * SAP SE - initial API and implementation - *******************************************************************************/ -package org.eclipse.tycho.core.utils; - -import java.util.Properties; - -import org.apache.maven.execution.MavenSession; -import org.apache.maven.project.MavenProject; -import org.eclipse.tycho.PlatformPropertiesUtils; -import org.eclipse.tycho.ReactorProject; -import org.eclipse.tycho.core.osgitools.DefaultReactorProject; - -public class TychoProjectUtils { - - public static final String TYCHO_ENV_OSGI_WS = "tycho.env.osgi.ws"; - public static final String TYCHO_ENV_OSGI_OS = "tycho.env.osgi.os"; - public static final String TYCHO_ENV_OSGI_ARCH = "tycho.env.osgi.arch"; - - /** - * Computes the merged properties from maven session and the project - * - * @param mavenProject - * @param mavenSession - * @return a (possibly cached) value, do not modify the object! - */ - public static Properties getMergedProperties(MavenProject mavenProject, MavenSession mavenSession) { - if (mavenSession == null) { - //only temporary ... - return computeMergedProperties(mavenProject, null); - } - return DefaultReactorProject.adapt(mavenProject, mavenSession).computeContextValue( - ReactorProject.CTX_MERGED_PROPERTIES, () -> computeMergedProperties(mavenProject, mavenSession)); - } - - private static Properties computeMergedProperties(MavenProject mavenProject, MavenSession mavenSession) { - Properties properties = new Properties(); - properties.putAll(mavenProject.getProperties()); - if (mavenSession != null) { - properties.putAll(mavenSession.getSystemProperties()); // session wins - properties.putAll(mavenSession.getUserProperties()); - } - setTychoEnvironmentProperties(properties, mavenProject); - return properties; - } - - public static void setTychoEnvironmentProperties(Properties properties, MavenProject project) { - String arch = PlatformPropertiesUtils.getArch(properties); - String os = PlatformPropertiesUtils.getOS(properties); - String ws = PlatformPropertiesUtils.getWS(properties); - project.getProperties().put(TYCHO_ENV_OSGI_WS, ws); - project.getProperties().put(TYCHO_ENV_OSGI_OS, os); - project.getProperties().put(TYCHO_ENV_OSGI_ARCH, arch); - } -} diff --git a/tycho-core/src/test/java/org/eclipse/tycho/core/test/DependencyComputerTest.java b/tycho-core/src/test/java/org/eclipse/tycho/core/test/DependencyComputerTest.java index 6ac357bab1..5e7a9eac07 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/core/test/DependencyComputerTest.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/core/test/DependencyComputerTest.java @@ -47,8 +47,8 @@ import org.eclipse.tycho.core.osgitools.DependenciesResolver; import org.eclipse.tycho.core.osgitools.DependencyComputer; import org.eclipse.tycho.core.osgitools.DependencyComputer.DependencyEntry; +import org.eclipse.tycho.test.util.MavenSessionUtils; import org.eclipse.tycho.core.osgitools.EquinoxResolver; -import org.eclipse.tycho.core.utils.MavenSessionUtils; import org.eclipse.tycho.testing.AbstractTychoMojoTestCase; import org.eclipse.tycho.version.TychoVersion; import org.junit.Assert; diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/utils/MavenSessionUtils.java b/tycho-core/src/test/java/org/eclipse/tycho/test/util/MavenSessionUtils.java similarity index 97% rename from tycho-core/src/main/java/org/eclipse/tycho/core/utils/MavenSessionUtils.java rename to tycho-core/src/test/java/org/eclipse/tycho/test/util/MavenSessionUtils.java index bb9d82c834..cfc4cc1a11 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/core/utils/MavenSessionUtils.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/test/util/MavenSessionUtils.java @@ -10,7 +10,7 @@ * Contributors: * Sonatype Inc. - initial API and implementation *******************************************************************************/ -package org.eclipse.tycho.core.utils; +package org.eclipse.tycho.test.util; import java.io.File; import java.util.HashMap; diff --git a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/AbstractEclipseTestMojo.java b/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/AbstractEclipseTestMojo.java index 42072387f3..5e880ad396 100644 --- a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/AbstractEclipseTestMojo.java +++ b/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/AbstractEclipseTestMojo.java @@ -85,7 +85,6 @@ import org.eclipse.tycho.core.TychoProject; import org.eclipse.tycho.core.osgitools.DefaultReactorProject; import org.eclipse.tycho.core.osgitools.project.BuildOutputJar; -import org.eclipse.tycho.core.utils.TychoProjectUtils; import org.eclipse.tycho.dev.DevBundleInfo; import org.eclipse.tycho.dev.DevWorkspaceResolver; import org.eclipse.tycho.p2.tools.RepositoryReferences; @@ -1046,11 +1045,10 @@ private EquinoxLaunchConfiguration createCommandLine(EquinoxInstallation testRun } cli.addVMArguments("-Dosgi.noShutdown=false"); - - Properties properties = TychoProjectUtils.getMergedProperties(project, session); - cli.addVMArguments("-Dosgi.os=" + PlatformPropertiesUtils.getOS(properties), // - "-Dosgi.ws=" + PlatformPropertiesUtils.getWS(properties), // - "-Dosgi.arch=" + PlatformPropertiesUtils.getArch(properties)); + TargetEnvironment environment = TargetEnvironment.getRunningEnvironment(); + cli.addVMArguments("-Dosgi.os=" + environment.getOs(), // + "-Dosgi.ws=" + environment.getWs(), // + "-Dosgi.arch=" + environment.getArch()); addCustomProfileArg(cli); cli.addVMArguments(splitArgLine(argLine));