Class AbstractJavaTool<Request extends JavaToolRequest>

java.lang.Object
org.codehaus.plexus.logging.AbstractLogEnabled
org.apache.maven.shared.utils.cli.javatool.AbstractJavaTool<Request>
Type Parameters:
Request - Tool-specific request type
All Implemented Interfaces:
JavaTool<Request>, org.codehaus.plexus.logging.LogEnabled

public abstract class AbstractJavaTool<Request extends JavaToolRequest> extends org.codehaus.plexus.logging.AbstractLogEnabled implements JavaTool<Request>
Abstract implementation of a JavaTool.
Since:
0.5
  • Field Details

    • javaToolName

      private final String javaToolName
      The java tool name to find out in the jdk.
    • javaToolFile

      private String javaToolFile
      The location of the java tool executable file.
    • toolchain

      private Object toolchain
      Optional toolChain used to find java tool executable file.
  • Constructor Details

    • AbstractJavaTool

      protected AbstractJavaTool(String javaToolName)
      Parameters:
      javaToolName - The name of the java tool.
  • Method Details

    • createCommandLine

      protected abstract Commandline createCommandLine(Request request, String javaToolFileLocation) throws JavaToolException
      Create the command line object given the request.
      Parameters:
      request - User request on the java tool
      javaToolFileLocation - Location of the java tool file to use
      Returns:
      the command line
      Throws:
      JavaToolException - if could not create the command line from the request
    • getJavaToolName

      public 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 interface JavaTool<Request extends JavaToolRequest>
      Returns:
      the name of the java tool.
    • setToolchain

      public void setToolchain(Object toolchain)
      Set an optional tool chain to find out the java tool executable location.
      Specified by:
      setToolchain in interface JavaTool<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 his JavaToolResult.getExecutionException() will be filled with the error, otherwise the exist code will be zero.

      Specified by:
      execute in interface JavaTool<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 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 String findJavaToolExecutable()
      Returns:
      The location of the java tool executable.
    • findToolchainExecutable

      private String findToolchainExecutable()
      Run toolchain.findTool( javaToolName ); through reflection to avoid compile dependency on Maven core.
    • findExecutable

      private String findExecutable(String command, String homeDir, String... subDirs)
      Finds the specified command in any of the given sub directories of the specified JDK/JRE home directory.
      Parameters:
      command - The command to find, must not be null.
      homeDir - The home directory to search in, may be null.
      subDirs - The sub directories of the home directory to search in, must not be null.
      Returns:
      The (absolute) path to the command if found, null otherwise.