Skip to content

Commit a17ce19

Browse files
committed
#1719: Refactor LocalToolCommandlet and Rust.java
1 parent c1b32d7 commit a17ce19

2 files changed

Lines changed: 38 additions & 20 deletions

File tree

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

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -223,25 +223,18 @@ public ToolInstallation installTool(ToolInstallRequest request) {
223223
}
224224

225225
/**
226-
* Performs the actual installation of the {@link #getName() tool} by downloading its binary, optionally extracting it, backing up any existing installation,
227-
* and writing the version file.
228-
* <p>
229-
* This method assumes that the version has already been resolved and dependencies installed. It handles the final steps of placing the tool into the
230-
* appropriate installation directory.
226+
* Performs the actual installation of the {@link #getName() tool}.
231227
*
232228
* @param request the {@link ToolInstallRequest}.
233229
* @param installationPath the target {@link Path} where the {@link #getName() tool} should be installed.
230+
* @see #doInstall(ToolInstallRequest, Path)
234231
*/
235232
protected void performToolInstallation(ToolInstallRequest request, Path installationPath) {
236233

234+
installDependencies(request);
237235
FileAccess fileAccess = this.context.getFileAccess();
238236
ToolEditionAndVersion requested = request.getRequested();
239237
VersionIdentifier resolvedVersion = requested.getResolvedVersion();
240-
Path downloadedToolFile = downloadTool(requested.getEdition().edition(), resolvedVersion);
241-
boolean extract = isExtract();
242-
if (!extract) {
243-
LOG.trace("Extraction is disabled for '{}' hence just moving the downloaded file {}.", this.tool, downloadedToolFile);
244-
}
245238
if (Files.isDirectory(installationPath)) {
246239
if (this.tool.equals(IdeasyCommandlet.TOOL_NAME)) {
247240
LOG.warn("Your IDEasy installation is missing the version file.");
@@ -250,13 +243,44 @@ protected void performToolInstallation(ToolInstallRequest request, Path installa
250243
}
251244
}
252245
fileAccess.mkdirs(installationPath.getParent());
253-
fileAccess.extract(downloadedToolFile, installationPath, this::postExtract, extract);
246+
247+
doInstall(request, installationPath);
248+
254249
this.context.writeVersionFile(resolvedVersion, installationPath);
255250
// fix macOS Gatekeeper blocking - must run after version file is written but before any executables are launched
256251
getMacOsHelper().removeQuarantineAttribute(installationPath);
257252
LOG.debug("Installed {} in version {} at {}", this.tool, resolvedVersion, installationPath);
258253
}
259254

255+
/**
256+
* Hook to install dependencies of this tool.
257+
*
258+
* @param request the {@link ToolInstallRequest}.
259+
*/
260+
protected void installDependencies(ToolInstallRequest request) {
261+
262+
// nothing to do by default...
263+
}
264+
265+
/**
266+
* Hook for the actual installation of the {@link #getName() tool}. The default implementation performs a
267+
* {@link #downloadTool(String, VersionIdentifier) download} and {@link FileAccess#extract(Path, Path, java.util.function.Consumer, boolean) extraction}.
268+
*
269+
* @param request the {@link ToolInstallRequest}.
270+
* @param installationPath the target {@link Path} where the {@link #getName() tool} should be installed.
271+
*/
272+
protected void doInstall(ToolInstallRequest request, Path installationPath) {
273+
274+
ToolEditionAndVersion requested = request.getRequested();
275+
VersionIdentifier resolvedVersion = requested.getResolvedVersion();
276+
Path downloadedToolFile = downloadTool(requested.getEdition().edition(), resolvedVersion);
277+
boolean extract = isExtract();
278+
if (!extract) {
279+
LOG.trace("Extraction is disabled for '{}' hence just moving the downloaded file {}.", this.tool, downloadedToolFile);
280+
}
281+
this.context.getFileAccess().extract(downloadedToolFile, installationPath, this::postExtract, extract);
282+
}
283+
260284
/**
261285
* @param edition the {@link #getConfiguredEdition() tool edition} to download.
262286
* @param resolvedVersion the resolved {@link VersionIdentifier version} to download.

cli/src/main/java/com/devonfw/tools/ide/tool/rust/Rust.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ protected boolean isExtract() {
5959
return false;
6060
}
6161

62-
private void installDependencies() {
62+
@Override
63+
protected void installDependencies(ToolInstallRequest request) {
6364

6465
if (this.context.getSystemInfo().isWindows()) {
6566
installWindowsMsvcBuildTools();
@@ -94,15 +95,11 @@ private void installWindowsMsvcBuildTools() {
9495
}
9596

9697
@Override
97-
protected void performToolInstallation(ToolInstallRequest request, Path installationPath) {
98+
protected void doInstall(ToolInstallRequest request, Path installationPath) {
9899

99-
installDependencies();
100100
VersionIdentifier resolvedVersion = request.getRequested().getResolvedVersion();
101101
FileAccess fileAccess = this.context.getFileAccess();
102102

103-
if (Files.isDirectory(installationPath)) {
104-
fileAccess.backup(installationPath);
105-
}
106103
fileAccess.mkdirs(installationPath);
107104

108105
Path cargoHome = installationPath.resolve(".cargo");
@@ -174,9 +171,6 @@ protected void performToolInstallation(ToolInstallRequest request, Path installa
174171
if (Files.isDirectory(cargoBin)) {
175172
fileAccess.symlink(cargoBin, toolBin);
176173
}
177-
178-
this.context.writeVersionFile(resolvedVersion, installationPath);
179-
LOG.debug("Installed {} in version {} at {}", this.tool, resolvedVersion, installationPath);
180174
}
181175

182176
private boolean isWindowsExeInstaller(Path installerPath) {

0 commit comments

Comments
 (0)