Search in sources :

Example 1 with PackageDependencyView

use of com.google.api.codegen.viewmodel.metadata.PackageDependencyView in project toolkit by googleapis.

the class PackageMetadataTransformer method getDependencies.

private List<PackageDependencyView> getDependencies(PackageMetadataNamer namer, Map<String, VersionBound> dependencies, Set<String> whitelistedDependencies) {
    List<PackageDependencyView> protoPackageDependencies = new ArrayList<>();
    if (dependencies != null) {
        Map<String, VersionBound> dependenciesCopy = new HashMap<>(dependencies);
        if (whitelistedDependencies != null) {
            dependenciesCopy.keySet().retainAll(whitelistedDependencies);
        }
        for (Map.Entry<String, VersionBound> entry : dependenciesCopy.entrySet()) {
            PackageDependencyView packageDependency = PackageDependencyView.newBuilder().group(namer.getProtoPackageGroup()).name(entry.getKey()).versionBound(entry.getValue()).build();
            protoPackageDependencies.add(packageDependency);
        }
        // Ensures deterministic test results.
        Collections.sort(protoPackageDependencies);
    }
    return protoPackageDependencies;
}
Also used : VersionBound(com.google.api.codegen.config.VersionBound) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) PackageDependencyView(com.google.api.codegen.viewmodel.metadata.PackageDependencyView)

Example 2 with PackageDependencyView

use of com.google.api.codegen.viewmodel.metadata.PackageDependencyView in project toolkit by googleapis.

the class JavaPackageMetadataTransformer method generateMetadataViewBuilders.

/**
 * Creates a partially initialized builders that can be used to build PackageMetadataViews later.
 */
protected final List<PackageMetadataView.Builder> generateMetadataViewBuilders(ApiModel model, PackageMetadataConfig config, ArtifactType artifactType) {
    JavaPackageMetadataNamer namer = new JavaPackageMetadataNamer(config.packageName(TargetLanguage.JAVA), artifactType);
    List<PackageDependencyView> additionalDependencies = new ArrayList<>();
    if (!SERVICES_WITH_NO_RESOURCE_NAMES.contains(config.shortName())) {
        PackageDependencyView packageDependency = PackageDependencyView.newBuilder().group("com.google.api").name("api-common").versionBound(config.apiCommonVersionBound(TargetLanguage.JAVA)).build();
        additionalDependencies.add(packageDependency);
    }
    ArrayList<PackageMetadataView.Builder> viewBuilders = new ArrayList<>();
    for (Map.Entry<String, String> entry : getSnippetsOutput().entrySet()) {
        PackageMetadataView.Builder viewBuilder = metadataTransformer.generateMetadataView(namer, config, model, entry.getKey(), entry.getValue(), TargetLanguage.JAVA).additionalDependencies(additionalDependencies).identifier(namer.getMetadataIdentifier()).protoPackageName(namer.getProtoPackageName()).grpcPackageName(namer.getGrpcPackageName()).publishProtos(artifactType == ArtifactType.PROTOBUF);
        viewBuilders.add(viewBuilder);
    }
    return viewBuilders;
}
Also used : JavaPackageMetadataNamer(com.google.api.codegen.transformer.java.JavaPackageMetadataNamer) ArrayList(java.util.ArrayList) PackageMetadataView(com.google.api.codegen.viewmodel.metadata.PackageMetadataView) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) PackageDependencyView(com.google.api.codegen.viewmodel.metadata.PackageDependencyView)

Example 3 with PackageDependencyView

use of com.google.api.codegen.viewmodel.metadata.PackageDependencyView in project toolkit by googleapis.

the class JavaGapicSamplesPackageTransformer method additionalSampleDependencies.

