Search in sources :

Example 1 with ConfigSource

use of com.google.api.tools.framework.model.ConfigSource in project toolkit by googleapis.

the class CodeGeneratorApi method process.

@Override
protected void process() throws Exception {
    // Read the YAML config and convert it to proto.
    List<String> configFileNames = options.get(GENERATOR_CONFIG_FILES);
    if (configFileNames.size() == 0) {
        error(String.format("--%s must be provided", GENERATOR_CONFIG_FILES.name()));
        return;
    }
    ConfigSource configSource = loadConfigFromFiles(configFileNames);
    if (configSource == null) {
        return;
    }
    ConfigProto configProto = (ConfigProto) configSource.getConfig();
    if (configProto == null) {
        return;
    }
    model.establishStage(Merged.KEY);
    List<String> adviceSuppressors = options.get(ADVICE_SUPPRESSORS);
    Adviser adviser = new Adviser(adviceSuppressors);
    adviser.advise(model, configProto);
    if (model.getDiagCollector().getErrorCount() > 0) {
        for (Diag diag : model.getDiagCollector().getDiags()) {
            System.err.println(diag.toString());
        }
        return;
    }
    PackageMetadataConfig packageConfig = null;
    if (!Strings.isNullOrEmpty(options.get(PACKAGE_CONFIG_FILE))) {
        String contents = new String(Files.readAllBytes(Paths.get(options.get(PACKAGE_CONFIG_FILE))), StandardCharsets.UTF_8);
        packageConfig = PackageMetadataConfig.createFromString(contents);
    }
    GeneratorProto generator = configProto.getGenerator();
    GapicProductConfig productConfig = GapicProductConfig.create(model, configProto);
    if (productConfig == null) {
        return;
    }
    if (generator != null) {
        String factory = generator.getFactory();
        String id = generator.getId();
        GapicProviderFactory<GapicProvider> providerFactory = createProviderFactory(model, factory);
        GapicGeneratorConfig generatorConfig = GapicGeneratorConfig.newBuilder().id(id).enabledArtifacts(options.get(ENABLED_ARTIFACTS)).build();
        String outputPath = options.get(OUTPUT_FILE);
        List<GapicProvider> providers = providerFactory.create(model, productConfig, generatorConfig, packageConfig);
        Map<String, Doc> outputFiles = Maps.newHashMap();
        for (GapicProvider provider : providers) {
            outputFiles.putAll(provider.generate());
        }
        writeCodeGenOutput(outputFiles, outputPath);
    }
}
Also used : GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) Adviser(com.google.api.codegen.advising.Adviser) GapicProvider(com.google.api.codegen.gapic.GapicProvider) Diag(com.google.api.tools.framework.model.Diag) ConfigSource(com.google.api.tools.framework.model.ConfigSource) GapicGeneratorConfig(com.google.api.codegen.gapic.GapicGeneratorConfig) PackageMetadataConfig(com.google.api.codegen.config.PackageMetadataConfig) Doc(com.google.api.tools.framework.snippet.Doc)

Example 2 with ConfigSource

use of com.google.api.tools.framework.model.ConfigSource in project toolkit by googleapis.

the class MultiYamlReader method read.

@Nullable
public static ConfigSource read(DiagCollector collector, List<String> inputNames, List<String> inputs, Map<String, Message> supportedConfigTypes) {
    Preconditions.checkArgument(inputNames.size() == inputs.size(), "size() of inputNames and inputs not equal: %d != %d", inputNames.size(), inputs.size());
    ConfigSource.Builder sourceBuilder = null;
    for (int i = 0; i < inputs.size(); i++) {
        String inputName = inputNames.get(i);
        String input = inputs.get(i);
        ConfigSource source = YamlReader.readConfig(collector, inputName, input, supportedConfigTypes);
        if (source != null) {
            if (sourceBuilder == null) {
                sourceBuilder = source.toBuilder();
            } else {
                sourceBuilder.mergeFrom(source);
            }
        }
    }
    if (sourceBuilder == null) {
        return null;
    } else {
        return sourceBuilder.build();
    }
}
Also used : ConfigSource(com.google.api.tools.framework.model.ConfigSource) Nullable(javax.annotation.Nullable)

Aggregations

ConfigSource (com.google.api.tools.framework.model.ConfigSource)2 Adviser (com.google.api.codegen.advising.Adviser)1 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)1 PackageMetadataConfig (com.google.api.codegen.config.PackageMetadataConfig)1 GapicGeneratorConfig (com.google.api.codegen.gapic.GapicGeneratorConfig)1 GapicProvider (com.google.api.codegen.gapic.GapicProvider)1 Diag (com.google.api.tools.framework.model.Diag)1 Doc (com.google.api.tools.framework.snippet.Doc)1 Nullable (javax.annotation.Nullable)1