diff --git a/tycho-core/src/main/java/org/eclipse/tycho/osgi/framework/Bundles.java b/tycho-core/src/main/java/org/eclipse/tycho/osgi/framework/Bundles.java index ef5db313e8..93b138fe43 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/osgi/framework/Bundles.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/osgi/framework/Bundles.java @@ -20,6 +20,7 @@ public record Bundles(Set bundles) { public static final String BUNDLE_ECLIPSE_HELP_BASE = "org.eclipse.help.base"; public static final String BUNDLE_PDE_CORE = "org.eclipse.pde.core"; public static final String BUNDLE_JDT_CORE = "org.eclipse.jdt.core"; + public static final String BUNDLE_JDT_LAUNCHING = "org.eclipse.jdt.launching"; static final String BUNDLE_LAUNCHING_MACOS = "org.eclipse.jdt.launching.macosx"; static final String BUNDLE_APP = "org.eclipse.equinox.app"; diff --git a/tycho-eclipse-plugin/pom.xml b/tycho-eclipse-plugin/pom.xml index 2dbfc436a3..c35d53e228 100644 --- a/tycho-eclipse-plugin/pom.xml +++ b/tycho-eclipse-plugin/pom.xml @@ -60,6 +60,17 @@ + + org.eclipse.jdt + org.eclipse.jdt.launching + 3.23.100 + + + * + * + + + org.eclipse.tycho sisu-equinox-launching diff --git a/tycho-eclipse-plugin/src/main/java/org/eclipse/tycho/eclipsebuild/AbstractEclipseBuildMojo.java b/tycho-eclipse-plugin/src/main/java/org/eclipse/tycho/eclipsebuild/AbstractEclipseBuildMojo.java index f0a48a277c..7417eaa125 100644 --- a/tycho-eclipse-plugin/src/main/java/org/eclipse/tycho/eclipsebuild/AbstractEclipseBuildMojo.java +++ b/tycho-eclipse-plugin/src/main/java/org/eclipse/tycho/eclipsebuild/AbstractEclipseBuildMojo.java @@ -15,9 +15,11 @@ import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.nio.file.Path; +import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -25,6 +27,7 @@ import java.util.function.Consumer; import java.util.stream.Collectors; +import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Repository; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -33,6 +36,8 @@ import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import org.apache.maven.toolchain.Toolchain; +import org.apache.maven.toolchain.ToolchainManager; import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.CoreException; import org.eclipse.tycho.ArtifactKey; @@ -102,6 +107,9 @@ public abstract class AbstractEclipseBuildMojo eclipseProjectValue = projectManager.getEclipseProject(project); @@ -169,6 +182,23 @@ public void run() { thread.start(); framework.waitForApplicationStart(TimeUnit.SECONDS.toMillis(30)); } + if (hasJDTNature(eclipseProject)) { + if (framework.hasBundle(Bundles.BUNDLE_JDT_LAUNCHING)) { + List jvms = new ArrayList<>(); + for (Toolchain toolchain : toolchainManager.getToolchains(mavenSession, "jdk", Map.of())) { + String tool = toolchain.findTool("java"); + if (tool != null) { + jvms.add(Path.of(tool).getParent().getParent()); + } + } + framework.execute(new SetJVMs(jvms, debug)); + } else { + getLog().info( + "Skip set JVMs because " + Bundles.BUNDLE_JDT_LAUNCHING + + " is not part of the framework..."); + } + } + if (hasPDENature(eclipseProject)) { if (framework.hasBundle(Bundles.BUNDLE_PDE_CORE)) { framework.execute(new SetTargetPlatform(projectDependencies, debug)); @@ -182,7 +212,7 @@ public void run() { if (hasBaselinesSet()) { framework.execute(new SetApiBaseline(project.getId(), getBaselineBundles(), debug)); } else { - getLog().info("Skip set ApiBasline because no baselines set..."); + getLog().info("Skip set ApiBaseline because no baselines set..."); } } else { getLog().info("Skip set ApiBasline because " + Bundles.BUNDLE_API_TOOLS diff --git a/tycho-eclipse-plugin/src/main/java/org/eclipse/tycho/eclipsebuild/SetJVMs.java b/tycho-eclipse-plugin/src/main/java/org/eclipse/tycho/eclipsebuild/SetJVMs.java new file mode 100644 index 0000000000..3a570d8d76 --- /dev/null +++ b/tycho-eclipse-plugin/src/main/java/org/eclipse/tycho/eclipsebuild/SetJVMs.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2025 Christoph Läubrich 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: + * Christoph Läubrich - initial API and implementation + *******************************************************************************/ +package org.eclipse.tycho.eclipsebuild; + +import java.io.File; +import java.io.Serializable; +import java.nio.file.Path; +import java.util.Collection; +import java.util.concurrent.Callable; + +import org.eclipse.jdt.internal.launching.StandardVMType; +import org.eclipse.jdt.launching.IVMInstall; +import org.eclipse.jdt.launching.IVMInstall2; +import org.eclipse.jdt.launching.JavaRuntime; +import org.eclipse.jdt.launching.VMStandin; + +public class SetJVMs implements Callable, Serializable { + + private static final long serialVersionUID = 1L; + private boolean debug; + private Collection jvms; + + public SetJVMs(Collection jvms, boolean debug) { + this.debug = debug; + this.jvms = jvms.stream().map(EclipseProjectBuild::pathAsString).toList(); + } + + @Override + public Serializable call() throws Exception { + StandardVMType standardType = (StandardVMType) JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE); + for (String entry : jvms) { + debug("Adding JVM " + entry + "..."); + VMStandin workingCopy = new VMStandin(standardType, entry); + workingCopy.setInstallLocation(new File(entry)); + workingCopy.setName(entry); + IVMInstall install = workingCopy.convertToRealVM(); + if (!isValid(install)) { + standardType.disposeVMInstall(install.getId()); + } + } + return null; + } + + private static boolean isValid(IVMInstall install) { + return install instanceof IVMInstall2 vm && vm.getJavaVersion() != null; + } + + private void debug(String string) { + if (debug) { + System.out.println(string); + } + } + +}