Interface ToolProvider
public interface ToolProvider
Tool providers are normally located using the service-provider loading facility defined by ServiceLoader
. Each provider must provide a name, and a method to run an instance of the corresponding tool. When a tool is run, it will be provided with an array of string arguments, and a pair of streams: one for normal (or expected) output and the other for reporting any errors that may occur. The interpretation of the string arguments will normally be defined by each individual tool provider, but will generally correspond to the arguments that could be provided to the tool when invoking the tool from the command line.
- Since:
- 9
Method Summary
Modifier and Type | Method | Description |
---|---|---|
static Optional<ToolProvider> |
findFirst |
Returns the first instance of a ToolProvider with the given name, as loaded by ServiceLoader using the system class loader. |
String |
name() |
Returns the name of this tool provider. |
default int |
run |
Runs an instance of the tool, returning zero for a successful run. |
int |
run |
Runs an instance of the tool, returning zero for a successful run. |
Method Details
name
String name()
- API Note:
- It is recommended that the name be the same as would be used on the command line: for example, "javac", "jar", "jlink".
- Returns:
- the name of this tool provider
run
int run(PrintWriter out, PrintWriter err, String... args)
- API Note:
- The interpretation of the arguments will be specific to each tool.
- Parameters:
-
out
- a stream to which "expected" output should be written -
err
- a stream to which any error messages should be written -
args
- the command-line arguments for the tool - Returns:
- the result of executing the tool. A return value of 0 means the tool did not encounter any errors; any other value indicates that at least one error occurred during execution.
- Throws:
-
NullPointerException
- if any of the arguments arenull
, or if there are anynull
values in theargs
array
run
default int run(PrintStream out, PrintStream err, String... args)
- API Note:
- The interpretation of the arguments will be specific to each tool.
- Implementation Note:
- This implementation wraps the
out
anderr
streams withinPrintWriter
s, and then callsrun(PrintWriter, PrintWriter, String[])
. - Parameters:
-
out
- a stream to which "expected" output should be written -
err
- a stream to which any error messages should be written -
args
- the command-line arguments for the tool - Returns:
- the result of executing the tool. A return value of 0 means the tool did not encounter any errors; any other value indicates that at least one error occurred during execution.
- Throws:
-
NullPointerException
- if any of the arguments arenull
, or if there are anynull
values in theargs
array
findFirst
static Optional<ToolProvider> findFirst(String name)
ToolProvider
with the given name, as loaded by ServiceLoader
using the system class loader.- Parameters:
-
name
- the name of the desired tool provider - Returns:
- an
Optional<ToolProvider>
of the first instance found - Throws:
-
NullPointerException
- ifname
isnull
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/spi/ToolProvider.html