Skip to content

Commit

Permalink
#663: eclipse force loop (#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille authored Sep 30, 2024
1 parent 55ea991 commit 805f545
Show file tree
Hide file tree
Showing 34 changed files with 282 additions and 82 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Release with new features and bugfixes:
* https://github.com/devonfw/IDEasy/issues/356[#356]: Eclipse plugin installation opens an Eclipse window for each plugin installed
* https://github.com/devonfw/IDEasy/issues/655[#655]: CVE-2024-26308 and library updates
* https://github.com/devonfw/IDEasy/issues/627[#627]: Still log messages break processable command output
* https://github.com/devonfw/IDEasy/issues/663[#663]: Endless loop when installing Eclipse in force mode

The full list of changes for this release can be found in https://github.com/devonfw/IDEasy/milestone/13?closed=1[milestone 2024.09.002].

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public abstract class AbstractIdeContext implements IdeContext {

private final CommandletManager commandletManager;

private final ToolRepository defaultToolRepository;
private ToolRepository defaultToolRepository;

private CustomToolRepository customToolRepository;

Expand All @@ -129,10 +129,8 @@ public abstract class AbstractIdeContext implements IdeContext {
*
* @param startContext the {@link IdeLogger}.
* @param userDir the optional {@link Path} to current working directory.
* @param toolRepository @param toolRepository the {@link ToolRepository} of the context. If it is set to {@code null} {@link DefaultToolRepository} will
* be used.
*/
public AbstractIdeContext(IdeStartContextImpl startContext, Path userDir, ToolRepository toolRepository) {
public AbstractIdeContext(IdeStartContextImpl startContext, Path userDir) {

super();
this.startContext = startContext;
Expand Down Expand Up @@ -190,11 +188,7 @@ public AbstractIdeContext(IdeStartContextImpl startContext, Path userDir, ToolRe
}
}

if (toolRepository == null) {
this.defaultToolRepository = new DefaultToolRepository(this);
} else {
this.defaultToolRepository = toolRepository;
}
this.defaultToolRepository = new DefaultToolRepository(this);
}

private Path findIdeRoot(Path ideHomePath) {
Expand Down Expand Up @@ -372,6 +366,14 @@ public ToolRepository getDefaultToolRepository() {
return this.defaultToolRepository;
}

/**
* @param defaultToolRepository the new value of {@link #getDefaultToolRepository()}.
*/
protected void setDefaultToolRepository(ToolRepository defaultToolRepository) {

this.defaultToolRepository = defaultToolRepository;
}

@Override
public CustomToolRepository getCustomToolRepository() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class IdeContextConsole extends AbstractIdeContext {
*/
public IdeContextConsole(IdeLogLevel minLogLevel, Appendable out, boolean colored) {

super(new IdeStartContextImpl(minLogLevel, level -> new IdeSubLoggerOut(level, out, colored, minLogLevel)), null, null);
super(new IdeStartContextImpl(minLogLevel, level -> new IdeSubLoggerOut(level, out, colored, minLogLevel)), null);
if (System.console() == null) {
debug("System console not available - using System.in as fallback");
this.scanner = new Scanner(System.in);
Expand All @@ -39,7 +39,7 @@ public IdeContextConsole(IdeLogLevel minLogLevel, Appendable out, boolean colore
*/
public IdeContextConsole(IdeStartContextImpl startContext) {

super(startContext, null, null);
super(startContext, null);
if (System.console() == null) {
debug("System console not available - using System.in as fallback");
this.scanner = new Scanner(System.in);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,9 @@ public ToolInstallation installTool(GenericVersionRange version, EnvironmentCont
FileAccess fileAccess = this.context.getFileAccess();
if (Files.isDirectory(installationPath)) {
if (Files.exists(toolVersionFile)) {
if (this.context.isForceMode()) {
fileAccess.delete(installationPath);
} else {
if (!ignoreSoftwareRepo || resolvedVersion.equals(getInstalledVersion())) {
this.context.debug("Version {} of tool {} is already installed at {}", resolvedVersion, getToolWithEdition(this.tool, edition), installationPath);
return createToolInstallation(installationPath, resolvedVersion, toolVersionFile, false, environmentContext, extraInstallation);
}
if (!ignoreSoftwareRepo || resolvedVersion.equals(getInstalledVersion())) {
this.context.debug("Version {} of tool {} is already installed at {}", resolvedVersion, getToolWithEdition(this.tool, edition), installationPath);
return createToolInstallation(installationPath, resolvedVersion, toolVersionFile, false, environmentContext, extraInstallation);
}
} else {
this.context.warning("Deleting corrupted installation at {}", installationPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,10 @@ protected static IdeTestContext newContext(String testProject, String projectPat
Path userDir = ideRoot.resolve(projectPath);
ToolRepositoryMock toolRepository = null;
Path repositoryFolder = ideRoot.resolve("repository");
IdeTestContext context = new IdeTestContext(userDir, logLevel);
if (Files.isDirectory(repositoryFolder)) {
toolRepository = new ToolRepositoryMock(repositoryFolder);
}
IdeTestContext context = new IdeTestContext(userDir, toolRepository, logLevel);
if (toolRepository != null) {
toolRepository.setContext(context);
toolRepository = new ToolRepositoryMock(context, repositoryFolder);
context.setDefaultToolRepository(toolRepository);
}
return context;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.devonfw.tools.ide.log.IdeLogger;
import com.devonfw.tools.ide.os.SystemInfo;
import com.devonfw.tools.ide.process.ProcessContext;
import com.devonfw.tools.ide.repo.DefaultToolRepository;
import com.devonfw.tools.ide.repo.ToolRepository;
import com.devonfw.tools.ide.variable.IdeVariables;

Expand Down Expand Up @@ -43,13 +42,11 @@ public class AbstractIdeTestContext extends AbstractIdeContext {
*
* @param logger the {@link IdeLogger}.
* @param userDir the optional {@link Path} to current working directory.
* @param toolRepository @param toolRepository the {@link ToolRepository} of the context. If it is set to {@code null} {@link DefaultToolRepository} will
* be used.
* @param answers the automatic answers simulating a user in test.
*/
public AbstractIdeTestContext(IdeStartContextImpl logger, Path userDir, ToolRepository toolRepository, String... answers) {
public AbstractIdeTestContext(IdeStartContextImpl logger, Path userDir, String... answers) {

super(logger, userDir, toolRepository);
super(logger, userDir);
this.answers = new String[0];
this.progressBarMap = new HashMap<>();
this.systemInfo = super.getSystemInfo();
Expand Down Expand Up @@ -186,4 +183,10 @@ public Path getUserHome() {
}
return super.getUserHome();
}

@Override
public void setDefaultToolRepository(ToolRepository defaultToolRepository) {

super.setDefaultToolRepository(defaultToolRepository);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class IdeSlf4jContext extends AbstractIdeTestContext {
*/
public IdeSlf4jContext(Path userDir) {

super(new IdeStartContextImpl(IdeLogLevel.TRACE, level -> new IdeSubLoggerSlf4j(level)), userDir, null);
super(new IdeStartContextImpl(IdeLogLevel.TRACE, level -> new IdeSubLoggerSlf4j(level)), userDir);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.devonfw.tools.ide.log.IdeLogLevel;
import com.devonfw.tools.ide.log.IdeTestLogger;
import com.devonfw.tools.ide.process.ProcessContext;
import com.devonfw.tools.ide.repo.ToolRepository;

/**
* Implementation of {@link IdeContext} for testing.
Expand All @@ -23,37 +22,23 @@ public class IdeTestContext extends AbstractIdeTestContext {
*/
public IdeTestContext(Path userDir) {

this(userDir, null);
this(userDir, IdeLogLevel.TRACE);
}

/**
* The constructor.
*
* @param userDir the optional {@link Path} to current working directory.
* @param toolRepository the {@link ToolRepository} of the context. If it is set to {@code null} *
* {@link com.devonfw.tools.ide.repo.DefaultToolRepository} will be used.
*/
public IdeTestContext(Path userDir, ToolRepository toolRepository) {

this(userDir, toolRepository, IdeLogLevel.TRACE);
}

/**
* The constructor.
*
* @param userDir the optional {@link Path} to current working directory.
* @param toolRepository the {@link ToolRepository} of the context. If it is set to {@code null} *
* {@link com.devonfw.tools.ide.repo.DefaultToolRepository} will be used.
* @param logLevel the {@link IdeLogLevel} used as threshold for logging.
*/
public IdeTestContext(Path userDir, ToolRepository toolRepository, IdeLogLevel logLevel) {
public IdeTestContext(Path userDir, IdeLogLevel logLevel) {

this(new IdeTestLogger(logLevel), userDir, toolRepository);
this(new IdeTestLogger(logLevel), userDir);
}

private IdeTestContext(IdeTestLogger logger, Path userDir, ToolRepository toolRepository) {
private IdeTestContext(IdeTestLogger logger, Path userDir) {

super(logger, userDir, toolRepository);
super(logger, userDir);
this.logger = logger;
this.gitContext = new GitContextMock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,42 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Iterator;
import java.util.stream.Stream;

import com.devonfw.tools.ide.cli.CliException;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.url.model.file.UrlDependencyFile;
import com.devonfw.tools.ide.url.model.file.json.ToolDependency;
import com.devonfw.tools.ide.version.GenericVersionRange;
import com.devonfw.tools.ide.version.VersionIdentifier;

/**
* Implementation of {@link ToolRepository} for testing.
*/
public class ToolRepositoryMock implements ToolRepository {

private static final Path PROJECTS_TARGET_PATH = Path.of("target/test-projects");

private static final String MOCK_DOWNLOAD_FOLDER = "repository";
public class ToolRepositoryMock extends DefaultToolRepository {

private final Path repositoryFolder;

private IdeContext context;

/**
* The constructor.
*
* @param context the {@link IdeContext}.
* @param repositoryFolder the {@link Path} to the mock repository.
*/
public ToolRepositoryMock(Path repositoryFolder) {
public ToolRepositoryMock(IdeContext context, Path repositoryFolder) {

super();
super(context);
this.repositoryFolder = repositoryFolder;
}

public void setContext(IdeContext context) {

this.context = context;

}

@Override
public String getId() {

return ID_DEFAULT;
}

@Override
public VersionIdentifier resolveVersion(String tool, String edition, GenericVersionRange version) {

return version.getMax();
try {
return super.resolveVersion(tool, edition, version);
} catch (CliException e) {
this.context.error(e, "Invalid test project using version {} that cannot be resolved in urls folder", version);
return version.getMax();
}
}

@Override
Expand Down Expand Up @@ -98,10 +84,4 @@ public Path download(String tool, String edition, VersionIdentifier version) {
return archiveFolder;
}

@Override
public Collection<ToolDependency> findDependencies(String tool, String edition, VersionIdentifier version) {

UrlDependencyFile dependencyFile = this.context.getUrls().getEdition(tool, edition).getDependencyFile();
return dependencyFile.getDependencies().findDependencies(version);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.devonfw.tools.ide.tool.eclipse;

import java.io.IOException;
import java.nio.file.Path;

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.IdeTestContext;
import com.devonfw.tools.ide.os.SystemInfo;
import com.devonfw.tools.ide.os.SystemInfoMock;
import com.devonfw.tools.ide.tool.intellij.Intellij;

/**
* Integration test of {@link Eclipse}.
*/
public class EclipseTest extends AbstractIdeContextTest {

private static final String PROJECT_ECLIPSE = "eclipse";

/**
* Tests if the {@link Intellij} can be installed properly.
*
* @param os String of the OS to use.
* @throws IOException if reading the content of the mocked plugin fails
*/
@ParameterizedTest
@ValueSource(strings = { "windows", "mac", "linux" })
public void testEclipse(String os) throws IOException {

// arrange
SystemInfo systemInfo = SystemInfoMock.of(os);
IdeTestContext context = newContext(PROJECT_ECLIPSE, "eclipseproject");
context.setSystemInfo(systemInfo);
context.getStartContext().setForceMode(true); // #663
Eclipse eclipse = context.getCommandletManager().getCommandlet(Eclipse.class);

// act
eclipse.run();

// assert
Path eclipsePath = context.getSoftwarePath().resolve("eclipse");
assertThat(eclipsePath.resolve(".ide.software.version")).exists().hasContent("2024-09");
assertThat(context).logAtSuccess().hasEntries("Successfully installed java in version 17.0.10_7",
"Successfully installed eclipse in version 2024-09");
assertThat(context).logAtSuccess().hasMessage("Successfully ended step 'Install plugin anyedit'.");
assertThat(context.getPluginsPath().resolve("eclipse")).isDirectory();
assertThat(eclipsePath.resolve("eclipsetest")).hasContent(
"eclipse " + os + " -data " + context.getWorkspacePath() + " -keyring " + context.getUserHome().resolve(".eclipse").resolve(".keyring")
+ " -configuration " + context.getPluginsPath().resolve("eclipse").resolve("configuration") + " gui -showlocation eclipseproject");

//if tool already installed
eclipse.install();
assertThat(context).logAtDebug().hasMessage("Version 2024-09 of tool eclipse is already installed");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import com.devonfw.tools.ide.log.IdeLogLevel;
import com.devonfw.tools.ide.tool.java.Java;

/**
* Test of {@link Tomcat}.
*/
public class TomcatTest extends AbstractIdeContextTest {

private static final String PROJECT_TOMCAT = "tomcat";
Expand Down Expand Up @@ -48,7 +51,7 @@ public void testTomcat() {
new IdeLogEntry(IdeLogLevel.SUCCESS, "Successfully installed java in version " + javaVersionProject), //
new IdeLogEntry(IdeLogLevel.INFO, "OpenJDK version " + javaVersionProject), //
new IdeLogEntry(IdeLogLevel.INFO,
"Configured version is 8u402b06 but does not match version to install [11,21_35] - need to use different version from software repository."), //
"Configured version is 8u402b06 but does not match version to install [11,22) - need to use different version from software repository."), //
new IdeLogEntry(IdeLogLevel.DEBUG, "Installed java in version " + javaVersionTomcat + " at ", true),
new IdeLogEntry(IdeLogLevel.SUCCESS, "Successfully installed tomcat in version " + tomcatVersion), //
new IdeLogEntry(IdeLogLevel.INFO, "OpenJDK version " + javaVersionTomcat), //
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://downloads.eclipse.org/dummytest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://adoptium.net/download/dummytest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is the download metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
M2_REPO=~/.m2/repository
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugin_url=https://raw.githubusercontent.com/iloveeclipse/plugins/latest/
plugin_id=AnyEditTools.feature.group
plugin_active=true
tags=productivity,diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugin_url=https://www.genuitec.com/updates/devstyle/ci/
plugin_id=com.genuitec.eclipse.theming.core.feature.feature.group
plugin_active=false
tags=style
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
JAVA_VERSION=17.0.10_7
ECLIPSE_VERSION=*
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is the main workspace of eclipse test case
Loading

0 comments on commit 805f545

Please sign in to comment.