forked from devonfw/IDEasy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'devonfw:main' into feature/devonfw#13-implement-ToolCom…
…mandlet-for-AWS-CLI
- Loading branch information
Showing
32 changed files
with
466 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
cli/src/main/java/com/devonfw/tools/ide/tool/GlobalToolCommandlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.devonfw.tools.ide.tool; | ||
|
||
import com.devonfw.tools.ide.context.IdeContext; | ||
import com.devonfw.tools.ide.io.FileAccess; | ||
import com.devonfw.tools.ide.process.ProcessContext; | ||
import com.devonfw.tools.ide.process.ProcessErrorHandling; | ||
import com.devonfw.tools.ide.repo.ToolRepository; | ||
import com.devonfw.tools.ide.version.VersionIdentifier; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Set; | ||
|
||
/** | ||
* {@link ToolCommandlet} that is installed globally. | ||
*/ | ||
public abstract class GlobalToolCommandlet extends ToolCommandlet { | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param context the {@link IdeContext}. | ||
* @param tool the {@link #getName() tool name}. | ||
* @param tags the {@link #getTags() tags} classifying the tool. Should be created via {@link Set#of(Object) Set.of} | ||
* method. | ||
*/ | ||
public GlobalToolCommandlet(IdeContext context, String tool, Set<String> tags) { | ||
|
||
super(context, tool, tags); | ||
} | ||
|
||
@Override | ||
protected boolean isExtract() { | ||
// for global tools we usually download installers and do not want to extract them (e.g. installer.msi file shall not be extracted) | ||
return false; | ||
} | ||
|
||
@Override | ||
protected boolean doInstall(boolean silent) { | ||
|
||
Path binaryPath = this.context.getPath().findBinary(Path.of(getBinaryName())); | ||
//if force mode is enabled, go through with the installation even if the tool is already installed | ||
if (binaryPath != null && Files.exists(binaryPath) && !this.context.isForceMode()) { | ||
this.context.debug("{} is already installed at {}", this.tool, binaryPath); | ||
return false; | ||
} | ||
String edition = getEdition(); | ||
ToolRepository toolRepository = this.context.getDefaultToolRepository(); | ||
VersionIdentifier configuredVersion = getConfiguredVersion(); | ||
VersionIdentifier resolvedVersion = toolRepository.resolveVersion(this.tool, edition, configuredVersion); | ||
// download and install the global tool | ||
FileAccess fileAccess = this.context.getFileAccess(); | ||
Path target = toolRepository.download(this.tool, edition, resolvedVersion); | ||
Path tmpDir = fileAccess.createTempDir(getName()); | ||
Path downloadBinaryPath = tmpDir.resolve(target.getFileName()); | ||
extract(target, downloadBinaryPath); | ||
if (isExtract()) { | ||
downloadBinaryPath = fileAccess.findFirst(downloadBinaryPath, Files::isExecutable, false); | ||
} | ||
ProcessContext pc = this.context.newProcess().errorHandling(ProcessErrorHandling.WARNING).executable(downloadBinaryPath); | ||
int exitCode = pc.run(); | ||
fileAccess.delete(tmpDir); | ||
fileAccess.delete(target); | ||
if (exitCode == 0) { | ||
this.context.success("Successfully installed {} in version {}", this.tool, resolvedVersion); | ||
} else { | ||
this.context.warning("{} in version {} was not successfully installed", this.tool, resolvedVersion); | ||
return false; | ||
} | ||
postInstall(); | ||
return true; | ||
} | ||
|
||
} |
Oops, something went wrong.