diff --git a/pkg/cmd/pulumi-language-java/language_test.go b/pkg/cmd/pulumi-language-java/language_test.go index 57df49465eb..89e2c6b57a6 100644 --- a/pkg/cmd/pulumi-language-java/language_test.go +++ b/pkg/cmd/pulumi-language-java/language_test.go @@ -160,7 +160,6 @@ func TestLanguage(t *testing.T) { // expectedFailures maps the set of conformance tests we expect to fail to reasons they currently do so, so that we may // skip them with an informative message until they are fixed. var expectedFailures = map[string]string{ - "l1-main": "unimplemented for Java", "l1-output-array": "unimplemented for Java", "l1-output-map": "unimplemented for Java", "l1-output-string": "unimplemented for Java", diff --git a/pkg/cmd/pulumi-language-java/testdata/projects/l1-main/Pulumi.yaml b/pkg/cmd/pulumi-language-java/testdata/projects/l1-main/Pulumi.yaml new file mode 100644 index 00000000000..d92b854445f --- /dev/null +++ b/pkg/cmd/pulumi-language-java/testdata/projects/l1-main/Pulumi.yaml @@ -0,0 +1,3 @@ +name: l1-main +runtime: java +main: subdir diff --git a/pkg/cmd/pulumi-language-java/testdata/projects/l1-main/subdir/pom.xml b/pkg/cmd/pulumi-language-java/testdata/projects/l1-main/subdir/pom.xml new file mode 100644 index 00000000000..1d7ca6a96ba --- /dev/null +++ b/pkg/cmd/pulumi-language-java/testdata/projects/l1-main/subdir/pom.xml @@ -0,0 +1,95 @@ + + + 4.0.0 + + com.pulumi + l1-main + 1.0-SNAPSHOT + + + UTF-8 + 11 + 11 + 11 + generated_program.App + + + + + + repository-0 + REPOSITORY + + + + + + com.pulumi + pulumi + CORE.VERSION + + + + + + + + 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/l1-main/subdir/src/main/java/generated_program/App.java b/pkg/cmd/pulumi-language-java/testdata/projects/l1-main/subdir/src/main/java/generated_program/App.java new file mode 100644 index 00000000000..a9b1b164966 --- /dev/null +++ b/pkg/cmd/pulumi-language-java/testdata/projects/l1-main/subdir/src/main/java/generated_program/App.java @@ -0,0 +1,21 @@ +package generated_program; + +import com.pulumi.Context; +import com.pulumi.Pulumi; +import com.pulumi.core.Output; +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) { + ctx.export("output_true", true); + } +} diff --git a/pkg/codegen/java/gen_program.go b/pkg/codegen/java/gen_program.go index 020a99f49a8..8194cf7f94d 100644 --- a/pkg/codegen/java/gen_program.go +++ b/pkg/codegen/java/gen_program.go @@ -9,6 +9,7 @@ import ( "io" "os" "path" + "path/filepath" "slices" "strings" @@ -225,6 +226,16 @@ func GenerateProject( return diagnostics } + rootDirectory := directory + if project.Main != "" { + directory = filepath.Join(rootDirectory, project.Main) + // mkdir -p the subdirectory + err = os.MkdirAll(directory, 0o700) + if err != nil { + return fmt.Errorf("create main directory: %w", err) + } + } + // Set the runtime to "java" then marshal to Pulumi.yaml project.Runtime = workspace.NewProjectRuntimeInfo("java", nil) projectBytes, err := encoding.YAML.Marshal(project) @@ -234,13 +245,13 @@ func GenerateProject( filesWithPackages := make(map[string][]byte) - filesWithPackages["Pulumi.yaml"] = projectBytes + filesWithPackages[filepath.Join(rootDirectory, "Pulumi.yaml")] = projectBytes for fileName, fileContents := range files { if fileName == "MyStack.java" { fileName = "App.java" } - fileWithPackage := fmt.Sprintf("src/main/java/generated_program/%s", fileName) + fileWithPackage := filepath.Join(directory, "src", "main", "java", "generated_program", fileName) filesWithPackages[fileWithPackage] = fileContents } @@ -407,15 +418,14 @@ func GenerateProject( coreSDKVersion, mavenDependenciesXML.String(), )) - filesWithPackages["pom.xml"] = mavenPomXML.Bytes() + filesWithPackages[filepath.Join(directory, "pom.xml")] = mavenPomXML.Bytes() for filePath, data := range filesWithPackages { - outPath := path.Join(directory, filePath) - err := os.MkdirAll(path.Dir(outPath), os.ModePerm) + err := os.MkdirAll(path.Dir(filePath), os.ModePerm) if err != nil { return fmt.Errorf("could not write output program: %w", err) } - err = os.WriteFile(outPath, data, 0o600) + err = os.WriteFile(filePath, data, 0o600) if err != nil { return fmt.Errorf("could not write output program: %w", err) }