Package com.github.fracpete.jshell
Class JShellExec
java.lang.Object
com.github.fracpete.jshell.JShellExec
- All Implemented Interfaces:
com.github.fracpete.processoutput4j.core.StreamingProcessOwner,Serializable
public class JShellExec
extends Object
implements Serializable, com.github.fracpete.processoutput4j.core.StreamingProcessOwner
For executing code via JShell.
- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Booleanwhether scripting is available.protected booleanwhether debugging is on.protected com.github.fracpete.processoutput4j.output.StreamingProcessOutputexecutes the script.protected Set<JShellErrorListener>the listeners for errors.protected Set<JShellExecListener>the listeners that listen for changes.protected com.github.fracpete.processoutput4j.core.StreamingProcessOwnerthe streaming process owner to forward the process output to. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the error listener to the internal list.voidAdds the exec listener to the internal list.protected voidOutputs the debugging message if debugging is enabled.booleangetDebug()Returns the debugging flag.Returns the jshell executable.com.github.fracpete.processoutput4j.core.StreamingProcessOutputTypeReturns what output from the process to forward.com.github.fracpete.processoutput4j.core.StreamingProcessOwnerReturns the current recipient of the process output.booleanChecks whether jshell executable is available.booleanReturns whether a script is currently running.voidNotifies all the listeners with the specified event.voidNotifies all the exec listeners with the specified event.voidprocessOutput(String line, boolean stdout) Processes the incoming line.voidRemoves the listener to the internal list.voidRemoves the exec listener to the internal list.voidExecutes the script with no flags.voidrunScript(String code, List<String> runtimeFlags, List<String> remoteRuntimeFlags, List<String> compilerFlags) Executes the script.voidsetDebug(boolean value) Sets the debugging flag.voidsetStreamingProcessOwner(com.github.fracpete.processoutput4j.core.StreamingProcessOwner value) Sets the object to stream the output of the process to.voidshowErrorMessage(String msg) Outputs the error message.voidshowErrorMessage(String msg, Throwable t) Outputs the error message.voidStops a running script.
-
Field Details
-
m_Debug
protected boolean m_Debugwhether debugging is on. -
m_Available
whether scripting is available. -
m_Execution
protected transient com.github.fracpete.processoutput4j.output.StreamingProcessOutput m_Executionexecutes the script. -
m_JShellExecListeners
the listeners that listen for changes. -
m_JShellErrorListeners
the listeners for errors. -
m_StreamingProcessOwner
protected com.github.fracpete.processoutput4j.core.StreamingProcessOwner m_StreamingProcessOwnerthe streaming process owner to forward the process output to.
-
-
Constructor Details
-
JShellExec
public JShellExec()Initializes the execution.
-
-
Method Details
-
setDebug
public void setDebug(boolean value) Sets the debugging flag.- Parameters:
value- true if to turn debugging output on
-
getDebug
public boolean getDebug()Returns the debugging flag.- Returns:
- true if debugging output on
-
debugMsg
Outputs the debugging message if debugging is enabled.- Parameters:
msg- the message output
-
setStreamingProcessOwner
public void setStreamingProcessOwner(com.github.fracpete.processoutput4j.core.StreamingProcessOwner value) Sets the object to stream the output of the process to. If none set, output is output on stdout/stderr.- Parameters:
value- the receiver of the output
-
getStreamingProcessOwner
public com.github.fracpete.processoutput4j.core.StreamingProcessOwner getStreamingProcessOwner()Returns the current recipient of the process output. If none set, output is output on stdout/stderr.- Returns:
- the receiver, null if none set
-
isRunning
public boolean isRunning()Returns whether a script is currently running.- Returns:
- true if a script is running
-
runScript
Executes the script with no flags.- Parameters:
code- the script code to execute
-
runScript
public void runScript(String code, List<String> runtimeFlags, List<String> remoteRuntimeFlags, List<String> compilerFlags) Executes the script.- Parameters:
code- the script code to executeruntimeFlags- optional runtime flags to pass through (-J gets prefixed automatically) - for JShell (eg -verbose)remoteRuntimeFlags- optional runtime flags to pass through (-R gets prefixed automatically) - for JVM that runs code (eg -javaagent:...)compilerFlags- optional runtime flags to pass through (-C gets prefixed automatically)
-
stopScript
public void stopScript()Stops a running script. -
getExecutable
Returns the jshell executable.- Returns:
- the executable path
-
isAvailable
public boolean isAvailable()Checks whether jshell executable is available.- Returns:
- true if available
-
getOutputType
public com.github.fracpete.processoutput4j.core.StreamingProcessOutputType getOutputType()Returns what output from the process to forward.- Specified by:
getOutputTypein interfacecom.github.fracpete.processoutput4j.core.StreamingProcessOwner- Returns:
- the output type
-
processOutput
Processes the incoming line.- Specified by:
processOutputin interfacecom.github.fracpete.processoutput4j.core.StreamingProcessOwner- Parameters:
line- the line to processstdout- whether stdout or stderr
-
showErrorMessage
Outputs the error message.- Parameters:
msg- the message to output
-
showErrorMessage
Outputs the error message.- Parameters:
msg- the message to outputt- the (optional) associated exception
-
addJShellExecListener
Adds the exec listener to the internal list.- Parameters:
l- the listener to add
-
removeJShellExecListener
Removes the exec listener to the internal list.- Parameters:
l- the listener to remove
-
notifyJShellExecListeners
Notifies all the exec listeners with the specified event.- Parameters:
e- the event to send
-
addJShellErrorListener
Adds the error listener to the internal list.- Parameters:
l- the listener to add
-
removeJShellErrorListener
Removes the listener to the internal list.- Parameters:
l- the listener to remove
-
notifyJShellErrorListeners
Notifies all the listeners with the specified event.- Parameters:
e- the event to send
-