diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index d3997294e0..ad9f31b61e 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -6,6 +6,7 @@ This file documents all notable changes to https://github.com/devonfw/IDEasy[IDE Release with new features and bugfixes: +* https://github.com/devonfw/IDEasy/issues/1165[#1165]: Fix automatic project import for Eclipse * https://github.com/devonfw/IDEasy/issues/2040[#2040]: Fixed buggy workspace selection in the GUI The full list of changes for this release can be found in https://github.com/devonfw/IDEasy/milestone/49?closed=1[milestone 2026.08.002]. diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/eclipse/Eclipse.java b/cli/src/main/java/com/devonfw/tools/ide/tool/eclipse/Eclipse.java index 6b5ffdf5c1..ce36ef0d8b 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/eclipse/Eclipse.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/eclipse/Eclipse.java @@ -145,9 +145,11 @@ public void importRepository(Path repositoryPath) { maven.getOrDownloadArtifact(groovyAnt); this.groovyInstalled = true; } - // -DdevonImportPath=\"${import_path}\" -DdevonImportWorkingSet=\"${importWorkingSets}\"" - runTool(ProcessMode.DEFAULT, null, ProcessErrorHandling.THROW_CLI, List.of(VMARGS, - "-DrepositoryImportPath=\"" + repositoryPath + "\" -DrepositoryImportWorkingSet=\"" + "" + "\"", "-application", "org.eclipse.ant.core.antRunner", - "-buildfile", this.context.getIdeInstallationPath().resolve(IdeContext.FOLDER_INTERNAL).resolve("eclipse-import.xml").toString())); + Path buildFile = this.context.getIdeInstallationPath().resolve(IdeContext.FOLDER_INTERNAL).resolve("eclipse-import.xml"); + // "-application" and "-buildfile" must come before "-vmargs" (added by super.configureToolArgs if ECLIPSE_VMARGS is set), + // as "-vmargs" and everything after it is passed to the JVM instead of being processed by eclipse itself. + runTool(ProcessMode.DEFAULT, null, ProcessErrorHandling.THROW_CLI, + List.of("-application", "org.eclipse.ant.core.antRunner", "-buildfile", buildFile.toString(), "-DrepositoryImportPath=" + repositoryPath, + "-DrepositoryImportWorkingSet=")); } } diff --git a/cli/src/main/package/internal/eclipse-import.groovy b/cli/src/main/package/internal/eclipse-import.groovy index b6b2a71372..ab5972619f 100644 --- a/cli/src/main/package/internal/eclipse-import.groovy +++ b/cli/src/main/package/internal/eclipse-import.groovy @@ -105,7 +105,7 @@ class MyWorkbenchAdvisor extends org.eclipse.ui.application.WorkbenchAdvisor { public void preStartup() { try { // Get path from ant properties - String path = antProperties.get("devonImportPath"); + String path = antProperties.get("repositoryImportPath"); if (path == null || path.equals("")) { throw new IllegalStateException("Parameter repositoryImportPath must be set."); } diff --git a/cli/src/test/java/com/devonfw/tools/ide/tool/eclipse/EclipseTest.java b/cli/src/test/java/com/devonfw/tools/ide/tool/eclipse/EclipseTest.java index b742c43b7e..b79f0b239e 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/tool/eclipse/EclipseTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/tool/eclipse/EclipseTest.java @@ -1,11 +1,15 @@ package com.devonfw.tools.ide.tool.eclipse; import java.io.IOException; +import java.lang.reflect.Field; +import java.nio.file.Path; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import com.devonfw.tools.ide.context.AbstractIdeContextTest; +import com.devonfw.tools.ide.context.IdeContext; import com.devonfw.tools.ide.context.IdeTestContext; import com.devonfw.tools.ide.log.IdeLogEntry; import com.devonfw.tools.ide.log.IdeLogLevel; @@ -56,4 +60,35 @@ void testEclipse(String os) throws IOException { assertThat(context).logAtDebug().hasMessageContaining("Version 2024-09 of tool eclipse is already installed"); } + /** + * Tests that {@link Eclipse#importRepository(Path)} invokes eclipse headlessly with the ant runner application and does not misplace "-application" behind + * "-vmargs" (see https://github.com/devonfw/IDEasy/issues/1165). + */ + @Test + void testImportRepository() throws Exception { + + // arrange + IdeTestContext context = newContext(PROJECT_ECLIPSE, "eclipseproject"); + context.setSystemInfo(SystemInfoMock.of("linux")); + context.getStartContext().setForceMode(true); // #663 + Eclipse eclipse = context.getCommandletManager().getCommandlet(Eclipse.class); + eclipse.install(); + // avoid downloading groovy-ant via maven in this test as it is not the concern of this test + Field groovyInstalledField = Eclipse.class.getDeclaredField("groovyInstalled"); + groovyInstalledField.setAccessible(true); + groovyInstalledField.set(eclipse, true); + Path repositoryPath = context.getWorkspacePath().resolve("my-repo"); + + // act + eclipse.importRepository(repositoryPath); + + // assert + Path buildFile = context.getIdeInstallationPath().resolve(IdeContext.FOLDER_INTERNAL).resolve("eclipse-import.xml"); + assertThat(eclipse.getToolBinPath().resolve("eclipsetest")).hasContent( + "eclipse linux -data " + context.getWorkspacePath() + " -keyring " + context.getUserHome().resolve(".eclipse").resolve(".keyring") + + " -configuration " + context.getPluginsPath().resolve("eclipse").resolve("configuration") + + " -consoleLog -nosplash -application org.eclipse.ant.core.antRunner -buildfile " + buildFile + " -DrepositoryImportPath=" + repositoryPath + + " -DrepositoryImportWorkingSet="); + } + }