Skip to content

Commit 9629ab4

Browse files
committed
devonfw#451: fixes and improvements for installation
1 parent 234a61f commit 9629ab4

File tree

1 file changed

+48
-24
lines changed

1 file changed

+48
-24
lines changed

cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java

+48-24
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,17 @@ protected boolean doInstall(boolean silent) {
7373
VersionIdentifier installedVersion = getInstalledVersion();
7474
Step step = this.context.newStep(silent, "Install " + this.tool, configuredVersion);
7575
try {
76-
// install configured version of our tool in the software repository if not already installed
77-
ToolInstallation installation = installInRepo(configuredVersion);
78-
// check if we already have this version installed (linked) locally in IDE_HOME/software
79-
VersionIdentifier resolvedVersion = installation.resolvedVersion();
80-
if (resolvedVersion.equals(installedVersion) && !installation.newInstallation()) {
76+
ToolRepository repository = this.context.getDefaultToolRepository();
77+
String edition = getEdition();
78+
VersionIdentifier resolvedVersion = repository.resolveVersion(this.tool, edition , configuredVersion);
79+
if (resolvedVersion.equals(installedVersion)) {
8180
IdeLogLevel level = silent ? IdeLogLevel.DEBUG : IdeLogLevel.INFO;
8281
this.context.level(level).log("Version {} of tool {} is already installed", installedVersion, getToolWithEdition());
8382
step.success();
8483
return false;
8584
}
85+
// install configured version of our tool in the software repository if not already installed
86+
ToolInstallation installation = installInRepo(resolvedVersion, edition, repository);
8687
// we need to link the version or update the link.
8788
Path toolPath = getToolPath();
8889
FileAccess fileAccess = this.context.getFileAccess();
@@ -145,30 +146,26 @@ public ToolInstallation installInRepo(VersionIdentifier version, String edition)
145146
public ToolInstallation installInRepo(VersionIdentifier version, String edition, ToolRepository toolRepository) {
146147

147148
VersionIdentifier resolvedVersion = toolRepository.resolveVersion(this.tool, edition, version);
148-
149-
if (Files.exists(this.dependency.getDependencyJsonPath(getEdition()))) {
150-
installDependencies(resolvedVersion);
151-
} else {
152-
this.context.trace("No Dependencies file found");
153-
}
154-
155149
Path toolPath = this.context.getSoftwareRepositoryPath().resolve(toolRepository.getId()).resolve(this.tool).resolve(edition)
156-
.resolve(resolvedVersion.toString());
150+
.resolve(resolvedVersion.toString());
157151
Path toolVersionFile = toolPath.resolve(IdeContext.FILE_SOFTWARE_VERSION);
158152
FileAccess fileAccess = this.context.getFileAccess();
159153
if (Files.isDirectory(toolPath)) {
160154
if (Files.exists(toolVersionFile)) {
161-
if (this.context.isForceMode()) {
162-
fileAccess.delete(toolPath);
163-
} else {
164-
this.context.debug("Version {} of tool {} is already installed at {}", resolvedVersion, getToolWithEdition(this.tool, edition), toolPath);
165-
return createToolInstallation(toolPath, resolvedVersion, toolVersionFile);
166-
}
155+
this.context.debug("Version {} of tool {} is already installed at {}", resolvedVersion, getToolWithEdition(this.tool, edition), toolPath);
156+
return createToolInstallation(toolPath, resolvedVersion, toolVersionFile);
167157
} else {
168-
this.context.warning("Deleting corrupted installation at {}", toolPath);
169-
fileAccess.delete(toolPath);
158+
this.context.warning("Archiving corrupted installation at {}", toolPath);
159+
fileAccess.backup(toolPath);
170160
}
171161
}
162+
163+
if (Files.exists(this.dependency.getDependencyJsonPath(getEdition()))) {
164+
installDependencies(resolvedVersion);
165+
} else {
166+
this.context.trace("No Dependencies file found");
167+
}
168+
172169
Path target = toolRepository.download(this.tool, edition, resolvedVersion);
173170
fileAccess.mkdirs(toolPath.getParent());
174171
boolean extract = isExtract();
@@ -262,13 +259,14 @@ public String getInstalledEdition(Path toolPath) {
262259

263260
}
264261

262+
@Override
265263
public void uninstall() {
266264

267265
try {
268266
Path softwarePath = getToolPath();
269267
if (Files.exists(softwarePath)) {
270268
try {
271-
context.getFileAccess().delete(softwarePath);
269+
this.context.getFileAccess().delete(softwarePath);
272270
this.context.success("Successfully uninstalled " + this.tool);
273271
} catch (Exception e) {
274272
this.context.error("Couldn't uninstall " + this.tool);
@@ -290,13 +288,39 @@ private ToolInstallation createToolInstallation(Path rootDir, VersionIdentifier
290288
if (Files.isDirectory(binFolder)) {
291289
binDir = binFolder;
292290
}
293-
if (linkDir != rootDir) {
291+
if (newInstallation && (linkDir != rootDir)) {
294292
assert (!linkDir.equals(rootDir));
295293
this.context.getFileAccess().copy(toolVersionFile, linkDir, FileCopyMode.COPY_FILE_OVERRIDE);
294+
if (this.context.getSystemInfo().isMac()) {
295+
Path macApp = findMacApp(linkDir);
296+
if (macApp != null) {
297+
ProcessContext pc = this.context.newProcess();
298+
pc.executable("sudo").addArgs("xattr", "-d", "com.apple.quarantine", macApp);
299+
pc.run();
300+
}
301+
}
296302
}
297303
return new ToolInstallation(rootDir, linkDir, binDir, resolvedVersion, newInstallation);
298304
}
299305

306+
private Path findMacApp(Path path) {
307+
308+
while (path != null) {
309+
Path fileName = path.getFileName();
310+
if (fileName == null) {
311+
return null;
312+
}
313+
String filename = fileName.toString();
314+
if (filename.endsWith(".app")) {
315+
return path;
316+
} else if (filename.equals(IdeContext.FOLDER_CONTENTS)) {
317+
return path.getParent();
318+
}
319+
path = path.getParent();
320+
}
321+
return null;
322+
}
323+
300324
private ToolInstallation createToolInstallation(Path rootDir, VersionIdentifier resolvedVersion, Path toolVersionFile) {
301325

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

407431
protected HashMap<String, String> listOfDependencyEnvVariableNames() {
408432

409-
return dependenciesEnvVariableNames;
433+
return this.dependenciesEnvVariableNames;
410434
}
411435

412436
private String getDependencyEnvironmentName(String dependencyName) {

0 commit comments

Comments
 (0)