From a4e8dcc18d57ff5913693458b61d614d1e088395 Mon Sep 17 00:00:00 2001 From: Will Jones Date: Tue, 19 Nov 2024 17:51:25 +0000 Subject: [PATCH] Enable the `l2-resource-alpha` conformance test This commit enables the `l2-resource-alpha` test. The test already passes, so it's just a matter of turning it on. --- pkg/cmd/pulumi-language-java/language_test.go | 1 - .../projects/l2-resource-alpha/Pulumi.yaml | 2 + .../projects/l2-resource-alpha/pom.xml | 99 +++++++++++ .../src/main/java/generated_program/App.java | 26 +++ .../alpha-3.0.0-alpha.1.internal/README.md | 1 + .../alpha-3.0.0-alpha.1.internal/build.gradle | 155 ++++++++++++++++++ .../settings.gradle | 14 ++ .../main/java/com/pulumi/alpha/Provider.java | 54 ++++++ .../java/com/pulumi/alpha/ProviderArgs.java | 28 ++++ .../main/java/com/pulumi/alpha/Resource.java | 78 +++++++++ .../java/com/pulumi/alpha/ResourceArgs.java | 65 ++++++++ .../main/java/com/pulumi/alpha/Utilities.java | 89 ++++++++++ 12 files changed, 611 insertions(+), 1 deletion(-) create mode 100644 pkg/cmd/pulumi-language-java/testdata/projects/l2-resource-alpha/Pulumi.yaml create mode 100644 pkg/cmd/pulumi-language-java/testdata/projects/l2-resource-alpha/pom.xml create mode 100644 pkg/cmd/pulumi-language-java/testdata/projects/l2-resource-alpha/src/main/java/generated_program/App.java create mode 100644 pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/README.md create mode 100644 pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/build.gradle create mode 100644 pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/settings.gradle create mode 100644 pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/src/main/java/com/pulumi/alpha/Provider.java create mode 100644 pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/src/main/java/com/pulumi/alpha/ProviderArgs.java create mode 100644 pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/src/main/java/com/pulumi/alpha/Resource.java create mode 100644 pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/src/main/java/com/pulumi/alpha/ResourceArgs.java create mode 100644 pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/src/main/java/com/pulumi/alpha/Utilities.java diff --git a/pkg/cmd/pulumi-language-java/language_test.go b/pkg/cmd/pulumi-language-java/language_test.go index 6cba5f8e689..32830c73fc1 100644 --- a/pkg/cmd/pulumi-language-java/language_test.go +++ b/pkg/cmd/pulumi-language-java/language_test.go @@ -183,7 +183,6 @@ var expectedFailures = map[string]string{ "l2-provider-grpc-config-secret": "unimplemented for Java", "l2-provider-grpc-config": "unimplemented for Java", "l2-ref-ref": "unimplemented for Java", - "l2-resource-alpha": "unimplemented for Java", "l2-resource-asset-archive": "unimplemented for Java", "l2-resource-config": "unimplemented for Java", "l2-resource-primitives": "unimplemented for Java", diff --git a/pkg/cmd/pulumi-language-java/testdata/projects/l2-resource-alpha/Pulumi.yaml b/pkg/cmd/pulumi-language-java/testdata/projects/l2-resource-alpha/Pulumi.yaml new file mode 100644 index 00000000000..2ed3c539e73 --- /dev/null +++ b/pkg/cmd/pulumi-language-java/testdata/projects/l2-resource-alpha/Pulumi.yaml @@ -0,0 +1,2 @@ +name: l2-resource-alpha +runtime: java diff --git a/pkg/cmd/pulumi-language-java/testdata/projects/l2-resource-alpha/pom.xml b/pkg/cmd/pulumi-language-java/testdata/projects/l2-resource-alpha/pom.xml new file mode 100644 index 00000000000..3d7e1a2a163 --- /dev/null +++ b/pkg/cmd/pulumi-language-java/testdata/projects/l2-resource-alpha/pom.xml @@ -0,0 +1,99 @@ + + + 4.0.0 + + com.pulumi + l2-resource-alpha + 1.0-SNAPSHOT + + + UTF-8 + 11 + 11 + 11 + generated_program.App + + + + + + repository-0 + REPOSITORY + + + + + + com.pulumi + pulumi + CORE.VERSION + + + com.pulumi + alpha + 3.0.0-alpha.1.internal + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.2.2 + + + + true + ${mainClass} + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.4.2 + + + + true + ${mainClass} + + + + jar-with-dependencies + + + + + make-my-jar-with-dependencies + package + + single + + + + + + org.codehaus.mojo + exec-maven-plugin + 3.1.0 + + ${mainClass} + ${mainArgs} + + + + org.apache.maven.plugins + maven-wrapper-plugin + 3.1.1 + + 3.8.5 + + + + + \ No newline at end of file diff --git a/pkg/cmd/pulumi-language-java/testdata/projects/l2-resource-alpha/src/main/java/generated_program/App.java b/pkg/cmd/pulumi-language-java/testdata/projects/l2-resource-alpha/src/main/java/generated_program/App.java new file mode 100644 index 00000000000..aff03a0c6f0 --- /dev/null +++ b/pkg/cmd/pulumi-language-java/testdata/projects/l2-resource-alpha/src/main/java/generated_program/App.java @@ -0,0 +1,26 @@ +package generated_program; + +import com.pulumi.Context; +import com.pulumi.Pulumi; +import com.pulumi.core.Output; +import com.pulumi.alpha.Resource; +import com.pulumi.alpha.ResourceArgs; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; + +public class App { + public static void main(String[] args) { + Pulumi.run(App::stack); + } + + public static void stack(Context ctx) { + var res = new Resource("res", ResourceArgs.builder() + .value(true) + .build()); + + } +} diff --git a/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/README.md b/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/README.md new file mode 100644 index 00000000000..8d1c8b69c3f --- /dev/null +++ b/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/README.md @@ -0,0 +1 @@ + diff --git a/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/build.gradle b/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/build.gradle new file mode 100644 index 00000000000..18bb0cb239f --- /dev/null +++ b/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/build.gradle @@ -0,0 +1,155 @@ +// *** WARNING: this file was generated by pulumi-java-gen *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +plugins { + id("signing") + id("java-library") + id("maven-publish") +} + +group = "com.pulumi" + +def resolvedVersion = System.getenv("PACKAGE_VERSION") ?: + (project.version == "unspecified" + ? "3.0.0-alpha.1.internal" + : project.version) + +def signingKey = System.getenv("SIGNING_KEY") +def signingPassword = System.getenv("SIGNING_PASSWORD") +def publishRepoURL = System.getenv("PUBLISH_REPO_URL") +def publishRepoUsername = System.getenv("PUBLISH_REPO_USERNAME") +def publishRepoPassword = System.getenv("PUBLISH_REPO_PASSWORD") + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(11) + } +} + +compileJava { + options.fork = true + options.forkOptions.jvmArgs.addAll(["-Xmx16g"]) + options.encoding = "UTF-8" +} + +repositories { + maven { + url("REPOSITORY") + } + mavenLocal() + maven { // The google mirror is less flaky than mavenCentral() + url("https://maven-central.storage-download.googleapis.com/maven2/") + } + mavenCentral() +} + +dependencies { + implementation("com.google.code.findbugs:jsr305:3.0.2") + implementation("com.google.code.gson:gson:2.8.9") + implementation("com.pulumi:pulumi:CORE.VERSION") +} + +task sourcesJar(type: Jar) { + from sourceSets.main.allJava + archiveClassifier.set('sources') +} + +task javadocJar(type: Jar) { + from javadoc + archiveClassifier.set('javadoc') + zip64 = true +} + +def genPulumiResources = tasks.register('genPulumiResources') { + doLast { + def resourcesDir = sourceSets.main.output.resourcesDir + def subDir = project.name.replace(".", "/") + def outDir = file("$resourcesDir/$subDir") + outDir.mkdirs() + new File(outDir, "version.txt").text = resolvedVersion + def info = new Object() + info.metaClass.resource = true + info.metaClass.name = "alpha" + info.metaClass.version = resolvedVersion + def infoJson = new groovy.json.JsonBuilder(info).toPrettyString() + new File(outDir, "plugin.json").text = infoJson + } +} + +jar.configure { + dependsOn genPulumiResources +} + +publishing { + publications { + mainPublication(MavenPublication) { + groupId = "com.pulumi" + artifactId = "alpha" + version = resolvedVersion + from components.java + artifact sourcesJar + artifact javadocJar + + pom { + inceptionYear = "" + name = "" + packaging = "jar" + description = " " + + url = "https://example.com" + + scm { + connection = "https://example.com" + developerConnection = "https://example.com" + url = "https://example.com" + } + + licenses { + license { + name = "" + url = "" + } + } + + developers { + developer { + id = "" + name = "" + email = "" + } + } + } + } + } + + if (publishRepoURL) { + repositories { + maven { + name = "PublishRepo" + url = publishRepoURL + credentials { + username = publishRepoUsername + password = publishRepoPassword + } + } + } + } +} + +javadoc { + if (JavaVersion.current().isJava9Compatible()) { + options.addBooleanOption('html5', true) + } + options.jFlags("-Xmx8g", "-Xms512m") +} + +jar { + zip64 = true +} + +if (signingKey) { + signing { + useInMemoryPgpKeys(signingKey, signingPassword) + sign publishing.publications.mainPublication + } +} diff --git a/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/settings.gradle b/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/settings.gradle new file mode 100644 index 00000000000..36f4e170bfa --- /dev/null +++ b/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/settings.gradle @@ -0,0 +1,14 @@ +// *** WARNING: this file was generated by pulumi-java-gen. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +pluginManagement { + repositories { + maven { // The google mirror is less flaky than mavenCentral() + url("https://maven-central.storage-download.googleapis.com/maven2/") + } + gradlePluginPortal() + } +} + +rootProject.name = "com.pulumi.alpha" +include("lib") diff --git a/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/src/main/java/com/pulumi/alpha/Provider.java b/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/src/main/java/com/pulumi/alpha/Provider.java new file mode 100644 index 00000000000..94f61e1e101 --- /dev/null +++ b/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/src/main/java/com/pulumi/alpha/Provider.java @@ -0,0 +1,54 @@ +// *** WARNING: this file was generated by pulumi-language-java. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +package com.pulumi.alpha; + +import com.pulumi.alpha.ProviderArgs; +import com.pulumi.alpha.Utilities; +import com.pulumi.core.Output; +import com.pulumi.core.annotations.ResourceType; +import com.pulumi.core.internal.Codegen; +import javax.annotation.Nullable; + +@ResourceType(type="pulumi:providers:alpha") +public class Provider extends com.pulumi.resources.ProviderResource { + /** + * + * @param name The _unique_ name of the resulting resource. + */ + public Provider(java.lang.String name) { + this(name, ProviderArgs.Empty); + } + /** + * + * @param name The _unique_ name of the resulting resource. + * @param args The arguments to use to populate this resource's properties. + */ + public Provider(java.lang.String name, @Nullable ProviderArgs args) { + this(name, args, null); + } + /** + * + * @param name The _unique_ name of the resulting resource. + * @param args The arguments to use to populate this resource's properties. + * @param options A bag of options that control this resource's behavior. + */ + public Provider(java.lang.String name, @Nullable ProviderArgs args, @Nullable com.pulumi.resources.CustomResourceOptions options) { + super("alpha", name, makeArgs(args, options), makeResourceOptions(options, Codegen.empty()), false); + } + + private static ProviderArgs makeArgs(@Nullable ProviderArgs args, @Nullable com.pulumi.resources.CustomResourceOptions options) { + if (options != null && options.getUrn().isPresent()) { + return null; + } + return args == null ? ProviderArgs.Empty : args; + } + + private static com.pulumi.resources.CustomResourceOptions makeResourceOptions(@Nullable com.pulumi.resources.CustomResourceOptions options, @Nullable Output id) { + var defaultOptions = com.pulumi.resources.CustomResourceOptions.builder() + .version(Utilities.getVersion()) + .build(); + return com.pulumi.resources.CustomResourceOptions.merge(defaultOptions, options, id); + } + +} diff --git a/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/src/main/java/com/pulumi/alpha/ProviderArgs.java b/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/src/main/java/com/pulumi/alpha/ProviderArgs.java new file mode 100644 index 00000000000..8dde82a133f --- /dev/null +++ b/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/src/main/java/com/pulumi/alpha/ProviderArgs.java @@ -0,0 +1,28 @@ +// *** WARNING: this file was generated by pulumi-language-java. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +package com.pulumi.alpha; + + + + +public final class ProviderArgs extends com.pulumi.resources.ResourceArgs { + + public static final ProviderArgs Empty = new ProviderArgs(); + + public static Builder builder() { + return new Builder(); + } + + public static final class Builder { + private ProviderArgs $; + + public Builder() { + $ = new ProviderArgs(); + } + public ProviderArgs build() { + return $; + } + } + +} diff --git a/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/src/main/java/com/pulumi/alpha/Resource.java b/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/src/main/java/com/pulumi/alpha/Resource.java new file mode 100644 index 00000000000..fd2a6dbfe5c --- /dev/null +++ b/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/src/main/java/com/pulumi/alpha/Resource.java @@ -0,0 +1,78 @@ +// *** WARNING: this file was generated by pulumi-language-java. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +package com.pulumi.alpha; + +import com.pulumi.alpha.ResourceArgs; +import com.pulumi.alpha.Utilities; +import com.pulumi.core.Output; +import com.pulumi.core.annotations.Export; +import com.pulumi.core.annotations.ResourceType; +import com.pulumi.core.internal.Codegen; +import java.lang.Boolean; +import javax.annotation.Nullable; + +@ResourceType(type="alpha:index:Resource") +public class Resource extends com.pulumi.resources.CustomResource { + @Export(name="value", refs={Boolean.class}, tree="[0]") + private Output value; + + public Output value() { + return this.value; + } + + /** + * + * @param name The _unique_ name of the resulting resource. + */ + public Resource(java.lang.String name) { + this(name, ResourceArgs.Empty); + } + /** + * + * @param name The _unique_ name of the resulting resource. + * @param args The arguments to use to populate this resource's properties. + */ + public Resource(java.lang.String name, ResourceArgs args) { + this(name, args, null); + } + /** + * + * @param name The _unique_ name of the resulting resource. + * @param args The arguments to use to populate this resource's properties. + * @param options A bag of options that control this resource's behavior. + */ + public Resource(java.lang.String name, ResourceArgs args, @Nullable com.pulumi.resources.CustomResourceOptions options) { + super("alpha:index:Resource", name, makeArgs(args, options), makeResourceOptions(options, Codegen.empty()), false); + } + + private Resource(java.lang.String name, Output id, @Nullable com.pulumi.resources.CustomResourceOptions options) { + super("alpha:index:Resource", name, null, makeResourceOptions(options, id), false); + } + + private static ResourceArgs makeArgs(ResourceArgs args, @Nullable com.pulumi.resources.CustomResourceOptions options) { + if (options != null && options.getUrn().isPresent()) { + return null; + } + return args == null ? ResourceArgs.Empty : args; + } + + private static com.pulumi.resources.CustomResourceOptions makeResourceOptions(@Nullable com.pulumi.resources.CustomResourceOptions options, @Nullable Output id) { + var defaultOptions = com.pulumi.resources.CustomResourceOptions.builder() + .version(Utilities.getVersion()) + .build(); + return com.pulumi.resources.CustomResourceOptions.merge(defaultOptions, options, id); + } + + /** + * Get an existing Host resource's state with the given name, ID, and optional extra + * properties used to qualify the lookup. + * + * @param name The _unique_ name of the resulting resource. + * @param id The _unique_ provider ID of the resource to lookup. + * @param options Optional settings to control the behavior of the CustomResource. + */ + public static Resource get(java.lang.String name, Output id, @Nullable com.pulumi.resources.CustomResourceOptions options) { + return new Resource(name, id, options); + } +} diff --git a/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/src/main/java/com/pulumi/alpha/ResourceArgs.java b/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/src/main/java/com/pulumi/alpha/ResourceArgs.java new file mode 100644 index 00000000000..f567699e4a8 --- /dev/null +++ b/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/src/main/java/com/pulumi/alpha/ResourceArgs.java @@ -0,0 +1,65 @@ +// *** WARNING: this file was generated by pulumi-language-java. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +package com.pulumi.alpha; + +import com.pulumi.core.Output; +import com.pulumi.core.annotations.Import; +import com.pulumi.exceptions.MissingRequiredPropertyException; +import java.lang.Boolean; +import java.util.Objects; + + +public final class ResourceArgs extends com.pulumi.resources.ResourceArgs { + + public static final ResourceArgs Empty = new ResourceArgs(); + + @Import(name="value", required=true) + private Output value; + + public Output value() { + return this.value; + } + + private ResourceArgs() {} + + private ResourceArgs(ResourceArgs $) { + this.value = $.value; + } + + public static Builder builder() { + return new Builder(); + } + public static Builder builder(ResourceArgs defaults) { + return new Builder(defaults); + } + + public static final class Builder { + private ResourceArgs $; + + public Builder() { + $ = new ResourceArgs(); + } + + public Builder(ResourceArgs defaults) { + $ = new ResourceArgs(Objects.requireNonNull(defaults)); + } + + public Builder value(Output value) { + $.value = value; + return this; + } + + public Builder value(Boolean value) { + return value(Output.of(value)); + } + + public ResourceArgs build() { + if ($.value == null) { + throw new MissingRequiredPropertyException("ResourceArgs", "value"); + } + return $; + } + } + +} diff --git a/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/src/main/java/com/pulumi/alpha/Utilities.java b/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/src/main/java/com/pulumi/alpha/Utilities.java new file mode 100644 index 00000000000..9558db97a2a --- /dev/null +++ b/pkg/cmd/pulumi-language-java/testdata/sdks/alpha-3.0.0-alpha.1.internal/src/main/java/com/pulumi/alpha/Utilities.java @@ -0,0 +1,89 @@ +// *** WARNING: this file was generated by pulumi-language-java. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +package com.pulumi.alpha; + + + + + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.Optional; +import java.util.stream.Collectors; +import javax.annotation.Nullable; +import com.pulumi.core.internal.Environment; +import com.pulumi.deployment.InvokeOptions; + +public class Utilities { + + public static Optional getEnv(java.lang.String... names) { + for (var n : names) { + var value = Environment.getEnvironmentVariable(n); + if (value.isValue()) { + return Optional.of(value.value()); + } + } + return Optional.empty(); + } + + public static Optional getEnvBoolean(java.lang.String... names) { + for (var n : names) { + var value = Environment.getBooleanEnvironmentVariable(n); + if (value.isValue()) { + return Optional.of(value.value()); + } + } + return Optional.empty(); + } + + public static Optional getEnvInteger(java.lang.String... names) { + for (var n : names) { + var value = Environment.getIntegerEnvironmentVariable(n); + if (value.isValue()) { + return Optional.of(value.value()); + } + } + return Optional.empty(); + } + + public static Optional getEnvDouble(java.lang.String... names) { + for (var n : names) { + var value = Environment.getDoubleEnvironmentVariable(n); + if (value.isValue()) { + return Optional.of(value.value()); + } + } + return Optional.empty(); + } + + public static InvokeOptions withVersion(@Nullable InvokeOptions options) { + if (options != null && options.getVersion().isPresent()) { + return options; + } + return new InvokeOptions( + options == null ? null : options.getParent().orElse(null), + options == null ? null : options.getProvider().orElse(null), + getVersion() + ); + } + + private static final java.lang.String version; + public static java.lang.String getVersion() { + return version; + } + + static { + var resourceName = "com/pulumi/alpha/version.txt"; + var versionFile = Utilities.class.getClassLoader().getResourceAsStream(resourceName); + if (versionFile == null) { + throw new IllegalStateException( + java.lang.String.format("expected resource '%s' on Classpath, not found", resourceName) + ); + } + version = new BufferedReader(new InputStreamReader(versionFile)) + .lines() + .collect(Collectors.joining("\n")) + .trim(); + } +}