Search in sources :

Example 1 with MessageGenerator

use of com.google.api.codegen.configgen.MessageGenerator in project toolkit by googleapis.

the class CodegenTestUtil method readConfig.

public static ConfigProto readConfig(DiagCollector diagCollector, TestDataLocator testDataLocator, String[] gapicConfigFileNames) {
    ConfigYamlReader yamlReader = new ConfigYamlReader();
    MessageGenerator messageGenerator = new MessageGenerator(ConfigProto.newBuilder());
    for (String gapicConfigFileName : gapicConfigFileNames) {
        URL gapicConfigUrl = testDataLocator.findTestData(gapicConfigFileName);
        File gapicConfigFile = null;
        try {
            gapicConfigFile = new File(gapicConfigUrl.toURI());
        } catch (URISyntaxException e) {
            continue;
        }
        ConfigHelper helper = new ConfigHelper(diagCollector, gapicConfigFile.getName());
        ConfigNode configNode = yamlReader.generateConfigNode(gapicConfigFile, helper);
        if (configNode == null) {
            continue;
        }
        messageGenerator.visit(configNode.getChild());
    }
    if (diagCollector.getErrorCount() > 0) {
        System.err.println(diagCollector.toString());
        return null;
    }
    return (ConfigProto) messageGenerator.getValue();
}
Also used : MessageGenerator(com.google.api.codegen.configgen.MessageGenerator) ConfigHelper(com.google.api.codegen.configgen.ConfigHelper) URISyntaxException(java.net.URISyntaxException) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) File(java.io.File) URL(java.net.URL) ConfigYamlReader(com.google.api.codegen.configgen.ConfigYamlReader)

Example 2 with MessageGenerator

use of com.google.api.codegen.configgen.MessageGenerator in project toolkit by googleapis.

the class DiscoGapicGeneratorApi method loadConfigFromFiles.

private static ConfigProto loadConfigFromFiles(List<String> configFileNames) {
    DiagCollector diagCollector = new SimpleDiagCollector();
    ConfigYamlReader yamlReader = new ConfigYamlReader();
    MessageGenerator messageGenerator = new MessageGenerator(ConfigProto.newBuilder());
    for (File file : pathsToFiles(configFileNames)) {
        ConfigHelper helper = new ConfigHelper(diagCollector, file.getName());
        ConfigNode configNode = yamlReader.generateConfigNode(file, helper);
        if (configNode == null) {
            continue;
        }
        messageGenerator.visit(configNode.getChild());
    }
    ConfigProto configProto = (ConfigProto) messageGenerator.getValue();
    if (configProto == null || configProto.equals(ConfigProto.getDefaultInstance())) {
        return null;
    }
    return configProto;
}
Also used : MessageGenerator(com.google.api.codegen.configgen.MessageGenerator) SimpleDiagCollector(com.google.api.tools.framework.model.SimpleDiagCollector) DiagCollector(com.google.api.tools.framework.model.DiagCollector) ConfigHelper(com.google.api.codegen.configgen.ConfigHelper) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) File(java.io.File) SimpleDiagCollector(com.google.api.tools.framework.model.SimpleDiagCollector) ConfigYamlReader(com.google.api.codegen.configgen.ConfigYamlReader)

Aggregations

ConfigHelper (com.google.api.codegen.configgen.ConfigHelper)2 ConfigYamlReader (com.google.api.codegen.configgen.ConfigYamlReader)2 MessageGenerator (com.google.api.codegen.configgen.MessageGenerator)2 ConfigNode (com.google.api.codegen.configgen.nodes.ConfigNode)2 File (java.io.File)2 DiagCollector (com.google.api.tools.framework.model.DiagCollector)1 SimpleDiagCollector (com.google.api.tools.framework.model.SimpleDiagCollector)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1