From 3dfa78fc79a2e9b1663a2c07f138b15931bd85d5 Mon Sep 17 00:00:00 2001 From: Mattes Mrzik Date: Mon, 22 Jan 2024 15:08:42 +0100 Subject: [PATCH] #183: removed isInstalledVersion() (#184) --- .../tools/ide/tool/GlobalToolCommandlet.java | 13 ++++--- .../tools/ide/tool/LocalToolCommandlet.java | 35 ++++++++----------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/GlobalToolCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/tool/GlobalToolCommandlet.java index 62cf0dcdf..2b2498893 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/GlobalToolCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/GlobalToolCommandlet.java @@ -3,6 +3,7 @@ import com.devonfw.tools.ide.common.Tag; import com.devonfw.tools.ide.context.IdeContext; import com.devonfw.tools.ide.io.FileAccess; +import com.devonfw.tools.ide.log.IdeLogLevel; import com.devonfw.tools.ide.process.ProcessContext; import com.devonfw.tools.ide.process.ProcessErrorHandling; import com.devonfw.tools.ide.repo.ToolRepository; @@ -32,7 +33,9 @@ public GlobalToolCommandlet(IdeContext context, String tool, Set tags) { @Override protected boolean isExtract() { - // for global tools we usually download installers and do not want to extract them (e.g. installer.msi file shall not be extracted) + + // for global tools we usually download installers and do not want to extract them (e.g. installer.msi file shall + // not be extracted) return false; } @@ -40,9 +43,10 @@ protected boolean isExtract() { protected boolean doInstall(boolean silent) { Path binaryPath = this.context.getPath().findBinary(Path.of(getBinaryName())); - //if force mode is enabled, go through with the installation even if the tool is already installed + // if force mode is enabled, go through with the installation even if the tool is already installed if (binaryPath != null && Files.exists(binaryPath) && !this.context.isForceMode()) { - this.context.debug("{} is already installed at {}", this.tool, binaryPath); + IdeLogLevel level = silent ? IdeLogLevel.DEBUG : IdeLogLevel.INFO; + this.context.level(level).log("{} is already installed at {}", this.tool, binaryPath); return false; } String edition = getEdition(); @@ -58,7 +62,8 @@ protected boolean doInstall(boolean silent) { if (isExtract()) { downloadBinaryPath = fileAccess.findFirst(downloadBinaryPath, Files::isExecutable, false); } - ProcessContext pc = this.context.newProcess().errorHandling(ProcessErrorHandling.WARNING).executable(downloadBinaryPath); + ProcessContext pc = this.context.newProcess().errorHandling(ProcessErrorHandling.WARNING) + .executable(downloadBinaryPath); int exitCode = pc.run(); fileAccess.delete(tmpDir); fileAccess.delete(target); diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java index ef11a0fa1..d1e58180a 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java @@ -66,7 +66,10 @@ protected boolean doInstall(boolean silent) { // check if we already have this version installed (linked) locally in IDE_HOME/software VersionIdentifier installedVersion = getInstalledVersion(); VersionIdentifier resolvedVersion = installation.resolvedVersion(); - if (isInstalledVersion(resolvedVersion, installedVersion, silent)) { + if (resolvedVersion.equals(installedVersion)) { + IdeLogLevel level = silent ? IdeLogLevel.DEBUG : IdeLogLevel.INFO; + this.context.level(level).log("Version {} of tool {} is already installed", installedVersion, + getToolWithEdition()); return false; } // we need to link the version or update the link. @@ -133,12 +136,17 @@ public ToolInstallation installInRepo(VersionIdentifier version, String edition, FileAccess fileAccess = this.context.getFileAccess(); if (Files.isDirectory(toolPath)) { if (Files.exists(toolVersionFile)) { - this.context.debug("Version {} of tool {} is already installed at {}", resolvedVersion, - getToolWithEdition(this.tool, edition), toolPath); - return createToolInstallation(toolPath, resolvedVersion, toolVersionFile); + if (this.context.isForceMode()) { + fileAccess.delete(toolPath); + } else { + this.context.debug("Version {} of tool {} is already installed at {}", resolvedVersion, + getToolWithEdition(this.tool, edition), toolPath); + return createToolInstallation(toolPath, resolvedVersion, toolVersionFile); + } + } else { + this.context.warning("Deleting corrupted installation at {}", toolPath); + fileAccess.delete(toolPath); } - this.context.warning("Deleting corrupted installation at {}", toolPath); - fileAccess.delete(toolPath); } Path target = toolRepository.download(this.tool, edition, resolvedVersion); fileAccess.mkdirs(toolPath.getParent()); @@ -167,19 +175,4 @@ private ToolInstallation createToolInstallation(Path rootDir, VersionIdentifier return new ToolInstallation(rootDir, linkDir, binDir, resolvedVersion); } - private boolean isInstalledVersion(VersionIdentifier expectedVersion, VersionIdentifier installedVersion, - boolean silent) { - - if (expectedVersion.equals(installedVersion)) { - IdeLogLevel level = IdeLogLevel.INFO; - if (silent) { - level = IdeLogLevel.DEBUG; - } - this.context.level(level).log("Version {} of tool {} is already installed", installedVersion, - getToolWithEdition()); - return true; - } - return false; - } - }