Skip to content

Commit 5b9364a

Browse files
Add Java gen as a bridge functionality (#3184)
This pull request adds the ability to generate the Java SDK via `pulumi-tfgen-foo --java`. It additionally introduces a breaking change to the `info.Java` struct by adding an `Overlay` field. I believe this is a breaking change we can afford to take, as the struct already advertises that its use is for overlay functionality, but this was never implemented. We can also choose to not support overlays via the bridge for Java for now, since I'm unaware of any of our bridged providers having them. Sample changes for pulumi-random: pulumi/pulumi-random#1863 Sample changes in pulumi-aws (warning; very noisy, as the autogenerated-file-warning has changed): pulumi/pulumi-aws#5817 TL;DR: - We see a new, empty `Pulumi.yaml` file, same as for the other SDKs - Autogenerated warning has changed - A nice bonus: Java inline docs no longer emit spurious PulumiCodeChooser tags, as the bridge filters that for us now. - Functional code remains the same --- - **Add Java as a valid bridge language for SDK generation** - **Add overlay info for Java** Fixes #3183
1 parent 98cdec5 commit 5b9364a

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

pkg/tfbridge/info/info.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -914,11 +914,10 @@ type CSharp struct {
914914
RespectSchemaVersion bool
915915
}
916916

917-
// See https://github.com/pulumi/pulumi-java/blob/main/pkg/codegen/java/package_info.go#L35C1-L108C1 documenting
918-
// supported options.
917+
// Java contains optional overlay information for Java code-generation.
919918
type Java struct {
920-
BasePackage string // the Base package for the Java SDK
921-
919+
BasePackage string // the Base package for the Java SDK
920+
Overlay *Overlay // optional overlay information for augmented code-generation.
922921
// If set to "gradle" enables a generation of a basic set of
923922
// Gradle build files.
924923
BuildFiles string

pkg/tfgen/docs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,8 @@ func genLanguageToSlice(input Language) []string {
20312031
return []string{convert.LanguageCSharp}
20322032
case Golang:
20332033
return []string{convert.LanguageGo}
2034+
case Java:
2035+
return []string{convert.LanguageJava}
20342036
case PCL:
20352037
return []string{convert.LanguagePulumi}
20362038
case Schema, RegistryDocs:

pkg/tfgen/generate.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ const (
9191
NodeJS Language = "nodejs"
9292
Python Language = "python"
9393
CSharp Language = "dotnet"
94+
Java Language = "java"
9495
Schema Language = "schema"
9596
PCL Language = "pulumi"
9697
// RegistryDocs
@@ -105,7 +106,7 @@ const (
105106

106107
func (l Language) shouldConvertExamples() bool {
107108
switch l {
108-
case Golang, NodeJS, Python, CSharp, Schema, PCL:
109+
case Golang, NodeJS, Python, CSharp, Java, Schema, PCL:
109110
return true
110111
}
111112
return false
@@ -292,12 +293,25 @@ func (l Language) emitSDK(pkg *pschema.Package, info tfbridge.ProviderInfo, root
292293
return nil, err
293294
}
294295
return runPulumiPackageGenSDK(l, pkg, extraFiles)
296+
case Java:
297+
if psi := info.Java; psi != nil && psi.Overlay != nil {
298+
extraFiles, err = getOverlayFiles(psi.Overlay, ".java", root)
299+
if err != nil {
300+
return nil, err
301+
}
302+
}
303+
err = cleanDir(root, "", nil)
304+
if err != nil && !os.IsNotExist(err) {
305+
return nil, err
306+
}
307+
return runPulumiPackageGenSDK(l, pkg, extraFiles)
308+
295309
default:
296310
return nil, fmt.Errorf("%v does not support SDK generation", l)
297311
}
298312
}
299313

300-
var AllLanguages = []Language{Golang, NodeJS, Python, CSharp}
314+
var AllSDKLanguages = []Language{Golang, NodeJS, Python, CSharp, Java}
301315

302316
// pkg is a directory containing one or more modules.
303317
type pkg struct {
@@ -935,7 +949,7 @@ func NewGenerator(opts GeneratorOptions) (*Generator, error) {
935949

936950
// Ensure the language is valid.
937951
switch lang {
938-
case Golang, NodeJS, Python, CSharp, Schema, PCL, RegistryDocs:
952+
case Golang, NodeJS, Python, CSharp, Java, Schema, PCL, RegistryDocs:
939953
// OK
940954
default:
941955
return nil, fmt.Errorf("unrecognized language runtime: %s", lang)
@@ -1745,6 +1759,10 @@ func (g *Generator) gatherOverlays() (moduleMap, error) {
17451759
if csharpinfo := g.info.CSharp; csharpinfo != nil {
17461760
overlay = csharpinfo.Overlay
17471761
}
1762+
case Java:
1763+
if javainfo := g.info.Java; javainfo != nil {
1764+
overlay = javainfo.Overlay
1765+
}
17481766
case Schema, PCL, RegistryDocs:
17491767
// N/A
17501768
default:

pkg/tfgen/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func newTFGenCmd(pkg string, version string, prov tfbridge.ProviderInfo,
8989
"and generate all of the Pulumi metadata necessary to consume the resources.\n" +
9090
"\n" +
9191
"<LANGUAGE> indicates which language/runtime to target; the current supported set of\n" +
92-
"languages is " + fmt.Sprintf("%v", AllLanguages) + ".\n" +
92+
"languages is " + fmt.Sprintf("%v", AllSDKLanguages) + ".\n" +
9393
"\n" +
9494
"Note that there is no custom Pulumi provider code required, because the generated\n" +
9595
"provider plugin is metadata-driven and thus works against all Terraform providers.\n",

0 commit comments

Comments
 (0)