Class Protoc
java.lang.Object
org.xolstice.maven.plugin.protobuf.Protoc
This class represents an invokable configuration of the
protoc
compiler.
The actual executable is invoked using the plexus Commandline
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
This class buildsProtoc
instances. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final File
A directory into which C++ source files will be generated.private final File
A directory into which C# source files will be generated.private final File
A directory into which a custom protoc plugin will generate files.private final File
private final org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer
A buffer to consume error output from theprotoc
executable.private final String
Path to theprotoc
executable.private final boolean
private final boolean
private final File
A directory into which JavaNano source files will be generated.private final File
A directory into which Java source files will be generated.private final File
A directory into which JavaScript source files will be generated.private static final String
Prefix for logging the debug messages.private final String
private final String
private final String
private final org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer
A buffer to consume standard output from theprotoc
executable.private final File
private final List
<ProtocPlugin> A set of protobuf definitions to process.A set of directories in which to search for definition imports.private final File
A directory into which Python source files will be generated.private final File
A directory where temporary files will be generated.private final boolean
A boolean indicating if the parameters to protoc should be passed in an argument file. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Protoc
(String executable, List<File> protoPath, List<File> protoFiles, File javaOutputDirectory, File javaNanoOutputDirectory, File cppOutputDirectory, File pythonOutputDirectory, File csharpOutputDirectory, File javaScriptOutputDirectory, File customOutputDirectory, File descriptorSetFile, boolean includeImportsInDescriptorSet, boolean includeSourceInfoInDescriptorSet, List<ProtocPlugin> plugins, File pluginDirectory, String nativePluginId, String nativePluginExecutable, String nativePluginParameter, File tempDirectory, boolean useArgumentFile) Constructs a new instance. -
Method Summary
Modifier and TypeMethodDescriptionCreates the command line arguments.private File
createFileWithArguments
(String[] args) Put args into a temp file to be referenced using the @ option in protoc command line.int
execute
(org.apache.maven.plugin.logging.Log log) Invokes theprotoc
compiler using the configuration specified at construction.private static String
fixUnicodeOutput
(String message) Transcodes the output from system default charset to UTF-8.getError()
void
logExecutionParameters
(org.apache.maven.plugin.logging.Log log) Logs execution parameters on debug level to the specified logger.
-
Field Details
-
LOG_PREFIX
Prefix for logging the debug messages.- See Also:
-
executable
Path to theprotoc
executable. -
protoPathElements
A set of directories in which to search for definition imports. -
protoFiles
A set of protobuf definitions to process. -
javaOutputDirectory
A directory into which Java source files will be generated. -
javaNanoOutputDirectory
A directory into which JavaNano source files will be generated. -
plugins
-
pluginDirectory
-
nativePluginId
-
nativePluginExecutable
-
nativePluginParameter
-
cppOutputDirectory
A directory into which C++ source files will be generated. -
pythonOutputDirectory
A directory into which Python source files will be generated. -
csharpOutputDirectory
A directory into which C# source files will be generated. -
javaScriptOutputDirectory
A directory into which JavaScript source files will be generated. -
customOutputDirectory
A directory into which a custom protoc plugin will generate files. -
descriptorSetFile
-
includeImportsInDescriptorSet
private final boolean includeImportsInDescriptorSet -
includeSourceInfoInDescriptorSet
private final boolean includeSourceInfoInDescriptorSet -
output
private final org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer outputA buffer to consume standard output from theprotoc
executable. -
error
private final org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer errorA buffer to consume error output from theprotoc
executable. -
tempDirectory
A directory where temporary files will be generated. -
useArgumentFile
private final boolean useArgumentFileA boolean indicating if the parameters to protoc should be passed in an argument file.
-
-
Constructor Details
-
Protoc
private Protoc(String executable, List<File> protoPath, List<File> protoFiles, File javaOutputDirectory, File javaNanoOutputDirectory, File cppOutputDirectory, File pythonOutputDirectory, File csharpOutputDirectory, File javaScriptOutputDirectory, File customOutputDirectory, File descriptorSetFile, boolean includeImportsInDescriptorSet, boolean includeSourceInfoInDescriptorSet, List<ProtocPlugin> plugins, File pluginDirectory, String nativePluginId, String nativePluginExecutable, String nativePluginParameter, File tempDirectory, boolean useArgumentFile) Constructs a new instance. This should only be used by theProtoc.Builder
.- Parameters:
executable
- path to theprotoc
executable.protoPath
- a set of directories in which to search for definition imports.protoFiles
- a set of protobuf definitions to process.javaOutputDirectory
- a directory into which Java source files will be generated.javaNanoOutputDirectory
- a directory into which JavaNano source files will be generated.cppOutputDirectory
- a directory into which C++ source files will be generated.pythonOutputDirectory
- a directory into which Python source files will be generated.csharpOutputDirectory
- a directory into which C# source files will be generated.javaScriptOutputDirectory
- a directory into which JavaScript source files will be generated.customOutputDirectory
- a directory into which a custom protoc plugin will generate files.descriptorSetFile
- The directory into which a descriptor set will be generated; ifnull
, no descriptor set will be writtenincludeImportsInDescriptorSet
- Iftrue
, dependencies will be included in the descriptor set.includeSourceInfoInDescriptorSet
- Iftrue
, source code information will be included in the descriptor set.plugins
- a set of java protoc plugins.pluginDirectory
- location of protoc plugins to be added to system path.nativePluginId
- a unique id of a native plugin.nativePluginExecutable
- path to the native plugin executable.nativePluginParameter
- an optional parameter for a native plugin.tempDirectory
- a directory where temporary files will be generated.useArgumentFile
- Iftrue
, parameters to protoc will be put in an argument file
-
-
Method Details
-
execute
public int execute(org.apache.maven.plugin.logging.Log log) throws org.codehaus.plexus.util.cli.CommandLineException, InterruptedException Invokes theprotoc
compiler using the configuration specified at construction.- Parameters:
log
- logger instance.- Returns:
- The exit status of
protoc
. - Throws:
org.codehaus.plexus.util.cli.CommandLineException
- if command line environment cannot be set up.InterruptedException
- if the execution was interrupted by the user.
-
buildProtocCommand
Creates the command line arguments.This method has been made visible for testing only.
- Returns:
- A list consisting of the executable followed by any arguments.
-
logExecutionParameters
public void logExecutionParameters(org.apache.maven.plugin.logging.Log log) Logs execution parameters on debug level to the specified logger. All log messages will be prefixed with ""[PROTOC] "".- Parameters:
log
- a logger.
-
getOutput
- Returns:
- the output
-
getError
- Returns:
- the error
-
fixUnicodeOutput
Transcodes the output from system default charset to UTF-8. Protoc emits messages in UTF-8, but they are captured into a stream that has a system-default encoding.- Parameters:
message
- a UTF-8 message in system-default encoding.- Returns:
- the same message converted into a unicode string.
-
createFileWithArguments
Put args into a temp file to be referenced using the @ option in protoc command line.- Parameters:
args
-- Returns:
- the temporary file wth the arguments
- Throws:
IOException
-