private List<PackageDependencyView> additionalSampleDependencies() {
    PackageDependencyView apiCommonDep = PackageDependencyView.newBuilder().group("com.google.api").name("api-common").versionBound(packageConfig.apiCommonVersionBound(TargetLanguage.JAVA)).build();
    PackageDependencyView commonsCliDep = PackageDependencyView.newBuilder().group("commons-cli").name("commons-cli").versionBound(packageConfig.commonsCliVersionBound(TargetLanguage.JAVA)).build();
    return ImmutableList.<PackageDependencyView>of(apiCommonDep, commonsCliDep);
}
Also used : PackageDependencyView(com.google.api.codegen.viewmodel.metadata.PackageDependencyView)

Example 4 with PackageDependencyView

use of com.google.api.codegen.viewmodel.metadata.PackageDependencyView in project toolkit by googleapis.

the class NodeJSSamplePackageMetadataTransformer method additionalDependencies.

private List<PackageDependencyView> additionalDependencies(NodeJSPackageMetadataNamer gapicPackageNamer) {
    PackageDependencyView yargsDep = PackageDependencyView.create("yargs", packageConfig.commonsCliVersionBound(TargetLanguage.NODEJS));
    PackageDependencyView gapicDep = PackageDependencyView.create(gapicPackageNamer.getMetadataIdentifier(), VersionBound.create("file:..", "file:.."));
    return ImmutableList.of(yargsDep, gapicDep);
}
Also used : PackageDependencyView(com.google.api.codegen.viewmodel.metadata.PackageDependencyView)

Example 5 with PackageDependencyView

use of com.google.api.codegen.viewmodel.metadata.PackageDependencyView in project toolkit by googleapis.

the class JavaPackageTransformer method generateMetadataViewBuilders.

/**
 * Creates a partially initialized builders that can be used to build PackageMetadataViews later.
 */
protected final List<PackageMetadataView.Builder> generateMetadataViewBuilders(ApiModel model, PackageMetadataConfig config, PackagingArtifactType artifactType) {
    String packageName = config.packageName();
    JavaPackageMetadataNamer namer = new JavaPackageMetadataNamer(packageName, artifactType);
    List<PackageDependencyView> additionalDependencies = new ArrayList<>();
    if (!SERVICES_WITH_NO_RESOURCE_NAMES.contains(config.shortName())) {
        PackageDependencyView packageDependency = PackageDependencyView.newBuilder().group("com.google.api").name("api-common").versionBound(config.apiCommonVersionBound(TargetLanguage.JAVA)).build();
        additionalDependencies.add(packageDependency);
    }
    ArrayList<PackageMetadataView.Builder> viewBuilders = new ArrayList<>();
    for (Map.Entry<String, String> entry : getSnippetsOutput().entrySet()) {
        PackageMetadataView.Builder viewBuilder = metadataTransformer.generateMetadataView(namer, config, model, entry.getKey(), entry.getValue(), TargetLanguage.JAVA).additionalDependencies(additionalDependencies).packageName(packageName).identifier(namer.getMetadataIdentifier()).protoPackageName(namer.getProtoPackageName()).grpcPackageName(namer.getGrpcPackageName()).publishProtos(artifactType == PackagingArtifactType.PROTOBUF);
        viewBuilders.add(viewBuilder);
    }
    return viewBuilders;
}
Also used : JavaPackageMetadataNamer(com.google.api.codegen.transformer.java.JavaPackageMetadataNamer) ArrayList(java.util.ArrayList) PackageMetadataView(com.google.api.codegen.viewmodel.metadata.PackageMetadataView) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) PackageDependencyView(com.google.api.codegen.viewmodel.metadata.PackageDependencyView)

Aggregations

PackageDependencyView (com.google.api.codegen.viewmodel.metadata.PackageDependencyView)5 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 JavaPackageMetadataNamer (com.google.api.codegen.transformer.java.JavaPackageMetadataNamer)2 PackageMetadataView (com.google.api.codegen.viewmodel.metadata.PackageMetadataView)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 VersionBound (com.google.api.codegen.config.VersionBound)1 HashMap (java.util.HashMap)1