Skip to content

Commit

Permalink
#183: removed isInstalledVersion() (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
MattesMrzik authored Jan 22, 2024
1 parent 7fcddb5 commit 3dfa78f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -32,17 +33,20 @@ public GlobalToolCommandlet(IdeContext context, String tool, Set<Tag> 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 @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;
}

}

0 comments on commit 3dfa78f

Please sign in to comment.