Skip to content

Commit

Permalink
Unskip the l1-main test
Browse files Browse the repository at this point in the history
This change fixes the Java language host to respect the `main:` property in
`Pulumi.yaml` files. This allows us to unskip the `l1-main` test, which
exercises this functionality and now passes.
  • Loading branch information
lunaris committed Jan 3, 2025
1 parent a65c5e3 commit a943ef1
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 7 deletions.
1 change: 0 additions & 1 deletion pkg/cmd/pulumi-language-java/language_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: l1-main
runtime: java
main: subdir
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.pulumi</groupId>
<artifactId>l1-main</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<encoding>UTF-8</encoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
<mainClass>generated_program.App</mainClass>
<mainArgs/>
</properties>

<repositories>
<repository>
<id>repository-0</id>
<url>REPOSITORY</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.pulumi</groupId>
<artifactId>pulumi</artifactId>
<version>CORE.VERSION</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<mainClass>${mainClass}</mainClass>
<commandlineArgs>${mainArgs}</commandlineArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-wrapper-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<mavenVersion>3.8.5</mavenVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -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);
}
}
22 changes: 16 additions & 6 deletions pkg/codegen/java/gen_program.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"os"
"path"
"path/filepath"
"slices"
"strings"

Expand Down Expand Up @@ -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)
Expand All @@ -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
}

Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit a943ef1

Please sign in to comment.