Class FileDescriptorUtils

java.lang.Object
io.apicurio.registry.utils.protobuf.schema.FileDescriptorUtils

public class FileDescriptorUtils extends Object
Author:
Fabian Martinez, Ravindranath Kakarla, Carles Arnal
  • Field Details

    • DEFAULT_LOCATION

      public static final com.squareup.wire.schema.Location DEFAULT_LOCATION
  • Constructor Details

    • FileDescriptorUtils

      public FileDescriptorUtils()
  • Method Details

    • baseDependencies

      public static com.google.protobuf.Descriptors.FileDescriptor[] baseDependencies()
    • protoFileToFileDescriptor

      public static com.google.protobuf.Descriptors.FileDescriptor protoFileToFileDescriptor(com.google.protobuf.DescriptorProtos.FileDescriptorProto descriptorProto) throws com.google.protobuf.Descriptors.DescriptorValidationException
      Throws:
      com.google.protobuf.Descriptors.DescriptorValidationException
    • protoFileToFileDescriptor

      public static com.google.protobuf.Descriptors.FileDescriptor protoFileToFileDescriptor(com.squareup.wire.schema.internal.parser.ProtoFileElement element) throws com.google.protobuf.Descriptors.DescriptorValidationException
      Throws:
      com.google.protobuf.Descriptors.DescriptorValidationException
    • protoFileToFileDescriptor

      public static com.google.protobuf.Descriptors.FileDescriptor protoFileToFileDescriptor(com.squareup.wire.schema.internal.parser.ProtoFileElement element, String protoFileName) throws com.google.protobuf.Descriptors.DescriptorValidationException
      Throws:
      com.google.protobuf.Descriptors.DescriptorValidationException
    • protoFileToFileDescriptor

      public static com.google.protobuf.Descriptors.FileDescriptor protoFileToFileDescriptor(String schemaDefinition, String protoFileName, Optional<String> optionalPackageName) throws com.google.protobuf.Descriptors.DescriptorValidationException
      Throws:
      com.google.protobuf.Descriptors.DescriptorValidationException
    • protoFileToFileDescriptor

      public static com.google.protobuf.Descriptors.FileDescriptor protoFileToFileDescriptor(String schemaDefinition, String protoFileName, Optional<String> optionalPackageName, Map<String,String> schemaDefs, Map<String,com.google.protobuf.Descriptors.FileDescriptor> dependencies) throws com.google.protobuf.Descriptors.DescriptorValidationException
      Throws:
      com.google.protobuf.Descriptors.DescriptorValidationException
    • parseProtoFileWithDependencies

      public static com.google.protobuf.Descriptors.FileDescriptor parseProtoFileWithDependencies(File mainProtoFile, Set<File> dependencies) throws com.google.protobuf.Descriptors.DescriptorValidationException, FileDescriptorUtils.ReadSchemaException, FileDescriptorUtils.ParseSchemaException
      Same as parseProtoFileWithDependencies(File, Set, Map), but with requiredSchemaDeps set to null.
      Throws:
      com.google.protobuf.Descriptors.DescriptorValidationException
      FileDescriptorUtils.ReadSchemaException
      FileDescriptorUtils.ParseSchemaException
    • parseProtoFileWithDependencies

      public static com.google.protobuf.Descriptors.FileDescriptor parseProtoFileWithDependencies(File mainProtoFile, Set<File> dependencies, Map<String,String> requiredSchemaDeps) throws FileDescriptorUtils.ReadSchemaException, com.google.protobuf.Descriptors.DescriptorValidationException, FileDescriptorUtils.ParseSchemaException
      Same as parseProtoFileWithDependencies(File, Set, Map, boolean), but with failFast set to true and requiredSchemaDeps set to null.
      Throws:
      FileDescriptorUtils.ReadSchemaException
      com.google.protobuf.Descriptors.DescriptorValidationException
      FileDescriptorUtils.ParseSchemaException
    • parseProtoFileWithDependencies

      public static com.google.protobuf.Descriptors.FileDescriptor parseProtoFileWithDependencies(File mainProtoFile, Set<File> dependencies, Map<String,String> requiredSchemaDeps, boolean failFast) throws com.google.protobuf.Descriptors.DescriptorValidationException, FileDescriptorUtils.ReadSchemaException, FileDescriptorUtils.ParseSchemaException
      Parse a proto file with its dependencies to produce a Descriptors.FileDescriptor of it, trying to resolve any transitive dependency.
      During the resolution of dependencies process, depending on failFast, the process will fail as soon as any parsing error happen in the list of provided dependencies, regardless been required or not, or it will proceed until a required dependency cannot be resolved.
      If requiredSchemaDeps is provided, it will be populated with the required dependencies, which keys are in the form of packageName/fileName and the value is the schema definition of the dependency.
      Throws:
      com.google.protobuf.Descriptors.DescriptorValidationException
      FileDescriptorUtils.ReadSchemaException
      FileDescriptorUtils.ParseSchemaException
    • parseProtoFileWithDependencies

      public static com.google.protobuf.Descriptors.FileDescriptor parseProtoFileWithDependencies(FileDescriptorUtils.ProtobufSchemaContent mainProtoFile, Collection<FileDescriptorUtils.ProtobufSchemaContent> dependencies) throws com.google.protobuf.Descriptors.DescriptorValidationException, FileDescriptorUtils.ParseSchemaException
      Same as parseProtoFileWithDependencies(ProtobufSchemaContent, Collection, Map, boolean), but with failFast set to true and requiredSchemaDeps set to null.
      Throws:
      com.google.protobuf.Descriptors.DescriptorValidationException
      FileDescriptorUtils.ParseSchemaException
    • parseProtoFileWithDependencies

      public static com.google.protobuf.Descriptors.FileDescriptor parseProtoFileWithDependencies(FileDescriptorUtils.ProtobufSchemaContent mainProtoFile, Collection<FileDescriptorUtils.ProtobufSchemaContent> dependencies, Map<String,String> requiredSchemaDeps, boolean failFast) throws com.google.protobuf.Descriptors.DescriptorValidationException, FileDescriptorUtils.ParseSchemaException
      Parse a proto file with its dependencies to produce a Descriptors.FileDescriptor of it, trying to resolve any transitive dependency.
      Both the dependencies and the main proto file must be provided as FileDescriptorUtils.ProtobufSchemaContent, still unparsed, and which FileDescriptorUtils.ProtobufSchemaContent.fileName() doesn't require to specify the package name, automatically later resolved by parsing FileDescriptorUtils.ProtobufSchemaContent.schemaDefinition().
      During the resolution of dependencies process, depending on failFast, the process will fail as soon as any parsing error happen in the list of provided dependencies, regardless been required or not, or it will proceed until a required dependency cannot be resolved.
      If requiredSchemaDeps is provided, it will be populated with the required dependencies, which keys are in the form of packageName/fileName and the value is the schema definition of the dependency.
      Throws:
      com.google.protobuf.Descriptors.DescriptorValidationException
      FileDescriptorUtils.ParseSchemaException
    • extractProtoFileName

      public static String extractProtoFileName(String protoFullName)
      Extract the proto file name out of a full proto file name, which is in the form of packageName/fileName.
    • toFileDescriptorProto

      public static com.google.protobuf.DescriptorProtos.FileDescriptorProto toFileDescriptorProto(String schemaDefinition, String protoFileName, Optional<String> optionalPackageName, Map<String,String> deps)
    • fileDescriptorWithDepsToProtoFile

      public static com.squareup.wire.schema.internal.parser.ProtoFileElement fileDescriptorWithDepsToProtoFile(com.google.protobuf.Descriptors.FileDescriptor file, Map<String,com.squareup.wire.schema.internal.parser.ProtoFileElement> dependencies)
    • fileDescriptorToProtoFile

      public static com.squareup.wire.schema.internal.parser.ProtoFileElement fileDescriptorToProtoFile(com.google.protobuf.DescriptorProtos.FileDescriptorProto file)
    • toDescriptor

      public static com.google.protobuf.Descriptors.Descriptor toDescriptor(String name, com.squareup.wire.schema.internal.parser.ProtoFileElement protoFileElement, Map<String,com.squareup.wire.schema.internal.parser.ProtoFileElement> dependencies)
    • firstMessage

      public static com.squareup.wire.schema.internal.parser.MessageElement firstMessage(com.squareup.wire.schema.internal.parser.ProtoFileElement fileElement)
    • findOption

      public static Optional<com.squareup.wire.schema.internal.parser.OptionElement> findOption(String name, List<com.squareup.wire.schema.internal.parser.OptionElement> options)
    • toMapField

      public static String toMapField(String s)