Class Protoc

java.lang.Object
org.xolstice.maven.plugin.protobuf.Protoc

final class Protoc extends Object
This class represents an invokable configuration of the protoc compiler. The actual executable is invoked using the plexus Commandline.
  • Field Details

    • LOG_PREFIX

      private static final String LOG_PREFIX
      Prefix for logging the debug messages.
      See Also:
    • executable

      private final String executable
      Path to the protoc executable.
    • protoPathElements

      private final List<File> protoPathElements
      A set of directories in which to search for definition imports.
    • protoFiles

      private final List<File> protoFiles
      A set of protobuf definitions to process.
    • javaOutputDirectory

      private final File javaOutputDirectory
      A directory into which Java source files will be generated.
    • javaNanoOutputDirectory

      private final File javaNanoOutputDirectory
      A directory into which JavaNano source files will be generated.
    • plugins

      private final List<ProtocPlugin> plugins
    • pluginDirectory

      private final File pluginDirectory
    • nativePluginId

      private final String nativePluginId
    • nativePluginExecutable

      private final String nativePluginExecutable
    • nativePluginParameter

      private final String nativePluginParameter
    • cppOutputDirectory

      private final File cppOutputDirectory
      A directory into which C++ source files will be generated.
    • pythonOutputDirectory

      private final File pythonOutputDirectory
      A directory into which Python source files will be generated.
    • csharpOutputDirectory

      private final File csharpOutputDirectory
      A directory into which C# source files will be generated.
    • javaScriptOutputDirectory

      private final File javaScriptOutputDirectory
      A directory into which JavaScript source files will be generated.
    • customOutputDirectory

      private final File customOutputDirectory
      A directory into which a custom protoc plugin will generate files.
    • descriptorSetFile

      private final 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 the protoc executable.
    • error

      private final org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer error
      A buffer to consume error output from the protoc executable.
    • tempDirectory

      private final 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 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 the Protoc.Builder.
      Parameters:
      executable - path to the protoc 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; if null, no descriptor set will be written
      includeImportsInDescriptorSet - If true, dependencies will be included in the descriptor set.
      includeSourceInfoInDescriptorSet - If true, 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 - If true, 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 the protoc 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

      public List<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 String getOutput()
      Returns:
      the output
    • getError

      public String getError()
      Returns:
      the error
    • fixUnicodeOutput

      private static String fixUnicodeOutput(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 File createFileWithArguments(String[] args) throws 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:
      IOException