-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make TermuxTask and TermuxSession agnostic to termux environment
Those classes shouldn't be tied to termux environment like variables, interpreters and working directory since commands may need to be executed with a different environment like android's or with a different logic. Now both classes use the ShellEnvironmentClient interface to dynamically get the environment to be used which currently for Termux's case is implemented by TermuxShellEnvironmentClient which is just a wrapper for TermuxShellUtils since later implements static functions.
- Loading branch information
1 parent
2aafcf8
commit 53c1a49
Showing
8 changed files
with
265 additions
and
153 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
47 changes: 47 additions & 0 deletions
47
termux-shared/src/main/java/com/termux/shared/shell/ShellEnvironmentClient.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,47 @@ | ||
package com.termux.shared.shell; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
public interface ShellEnvironmentClient { | ||
|
||
/** | ||
* Get the default working directory path for the environment in case the path that was passed | ||
* was {@code null} or empty. | ||
* | ||
* @return Should return the default working directory path. | ||
*/ | ||
@NonNull | ||
String getDefaultWorkingDirectoryPath(); | ||
|
||
/** | ||
* Get the default "/bin" path, likely $PREFIX/bin. | ||
* | ||
* @return Should return the "/bin" path. | ||
*/ | ||
@NonNull | ||
String getDefaultBinPath(); | ||
|
||
/** | ||
* Build the shell environment to be used for commands. | ||
* | ||
* @param currentPackageContext The {@link Context} for the current package. | ||
* @param isFailSafe If running a failsafe session. | ||
* @param workingDirectory The working directory for the environment. | ||
* @return Should return the build environment. | ||
*/ | ||
@NonNull | ||
String[] buildEnvironment(Context currentPackageContext, boolean isFailSafe, String workingDirectory); | ||
|
||
/** | ||
* Setup process arguments for the file to execute, like interpreter, etc. | ||
* | ||
* @param fileToExecute The file to execute. | ||
* @param arguments The arguments to pass to the executable. | ||
* @return Should return the final process arguments. | ||
*/ | ||
@NonNull | ||
String[] setupProcessArgs(@NonNull String fileToExecute, String[] arguments); | ||
|
||
} |
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
33 changes: 33 additions & 0 deletions
33
termux-shared/src/main/java/com/termux/shared/shell/TermuxShellEnvironmentClient.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,33 @@ | ||
package com.termux.shared.shell; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
public class TermuxShellEnvironmentClient implements ShellEnvironmentClient { | ||
|
||
@NonNull | ||
@Override | ||
public String getDefaultWorkingDirectoryPath() { | ||
return TermuxShellUtils.getDefaultWorkingDirectoryPath(); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String getDefaultBinPath() { | ||
return TermuxShellUtils.getDefaultBinPath(); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String[] buildEnvironment(Context currentPackageContext, boolean isFailSafe, String workingDirectory) { | ||
return TermuxShellUtils.buildEnvironment(currentPackageContext, isFailSafe, workingDirectory); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String[] setupProcessArgs(@NonNull String fileToExecute, String[] arguments) { | ||
return TermuxShellUtils.setupProcessArgs(fileToExecute, arguments); | ||
} | ||
|
||
} |
Oops, something went wrong.