Search in sources :

Example 1 with DocumentToProtoConverter

use of com.google.cloud.discotoproto3converter.proto3.DocumentToProtoConverter in project disco-to-proto3-converter by googleapis.

the class ConverterApp method convert.

public void convert(String discoveryDocPath, String previousProtoPath, String outputFilePath, String serviceIgnorelist, String messageIgnorelist, String relativeLinkPrefix, String enumsAsStrings, String outputComments) throws IOException {
    ProtoFile newProtoFile = null;
    if (discoveryDocPath != null) {
        Document document = createDocument(discoveryDocPath);
        DocumentToProtoConverter converter = new DocumentToProtoConverter(document, Paths.get(discoveryDocPath).getFileName().toString(), new HashSet<>(Arrays.asList(serviceIgnorelist.split(","))), new HashSet<>(Arrays.asList(messageIgnorelist.split(","))), relativeLinkPrefix, Boolean.valueOf(enumsAsStrings));
        newProtoFile = converter.getProtoFile();
    }
    ProtoFile previousProtoFile = null;
    if (previousProtoPath != null) {
        ProtoParser parser = new ProtoParser(readProtoFile(previousProtoPath));
        previousProtoFile = new ProtoParser(readProtoFile(previousProtoPath)).getProtoFile();
    }
    if (newProtoFile != null) {
        ProtoFile mergedProtoFile = newProtoFile;
        if (previousProtoFile != null) {
        // TODO: merge previousProtoFile and newProtoFile and assign to mergedProtoFile
        }
        try (PrintWriter pw = makeDefaultDirsAndWriter(outputFilePath)) {
            writer.writeToFile(pw, mergedProtoFile, Boolean.valueOf(outputComments));
        }
    } else if (previousProtoFile != null) {
        try (PrintWriter pw = makeDefaultDirsAndWriter(outputFilePath)) {
            writer.writeToFile(pw, previousProtoFile, Boolean.valueOf(outputComments));
        }
    }
}
Also used : ProtoParser(com.google.cloud.discotoproto3converter.proto3.ProtoParser) ProtoFile(com.google.cloud.discotoproto3converter.proto3.ProtoFile) DocumentToProtoConverter(com.google.cloud.discotoproto3converter.proto3.DocumentToProtoConverter) Document(com.google.cloud.discotoproto3converter.disco.Document) PrintWriter(java.io.PrintWriter)

Aggregations

Document (com.google.cloud.discotoproto3converter.disco.Document)1 DocumentToProtoConverter (com.google.cloud.discotoproto3converter.proto3.DocumentToProtoConverter)1 ProtoFile (com.google.cloud.discotoproto3converter.proto3.ProtoFile)1 ProtoParser (com.google.cloud.discotoproto3converter.proto3.ProtoParser)1 PrintWriter (java.io.PrintWriter)1