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

Extend ProcessContext with method to set executable and get feedback if available #900

Open
hohwille opened this issue Dec 13, 2024 · 0 comments
Labels
core FileAccess, ProcessUtil, IdeContext, etc. enhancement New feature or request process executing external programs (ProcessContext)

Comments

@hohwille
Copy link
Member

In PR #890 we had the situation that we want to execute a command via ProcessContext but only if that binary executable is actually available.
Instead of implementing such features inside one or multiple commandlets, it should belong to ProcessContext.
The idea is to add the following method to ProcessContext:

boolean setAndCheckExecutable(Path executable);

It should do the same as executable(Path executable) but additionally, it should check if that executable can really be executed.

For the implementation this code should be moved to a private method (except for the log message):

SystemPath systemPath = this.context.getPath();
if ((this.overriddenPath != null) || !this.extraPathEntries.isEmpty()) {
systemPath = systemPath.withPath(this.overriddenPath, this.extraPathEntries);
}
String path = systemPath.toString();
this.context.trace("Setting PATH for process execution of {} to {}", this.executable.getFileName(), path);
this.executable = systemPath.findBinary(this.executable);

Then this method can be reused by the new setAndCheckExecutable method.
Only this way, we will also reuse the logic that is later performed to run the command (e.g. adding potential .bat or .exe or .msi extensions and more) without replicating such logic.

ATTENTION: We have some special situations where we create the ProcessContext early on and set the executable first and then other things happen (in this case installation of dependencies) and later when the run method is called, the PATH is updated and the executable can be fully resolved. Therefore the default behaviour of the existing executable(Path executable) method shall not change. Only the new method should do the additional features on top.

@hohwille hohwille added enhancement New feature or request process executing external programs (ProcessContext) core FileAccess, ProcessUtil, IdeContext, etc. labels Dec 13, 2024
@github-project-automation github-project-automation bot moved this to 🆕 New in IDEasy board Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core FileAccess, ProcessUtil, IdeContext, etc. enhancement New feature or request process executing external programs (ProcessContext)
Projects
Status: 🆕 New
Development

No branches or pull requests

1 participant