Skip to content

Commit

Permalink
Fix the language plugin to return a version
Browse files Browse the repository at this point in the history
This change fixes `pulumi about` to show the real version instead of `unknown` for the java language plugin.

The fix updates `GetPluginInfo` to return the `Version` from the right `version` Go package—the one that's actually being set during build via `ldflags` (`"github.com/pulumi/pulumi-java/pkg/version"` instead of `"github.com/pulumi/pulumi/sdk/v3/go/common/version"`).
  • Loading branch information
justinvp committed Dec 6, 2024
1 parent b229e09 commit b8b8052
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@

- Update `io.github.gradle-nexus.publish-plugin` to 2.0.0 from 1.1.0.

### Bug Fixes
### Bug Fixes

- Fix the language plugin to return a version
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ test_go:: build_go submodule_update

bin/pulumi-language-java: ${PKG_FILES}
mkdir -p bin
cd pkg && go build -o ../bin github.com/pulumi/pulumi-java/pkg/cmd/pulumi-language-java
cd pkg && go build -o ../bin \
-ldflags "-X github.com/pulumi/pulumi-java/pkg/version.Version=$(shell pulumictl get version --tag-pattern '^pkg')" \
github.com/pulumi/pulumi-java/pkg/cmd/pulumi-language-java

bin/pulumi-java-gen: ${PKG_FILES}
mkdir -p bin
cd pkg && go build -o ../bin -ldflags "-X github.com/pulumi/pulumi-java/pkg/version.Version=$(shell pulumictl get version --tag-pattern '^pkg')" github.com/pulumi/pulumi-java/pkg/cmd/pulumi-java-gen
cd pkg && go build -o ../bin \
-ldflags "-X github.com/pulumi/pulumi-java/pkg/version.Version=$(shell pulumictl get version --tag-pattern '^pkg')" \
github.com/pulumi/pulumi-java/pkg/cmd/pulumi-java-gen

# Java SDK is a gradle project rooted at `sdk/java`

Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/pulumi-language-java/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

pbempty "github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"
hclsyntax "github.com/pulumi/pulumi/pkg/v3/codegen/hcl2/syntax"
"github.com/pulumi/pulumi/pkg/v3/codegen/pcl"
"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
Expand All @@ -29,7 +30,6 @@ import (
"github.com/pulumi/pulumi/sdk/v3/go/common/util/fsutil"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/logging"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/rpcutil"
"github.com/pulumi/pulumi/sdk/v3/go/common/version"
"github.com/pulumi/pulumi/sdk/v3/go/common/workspace"
pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go"
"golang.org/x/exp/maps"
Expand All @@ -40,7 +40,7 @@ import (
codegen "github.com/pulumi/pulumi-java/pkg/codegen/java"
"github.com/pulumi/pulumi-java/pkg/internal/executors"
"github.com/pulumi/pulumi-java/pkg/internal/fsys"
hclsyntax "github.com/pulumi/pulumi/pkg/v3/codegen/hcl2/syntax"
"github.com/pulumi/pulumi-java/pkg/version"
)

// Launches the language host RPC endpoint, which in turn fires up an RPC server implementing the
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/about/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: about
description: An empty project
runtime: java
112 changes: 112 additions & 0 deletions tests/integration/about/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?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.example</groupId>
<artifactId>about</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>${project.groupId}.${project.artifactId}.App</mainClass>
<mainArgs/>
<pulumiSdkVersion>0.0.1</pulumiSdkVersion>
</properties>

<profiles>
<profile>
<id>env-dependencies</id>
<activation>
<property>
<name>env.PULUMI_JAVA_SDK_VERSION</name>
</property>
</activation>
<properties>
<pulumiSdkVersion>${env.PULUMI_JAVA_SDK_VERSION}</pulumiSdkVersion>
</properties>
</profile>
</profiles>

<dependencies>
<dependency>
<groupId>com.pulumi</groupId>
<artifactId>pulumi</artifactId>
<version>${pulumiSdkVersion}</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>com.pulumi</groupId>
<artifactId>random</artifactId>
<version>4.8.1</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.3.0</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.0.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.0</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,12 @@
package com.pulumi.example.about;

import com.pulumi.Pulumi;
import com.pulumi.core.Output;

public class App {
public static void main(String[] args) {
Pulumi.run(ctx -> {
ctx.export("exampleOutput", Output.of("example"));
});
}
}
15 changes: 15 additions & 0 deletions tests/integration/java_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,25 @@ import (

"github.com/pulumi/pulumi/pkg/v3/testing/integration"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
ptesting "github.com/pulumi/pulumi/sdk/v3/go/common/testing"
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
)

func TestIntegrations(t *testing.T) {
t.Run("about", func(t *testing.T) {
t.Parallel()

e := ptesting.NewEnvironment(t)
defer e.DeleteIfNotFailed()

e.ImportDirectory(filepath.Join(getCwd(t), "about"))

stdout, stderr := e.RunCommand("pulumi", "about")
// There should be no "unknown" plugin versions.
assert.NotContains(t, stdout, "unknown")
assert.NotContains(t, stderr, "unknown")
})

t.Run("stack-reference", func(t *testing.T) {
dir := filepath.Join(getCwd(t), "stack-reference")
test := getJavaBase(t, integration.ProgramTestOptions{
Expand Down

0 comments on commit b8b8052

Please sign in to comment.