Search in sources :

Example 6 with FileDescriptorProto

use of com.google.protobuf.DescriptorProtos.FileDescriptorProto in project dubbo by alibaba.

the class AbstractGenerator method generateFiles.

@Override
public List<PluginProtos.CodeGeneratorResponse.File> generateFiles(PluginProtos.CodeGeneratorRequest request) throws GeneratorException {
    final ProtoTypeMap typeMap = ProtoTypeMap.of(request.getProtoFileList());
    List<FileDescriptorProto> protosToGenerate = request.getProtoFileList().stream().filter(protoFile -> request.getFileToGenerateList().contains(protoFile.getName())).collect(Collectors.toList());
    List<ServiceContext> services = findServices(protosToGenerate, typeMap);
    return generateFiles(services);
}
Also used : Arrays(java.util.Arrays) ServiceDescriptorProto(com.google.protobuf.DescriptorProtos.ServiceDescriptorProto) Set(java.util.Set) HtmlEscapers(com.google.common.html.HtmlEscapers) Generator(com.salesforce.jprotoc.Generator) Collectors(java.util.stream.Collectors) Location(com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location) PluginProtos(com.google.protobuf.compiler.PluginProtos) ProtoTypeMap(com.salesforce.jprotoc.ProtoTypeMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) List(java.util.List) GeneratorException(com.salesforce.jprotoc.GeneratorException) FileDescriptorProto(com.google.protobuf.DescriptorProtos.FileDescriptorProto) MethodDescriptorProto(com.google.protobuf.DescriptorProtos.MethodDescriptorProto) FileOptions(com.google.protobuf.DescriptorProtos.FileOptions) ProtoTypeMap(com.salesforce.jprotoc.ProtoTypeMap) FileDescriptorProto(com.google.protobuf.DescriptorProtos.FileDescriptorProto)

Example 7 with FileDescriptorProto

use of com.google.protobuf.DescriptorProtos.FileDescriptorProto in project atlasdb by palantir.

the class ColumnValueDescription method hydrateFileDescriptorTree.

private static FileDescriptor hydrateFileDescriptorTree(FileDescriptorTreeProto proto) throws DescriptorValidationException, InvalidProtocolBufferException {
    FileDescriptor[] dependencies = new FileDescriptor[proto.getDependenciesCount()];
    for (int i = 0; i < proto.getDependenciesCount(); i++) {
        dependencies[i] = hydrateFileDescriptorTree(proto.getDependencies(i));
    }
    FileDescriptorProto fileProto = FileDescriptorProto.parseFrom(proto.getProtoFileDescriptor());
    return FileDescriptor.buildFrom(fileProto, dependencies);
}
Also used : FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) FileDescriptorProto(com.google.protobuf.DescriptorProtos.FileDescriptorProto)

Example 8 with FileDescriptorProto

use of com.google.protobuf.DescriptorProtos.FileDescriptorProto in project toolkit by googleapis.

the class ProtocGeneratorMain method parseOptions.

private static ToolOptions parseOptions(CodeGeneratorRequest request) throws Exception {
    List<FileDescriptorProto> fileDescriptorProtoList = request.getProtoFileList();
    FileDescriptorSet descriptorSet = FileDescriptorSet.newBuilder().addAllFile(fileDescriptorProtoList).build();
    // Write out DescriptorSet to temp file.
    File descriptorSetFile;
    descriptorSetFile = File.createTempFile("api", ".desc");
    FileOutputStream fileoutput = new FileOutputStream(descriptorSetFile);
    descriptorSet.writeTo(fileoutput);
    fileoutput.close();
    descriptorSetFile.deleteOnExit();
    List<String> parsedArgs = new LinkedList<>();
    parsedArgs.add("--descriptor_set");
    parsedArgs.add(descriptorSetFile.getAbsolutePath());
    List<String> protoPackages = getProtoPackageList(request);
    if (protoPackages.size() > 1) {
        // can be changed when the use case arises.
        throw new IllegalStateException(String.format("Not expecting more than one proto package." + " Found proto packages for generation: %s", protoPackages.toString()));
    } else if (protoPackages.size() == 0) {
        throw new IllegalStateException("No proto files given to generate.");
    }
    parsedArgs.add("--package");
    parsedArgs.add(protoPackages.get(0));
    // Parse plugin params, ignoring unknown params.
    String[] requestArgs = request.getParameter().split(",");
    for (String arg : requestArgs) {
        if (Strings.isNullOrEmpty(arg))
            continue;
        parsedArgs.add("--" + arg);
    }
    String[] argsArray = parsedArgs.toArray(new String[] {});
    return GeneratorMain.createCodeGeneratorOptionsFromProtoc(argsArray);
}
Also used : FileDescriptorSet(com.google.protobuf.DescriptorProtos.FileDescriptorSet) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileDescriptorProto(com.google.protobuf.DescriptorProtos.FileDescriptorProto) LinkedList(java.util.LinkedList)

