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 classThis class buildsProtocinstances. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final FileA directory into which C++ source files will be generated.private final FileA directory into which C# source files will be generated.private final FileA directory into which a custom protoc plugin will generate files.private final Fileprivate final org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumerA buffer to consume error output from theprotocexecutable.private final StringPath to theprotocexecutable.private final booleanprivate final booleanprivate final FileA directory into which JavaNano source files will be generated.private final FileA directory into which Java source files will be generated.private final FileA directory into which JavaScript source files will be generated.private static final StringPrefix for logging the debug messages.private final Stringprivate final Stringprivate final Stringprivate final org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumerA buffer to consume standard output from theprotocexecutable.private final Fileprivate final List<ProtocPlugin> A set of protobuf definitions to process.A set of directories in which to search for definition imports.private final FileA directory into which Python source files will be generated.private final FileA directory where temporary files will be generated.private final booleanA boolean indicating if the parameters to protoc should be passed in an argument file. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateProtoc(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 FilecreateFileWithArguments(String[] args) Put args into a temp file to be referenced using the @ option in protoc command line.intexecute(org.apache.maven.plugin.logging.Log log) Invokes theprotoccompiler using the configuration specified at construction.private static StringfixUnicodeOutput(String message) Transcodes the output from system default charset to UTF-8.getError()voidlogExecutionParameters(org.apache.maven.plugin.logging.Log log) Logs execution parameters on debug level to the specified logger.
-
Field Details
-
LOG_PREFIX
-
executable
Path to theprotocexecutable. -
protoPathElements
-
protoFiles
-
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 theprotocexecutable. -
error
private final org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer errorA buffer to consume error output from theprotocexecutable. -
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 theprotocexecutable.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 theprotoccompiler 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
-
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
-