Class Protoc
- java.lang.Object
-
- org.xolstice.maven.plugin.protobuf.Protoc
-
final class Protoc extends java.lang.ObjectThis class represents an invokable configuration of theprotoccompiler. The actual executable is invoked using the plexusCommandline.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classProtoc.BuilderThis class buildsProtocinstances.
-
Field Summary
Fields Modifier and Type Field Description private java.io.FilecppOutputDirectoryA directory into which C++ source files will be generated.private java.io.FilecsharpOutputDirectoryA directory into which C# source files will be generated.private java.io.FilecustomOutputDirectoryA directory into which a custom protoc plugin will generate files.private java.io.FiledescriptorSetFileprivate org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumererrorA buffer to consume error output from theprotocexecutable.private java.lang.StringexecutablePath to theprotocexecutable.private booleanincludeImportsInDescriptorSetprivate booleanincludeSourceInfoInDescriptorSetprivate java.io.FilejavaNanoOutputDirectoryA directory into which JavaNano source files will be generated.private java.io.FilejavaOutputDirectoryA directory into which Java source files will be generated.private java.io.FilejavaScriptOutputDirectoryA directory into which JavaScript source files will be generated.private static java.lang.StringLOG_PREFIXPrefix for logging the debug messages.private java.lang.StringnativePluginExecutableprivate java.lang.StringnativePluginIdprivate java.lang.StringnativePluginParameterprivate org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumeroutputA buffer to consume standard output from theprotocexecutable.private java.io.FilepluginDirectoryprivate java.util.List<ProtocPlugin>pluginsprivate java.util.List<java.io.File>protoFilesA set of protobuf definitions to process.private java.util.List<java.io.File>protoPathElementsA set of directories in which to search for definition imports.private java.io.FilepythonOutputDirectoryA directory into which Python source files will be generated.private java.io.FiletempDirectoryA directory where temporary files will be generated.private booleanuseArgumentFileA boolean indicating if the parameters to protoc should be passed in an argument file.
-
Constructor Summary
Constructors Modifier Constructor Description privateProtoc(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.FilecreateFileWithArguments(java.lang.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 java.lang.StringfixUnicodeOutput(java.lang.String message)Transcodes the output from system default charset to UTF-8.java.lang.StringgetError()java.lang.StringgetOutput()voidlogExecutionParameters(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 theprotocexecutable.
-
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 theprotocexecutable.
-
error
private final org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer error
A buffer to consume error output from theprotocexecutable.
-
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 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 Detail
-
execute
public int execute(org.apache.maven.plugin.logging.Log log) throws org.codehaus.plexus.util.cli.CommandLineException, java.lang.InterruptedExceptionInvokes 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.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.IOExceptionPut 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
-
-