Example 9 with FileDescriptorProto

use of com.google.protobuf.DescriptorProtos.FileDescriptorProto in project BIMserver by opensourceBIM.

the class ProtocolBuffersMetaData method load.

public void load(InputStream inputStream) {
    try {
        FileDescriptorSet descriptorSet = FileDescriptorSet.parseFrom(inputStream);
        List<FileDescriptorProto> fileList = descriptorSet.getFileList();
        FileDescriptorProto fileDescriptorProto = fileList.get(0);
        FileDescriptor[] dependencyDescriptors = getDependencyDescriptors(fileDescriptorProto);
        FileDescriptor fileDescriptor = FileDescriptor.buildFrom(fileDescriptorProto, dependencyDescriptors);
        loaded.put(fileDescriptor.getName(), fileDescriptor);
        fileDescriptor.getMessageTypes().forEach(descriptor -> this.messageDescriptors.put(descriptor.getName(), new MessageDescriptorContainer(descriptor)));
        fileDescriptor.getServices().forEach(serviceDescriptor -> this.serviceDescriptors.put(serviceDescriptor.getName(), new ServiceDescriptorContainer(serviceDescriptor)));
    } catch (IOException e) {
        LOGGER.error("", e);
    } catch (DescriptorValidationException e) {
        LOGGER.error("", e);
    } finally {
        try {
            inputStream.close();
        } catch (IOException e) {
            LOGGER.error("", e);
        }
    }
}
Also used : FileDescriptorSet(com.google.protobuf.DescriptorProtos.FileDescriptorSet) DescriptorValidationException(com.google.protobuf.Descriptors.DescriptorValidationException) IOException(java.io.IOException) FileDescriptorProto(com.google.protobuf.DescriptorProtos.FileDescriptorProto) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor)

Aggregations

FileDescriptorProto (com.google.protobuf.DescriptorProtos.FileDescriptorProto)9 FileDescriptor (com.google.protobuf.Descriptors.FileDescriptor)7 DescriptorValidationException (com.google.protobuf.Descriptors.DescriptorValidationException)3 ImmutableList (com.google.common.collect.ImmutableList)2 DescriptorProto (com.google.protobuf.DescriptorProtos.DescriptorProto)2 FieldDescriptorProto (com.google.protobuf.DescriptorProtos.FieldDescriptorProto)2 FileDescriptorSet (com.google.protobuf.DescriptorProtos.FileDescriptorSet)2 IOException (java.io.IOException)2 Strings (com.google.common.base.Strings)1 HtmlEscapers (com.google.common.html.HtmlEscapers)1 FileOptions (com.google.protobuf.DescriptorProtos.FileOptions)1 MethodDescriptorProto (com.google.protobuf.DescriptorProtos.MethodDescriptorProto)1 ServiceDescriptorProto (com.google.protobuf.DescriptorProtos.ServiceDescriptorProto)1 Location (com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location)1 Descriptor (com.google.protobuf.Descriptors.Descriptor)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 PluginProtos (com.google.protobuf.compiler.PluginProtos)1 JsonFormat (com.googlecode.protobuf.format.JsonFormat)1 ParseException (com.googlecode.protobuf.format.JsonFormat.ParseException)1 Generator (com.salesforce.jprotoc.Generator)1