Search in sources :

Example 1 with Diag

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

the class GrpcMetadataGenerator method process.

@Override
protected void process() throws Exception {
    model.establishStage(Merged.KEY);
    if (model.getDiagCollector().getErrorCount() > 0) {
        for (Diag diag : model.getDiagCollector().getDiags()) {
            System.err.println(diag.toString());
        }
        return;
    }
    Map<String, Doc> docs = generate(model);
    ToolUtil.writeFiles(docs, options.get(OUTPUT_DIR));
}
Also used : Doc(com.google.api.tools.framework.snippet.Doc) Diag(com.google.api.tools.framework.model.Diag)

Example 2 with Diag

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

the class FieldConfig method createFieldConfig.

/**
 * Package-private since this is not used outside the config package.
 */
static FieldConfig createFieldConfig(DiagCollector diagCollector, ResourceNameMessageConfigs messageConfigs, Map<String, String> fieldNamePatterns, Map<String, ResourceNameConfig> resourceNameConfigs, FieldModel field, ResourceNameTreatment treatment, ResourceNameTreatment defaultResourceNameTreatment) {
    String messageFieldEntityName = null;
    String flattenedFieldEntityName = null;
    if (messageConfigs != null && messageConfigs.fieldHasResourceName(field)) {
        messageFieldEntityName = messageConfigs.getFieldResourceName(field);
    }
    if (fieldNamePatterns != null) {
        flattenedFieldEntityName = fieldNamePatterns.get(field.getNameAsParameter());
    }
    if (flattenedFieldEntityName == null) {
        flattenedFieldEntityName = messageFieldEntityName;
    }
    if (treatment == null || treatment.equals(ResourceNameTreatment.UNSET_TREATMENT)) {
        // the method-level default and the specified entities.
        if (flattenedFieldEntityName == null) {
            treatment = ResourceNameTreatment.NONE;
        } else {
            treatment = defaultResourceNameTreatment;
        }
    }
    ResourceNameConfig messageFieldResourceNameConfig = getResourceNameConfig(diagCollector, resourceNameConfigs, messageFieldEntityName);
    ResourceNameConfig flattenedFieldResourceNameConfig = getResourceNameConfig(diagCollector, resourceNameConfigs, flattenedFieldEntityName);
    if (messageFieldResourceNameConfig != null && !messageFieldResourceNameConfig.equals(flattenedFieldResourceNameConfig)) {
        // We support the case of the flattenedField using a specific resource name type when the
        // messageField uses a oneof containing that type, or when the messageField accepts any
        // resource name, or for Discovery fields.
        ResourceNameType resourceTypeName = messageFieldResourceNameConfig.getResourceNameType();
        boolean ok = resourceTypeName == ResourceNameType.ANY;
        if (resourceTypeName == ResourceNameType.ONEOF) {
            ResourceNameOneofConfig oneofConfig = (ResourceNameOneofConfig) messageFieldResourceNameConfig;
            ok = oneofConfig.getResourceNameConfigs().contains(flattenedFieldResourceNameConfig);
        }
        if (!ok) {
            Diag error = Diag.error(SimpleLocation.TOPLEVEL, "Multiple entity names specified for field: " + field.getFullName() + ": [" + flattenedFieldEntityName + ", " + messageFieldEntityName + "]");
            if (diagCollector == null) {
                throw new IllegalArgumentException(error.toString());
            }
            diagCollector.addDiag(error);
            return null;
        }
    }
    validate(messageConfigs, field, treatment, flattenedFieldResourceNameConfig);
    return createFieldConfig(field, treatment, flattenedFieldResourceNameConfig, messageFieldResourceNameConfig);
}
Also used : Diag(com.google.api.tools.framework.model.Diag)

Example 3 with Diag

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

the class FieldConfig method getResourceNameConfig.

private static ResourceNameConfig getResourceNameConfig(DiagCollector diagCollector, Map<String, ResourceNameConfig> resourceNameConfigs, String entityName) {
    if (entityName != null) {
        if (entityName.equals(AnyResourceNameConfig.GAPIC_CONFIG_ANY_VALUE)) {
            return AnyResourceNameConfig.instance();
        } else {
            ResourceNameConfig flattenedFieldResourceNameConfig = resourceNameConfigs.get(entityName);
            if (flattenedFieldResourceNameConfig == null) {
                Diag error = Diag.error(SimpleLocation.TOPLEVEL, "No resourceNameConfig with entity_name \"%s\"", entityName);
                if (diagCollector == null) {
                    throw new IllegalArgumentException(error.toString());
                }
                diagCollector.addDiag(error);
                return null;
            }
            return flattenedFieldResourceNameConfig;
        }
    }
    return null;
}
Also used : Diag(com.google.api.tools.framework.model.Diag)

Example 4 with Diag

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

the class GapicTestBase2 method setupModel.

@Override
protected void setupModel() {
    super.setupModel();
    gapicConfig = CodegenTestUtil.readConfig(model.getDiagCollector(), getTestDataLocator(), gapicConfigFileNames);
    if (!Strings.isNullOrEmpty(packageConfigFileName)) {
        try {
            URI packageConfigUrl = getTestDataLocator().findTestData(packageConfigFileName).toURI();
            String contents = new String(Files.readAllBytes(Paths.get(packageConfigUrl)), StandardCharsets.UTF_8);
            packageConfig = PackageMetadataConfig.createFromString(contents);
        } catch (IOException | URISyntaxException e) {
            throw new IllegalArgumentException("Problem creating packageConfig");
        }
    }
    // TODO (garrettjones) depend on the framework to take care of this.
    if (model.getDiagCollector().getErrorCount() > 0) {
        for (Diag diag : model.getDiagCollector().getDiags()) {
            System.err.println(diag.toString());
        }
        throw new IllegalArgumentException("Problem creating Generator");
    }
}
Also used : IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) Diag(com.google.api.tools.framework.model.Diag) URI(java.net.URI)

Example 5 with Diag

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

the class ConfigGeneratorApi method process.

@Override
protected void process() throws Exception {
    model.establishStage(Merged.KEY);
    if (model.getDiagCollector().getErrorCount() > 0) {
        for (Diag diag : model.getDiagCollector().getDiags()) {
            System.err.println(diag.toString());
        }
        return;
    }
    String outputPath = options.get(OUTPUT_FILE);
    Map<String, String> outputFiles = generateConfig(outputPath);
    ToolUtil.writeFiles(outputFiles, "");
}
Also used : Diag(com.google.api.tools.framework.model.Diag)

Aggregations

Diag (com.google.api.tools.framework.model.Diag)8 Doc (com.google.api.tools.framework.snippet.Doc)3 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)2 GapicGeneratorConfig (com.google.api.codegen.gapic.GapicGeneratorConfig)2 GapicProvider (com.google.api.codegen.gapic.GapicProvider)2 ConfigProto (com.google.api.codegen.ConfigProto)1 Adviser (com.google.api.codegen.advising.Adviser)1 PackageMetadataConfig (com.google.api.codegen.config.PackageMetadataConfig)1 ConfigSource (com.google.api.tools.framework.model.ConfigSource)1 TestDataLocator (com.google.api.tools.framework.model.testing.TestDataLocator)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 Test (org.junit.Test)1