Skip to content

Commit

Permalink
#352: implemented new design for tools like python and node (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
salimbouch authored Jul 30, 2024
1 parent 7b8ff7a commit ddcf149
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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) {
Expand All @@ -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);

Expand All @@ -152,29 +162,39 @@ 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)) {
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);
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);
fileAccess.delete(toolPath);
}
}
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);
Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/tool/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit ddcf149

Please sign in to comment.