Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#47: Support for global tools #113

Merged
merged 29 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
74ef1e3
first changes
salimbouch Oct 19, 2023
baed11e
changes
salimbouch Oct 24, 2023
6bf0f17
tools extend LocalToolCommandlet, globalToolCommand not yet fully imp…
salimbouch Oct 24, 2023
c743813
corrected coding style
salimbouch Oct 24, 2023
fe286c4
corrected coding style
salimbouch Oct 24, 2023
171ba7c
updated TODOs
salimbouch Oct 24, 2023
f1b4f1d
updated TODOs
salimbouch Oct 24, 2023
4bf385d
Merge branch 'main' into 47-support-global-tools
salimbouch Oct 24, 2023
74461da
updated branch
salimbouch Oct 24, 2023
27fc1b8
added -f option
salimbouch Oct 27, 2023
fa3b967
Merge branch 'main' of https://github.com/devonfw/IDEasy into 47-supp…
salimbouch Oct 27, 2023
1580a68
removed unecessary imports
salimbouch Oct 27, 2023
f90d5c9
updated TODOs and JavaDoc
salimbouch Oct 27, 2023
ecd1a13
updated javaDoc
salimbouch Oct 27, 2023
97ae735
merged other PR
salimbouch Oct 28, 2023
886e845
merged other PR
salimbouch Oct 28, 2023
50373eb
removed package-lock.json
salimbouch Oct 29, 2023
ae58363
rearranged local and global TC
salimbouch Oct 30, 2023
e9517f8
Update GlobalToolCommandlet.java
salimbouch Oct 30, 2023
9a8e2f3
removed getToolBinary
salimbouch Oct 30, 2023
bbd224b
updated doInstall
salimbouch Oct 30, 2023
de84209
Merge branch 'main' into 47-support-global-tools
salimbouch Oct 30, 2023
387b7a6
Merge branch 'main' of https://github.com/devonfw/IDEasy into 47-supp…
salimbouch Oct 30, 2023
6cf4682
doInstall in GTC implemented
salimbouch Oct 30, 2023
efd5053
Merge branch '47-support-global-tools' of https://github.com/salimbou…
salimbouch Oct 30, 2023
2b31f10
JavaDocs
salimbouch Oct 30, 2023
830e6d3
updated doInstall
salimbouch Oct 31, 2023
0fa34f3
reviewed changes
salimbouch Nov 6, 2023
d94c0ab
Merge branch 'main' into 47-support-global-tools
hohwille Nov 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.devonfw.tools.ide.tool;

import com.devonfw.tools.ide.context.IdeContext;
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.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Set;

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);
}

/**
* @return the {@link Path} where the main executable file of this tool is installed.
*/
@Override
public Path getToolBinary() {

String path = System.getenv("PATH");
String[] pathDirs = path.split(File.pathSeparator);
for (String dir : pathDirs) {
Path toolPath = Paths.get(dir, getName());
if (Files.isExecutable(toolPath)) {
return toolPath;
}
}
return null;
hohwille marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @return the {@link Path} where the tool is located (installed).
*/
@Override
public Path getToolPath() {

// TODO: get rootDir of global tool? is RootDir accessible from BinDir (getToolBinary())?
return null;
}

/**
* Installs or updates the managed {@link #getName() tool}.
*
* @param silent - {@code true} if called recursively to suppress verbose logging, {@code false} otherwise.
* @return {@code true} if the tool was newly installed, {@code false} if the tool was already installed before and
* nothing has changed.
*/
@Override
protected boolean doInstall(boolean silent) {

String edition = getEdition();
ToolRepository toolRepository = this.context.getDefaultToolRepository();
VersionIdentifier configuredVersion = getConfiguredVersion();
VersionIdentifier resolvedVersion = toolRepository.resolveVersion(this.tool, edition, configuredVersion);
Path binaryPath = getToolBinary();
if (Files.exists(binaryPath)) {
// TODO: check whether resolvedVersion is different than installedVersion, if so update the tool?
return false;
}
// download and install the global tool
Path target = toolRepository.download(this.tool, edition, resolvedVersion);
hohwille marked this conversation as resolved.
Show resolved Hide resolved
ProcessContext pc = this.context.newProcess().errorHandling(ProcessErrorHandling.WARNING).executable(target);
pc.run();
this.context.success("Successfully installed {} in version {}", this.tool, resolvedVersion);
//TODO: create a toolVersionFile? If so, in binDir or rootDir? if not, how do we retrieve the version so that getInstalledVersion works?
postInstall();
return true;
}

}
Loading