Class AbstractJavaTool<Request extends JavaToolRequest>
- java.lang.Object
-
- org.apache.maven.shared.utils.cli.javatool.AbstractJavaTool<Request>
-
- Type Parameters:
Request
- Tool-specific request type
- All Implemented Interfaces:
JavaTool<Request>
public abstract class AbstractJavaTool<Request extends JavaToolRequest> extends java.lang.Object implements JavaTool<Request>
Abstract implementation of aJavaTool
.- Since:
- 0.5
- Author:
- Tony Chemit
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractJavaTool(java.lang.String javaToolName)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract Commandline
createCommandLine(Request request, java.lang.String javaToolFileLocation)
Create the command line object given the request.protected JavaToolResult
createResult()
protected StreamConsumer
createSystemErrorStreamConsumer(Request request)
protected java.io.InputStream
createSystemInputStream()
protected StreamConsumer
createSystemOutStreamConsumer(Request request)
JavaToolResult
execute(Request request)
Execute the input request and then returns the result of the execution.protected JavaToolResult
executeCommandLine(Commandline cli, Request request)
protected java.lang.String
findJavaToolExecutable()
java.lang.String
getJavaToolName()
Return the name of the java tool.protected org.slf4j.Logger
getLogger()
void
setToolchain(java.lang.Object toolchain)
Set an optional tool chain to find out the java tool executable location.
-
-
-
Method Detail
-
createCommandLine
protected abstract Commandline createCommandLine(Request request, java.lang.String javaToolFileLocation) throws JavaToolException
Create the command line object given the request.- Parameters:
request
- User request on the java tooljavaToolFileLocation
- Location of the java tool file to use- Returns:
- the command line
- Throws:
JavaToolException
- if could not create the command line from the request
-
getLogger
protected org.slf4j.Logger getLogger()
-
getJavaToolName
public java.lang.String getJavaToolName()
Return the name of the java tool. This is exactly the name (without his extension) of the executable to find in the
jdk/bin
directory.For example:
jarsigner, keytool, javadoc, ...
- Specified by:
getJavaToolName
in interfaceJavaTool<Request extends JavaToolRequest>
- Returns:
- the name of the java tool.
-
setToolchain
public void setToolchain(java.lang.Object toolchain)
Set an optional tool chain to find out the java tool executable location.- Specified by:
setToolchain
in interfaceJavaTool<Request extends JavaToolRequest>
- Parameters:
toolchain
- optional tool chain to find out the java tool executable location. To avoid direct dependency on Maven core, this parameter is an Object that will be used as Toolchain through reflection
-
execute
public JavaToolResult execute(Request request) throws JavaToolException
Execute the input request and then returns the result of the execution.
If could not create the java tool invocation, a
JavaToolException
will be thrown.If execution fails, then the result will have a none-zero
JavaToolResult.getExitCode()
and hisJavaToolResult.getExecutionException()
will be filled with the error, otherwise the exist code will be zero.- Specified by:
execute
in interfaceJavaTool<Request extends JavaToolRequest>
- Parameters:
request
- the request to perform- Returns:
- the result of the tool execution
- Throws:
JavaToolException
- if could not create the java tool invocation
-
createSystemInputStream
protected java.io.InputStream createSystemInputStream()
- Returns:
InputStream
-
executeCommandLine
protected JavaToolResult executeCommandLine(Commandline cli, Request request)
- Parameters:
cli
-Commandline
request
- The request.- Returns:
JavaToolRequest
-
createSystemErrorStreamConsumer
protected StreamConsumer createSystemErrorStreamConsumer(Request request)
- Parameters:
request
- The request.- Returns:
StreamConsumer
-
createSystemOutStreamConsumer
protected StreamConsumer createSystemOutStreamConsumer(Request request)
- Parameters:
request
- The request.- Returns:
StreamConsumer
-
createResult
protected JavaToolResult createResult()
- Returns:
- The JavaToolResult.
-
findJavaToolExecutable
protected java.lang.String findJavaToolExecutable()
- Returns:
- The location of the java tool executable.
-
-