diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/CustomToolCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/tool/CustomToolCommandlet.java index f332f9ce4..bb0af77cc 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/CustomToolCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/CustomToolCommandlet.java @@ -16,15 +16,15 @@ public CustomToolCommandlet(IdeContext context, CustomTool customTool) { } @Override - public ToolInstallation installInRepo(VersionIdentifier version) { + public ToolInstallation installTool(VersionIdentifier version) { - return installInRepo(version, this.customTool.getEdition()); + return installTool(version, this.customTool.getEdition()); } @Override - public ToolInstallation installInRepo(VersionIdentifier version, String edition) { + public ToolInstallation installTool(VersionIdentifier version, String edition) { - return installInRepo(version, edition, this.context.getCustomToolRepository()); + return installTool(version, edition, this.context.getCustomToolRepository()); } @Override diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java index 14db1f007..b52a9508a 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java @@ -74,7 +74,7 @@ protected boolean doInstall(boolean silent) { 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); + ToolInstallation installation = installTool(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()) { @@ -83,14 +83,16 @@ protected boolean doInstall(boolean silent) { step.success(); return false; } - // we need to link the version or update the link. - Path toolPath = getToolPath(); - FileAccess fileAccess = this.context.getFileAccess(); - if (Files.exists(toolPath)) { - fileAccess.backup(toolPath); + if (!isIgnoreSoftwareRepo()) { + // we need to link the version or update the link. + Path toolPath = getToolPath(); + FileAccess fileAccess = this.context.getFileAccess(); + if (Files.exists(toolPath)) { + fileAccess.backup(toolPath); + } + fileAccess.mkdirs(toolPath.getParent()); + fileAccess.symlink(installation.linkDir(), toolPath); } - fileAccess.mkdirs(toolPath.getParent()); - fileAccess.symlink(installation.linkDir(), toolPath); this.context.getPath().setPath(this.tool, installation.binDir()); postInstall(); if (installedVersion == null) { @@ -109,40 +111,48 @@ protected boolean doInstall(boolean silent) { } /** - * Performs the installation of the {@link #getName() tool} managed by this {@link com.devonfw.tools.ide.commandlet.Commandlet} only in the central software - * repository without touching the IDE installation. + * Determines whether this tool should be installed directly in the software folder or in the software repository. + * + * @return {@code true} if the tool should be installed directly in the software folder, ignoring the central software repository; {@code false} if + * the tool should be installed in the central software repository (default behavior). + */ + protected boolean isIgnoreSoftwareRepo() { + + return false; + } + + /** + * Performs the installation of the {@link #getName() tool} managed by this {@link com.devonfw.tools.ide.commandlet.Commandlet}. * * @param version the {@link VersionIdentifier} requested to be installed. May also be a {@link VersionIdentifier#isPattern() version pattern}. - * @return the {@link ToolInstallation} in the central software repository matching the given {@code version}. + * @return the {@link ToolInstallation} matching the given {@code version}. */ - public ToolInstallation installInRepo(VersionIdentifier version) { + public ToolInstallation installTool(VersionIdentifier version) { - return installInRepo(version, getConfiguredEdition()); + return installTool(version, getConfiguredEdition()); } /** - * Performs the installation of the {@link #getName() tool} managed by this {@link com.devonfw.tools.ide.commandlet.Commandlet} only in the central software - * repository without touching the IDE installation. + * Performs the installation of the {@link #getName() tool} managed by this {@link com.devonfw.tools.ide.commandlet.Commandlet}. * * @param version the {@link VersionIdentifier} requested to be installed. May also be a {@link VersionIdentifier#isPattern() version pattern}. * @param edition the specific edition to install. - * @return the {@link ToolInstallation} in the central software repository matching the given {@code version}. + * @return the {@link ToolInstallation} matching the given {@code version}. */ - public ToolInstallation installInRepo(VersionIdentifier version, String edition) { + public ToolInstallation installTool(VersionIdentifier version, String edition) { - return installInRepo(version, edition, this.context.getDefaultToolRepository()); + return installTool(version, edition, this.context.getDefaultToolRepository()); } /** - * Performs the installation of the {@link #getName() tool} managed by this {@link com.devonfw.tools.ide.commandlet.Commandlet} only in the central software - * repository without touching the IDE installation. + * Performs the installation of the {@link #getName() tool} managed by this {@link com.devonfw.tools.ide.commandlet.Commandlet}. * * @param version the {@link VersionIdentifier} requested to be installed. May also be a {@link VersionIdentifier#isPattern() version pattern}. * @param edition the specific edition to install. * @param toolRepository the {@link ToolRepository} to use. - * @return the {@link ToolInstallation} in the central software repository matching the given {@code version}. + * @return the {@link ToolInstallation} matching the given {@code version}. */ - public ToolInstallation installInRepo(VersionIdentifier version, String edition, ToolRepository toolRepository) { + public ToolInstallation installTool(VersionIdentifier version, String edition, ToolRepository toolRepository) { VersionIdentifier resolvedVersion = toolRepository.resolveVersion(this.tool, edition, version); @@ -152,8 +162,13 @@ public ToolInstallation installInRepo(VersionIdentifier version, String edition, this.context.trace("No Dependencies file found"); } - Path toolPath = this.context.getSoftwareRepositoryPath().resolve(toolRepository.getId()).resolve(this.tool).resolve(edition) - .resolve(resolvedVersion.toString()); + Path toolPath; + if (isIgnoreSoftwareRepo()) { + toolPath = getToolPath(); + } else { + toolPath = this.context.getSoftwareRepositoryPath().resolve(toolRepository.getId()).resolve(this.tool).resolve(edition) + .resolve(resolvedVersion.toString()); + } Path toolVersionFile = toolPath.resolve(IdeContext.FILE_SOFTWARE_VERSION); FileAccess fileAccess = this.context.getFileAccess(); if (Files.isDirectory(toolPath)) { @@ -161,8 +176,10 @@ public ToolInstallation installInRepo(VersionIdentifier version, String edition, 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); + if (!isIgnoreSoftwareRepo() || resolvedVersion.equals(getInstalledVersion())) { + 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); @@ -170,11 +187,14 @@ public ToolInstallation installInRepo(VersionIdentifier version, String edition, } } Path target = toolRepository.download(this.tool, edition, resolvedVersion); - fileAccess.mkdirs(toolPath.getParent()); boolean extract = isExtract(); if (!extract) { this.context.trace("Extraction is disabled for '{}' hence just moving the downloaded file {}.", this.tool, target); } + if (Files.exists(toolPath)) { + fileAccess.backup(toolPath); + } + fileAccess.mkdirs(toolPath.getParent()); fileAccess.extract(target, toolPath, this::postExtract, extract); try { Files.writeString(toolVersionFile, resolvedVersion.toString(), StandardOpenOption.CREATE_NEW); @@ -365,7 +385,7 @@ private void installDependencyInRepo(String dependencyName, ToolCommandlet depen this.context.info("The version {} of the dependency {} is being installed", dependencyVersionToInstall, dependencyName); LocalToolCommandlet dependencyLocal = (LocalToolCommandlet) dependencyTool; - dependencyLocal.installInRepo(dependencyVersionToInstall); + dependencyLocal.installTool(dependencyVersionToInstall); this.context.info("The version {} of the dependency {} was successfully installed", dependencyVersionToInstall, dependencyName); } diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/node/Node.java b/cli/src/main/java/com/devonfw/tools/ide/tool/node/Node.java index b59fe5514..2becfd8f8 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/node/Node.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/node/Node.java @@ -28,4 +28,10 @@ public void printHelp(NlsBundle bundle) { this.context.info("For a list of supported options and arguments, use \"node --help\""); } + + @Override + protected boolean isIgnoreSoftwareRepo() { + + return true; + } }