Search in sources :

Example 6 with ProtoFile

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

the class PythonImportSectionTransformer method generateTypesProtoImports.

private List<ImportFileView> generateTypesProtoImports(Model model, GapicProductConfig productConfig) {
    ModelTypeTable typeTable = emptyTypeTable(productConfig);
    Set<ImportFileView> imports = new TreeSet<>(importFileViewComparator());
    // Save proto file import names to the type table for disambiguation.
    List<ProtoFile> protoFileDependencies = model.getFiles();
    populateTypeTable(protoFileDependencies, typeTable);
    // Get disambiguated imports.
    for (Map.Entry<String, TypeAlias> entry : typeTable.getImports().entrySet()) {
        imports.add(generateAppImport(entry.getKey(), entry.getValue().getNickname()));
    }
    return ImmutableList.<ImportFileView>builder().addAll(imports).build();
}
Also used : ImportFileView(com.google.api.codegen.viewmodel.ImportFileView) TreeSet(java.util.TreeSet) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) ProtoFile(com.google.api.tools.framework.model.ProtoFile) TypeAlias(com.google.api.codegen.util.TypeAlias) Map(java.util.Map)

Example 7 with ProtoFile

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

the class ProtoFileView method protoFiles.

private Set<ProtoFile> protoFiles(Field field) {
    Set<ProtoFile> fields = new HashSet<ProtoFile>();
    if (field.getType().getKind() != Type.TYPE_MESSAGE) {
        return fields;
    }
    MessageType messageType = field.getType().getMessageType();
    fields.add(messageType.getFile());
    for (Field f : messageType.getNonCyclicFields()) {
        fields.addAll(protoFiles(f));
    }
    return fields;
}
Also used : Field(com.google.api.tools.framework.model.Field) ProtoFile(com.google.api.tools.framework.model.ProtoFile) MessageType(com.google.api.tools.framework.model.MessageType) HashSet(java.util.HashSet)

Example 8 with ProtoFile

use of com.google.api.tools.framework.model.ProtoFile 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

ProtoFile (com.google.api.tools.framework.model.ProtoFile)8 MessageType (com.google.api.tools.framework.model.MessageType)3 ProtoFileView (com.google.api.codegen.ProtoFileView)2 ViewModel (com.google.api.codegen.viewmodel.ViewModel)2 Field (com.google.api.tools.framework.model.Field)2 ProtoElement (com.google.api.tools.framework.model.ProtoElement)2 ImmutableList (com.google.common.collect.ImmutableList)2 HashSet (java.util.HashSet)2 Nullable (javax.annotation.Nullable)2 LanguageSettingsProto (com.google.api.codegen.LanguageSettingsProto)1 LicenseHeaderProto (com.google.api.codegen.LicenseHeaderProto)1 ResourceNameMessageConfigProto (com.google.api.codegen.ResourceNameMessageConfigProto)1 ApiModel (com.google.api.codegen.config.ApiModel)1 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)1 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)1 TypeAlias (com.google.api.codegen.util.TypeAlias)1 TypeName (com.google.api.codegen.util.TypeName)1 ImportFileView (com.google.api.codegen.viewmodel.ImportFileView)1 Model (com.google.api.tools.framework.model.Model)1 ImmutableMap (com.google.common.collect.ImmutableMap)1