From 75bc0476af62edfe9c463e4b50bb764c753c7c8f Mon Sep 17 00:00:00 2001 From: Julien Poissonnier Date: Thu, 30 Jan 2025 15:41:29 +0100 Subject: [PATCH] Default to using gradle0nexus in gen-sdk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When using `pulumi-java-gen`, the user can bass a `—build` flag which the following options: * `none`: no gradle file is generated (the default) * `gradle`: a gradle file is generated -> BuildFiles: gradle * `gradle-nexus`: a gradle file using the nexus publishing plugin is generated, using a default version of the plugin -> BuildFiles: gradle, GradleNexusPublishPluginVersion: 2.0.0 * `gradle-nexus:$VER`: a gradle file using the nexus publishing plugin is generated, using the version $VER for the plugin -> BuildFiles: gradle, GradleNexusPublishPluginVersion: $VER Using `gen-sdk`, the options are managed via the schema, `buildFiles` can take the following options: * `gradle-nexus`: the default if the buildFiles is not set, a gradle file using the nexus publishing plugin is generated, implies `gradleNexusPublishPluginVersion: 2.0.0` if `gradleNexusPublishPluginVersionA` is not set. * `gradle`: a gradle file is generated, but without the nexus publishing plugin * `none`: no gradle file is generated Fixes https://github.com/pulumi/pulumi-java/issues/1593 --- pkg/cmd/pulumi-java-gen/generate.go | 1 + pkg/cmd/pulumi-language-java/main.go | 1 + pkg/codegen/java/gen.go | 35 ++-- pkg/codegen/java/gen_test.go | 35 +++- pkg/codegen/java/templates_gradle.go | 20 ++- pkg/codegen/java/templates_gradle_test.go | 61 ++++++- .../build-files/gradle-nexus/java/README.md | 1 + .../gradle-nexus/java/build.gradle | 155 ++++++++++++++++++ .../gradle-nexus/java/codegen-manifest.json | 10 ++ .../gradle-nexus/java/settings.gradle | 14 ++ .../java/com/pulumi/example/Provider.java | 54 ++++++ .../java/com/pulumi/example/ProviderArgs.java | 28 ++++ .../java/com/pulumi/example/Utilities.java | 102 ++++++++++++ .../build-files/gradle-nexus/schema.json | 21 +++ .../build-files/gradle/java/README.md | 1 + .../build-files/gradle/java/build.gradle | 154 +++++++++++++++++ .../gradle/java/codegen-manifest.json | 10 ++ .../build-files/gradle/java/settings.gradle | 14 ++ .../java/com/pulumi/example/Provider.java | 54 ++++++ .../java/com/pulumi/example/ProviderArgs.java | 28 ++++ .../java/com/pulumi/example/Utilities.java | 102 ++++++++++++ .../testdata/build-files/gradle/schema.json | 21 +++ .../testdata/build-files/none/java/README.md | 1 + .../none/java/codegen-manifest.json | 9 + .../java/com/pulumi/example/Provider.java | 54 ++++++ .../java/com/pulumi/example/ProviderArgs.java | 28 ++++ .../java/com/pulumi/example/Utilities.java | 102 ++++++++++++ .../resources/com/pulumi/example/version.txt | 1 + .../testdata/build-files/none/schema.json | 21 +++ .../build-files/unspecified/java/README.md | 1 + .../build-files/unspecified/java/build.gradle | 155 ++++++++++++++++++ .../unspecified/java/codegen-manifest.json | 10 ++ .../unspecified/java/settings.gradle | 14 ++ .../java/com/pulumi/example/Provider.java | 54 ++++++ .../java/com/pulumi/example/ProviderArgs.java | 28 ++++ .../java/com/pulumi/example/Utilities.java | 102 ++++++++++++ .../build-files/unspecified/schema.json | 19 +++ 37 files changed, 1499 insertions(+), 22 deletions(-) create mode 100644 pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/README.md create mode 100644 pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/build.gradle create mode 100644 pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/codegen-manifest.json create mode 100644 pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/settings.gradle create mode 100644 pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/src/main/java/com/pulumi/example/Provider.java create mode 100644 pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/src/main/java/com/pulumi/example/ProviderArgs.java create mode 100644 pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/src/main/java/com/pulumi/example/Utilities.java create mode 100644 pkg/codegen/testing/test/testdata/build-files/gradle-nexus/schema.json create mode 100644 pkg/codegen/testing/test/testdata/build-files/gradle/java/README.md create mode 100644 pkg/codegen/testing/test/testdata/build-files/gradle/java/build.gradle create mode 100644 pkg/codegen/testing/test/testdata/build-files/gradle/java/codegen-manifest.json create mode 100644 pkg/codegen/testing/test/testdata/build-files/gradle/java/settings.gradle create mode 100644 pkg/codegen/testing/test/testdata/build-files/gradle/java/src/main/java/com/pulumi/example/Provider.java create mode 100644 pkg/codegen/testing/test/testdata/build-files/gradle/java/src/main/java/com/pulumi/example/ProviderArgs.java create mode 100644 pkg/codegen/testing/test/testdata/build-files/gradle/java/src/main/java/com/pulumi/example/Utilities.java create mode 100644 pkg/codegen/testing/test/testdata/build-files/gradle/schema.json create mode 100644 pkg/codegen/testing/test/testdata/build-files/none/java/README.md create mode 100644 pkg/codegen/testing/test/testdata/build-files/none/java/codegen-manifest.json create mode 100644 pkg/codegen/testing/test/testdata/build-files/none/java/src/main/java/com/pulumi/example/Provider.java create mode 100644 pkg/codegen/testing/test/testdata/build-files/none/java/src/main/java/com/pulumi/example/ProviderArgs.java create mode 100644 pkg/codegen/testing/test/testdata/build-files/none/java/src/main/java/com/pulumi/example/Utilities.java create mode 100644 pkg/codegen/testing/test/testdata/build-files/none/java/src/main/resources/com/pulumi/example/version.txt create mode 100644 pkg/codegen/testing/test/testdata/build-files/none/schema.json create mode 100644 pkg/codegen/testing/test/testdata/build-files/unspecified/java/README.md create mode 100644 pkg/codegen/testing/test/testdata/build-files/unspecified/java/build.gradle create mode 100644 pkg/codegen/testing/test/testdata/build-files/unspecified/java/codegen-manifest.json create mode 100644 pkg/codegen/testing/test/testdata/build-files/unspecified/java/settings.gradle create mode 100644 pkg/codegen/testing/test/testdata/build-files/unspecified/java/src/main/java/com/pulumi/example/Provider.java create mode 100644 pkg/codegen/testing/test/testdata/build-files/unspecified/java/src/main/java/com/pulumi/example/ProviderArgs.java create mode 100644 pkg/codegen/testing/test/testdata/build-files/unspecified/java/src/main/java/com/pulumi/example/Utilities.java create mode 100644 pkg/codegen/testing/test/testdata/build-files/unspecified/schema.json diff --git a/pkg/cmd/pulumi-java-gen/generate.go b/pkg/cmd/pulumi-java-gen/generate.go index 8ba1511862f..c9437ca0bf4 100644 --- a/pkg/cmd/pulumi-java-gen/generate.go +++ b/pkg/cmd/pulumi-java-gen/generate.go @@ -91,6 +91,7 @@ func generateJava(cfg generateJavaOptions) error { extraFiles, nil, /*localDependencies*/ cfg.Local, + true, /*legacyBuildFiles*/ ) if err != nil { return err diff --git a/pkg/cmd/pulumi-language-java/main.go b/pkg/cmd/pulumi-language-java/main.go index 0da112f0c55..39d93d8633a 100644 --- a/pkg/cmd/pulumi-language-java/main.go +++ b/pkg/cmd/pulumi-language-java/main.go @@ -749,6 +749,7 @@ func (host *javaLanguageHost) GeneratePackage( req.ExtraFiles, req.LocalDependencies, req.Local, + false, /*legacyBuildFiles*/ ) if err != nil { return nil, err diff --git a/pkg/codegen/java/gen.go b/pkg/codegen/java/gen.go index d4ebcea1ace..720accd944b 100644 --- a/pkg/codegen/java/gen.go +++ b/pkg/codegen/java/gen.go @@ -2239,6 +2239,7 @@ func GeneratePackage( extraFiles map[string][]byte, localDependencies map[string]string, local bool, + legacyBuildFiles bool, ) (map[string][]byte, error) { // Presently, Gradle is the primary build system we support for generated SDKs. Later on, when we validate the // package in order to produce build system artifacts, we'll need a description and repository. To this end, we @@ -2308,13 +2309,33 @@ func GeneratePackage( } } + // Unless we are generating a local package, we use gradle as the build + // system. Note that we do not support generating build files for any other + // system than gradle at this time. + // + // If the legacyBuildFiles is set to true, we will only use gradle if the + // BuildFiles field is explicitly set to `gradle`. This is to support the + // legacy behavior of `pulumi-java-gen`. Once `pulumi-java-gen` is + // deprecated, we can remove the legacyBuildFiles flag, and always use + // gradle if `local` is false. + useGradle := !local && // Only use gradle if we are not generating a local package. + // legacy behavior requires explicit gradle setting + (legacyBuildFiles && info.BuildFiles == "gradle") || + // new behavior uses gradle by default, unless explicitly disabled + (!legacyBuildFiles && info.BuildFiles != "none") + // Currently, packages come bundled with a version.txt resource that is used by generated code to report a version. // When a build tool is configured, we defer the generation of this file to the build process so that e.g. CI // processes can set the version to be used when releasing or publishing a package, as opposed to when the code for // that package is generated. In the case that we are generating a package without a build tool, or a local package // to be incorporated into a program with an existing build process, we need to emit the version.txt file explicitly // as part of code generation. - if info.BuildFiles == "" || local { + if useGradle { + if err := genGradleProject(pkg, info, files, legacyBuildFiles); err != nil { + return nil, err + } + return files, nil + } else { pkgName := fmt.Sprintf("%s%s", info.BasePackageOrDefault(), pkg.Name) pkgPath := strings.ReplaceAll(pkgName, ".", "/") @@ -2328,18 +2349,6 @@ func GeneratePackage( files.add("src/main/resources/"+pkgPath+"/version.txt", []byte(version)) return files, nil } - - // If we are emitting a publishable package with a configured build system, emit those files now. - switch info.BuildFiles { - case "gradle": - if err := genGradleProject(pkg, info, files); err != nil { - return nil, err - } - return files, nil - default: - return nil, fmt.Errorf("Only `gradle` value currently supported for the `buildFiles` setting, given `%s`", - info.BuildFiles) - } } func isInputType(t schema.Type) bool { diff --git a/pkg/codegen/java/gen_test.go b/pkg/codegen/java/gen_test.go index 9e9047fcf42..ec393005437 100644 --- a/pkg/codegen/java/gen_test.go +++ b/pkg/codegen/java/gen_test.go @@ -81,6 +81,24 @@ func javaSpecificTests(keyDeps map[string]string) []generatePackageTestConfig { Directory: "parameterized", Description: "Tests for parameterized providers", }), + newGeneratePackageTestConfig(&test.SDKTest{ + Directory: "build-files/none", + Description: "Tests for build-files = none", + // We don't generate a gradle file, so we can't compile. + SkipCompileCheck: codegen.NewStringSet("java"), + }), + newGeneratePackageTestConfig(&test.SDKTest{ + Directory: "build-files/gradle", + Description: "Tests for build-files = gradle", + }), + newGeneratePackageTestConfig(&test.SDKTest{ + Directory: "build-files/gradle-nexus", + Description: "Tests for build-files = gradle-nexus", + }), + newGeneratePackageTestConfig(&test.SDKTest{ + Directory: "build-files/unspecified", + Description: "Tests for build-files not set", + }), } } @@ -224,10 +242,20 @@ func TestGeneratePackage(t *testing.T) { ) (map[string][]byte, error) { pkg.Description = "test description" pkg.Repository = "https://github.com/pulumi/pulumi-java" - pkg.Language = map[string]interface{}{ - "java": testCase.packageInfo, + + if pkg.Language == nil { + pkg.Language = map[string]interface{}{} } - return GeneratePackage(tool, pkg, extraFiles, nil, false) + if pkg.Language["java"] == nil { + pkg.Language["java"] = testCase.packageInfo + } else { + if err := pkg.ImportLanguages(map[string]schema.Language{"java": Importer}); err != nil { + panic(err) + } + info := pkg.Language["java"].(PackageInfo) + pkg.Language["java"] = info.With(testCase.packageInfo) + } + return GeneratePackage(tool, pkg, extraFiles, nil, false /*local*/, false /*legacyBuildFiles*/) }, Language: "java", TestCases: []*test.SDKTest{testCase.sdkTest}, @@ -239,7 +267,6 @@ func TestGeneratePackage(t *testing.T) { // Minimal test config that verifies code generation and compilation. func newGeneratePackageTestConfig(test *test.SDKTest) generatePackageTestConfig { packageInfo := PackageInfo{ - BuildFiles: "gradle", Dependencies: map[string]string{ "com.pulumi:pulumi": "0.0.1", }, diff --git a/pkg/codegen/java/templates_gradle.go b/pkg/codegen/java/templates_gradle.go index 10c303347ab..a6b03648494 100644 --- a/pkg/codegen/java/templates_gradle.go +++ b/pkg/codegen/java/templates_gradle.go @@ -14,16 +14,19 @@ import ( "github.com/pulumi/pulumi/pkg/v3/codegen/schema" ) +const DefaultGradleNexusPublishPluginVersion = "2.0.0" + func genGradleProject( pkg *schema.Package, packageInfo *PackageInfo, files fs, + legacyBuildFiles bool, ) error { if err := gradleValidatePackage(pkg); err != nil { return err } - ctx := newGradleTemplateContext(pkg, packageInfo) + ctx := newGradleTemplateContext(pkg, packageInfo, legacyBuildFiles) templates := map[string]string{ "build.gradle": buildGradleTemplate, "settings.gradle": settingsGradleTemplate, @@ -99,6 +102,7 @@ type gradleTemplateParameterization struct { func newGradleTemplateContext( pkg *schema.Package, packageInfo *PackageInfo, + legacyBuildFiles bool, ) gradleTemplateContext { ctx := gradleTemplateContext{ Name: pkg.Name, @@ -126,9 +130,19 @@ func newGradleTemplateContext( ctx.Version = pkg.Parameterization.BaseProvider.Version.String() } - if packageInfo.GradleNexusPublishPluginVersion != "" { + if legacyBuildFiles { + // In legacy mode, we require the user to provide the Gradle Nexus Publish Plugin version. + if packageInfo.GradleNexusPublishPluginVersion != "" { + ctx.GradleNexusPublishPluginEnabled = true + ctx.GradleNexusPublishPluginVersion = packageInfo.GradleNexusPublishPluginVersion + } + } else if packageInfo.BuildFiles == "" || packageInfo.BuildFiles == "gradle-nexus" { + version := DefaultGradleNexusPublishPluginVersion + if packageInfo.GradleNexusPublishPluginVersion != "" { + version = packageInfo.GradleNexusPublishPluginVersion + } ctx.GradleNexusPublishPluginEnabled = true - ctx.GradleNexusPublishPluginVersion = packageInfo.GradleNexusPublishPluginVersion + ctx.GradleNexusPublishPluginVersion = version } if packageInfo.Repositories != nil { diff --git a/pkg/codegen/java/templates_gradle_test.go b/pkg/codegen/java/templates_gradle_test.go index e66a52eb569..cf51ade8262 100644 --- a/pkg/codegen/java/templates_gradle_test.go +++ b/pkg/codegen/java/templates_gradle_test.go @@ -11,9 +11,30 @@ import ( "github.com/pulumi/pulumi/pkg/v3/codegen/schema" ) +func TestNewGradleTemplateContextLegacy(t *testing.T) { + pkg, info := eksExample() + tctx := newGradleTemplateContext(pkg, info, true /*legacyBuildFiles*/) + assert.Equal(t, "0.37.1", tctx.Version) + assert.Equal(t, "com.pulumi", tctx.GroupID) + assert.Equal(t, "eks", tctx.Name) + assert.Equal(t, "https://github.com/pulumi/pulumi-eks", tctx.ProjectURL) + assert.Equal(t, "git@github.com/pulumi/pulumi-eks.git", tctx.ProjectGitURL) + assert.Equal(t, "Pulumi Amazon Web Services (AWS) EKS Components.", tctx.ProjectDescription) + assert.Equal(t, "2022", tctx.ProjectInceptionYear) + assert.Equal(t, "com.pulumi.eks", tctx.RootProjectName) + assert.Equal(t, "pulumi-eks", tctx.ProjectName) + assert.Equal(t, "pulumi", tctx.DeveloperID) + assert.Equal(t, "support@pulumi.com", tctx.DeveloperEmail) + assert.Equal(t, "The Apache License, Version 2.0", tctx.LicenceName) + assert.Equal(t, "http://www.apache.org/licenses/LICENSE-2.0.txt", tctx.LicenceURL) + assert.Equal(t, info.Dependencies, tctx.Dependencies) + assert.Equal(t, "", tctx.GradleNexusPublishPluginVersion) + assert.Equal(t, false, tctx.GradleNexusPublishPluginEnabled) +} + func TestNewGradleTemplateContext(t *testing.T) { pkg, info := eksExample() - tctx := newGradleTemplateContext(pkg, info) + tctx := newGradleTemplateContext(pkg, info, false /*legacyBuildFiles*/) assert.Equal(t, "0.37.1", tctx.Version) assert.Equal(t, "com.pulumi", tctx.GroupID) assert.Equal(t, "eks", tctx.Name) @@ -28,12 +49,48 @@ func TestNewGradleTemplateContext(t *testing.T) { assert.Equal(t, "The Apache License, Version 2.0", tctx.LicenceName) assert.Equal(t, "http://www.apache.org/licenses/LICENSE-2.0.txt", tctx.LicenceURL) assert.Equal(t, info.Dependencies, tctx.Dependencies) + assert.Equal(t, "2.0.0", tctx.GradleNexusPublishPluginVersion) + assert.Equal(t, true, tctx.GradleNexusPublishPluginEnabled) +} + +func TestNewGradleTemplateContextBuildFiles(t *testing.T) { + pkg, _ := eksExample() + + // Legacy build files: false + + // We default to the behavior of `gradle-nexus`. + info := &PackageInfo{BuildFiles: ""} + tctx := newGradleTemplateContext(pkg, info, false /*legacyBuildFiles*/) + assert.Equal(t, "2.0.0", tctx.GradleNexusPublishPluginVersion) + assert.Equal(t, true, tctx.GradleNexusPublishPluginEnabled) + + info = &PackageInfo{BuildFiles: "gradle-nexus"} + tctx = newGradleTemplateContext(pkg, info, false /*legacyBuildFiles*/) + assert.Equal(t, "2.0.0", tctx.GradleNexusPublishPluginVersion) + assert.Equal(t, true, tctx.GradleNexusPublishPluginEnabled) + + info = &PackageInfo{BuildFiles: "gradle"} + tctx = newGradleTemplateContext(pkg, info, false /*legacyBuildFiles*/) + assert.Equal(t, "", tctx.GradleNexusPublishPluginVersion) + assert.Equal(t, false, tctx.GradleNexusPublishPluginEnabled) + + // Legacy build files: true + + info = &PackageInfo{BuildFiles: "gradle"} + tctx = newGradleTemplateContext(pkg, info, true /*legacyBuildFiles*/) + assert.Equal(t, "", tctx.GradleNexusPublishPluginVersion) + assert.Equal(t, false, tctx.GradleNexusPublishPluginEnabled) + + info = &PackageInfo{BuildFiles: "gradle", GradleNexusPublishPluginVersion: "1.2.3"} + tctx = newGradleTemplateContext(pkg, info, true /*legacyBuildFiles*/) + assert.Equal(t, "1.2.3", tctx.GradleNexusPublishPluginVersion) + assert.Equal(t, true, tctx.GradleNexusPublishPluginEnabled) } func TestGenGradleProject(t *testing.T) { pkg, info := eksExample() files := fs{} - err := genGradleProject(pkg, info, files) + err := genGradleProject(pkg, info, files, true /*legacyBuildFiles*/) if err != nil { t.Error(err) } diff --git a/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/README.md b/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/README.md new file mode 100644 index 00000000000..6b0d347bb27 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/README.md @@ -0,0 +1 @@ +test description diff --git a/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/build.gradle b/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/build.gradle new file mode 100644 index 00000000000..f7d8729b951 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/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") + id("io.github.gradle-nexus.publish-plugin") version "2.0.0" +} + +group = "com.pulumi" + +def resolvedVersion = System.getenv("PACKAGE_VERSION") ?: + (project.version == "unspecified" + ? "0.0.1" + : project.version) + +def signingKey = System.getenv("SIGNING_KEY") +def signingPassword = System.getenv("SIGNING_PASSWORD") +def publishRepoURL = System.getenv("PUBLISH_REPO_URL") ?: "https://s01.oss.sonatype.org" +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 { + 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:0.0.1") +} + +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 builder = new groovy.json.JsonBuilder() + builder { + resource true + name "example" + version resolvedVersion + } + def infoJson = builder.toPrettyString() + new File(outDir, "plugin.json").text = infoJson + } +} + +jar.configure { + dependsOn genPulumiResources +} + +publishing { + publications { + mainPublication(MavenPublication) { + groupId = "com.pulumi" + artifactId = "example" + version = resolvedVersion + from components.java + artifact sourcesJar + artifact javadocJar + + pom { + inceptionYear = "2022" + name = "pulumi-example" + packaging = "jar" + description = "test description" + + url = "https://github.com/pulumi/pulumi-java" + + scm { + connection = "git@github.com/pulumi/pulumi-java.git" + developerConnection = "git@github.com/pulumi/pulumi-java.git" + url = "https://github.com/pulumi/pulumi-java" + } + + licenses { + license { + name = "" + url = "" + } + } + + developers { + developer { + id = "pulumi" + name = "Pulumi" + email = "support@pulumi.com" + } + } + } + } + } +} + +javadoc { + if (JavaVersion.current().isJava9Compatible()) { + options.addBooleanOption('html5', true) + } + options.jFlags("-Xmx8g", "-Xms512m") +} + +jar { + zip64 = true +} + +if (publishRepoUsername) { + nexusPublishing { + repositories { + sonatype { + nexusUrl.set(uri(publishRepoURL + "/service/local/")) + snapshotRepositoryUrl.set(uri(publishRepoURL + "/content/repositories/snapshots/")) + username = publishRepoUsername + password = publishRepoPassword + } + } + } +} + +if (signingKey) { + signing { + useInMemoryPgpKeys(signingKey, signingPassword) + sign publishing.publications.mainPublication + } +} \ No newline at end of file diff --git a/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/codegen-manifest.json b/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/codegen-manifest.json new file mode 100644 index 00000000000..d73a9826d6c --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/codegen-manifest.json @@ -0,0 +1,10 @@ +{ + "emittedFiles": [ + "README.md", + "build.gradle", + "settings.gradle", + "src/main/java/com/pulumi/example/Provider.java", + "src/main/java/com/pulumi/example/ProviderArgs.java", + "src/main/java/com/pulumi/example/Utilities.java" + ] +} diff --git a/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/settings.gradle b/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/settings.gradle new file mode 100644 index 00000000000..a5ad86818fe --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/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.example" +include("lib") diff --git a/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/src/main/java/com/pulumi/example/Provider.java b/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/src/main/java/com/pulumi/example/Provider.java new file mode 100644 index 00000000000..a76332ced95 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/src/main/java/com/pulumi/example/Provider.java @@ -0,0 +1,54 @@ +// *** WARNING: this file was generated by test. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +package com.pulumi.example; + +import com.pulumi.core.Output; +import com.pulumi.core.annotations.ResourceType; +import com.pulumi.core.internal.Codegen; +import com.pulumi.example.ProviderArgs; +import com.pulumi.example.Utilities; +import javax.annotation.Nullable; + +@ResourceType(type="pulumi:providers:example") +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("example", 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/codegen/testing/test/testdata/build-files/gradle-nexus/java/src/main/java/com/pulumi/example/ProviderArgs.java b/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/src/main/java/com/pulumi/example/ProviderArgs.java new file mode 100644 index 00000000000..e07bfe9857d --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/src/main/java/com/pulumi/example/ProviderArgs.java @@ -0,0 +1,28 @@ +// *** WARNING: this file was generated by test. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +package com.pulumi.example; + + + + +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/codegen/testing/test/testdata/build-files/gradle-nexus/java/src/main/java/com/pulumi/example/Utilities.java b/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/src/main/java/com/pulumi/example/Utilities.java new file mode 100644 index 00000000000..f248a63d2b3 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/java/src/main/java/com/pulumi/example/Utilities.java @@ -0,0 +1,102 @@ +// *** WARNING: this file was generated by test. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +package com.pulumi.example; + + + + + +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; +import com.pulumi.deployment.InvokeOutputOptions; + +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() + ); + } + + public static InvokeOutputOptions withVersion(@Nullable InvokeOutputOptions options) { + if (options != null && options.getVersion().isPresent()) { + return options; + } + return new InvokeOutputOptions( + options == null ? null : options.getParent().orElse(null), + options == null ? null : options.getProvider().orElse(null), + getVersion(), + options == null ? null : options.getDependsOn() + ); + } + + private static final java.lang.String version; + public static java.lang.String getVersion() { + return version; + } + + static { + var resourceName = "com/pulumi/example/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(); + } +} diff --git a/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/schema.json b/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/schema.json new file mode 100644 index 00000000000..57a25392bba --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/gradle-nexus/schema.json @@ -0,0 +1,21 @@ +{ + "version": "0.0.1", + "name": "example", + "keywords": [ + "Testing", + "Pulumipus" + ], + "description": "Test the none setting for build-files", + "license": "MIT", + "types": {}, + "readme": "hello this is the readme body.", + "homepage": "https://pulumi.com", + "repository": "https://github.com/pulumi/pulumi", + "resources": {}, + "functions": {}, + "language": { + "java": { + "buildFiles": "gradle-nexus" + } + } +} \ No newline at end of file diff --git a/pkg/codegen/testing/test/testdata/build-files/gradle/java/README.md b/pkg/codegen/testing/test/testdata/build-files/gradle/java/README.md new file mode 100644 index 00000000000..6b0d347bb27 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/gradle/java/README.md @@ -0,0 +1 @@ +test description diff --git a/pkg/codegen/testing/test/testdata/build-files/gradle/java/build.gradle b/pkg/codegen/testing/test/testdata/build-files/gradle/java/build.gradle new file mode 100644 index 00000000000..8e038efaba3 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/gradle/java/build.gradle @@ -0,0 +1,154 @@ +// *** 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" + ? "0.0.1" + : 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 { + 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:0.0.1") +} + +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 builder = new groovy.json.JsonBuilder() + builder { + resource true + name "example" + version resolvedVersion + } + def infoJson = builder.toPrettyString() + new File(outDir, "plugin.json").text = infoJson + } +} + +jar.configure { + dependsOn genPulumiResources +} + +publishing { + publications { + mainPublication(MavenPublication) { + groupId = "com.pulumi" + artifactId = "example" + version = resolvedVersion + from components.java + artifact sourcesJar + artifact javadocJar + + pom { + inceptionYear = "2022" + name = "pulumi-example" + packaging = "jar" + description = "test description" + + url = "https://github.com/pulumi/pulumi-java" + + scm { + connection = "git@github.com/pulumi/pulumi-java.git" + developerConnection = "git@github.com/pulumi/pulumi-java.git" + url = "https://github.com/pulumi/pulumi-java" + } + + licenses { + license { + name = "" + url = "" + } + } + + developers { + developer { + id = "pulumi" + name = "Pulumi" + email = "support@pulumi.com" + } + } + } + } + } + + 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 + } +} \ No newline at end of file diff --git a/pkg/codegen/testing/test/testdata/build-files/gradle/java/codegen-manifest.json b/pkg/codegen/testing/test/testdata/build-files/gradle/java/codegen-manifest.json new file mode 100644 index 00000000000..d73a9826d6c --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/gradle/java/codegen-manifest.json @@ -0,0 +1,10 @@ +{ + "emittedFiles": [ + "README.md", + "build.gradle", + "settings.gradle", + "src/main/java/com/pulumi/example/Provider.java", + "src/main/java/com/pulumi/example/ProviderArgs.java", + "src/main/java/com/pulumi/example/Utilities.java" + ] +} diff --git a/pkg/codegen/testing/test/testdata/build-files/gradle/java/settings.gradle b/pkg/codegen/testing/test/testdata/build-files/gradle/java/settings.gradle new file mode 100644 index 00000000000..a5ad86818fe --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/gradle/java/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.example" +include("lib") diff --git a/pkg/codegen/testing/test/testdata/build-files/gradle/java/src/main/java/com/pulumi/example/Provider.java b/pkg/codegen/testing/test/testdata/build-files/gradle/java/src/main/java/com/pulumi/example/Provider.java new file mode 100644 index 00000000000..a76332ced95 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/gradle/java/src/main/java/com/pulumi/example/Provider.java @@ -0,0 +1,54 @@ +// *** WARNING: this file was generated by test. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +package com.pulumi.example; + +import com.pulumi.core.Output; +import com.pulumi.core.annotations.ResourceType; +import com.pulumi.core.internal.Codegen; +import com.pulumi.example.ProviderArgs; +import com.pulumi.example.Utilities; +import javax.annotation.Nullable; + +@ResourceType(type="pulumi:providers:example") +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("example", 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/codegen/testing/test/testdata/build-files/gradle/java/src/main/java/com/pulumi/example/ProviderArgs.java b/pkg/codegen/testing/test/testdata/build-files/gradle/java/src/main/java/com/pulumi/example/ProviderArgs.java new file mode 100644 index 00000000000..e07bfe9857d --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/gradle/java/src/main/java/com/pulumi/example/ProviderArgs.java @@ -0,0 +1,28 @@ +// *** WARNING: this file was generated by test. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +package com.pulumi.example; + + + + +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/codegen/testing/test/testdata/build-files/gradle/java/src/main/java/com/pulumi/example/Utilities.java b/pkg/codegen/testing/test/testdata/build-files/gradle/java/src/main/java/com/pulumi/example/Utilities.java new file mode 100644 index 00000000000..f248a63d2b3 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/gradle/java/src/main/java/com/pulumi/example/Utilities.java @@ -0,0 +1,102 @@ +// *** WARNING: this file was generated by test. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +package com.pulumi.example; + + + + + +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; +import com.pulumi.deployment.InvokeOutputOptions; + +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() + ); + } + + public static InvokeOutputOptions withVersion(@Nullable InvokeOutputOptions options) { + if (options != null && options.getVersion().isPresent()) { + return options; + } + return new InvokeOutputOptions( + options == null ? null : options.getParent().orElse(null), + options == null ? null : options.getProvider().orElse(null), + getVersion(), + options == null ? null : options.getDependsOn() + ); + } + + private static final java.lang.String version; + public static java.lang.String getVersion() { + return version; + } + + static { + var resourceName = "com/pulumi/example/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(); + } +} diff --git a/pkg/codegen/testing/test/testdata/build-files/gradle/schema.json b/pkg/codegen/testing/test/testdata/build-files/gradle/schema.json new file mode 100644 index 00000000000..7e786066dd0 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/gradle/schema.json @@ -0,0 +1,21 @@ +{ + "version": "0.0.1", + "name": "example", + "keywords": [ + "Testing", + "Pulumipus" + ], + "description": "Test the none setting for build-files", + "license": "MIT", + "types": {}, + "readme": "hello this is the readme body.", + "homepage": "https://pulumi.com", + "repository": "https://github.com/pulumi/pulumi", + "resources": {}, + "functions": {}, + "language": { + "java": { + "buildFiles": "gradle" + } + } +} \ No newline at end of file diff --git a/pkg/codegen/testing/test/testdata/build-files/none/java/README.md b/pkg/codegen/testing/test/testdata/build-files/none/java/README.md new file mode 100644 index 00000000000..6b0d347bb27 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/none/java/README.md @@ -0,0 +1 @@ +test description diff --git a/pkg/codegen/testing/test/testdata/build-files/none/java/codegen-manifest.json b/pkg/codegen/testing/test/testdata/build-files/none/java/codegen-manifest.json new file mode 100644 index 00000000000..3f41fd4d816 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/none/java/codegen-manifest.json @@ -0,0 +1,9 @@ +{ + "emittedFiles": [ + "README.md", + "src/main/java/com/pulumi/example/Provider.java", + "src/main/java/com/pulumi/example/ProviderArgs.java", + "src/main/java/com/pulumi/example/Utilities.java", + "src/main/resources/com/pulumi/example/version.txt" + ] +} diff --git a/pkg/codegen/testing/test/testdata/build-files/none/java/src/main/java/com/pulumi/example/Provider.java b/pkg/codegen/testing/test/testdata/build-files/none/java/src/main/java/com/pulumi/example/Provider.java new file mode 100644 index 00000000000..a76332ced95 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/none/java/src/main/java/com/pulumi/example/Provider.java @@ -0,0 +1,54 @@ +// *** WARNING: this file was generated by test. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +package com.pulumi.example; + +import com.pulumi.core.Output; +import com.pulumi.core.annotations.ResourceType; +import com.pulumi.core.internal.Codegen; +import com.pulumi.example.ProviderArgs; +import com.pulumi.example.Utilities; +import javax.annotation.Nullable; + +@ResourceType(type="pulumi:providers:example") +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("example", 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/codegen/testing/test/testdata/build-files/none/java/src/main/java/com/pulumi/example/ProviderArgs.java b/pkg/codegen/testing/test/testdata/build-files/none/java/src/main/java/com/pulumi/example/ProviderArgs.java new file mode 100644 index 00000000000..e07bfe9857d --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/none/java/src/main/java/com/pulumi/example/ProviderArgs.java @@ -0,0 +1,28 @@ +// *** WARNING: this file was generated by test. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +package com.pulumi.example; + + + + +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/codegen/testing/test/testdata/build-files/none/java/src/main/java/com/pulumi/example/Utilities.java b/pkg/codegen/testing/test/testdata/build-files/none/java/src/main/java/com/pulumi/example/Utilities.java new file mode 100644 index 00000000000..f248a63d2b3 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/none/java/src/main/java/com/pulumi/example/Utilities.java @@ -0,0 +1,102 @@ +// *** WARNING: this file was generated by test. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +package com.pulumi.example; + + + + + +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; +import com.pulumi.deployment.InvokeOutputOptions; + +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() + ); + } + + public static InvokeOutputOptions withVersion(@Nullable InvokeOutputOptions options) { + if (options != null && options.getVersion().isPresent()) { + return options; + } + return new InvokeOutputOptions( + options == null ? null : options.getParent().orElse(null), + options == null ? null : options.getProvider().orElse(null), + getVersion(), + options == null ? null : options.getDependsOn() + ); + } + + private static final java.lang.String version; + public static java.lang.String getVersion() { + return version; + } + + static { + var resourceName = "com/pulumi/example/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(); + } +} diff --git a/pkg/codegen/testing/test/testdata/build-files/none/java/src/main/resources/com/pulumi/example/version.txt b/pkg/codegen/testing/test/testdata/build-files/none/java/src/main/resources/com/pulumi/example/version.txt new file mode 100644 index 00000000000..8a9ecc2ea99 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/none/java/src/main/resources/com/pulumi/example/version.txt @@ -0,0 +1 @@ +0.0.1 \ No newline at end of file diff --git a/pkg/codegen/testing/test/testdata/build-files/none/schema.json b/pkg/codegen/testing/test/testdata/build-files/none/schema.json new file mode 100644 index 00000000000..d5d4b9c2257 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/none/schema.json @@ -0,0 +1,21 @@ +{ + "version": "0.0.1", + "name": "example", + "keywords": [ + "Testing", + "Pulumipus" + ], + "description": "Test the none setting for build-files", + "license": "MIT", + "types": {}, + "readme": "hello this is the readme body.", + "homepage": "https://pulumi.com", + "repository": "https://github.com/pulumi/pulumi", + "resources": {}, + "functions": {}, + "language": { + "java": { + "buildFiles": "none" + } + } +} \ No newline at end of file diff --git a/pkg/codegen/testing/test/testdata/build-files/unspecified/java/README.md b/pkg/codegen/testing/test/testdata/build-files/unspecified/java/README.md new file mode 100644 index 00000000000..6b0d347bb27 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/unspecified/java/README.md @@ -0,0 +1 @@ +test description diff --git a/pkg/codegen/testing/test/testdata/build-files/unspecified/java/build.gradle b/pkg/codegen/testing/test/testdata/build-files/unspecified/java/build.gradle new file mode 100644 index 00000000000..f7d8729b951 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/unspecified/java/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") + id("io.github.gradle-nexus.publish-plugin") version "2.0.0" +} + +group = "com.pulumi" + +def resolvedVersion = System.getenv("PACKAGE_VERSION") ?: + (project.version == "unspecified" + ? "0.0.1" + : project.version) + +def signingKey = System.getenv("SIGNING_KEY") +def signingPassword = System.getenv("SIGNING_PASSWORD") +def publishRepoURL = System.getenv("PUBLISH_REPO_URL") ?: "https://s01.oss.sonatype.org" +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 { + 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:0.0.1") +} + +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 builder = new groovy.json.JsonBuilder() + builder { + resource true + name "example" + version resolvedVersion + } + def infoJson = builder.toPrettyString() + new File(outDir, "plugin.json").text = infoJson + } +} + +jar.configure { + dependsOn genPulumiResources +} + +publishing { + publications { + mainPublication(MavenPublication) { + groupId = "com.pulumi" + artifactId = "example" + version = resolvedVersion + from components.java + artifact sourcesJar + artifact javadocJar + + pom { + inceptionYear = "2022" + name = "pulumi-example" + packaging = "jar" + description = "test description" + + url = "https://github.com/pulumi/pulumi-java" + + scm { + connection = "git@github.com/pulumi/pulumi-java.git" + developerConnection = "git@github.com/pulumi/pulumi-java.git" + url = "https://github.com/pulumi/pulumi-java" + } + + licenses { + license { + name = "" + url = "" + } + } + + developers { + developer { + id = "pulumi" + name = "Pulumi" + email = "support@pulumi.com" + } + } + } + } + } +} + +javadoc { + if (JavaVersion.current().isJava9Compatible()) { + options.addBooleanOption('html5', true) + } + options.jFlags("-Xmx8g", "-Xms512m") +} + +jar { + zip64 = true +} + +if (publishRepoUsername) { + nexusPublishing { + repositories { + sonatype { + nexusUrl.set(uri(publishRepoURL + "/service/local/")) + snapshotRepositoryUrl.set(uri(publishRepoURL + "/content/repositories/snapshots/")) + username = publishRepoUsername + password = publishRepoPassword + } + } + } +} + +if (signingKey) { + signing { + useInMemoryPgpKeys(signingKey, signingPassword) + sign publishing.publications.mainPublication + } +} \ No newline at end of file diff --git a/pkg/codegen/testing/test/testdata/build-files/unspecified/java/codegen-manifest.json b/pkg/codegen/testing/test/testdata/build-files/unspecified/java/codegen-manifest.json new file mode 100644 index 00000000000..d73a9826d6c --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/unspecified/java/codegen-manifest.json @@ -0,0 +1,10 @@ +{ + "emittedFiles": [ + "README.md", + "build.gradle", + "settings.gradle", + "src/main/java/com/pulumi/example/Provider.java", + "src/main/java/com/pulumi/example/ProviderArgs.java", + "src/main/java/com/pulumi/example/Utilities.java" + ] +} diff --git a/pkg/codegen/testing/test/testdata/build-files/unspecified/java/settings.gradle b/pkg/codegen/testing/test/testdata/build-files/unspecified/java/settings.gradle new file mode 100644 index 00000000000..a5ad86818fe --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/unspecified/java/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.example" +include("lib") diff --git a/pkg/codegen/testing/test/testdata/build-files/unspecified/java/src/main/java/com/pulumi/example/Provider.java b/pkg/codegen/testing/test/testdata/build-files/unspecified/java/src/main/java/com/pulumi/example/Provider.java new file mode 100644 index 00000000000..a76332ced95 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/unspecified/java/src/main/java/com/pulumi/example/Provider.java @@ -0,0 +1,54 @@ +// *** WARNING: this file was generated by test. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +package com.pulumi.example; + +import com.pulumi.core.Output; +import com.pulumi.core.annotations.ResourceType; +import com.pulumi.core.internal.Codegen; +import com.pulumi.example.ProviderArgs; +import com.pulumi.example.Utilities; +import javax.annotation.Nullable; + +@ResourceType(type="pulumi:providers:example") +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("example", 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/codegen/testing/test/testdata/build-files/unspecified/java/src/main/java/com/pulumi/example/ProviderArgs.java b/pkg/codegen/testing/test/testdata/build-files/unspecified/java/src/main/java/com/pulumi/example/ProviderArgs.java new file mode 100644 index 00000000000..e07bfe9857d --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/unspecified/java/src/main/java/com/pulumi/example/ProviderArgs.java @@ -0,0 +1,28 @@ +// *** WARNING: this file was generated by test. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +package com.pulumi.example; + + + + +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/codegen/testing/test/testdata/build-files/unspecified/java/src/main/java/com/pulumi/example/Utilities.java b/pkg/codegen/testing/test/testdata/build-files/unspecified/java/src/main/java/com/pulumi/example/Utilities.java new file mode 100644 index 00000000000..f248a63d2b3 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/unspecified/java/src/main/java/com/pulumi/example/Utilities.java @@ -0,0 +1,102 @@ +// *** WARNING: this file was generated by test. *** +// *** Do not edit by hand unless you're certain you know what you are doing! *** + +package com.pulumi.example; + + + + + +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; +import com.pulumi.deployment.InvokeOutputOptions; + +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() + ); + } + + public static InvokeOutputOptions withVersion(@Nullable InvokeOutputOptions options) { + if (options != null && options.getVersion().isPresent()) { + return options; + } + return new InvokeOutputOptions( + options == null ? null : options.getParent().orElse(null), + options == null ? null : options.getProvider().orElse(null), + getVersion(), + options == null ? null : options.getDependsOn() + ); + } + + private static final java.lang.String version; + public static java.lang.String getVersion() { + return version; + } + + static { + var resourceName = "com/pulumi/example/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(); + } +} diff --git a/pkg/codegen/testing/test/testdata/build-files/unspecified/schema.json b/pkg/codegen/testing/test/testdata/build-files/unspecified/schema.json new file mode 100644 index 00000000000..d0c2bfad0cd --- /dev/null +++ b/pkg/codegen/testing/test/testdata/build-files/unspecified/schema.json @@ -0,0 +1,19 @@ +{ + "version": "0.0.1", + "name": "example", + "keywords": [ + "Testing", + "Pulumipus" + ], + "description": "Test the none setting for build-files", + "license": "MIT", + "types": {}, + "readme": "hello this is the readme body.", + "homepage": "https://pulumi.com", + "repository": "https://github.com/pulumi/pulumi", + "resources": {}, + "functions": {}, + "language": { + "java": {} + } +} \ No newline at end of file