Package com.github.fracpete.rsync4j.core
Class AbstractBinary
- java.lang.Object
-
- com.github.fracpete.rsync4j.core.AbstractBinary
-
- Direct Known Subclasses:
AbstractBinaryWithTimeout,SshKeyGen,SshPass
public abstract class AbstractBinary extends java.lang.ObjectAncestor of wrappers for binaries.- Author:
- fracpete (fracpete at gmail dot com)
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.logging.Loggerloggerfor logging.protected booleanoutputCommandlinewhether to output the commandline.protected booleanoutputSingleCommandlinewhether to output the commandline arguments one per line or combined in a single line.
-
Constructor Summary
Constructors Constructor Description AbstractBinary()Initializes the object.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.ProcessBuilderbuilder()Returns a configuredProcessBuilderto be used for executing the rsync process.java.lang.StringcommandLine()Assembles the full command-line.abstract java.util.List<java.lang.String>commandLineArgs()Assembles the full command-line arguments.protected abstract java.lang.Stringdescription()Returns a short description for the binary.com.github.fracpete.processoutput4j.output.CollectingProcessOutputexecute()Executes the rsync binary for the platform and waits for its completion.booleangetOutputCommandline()Returns output commandline flag.booleangetOutputSingleCommandline()Returns whether to output the command-line as single line or each argument on a separate one.protected net.sourceforge.argparse4j.inf.ArgumentParsergetParser()Configures and returns the commandline parser.abstract java.util.List<java.lang.String>options()Assembles the arguments for the rsync binary.AbstractBinaryoutputCommandline(boolean value)Sets output commandline flag.AbstractBinaryoutputSingleCommandline(boolean value)Sets whether to output the command-line as single line or each argument on a separate one.voidreset()Resets the members.static voidrun(AbstractBinary binary, java.lang.String[] args)Runs the binary with the arguments.booleansetOptions(java.lang.String[] options)Sets the commandline options.protected booleansetOptions(net.sourceforge.argparse4j.inf.Namespace ns)Sets the parsed options.java.lang.Processstart()Starts the rsync process for the platform.
-
-
-
Field Detail
-
logger
protected java.util.logging.Logger logger
for logging.
-
outputCommandline
protected boolean outputCommandline
whether to output the commandline.
-
outputSingleCommandline
protected boolean outputSingleCommandline
whether to output the commandline arguments one per line or combined in a single line.
-
-
Method Detail
-
reset
public void reset()
Resets the members.
-
outputCommandline
public AbstractBinary outputCommandline(boolean value)
Sets output commandline flag.- Parameters:
value- true if to output commandline- Returns:
- itself
-
getOutputCommandline
public boolean getOutputCommandline()
Returns output commandline flag.- Returns:
- true if to output commandline
-
outputSingleCommandline
public AbstractBinary outputSingleCommandline(boolean value)
Sets whether to output the command-line as single line or each argument on a separate one.- Parameters:
value- true for single line- Returns:
- itself
-
getOutputSingleCommandline
public boolean getOutputSingleCommandline()
Returns whether to output the command-line as single line or each argument on a separate one.- Returns:
- true if single line
-
options
public abstract java.util.List<java.lang.String> options() throws java.lang.ExceptionAssembles the arguments for the rsync binary.- Returns:
- the options
- Throws:
java.lang.Exception- if failed to determine binary
-
commandLineArgs
public abstract java.util.List<java.lang.String> commandLineArgs() throws java.lang.ExceptionAssembles the full command-line arguments.- Returns:
- the command-line arguments
- Throws:
java.lang.Exception- if failed to determine binary- See Also:
options()
-
commandLine
public java.lang.String commandLine() throws java.lang.ExceptionAssembles the full command-line.- Returns:
- the command-line arguments
- Throws:
java.lang.Exception- if failed to determine binary- See Also:
commandLineArgs()
-
builder
public java.lang.ProcessBuilder builder() throws java.lang.ExceptionReturns a configuredProcessBuilderto be used for executing the rsync process.- Returns:
- the configured process builder
- Throws:
java.lang.Exception- if execution fails or failed to determine binary- See Also:
commandLineArgs()
-
start
public java.lang.Process start() throws java.lang.ExceptionStarts the rsync process for the platform.
If you are not interested in an incremental progress output, then you can also useexecute(), which waits for the process to finish while collecting stdout and stderr output.- Returns:
- the process object
- Throws:
java.lang.Exception- if execution fails or failed to determine binary- See Also:
builder()
-
execute
public com.github.fracpete.processoutput4j.output.CollectingProcessOutput execute() throws java.lang.ExceptionExecutes the rsync binary for the platform and waits for its completion. Collects stdout and stderr output in the result.
If you want an incremental output, you can usestart()and monitor the output yourself.- Returns:
- the process result object
- Throws:
java.lang.Exception- if execution fails or failed to determine binary- See Also:
commandLineArgs()
-
description
protected abstract java.lang.String description()
Returns a short description for the binary.- Returns:
- the description
-
getParser
protected net.sourceforge.argparse4j.inf.ArgumentParser getParser()
Configures and returns the commandline parser.- Returns:
- the parser
-
setOptions
protected boolean setOptions(net.sourceforge.argparse4j.inf.Namespace ns)
Sets the parsed options.- Parameters:
ns- the parsed options- Returns:
- if successfully set
-
setOptions
public boolean setOptions(java.lang.String[] options) throws java.lang.ExceptionSets the commandline options.- Parameters:
options- the options to use- Returns:
- true if successful
- Throws:
java.lang.Exception- in case of an invalid option
-
run
public static void run(AbstractBinary binary, java.lang.String[] args) throws java.lang.Exception
Runs the binary with the arguments.- Parameters:
args- the arguments- Throws:
java.lang.Exception
-
-