Class Protoc
- java.lang.Object
-
- org.xolstice.maven.plugin.protobuf.Protoc
-
final class Protoc extends java.lang.Object
This class represents an invokable configuration of theprotoc
compiler. The actual executable is invoked using the plexusCommandline
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
Protoc.Builder
This class buildsProtoc
instances.
-
Field Summary
Fields Modifier and Type Field Description private java.io.File
cppOutputDirectory
A directory into which C++ source files will be generated.private java.io.File
csharpOutputDirectory
A directory into which C# source files will be generated.private java.io.File
customOutputDirectory
A directory into which a custom protoc plugin will generate files.private java.io.File
descriptorSetFile
private org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer
error
A buffer to consume error output from theprotoc
executable.private java.lang.String
executable
Path to theprotoc
executable.private boolean
includeImportsInDescriptorSet
private boolean
includeSourceInfoInDescriptorSet
private java.io.File
javaNanoOutputDirectory
A directory into which JavaNano source files will be generated.private java.io.File
javaOutputDirectory
A directory into which Java source files will be generated.private java.io.File
javaScriptOutputDirectory
A directory into which JavaScript source files will be generated.private static java.lang.String
LOG_PREFIX
Prefix for logging the debug messages.private java.lang.String
nativePluginExecutable
private java.lang.String
nativePluginId
private java.lang.String
nativePluginParameter
private org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer
output
A buffer to consume standard output from theprotoc
executable.private java.io.File
pluginDirectory
private java.util.List<ProtocPlugin>
plugins
private java.util.List<java.io.File>
protoFiles
A set of protobuf definitions to process.private java.util.List<java.io.File>
protoPathElements
A set of directories in which to search for definition imports.private java.io.File
pythonOutputDirectory
A directory into which Python source files will be generated.private java.io.File
tempDirectory
A directory where temporary files will be generated.private boolean
useArgumentFile
A boolean indicating if the parameters to protoc should be passed in an argument file.
-
Constructor Summary
Constructors Modifier Constructor Description private
Protoc(java.lang.String executable, java.util.List<java.io.File> protoPath, java.util.List<java.io.File> protoFiles, java.io.File javaOutputDirectory, java.io.File javaNanoOutputDirectory, java.io.File cppOutputDirectory, java.io.File pythonOutputDirectory, java.io.File csharpOutputDirectory, java.io.File javaScriptOutputDirectory, java.io.File customOutputDirectory, java.io.File descriptorSetFile, boolean includeImportsInDescriptorSet, boolean includeSourceInfoInDescriptorSet, java.util.List<ProtocPlugin> plugins, java.io.File pluginDirectory, java.lang.String nativePluginId, java.lang.String nativePluginExecutable, java.lang.String nativePluginParameter, java.io.File tempDirectory, boolean useArgumentFile)
Constructs a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<java.lang.String>
buildProtocCommand()
Creates the command line arguments.private java.io.File
createFileWithArguments(java.lang.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 java.lang.String
fixUnicodeOutput(java.lang.String message)
Transcodes the output from system default charset to UTF-8.java.lang.String
getError()
java.lang.String
getOutput()
void
logExecutionParameters(org.apache.maven.plugin.logging.Log log)
Logs execution parameters on debug level to the specified logger.
-
-
-
Field Detail
-
LOG_PREFIX
private static final java.lang.String LOG_PREFIX
Prefix for logging the debug messages.- See Also:
- Constant Field Values
-
executable
private final java.lang.String executable
Path to theprotoc
executable.
-
protoPathElements
private final java.util.List<java.io.File> protoPathElements
A set of directories in which to search for definition imports.
-
protoFiles
private final java.util.List<java.io.File> protoFiles
A set of protobuf definitions to process.
-
javaOutputDirectory
private final java.io.File javaOutputDirectory
A directory into which Java source files will be generated.
-
javaNanoOutputDirectory
private final java.io.File javaNanoOutputDirectory
A directory into which JavaNano source files will be generated.
-
plugins
private final java.util.List<ProtocPlugin> plugins
-
pluginDirectory
private final java.io.File pluginDirectory
-
nativePluginId
private final java.lang.String nativePluginId
-
nativePluginExecutable
private final java.lang.String nativePluginExecutable
-
nativePluginParameter
private final java.lang.String nativePluginParameter
-
cppOutputDirectory
private final java.io.File cppOutputDirectory
A directory into which C++ source files will be generated.
-
pythonOutputDirectory
private final java.io.File pythonOutputDirectory
A directory into which Python source files will be generated.
-
csharpOutputDirectory
private final java.io.File csharpOutputDirectory
A directory into which C# source files will be generated.
-
javaScriptOutputDirectory
private final java.io.File javaScriptOutputDirectory
A directory into which JavaScript source files will be generated.
-
customOutputDirectory
private final java.io.File customOutputDirectory
A directory into which a custom protoc plugin will generate files.
-
descriptorSetFile
private final java.io.File descriptorSetFile
-
includeImportsInDescriptorSet
private final boolean includeImportsInDescriptorSet
-
includeSourceInfoInDescriptorSet
private final boolean includeSourceInfoInDescriptorSet
-
output
private final org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer output
A buffer to consume standard output from theprotoc
executable.
-
error
private final org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer error
A buffer to consume error output from theprotoc
executable.
-
tempDirectory
private final java.io.File tempDirectory
A directory where temporary files will be generated.
-
useArgumentFile
private final boolean useArgumentFile
A boolean indicating if the parameters to protoc should be passed in an argument file.
-
-
Constructor Detail
-
Protoc
private Protoc(java.lang.String executable, java.util.List<java.io.File> protoPath, java.util.List<java.io.File> protoFiles, java.io.File javaOutputDirectory, java.io.File javaNanoOutputDirectory, java.io.File cppOutputDirectory, java.io.File pythonOutputDirectory, java.io.File csharpOutputDirectory, java.io.File javaScriptOutputDirectory, java.io.File customOutputDirectory, java.io.File descriptorSetFile, boolean includeImportsInDescriptorSet, boolean includeSourceInfoInDescriptorSet, java.util.List<ProtocPlugin> plugins, java.io.File pluginDirectory, java.lang.String nativePluginId, java.lang.String nativePluginExecutable, java.lang.String nativePluginParameter, java.io.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 Detail
-
execute
public int execute(org.apache.maven.plugin.logging.Log log) throws org.codehaus.plexus.util.cli.CommandLineException, java.lang.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.java.lang.InterruptedException
- if the execution was interrupted by the user.
-
buildProtocCommand
public java.util.List<java.lang.String> 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
public java.lang.String getOutput()
- Returns:
- the output
-
getError
public java.lang.String getError()
- Returns:
- the error
-
fixUnicodeOutput
private static java.lang.String fixUnicodeOutput(java.lang.String message)
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
private java.io.File createFileWithArguments(java.lang.String[] args) throws java.io.IOException
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:
java.io.IOException
-
-