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 8c83a16a1..a09753e7d 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 @@ -2,6 +2,7 @@ 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; @@ -31,7 +32,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; } @@ -39,9 +42,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(); @@ -57,7 +61,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 a5c7a3a7b..5505a3553 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,6 +66,9 @@ protected boolean doInstall(boolean silent) { VersionIdentifier installedVersion = getInstalledVersion(); VersionIdentifier resolvedVersion = installation.resolvedVersion(); 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. @@ -132,12 +135,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());