Search in sources :

Example 1 with LicenseHeaderProto

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

the class GapicProductConfig method create.

public static GapicProductConfig create(DiscoApiModel model, ConfigProto configProto, SurfaceNamer namer) {
    String defaultPackage = configProto.getLanguageSettingsMap().get(configProto.getLanguage()).getPackageName();
    ResourceNameMessageConfigs messageConfigs = ResourceNameMessageConfigs.createMessageResourceTypesConfig(model, configProto, defaultPackage, namer);
    ImmutableMap<String, ResourceNameConfig> resourceNameConfigs = createResourceNameConfigs(model.getDiagCollector(), configProto, null);
    TransportProtocol transportProtocol = TransportProtocol.HTTP;
    LanguageSettingsProto settings = configProto.getLanguageSettingsMap().get(configProto.getLanguage());
    if (settings == null) {
        settings = LanguageSettingsProto.getDefaultInstance();
    }
    ImmutableMap<String, InterfaceConfig> interfaceConfigMap = createDiscoGapicInterfaceConfigMap(model, configProto, settings, messageConfigs, resourceNameConfigs);
    ImmutableList<String> copyrightLines;
    ImmutableList<String> licenseLines;
    try {
        LicenseHeaderProto licenseHeader = configProto.getLicenseHeader().toBuilder().mergeFrom(settings.getLicenseHeaderOverride()).build();
        copyrightLines = getResourceLines(licenseHeader.getCopyrightFile());
        licenseLines = getResourceLines(licenseHeader.getLicenseFile());
    } catch (Exception e) {
        model.getDiagCollector().addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Exception: %s", e.getMessage()));
        e.printStackTrace(System.err);
        throw new RuntimeException(e);
    }
    String configSchemaVersion = configProto.getConfigSchemaVersion();
    // TODO(eoogbe): Move the validation logic to GAPIC config advisor.
    if (Strings.isNullOrEmpty(configSchemaVersion)) {
        model.getDiagCollector().addDiag(Diag.error(SimpleLocation.TOPLEVEL, "config_schema_version field is required in GAPIC yaml."));
    }
    return new AutoValue_GapicProductConfig(interfaceConfigMap, settings.getPackageName(), settings.getDomainLayerLocation(), settings.getReleaseLevel(), messageConfigs, copyrightLines, licenseLines, resourceNameConfigs, transportProtocol, createResponseFieldConfigMap(messageConfigs, resourceNameConfigs), configSchemaVersion);
}
Also used : LicenseHeaderProto(com.google.api.codegen.LicenseHeaderProto) IOException(java.io.IOException) LanguageSettingsProto(com.google.api.codegen.LanguageSettingsProto)

Example 2 with LicenseHeaderProto

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

the class GapicProductConfig method create.

/**
 * Creates an instance of GapicProductConfig based on ConfigProto, linking up API interface
 * configurations with specified interfaces in interfaceConfigMap. On errors, null will be
 * returned, and diagnostics are reported to the model.
 */
@Nullable
public static GapicProductConfig create(Model model, ConfigProto configProto) {
    // Get the proto file containing the first interface listed in the config proto, and use it as
    // the assigned file for generated resource names, and to get the default message namespace
    ProtoFile file = model.getSymbolTable().lookupInterface(configProto.getInterfaces(0).getName()).getFile();
    String defaultPackage = file.getProto().getPackage();
    ResourceNameMessageConfigs messageConfigs = ResourceNameMessageConfigs.createMessageResourceTypesConfig(model, configProto, defaultPackage);
    ImmutableMap<String, ResourceNameConfig> resourceNameConfigs = createResourceNameConfigs(model.getDiagCollector(), configProto, file);
    TransportProtocol transportProtocol = TransportProtocol.GRPC;
    LanguageSettingsProto settings = configProto.getLanguageSettings().get(configProto.getLanguage());
    if (settings == null) {
        settings = LanguageSettingsProto.getDefaultInstance();
    }
    ImmutableMap<String, InterfaceConfig> interfaceConfigMap = createInterfaceConfigMap(model.getDiagCollector(), configProto, settings, messageConfigs, resourceNameConfigs, model.getSymbolTable());
    ImmutableList<String> copyrightLines = null;
    ImmutableList<String> licenseLines = null;
    try {
        LicenseHeaderProto licenseHeader = configProto.getLicenseHeader().toBuilder().mergeFrom(settings.getLicenseHeaderOverride()).build();
        copyrightLines = loadCopyrightLines(model.getDiagCollector(), licenseHeader);
        licenseLines = loadLicenseLines(model.getDiagCollector(), licenseHeader);
    } catch (Exception e) {
        model.getDiagCollector().addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Exception: %s", e.getMessage()));
        e.printStackTrace(System.err);
        throw new RuntimeException(e);
    }
    String configSchemaVersion = configProto.getConfigSchemaVersion();
    // TODO(eoogbe): Move the validation logic to GAPIC config advisor.
    if (Strings.isNullOrEmpty(configSchemaVersion)) {
        model.getDiagCollector().addDiag(Diag.error(SimpleLocation.TOPLEVEL, "config_schema_version field is required in GAPIC yaml."));
    }
    if (interfaceConfigMap == null || copyrightLines == null || licenseLines == null) {
        return null;
    }
    return new AutoValue_GapicProductConfig(interfaceConfigMap, settings.getPackageName(), settings.getDomainLayerLocation(), settings.getReleaseLevel(), messageConfigs, copyrightLines, licenseLines, resourceNameConfigs, transportProtocol, createResponseFieldConfigMap(messageConfigs, resourceNameConfigs), configSchemaVersion);
}
Also used : LicenseHeaderProto(com.google.api.codegen.LicenseHeaderProto) ProtoFile(com.google.api.tools.framework.model.ProtoFile) IOException(java.io.IOException) LanguageSettingsProto(com.google.api.codegen.LanguageSettingsProto) Nullable(javax.annotation.Nullable)

Aggregations

LanguageSettingsProto (com.google.api.codegen.LanguageSettingsProto)2 LicenseHeaderProto (com.google.api.codegen.LicenseHeaderProto)2 IOException (java.io.IOException)2 ProtoFile (com.google.api.tools.framework.model.ProtoFile)1 Nullable (javax.annotation.Nullable)1