Skip to content

Commit

Permalink
[program-gen] Fix emitted import statements in generated programs suc…
Browse files Browse the repository at this point in the history
…h that imports with the same symbol are fully qualified (#1573)

### Description

Fix emitted import statements in generated programs such that imports
with the same symbol are fully qualified

if we have two imports such as the following:
- `com.pulumi.my_package.ResourceType`
- `com.pulumi.your_package.ResourceType`

then we shouldn't generate import statements for them instead, we use
the fully qualified name at the usage site.

Unskips `l2-failed-create-continue-on-error`

Fixes #1558
  • Loading branch information
Zaid-Ajaj authored Jan 7, 2025
1 parent eac66c2 commit 784fa7b
Show file tree
Hide file tree
Showing 15 changed files with 733 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### Improvements

- Fix emitted import statements in generated programs such that imports with the same symbol are fully qualified

### Bug Fixes
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 @@ -163,7 +163,6 @@ var expectedFailures = map[string]string{
"l1-output-array": "#1560 Empty array literals are not generated correctly",
"l1-output-map": "#1561 Map literals are not generated correctly",
"l1-output-string": "#1562 Large string literals are not generated correctly",
"l2-failed-create-continue-on-error": "#1558 Duplicate identifiers aren't fully qualified",
"l2-invoke-dependencies": "#1563 Invoke argument and result handling",
"l2-invoke-options": "#1563 Invoke argument and result handling",
"l2-invoke-options-depends-on": "#1563 Invoke argument and result handling",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: l2-failed-create-continue-on-error
runtime: java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?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>l2-failed-create-continue-on-error</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>
<dependency>
<groupId>com.pulumi</groupId>
<artifactId>fail_on_create</artifactId>
<version>4.0.0</version>
</dependency><dependency>
<groupId>com.pulumi</groupId>
<artifactId>simple</artifactId>
<version>2.0.0</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,47 @@
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.resources.CustomResourceOptions;
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) {
var failing = new com.pulumi.fail_on_create.Resource("failing", com.pulumi.fail_on_create.ResourceArgs.builder()
.value(false)
.build());

var dependent = new com.pulumi.simple.Resource("dependent", com.pulumi.simple.ResourceArgs.builder()
.value(true)
.build(), CustomResourceOptions.builder()
.dependsOn(failing)
.build());

var dependent_on_output = new com.pulumi.simple.Resource("dependent_on_output", com.pulumi.simple.ResourceArgs.builder()
.value(failing.value())
.build());

var independent = new com.pulumi.simple.Resource("independent", com.pulumi.simple.ResourceArgs.builder()
.value(true)
.build());

var double_dependency = new com.pulumi.simple.Resource("double_dependency", com.pulumi.simple.ResourceArgs.builder()
.value(true)
.build(), CustomResourceOptions.builder()
.dependsOn(
independent,
dependent_on_output)
.build());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// *** 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"
? "4.0.0"
: 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 {
maven {
url("REPOSITORY")
}
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:CORE.VERSION")
}

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 "fail_on_create"
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 = "fail_on_create"
version = resolvedVersion
from components.java
artifact sourcesJar
artifact javadocJar

pom {
inceptionYear = ""
name = ""
packaging = "jar"
description = " "

url = "https://example.com"

scm {
connection = "https://example.com"
developerConnection = "https://example.com"
url = "https://example.com"
}

licenses {
license {
name = ""
url = ""
}
}

developers {
developer {
id = ""
name = ""
email = ""
}
}
}
}
}

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
}
}
Original file line number Diff line number Diff line change
@@ -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.fail_on_create"
include("lib")
Loading

0 comments on commit 784fa7b

Please sign in to comment.