Skip to content

Commit

Permalink
devonfw#451: fixes and improvements for installation
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille committed Jul 5, 2024
1 parent 234a61f commit 9629ab4
Showing 1 changed file with 48 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,17 @@ protected boolean doInstall(boolean silent) {
VersionIdentifier installedVersion = getInstalledVersion();
Step step = this.context.newStep(silent, "Install " + this.tool, configuredVersion);
try {
// install configured version of our tool in the software repository if not already installed
ToolInstallation installation = installInRepo(configuredVersion);
// check if we already have this version installed (linked) locally in IDE_HOME/software
VersionIdentifier resolvedVersion = installation.resolvedVersion();
if (resolvedVersion.equals(installedVersion) && !installation.newInstallation()) {
ToolRepository repository = this.context.getDefaultToolRepository();
String edition = getEdition();
VersionIdentifier resolvedVersion = repository.resolveVersion(this.tool, edition , configuredVersion);
if (resolvedVersion.equals(installedVersion)) {
IdeLogLevel level = silent ? IdeLogLevel.DEBUG : IdeLogLevel.INFO;
this.context.level(level).log("Version {} of tool {} is already installed", installedVersion, getToolWithEdition());
step.success();
return false;
}
// install configured version of our tool in the software repository if not already installed
ToolInstallation installation = installInRepo(resolvedVersion, edition, repository);
// we need to link the version or update the link.
Path toolPath = getToolPath();
FileAccess fileAccess = this.context.getFileAccess();
Expand Down Expand Up @@ -145,30 +146,26 @@ public ToolInstallation installInRepo(VersionIdentifier version, String edition)
public ToolInstallation installInRepo(VersionIdentifier version, String edition, ToolRepository toolRepository) {

VersionIdentifier resolvedVersion = toolRepository.resolveVersion(this.tool, edition, version);

if (Files.exists(this.dependency.getDependencyJsonPath(getEdition()))) {
installDependencies(resolvedVersion);
} else {
this.context.trace("No Dependencies file found");
}

Path toolPath = this.context.getSoftwareRepositoryPath().resolve(toolRepository.getId()).resolve(this.tool).resolve(edition)
.resolve(resolvedVersion.toString());
.resolve(resolvedVersion.toString());
Path toolVersionFile = toolPath.resolve(IdeContext.FILE_SOFTWARE_VERSION);
FileAccess fileAccess = this.context.getFileAccess();
if (Files.isDirectory(toolPath)) {
if (Files.exists(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);
}
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("Archiving corrupted installation at {}", toolPath);
fileAccess.backup(toolPath);
}
}

if (Files.exists(this.dependency.getDependencyJsonPath(getEdition()))) {
installDependencies(resolvedVersion);
} else {
this.context.trace("No Dependencies file found");
}

Path target = toolRepository.download(this.tool, edition, resolvedVersion);
fileAccess.mkdirs(toolPath.getParent());
boolean extract = isExtract();
Expand Down Expand Up @@ -262,13 +259,14 @@ public String getInstalledEdition(Path toolPath) {

}

@Override
public void uninstall() {

try {
Path softwarePath = getToolPath();
if (Files.exists(softwarePath)) {
try {
context.getFileAccess().delete(softwarePath);
this.context.getFileAccess().delete(softwarePath);
this.context.success("Successfully uninstalled " + this.tool);
} catch (Exception e) {
this.context.error("Couldn't uninstall " + this.tool);
Expand All @@ -290,13 +288,39 @@ private ToolInstallation createToolInstallation(Path rootDir, VersionIdentifier
if (Files.isDirectory(binFolder)) {
binDir = binFolder;
}
if (linkDir != rootDir) {
if (newInstallation && (linkDir != rootDir)) {
assert (!linkDir.equals(rootDir));
this.context.getFileAccess().copy(toolVersionFile, linkDir, FileCopyMode.COPY_FILE_OVERRIDE);
if (this.context.getSystemInfo().isMac()) {
Path macApp = findMacApp(linkDir);
if (macApp != null) {
ProcessContext pc = this.context.newProcess();
pc.executable("sudo").addArgs("xattr", "-d", "com.apple.quarantine", macApp);
pc.run();
}
}
}
return new ToolInstallation(rootDir, linkDir, binDir, resolvedVersion, newInstallation);
}

private Path findMacApp(Path path) {

while (path != null) {
Path fileName = path.getFileName();
if (fileName == null) {
return null;
}
String filename = fileName.toString();
if (filename.endsWith(".app")) {
return path;
} else if (filename.equals(IdeContext.FOLDER_CONTENTS)) {
return path.getParent();
}
path = path.getParent();
}
return null;
}

private ToolInstallation createToolInstallation(Path rootDir, VersionIdentifier resolvedVersion, Path toolVersionFile) {

return createToolInstallation(rootDir, resolvedVersion, toolVersionFile, false);
Expand Down Expand Up @@ -406,7 +430,7 @@ private void setDependencyEnvironmentPath(String dependencyEnvironmentName, Path

protected HashMap<String, String> listOfDependencyEnvVariableNames() {

return dependenciesEnvVariableNames;
return this.dependenciesEnvVariableNames;
}

private String getDependencyEnvironmentName(String dependencyName) {
Expand Down

0 comments on commit 9629ab4

Please sign in to comment.