Skip to content

Commit

Permalink
#183: improved logging
Browse files Browse the repository at this point in the history
  • Loading branch information
MattesMrzik committed Jan 17, 2024
1 parent adb48f2 commit fa1984e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -31,17 +32,20 @@ public GlobalToolCommandlet(IdeContext context, String tool, Set<String> 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;
}

@Override
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();
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit fa1984e

Please sign in to comment.