diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 9403bdf3401..e9284a6a64e 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -1,5 +1,7 @@ ### Improvements +- Classloader: now supports dynamic exclusions of packages from system property. + ### Bug Fixes - Fix HTML escaping after `{@literal ...}` blocks in Javadocs \ No newline at end of file diff --git a/pulumi b/pulumi index 1416a34e69e..487b4a8494e 160000 --- a/pulumi +++ b/pulumi @@ -1 +1 @@ -Subproject commit 1416a34e69e6939b7e2ff1415e247a8ac52342de +Subproject commit 487b4a8494ef556063aaf8335e6bad6317bb1072 diff --git a/sdk/java/pulumi/build.gradle b/sdk/java/pulumi/build.gradle index 901d65d17ea..ece6630ae3b 100644 --- a/sdk/java/pulumi/build.gradle +++ b/sdk/java/pulumi/build.gradle @@ -121,8 +121,17 @@ sourceSets { } } -test { +task isolatedTest(type: Test) { useJUnitPlatform() + + // Include only the specific test class you want to run in isolation + include '**/ResourcePackagesIsolatedTest.class' + + // Fork a new JVM process for this specific test + forkEvery = 1 + maxParallelForks = 1 + + // Set up test logging if needed testLogging { showStandardStreams = true exceptionFormat = 'full' @@ -142,6 +151,36 @@ test { systemProperty 'java.util.logging.config.file', "${projectDir}/src/test/resources/logging.properties" } +test { + useJUnitPlatform() + + // Run general tests, excluding the isolated test + filter { + excludeTestsMatching "com.pulumi.serialization.internal.ResourcePackagesIsolatedTest" + } + + testLogging { + showStandardStreams = true + exceptionFormat = 'full' + + events = ['failed'] + + info { + events = ['failed', 'skipped'] + } + + debug { + events = ['started', 'skipped', 'failed'] + } + } + + systemProperty 'java.util.logging.config.file', "${projectDir}/src/test/resources/logging.properties" + + // Ensure isolatedTest runs after the main tests + finalizedBy isolatedTest +} + + def ossrhUsername = project.findProperty("ossrhUsername") ?: System.getenv("OSSRH_USERNAME") def ossrhPassword = project.findProperty("ossrhPassword") ?: System.getenv("OSSRH_PASSWORD") diff --git a/sdk/java/pulumi/src/main/java/com/pulumi/serialization/internal/ResourcePackages.java b/sdk/java/pulumi/src/main/java/com/pulumi/serialization/internal/ResourcePackages.java index 2bc119af858..197f7b9cd5f 100644 --- a/sdk/java/pulumi/src/main/java/com/pulumi/serialization/internal/ResourcePackages.java +++ b/sdk/java/pulumi/src/main/java/com/pulumi/serialization/internal/ResourcePackages.java @@ -158,7 +158,21 @@ private static boolean excludePackages(ClassInfo c) { && !c.getPackageName().equals("net.bytebuddy") && !c.getPackageName().startsWith("net.bytebuddy.") && !c.getPackageName().startsWith(Resource.class.getPackageName()) - && !c.getPackageName().startsWith(EngineGrpc.class.getPackageName()); + && !c.getPackageName().startsWith(EngineGrpc.class.getPackageName()) + && !excludePackagesFromProperties(c); + } + + private static boolean excludePackagesFromProperties(ClassInfo c) { + String packages = System.getProperty("pulumi.resourcepackages.excludes"); + if (packages != null) { + String[] items = packages.split(","); + for (String item: items){ + if (c.getPackageName().startsWith(item)) { + return true; + } + } + } + return false; } public ResourcePackages(Log log) { diff --git a/sdk/java/pulumi/src/test/java/com/pulumi/serialization/internal/ResourcePackagesIsolatedTest.java b/sdk/java/pulumi/src/test/java/com/pulumi/serialization/internal/ResourcePackagesIsolatedTest.java new file mode 100644 index 00000000000..238d3aad2bd --- /dev/null +++ b/sdk/java/pulumi/src/test/java/com/pulumi/serialization/internal/ResourcePackagesIsolatedTest.java @@ -0,0 +1,46 @@ +package com.pulumi.serialization.internal; + +import com.pulumi.Log; +import org.junit.jupiter.api.Test; +import java.util.Optional; +import com.pulumi.core.annotations.ResourceType; +import com.pulumi.resources.ComponentResource; +import com.pulumi.resources.ComponentResourceOptions; +import com.pulumi.resources.Resource; +import com.pulumi.resources.ResourceArgs; + +import javax.annotation.Nullable; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + + + +public class ResourcePackagesIsolatedTest { + + @Test + void ExcludedResource() { + try { + System.setProperty("pulumi.resourcepackages.excludes", ResourcePackagesIsolatedTest.ExcludedResource.class.getPackageName()); + var resourcePackages = new ResourcePackages(Log.ignore()); + Optional> resourceType = resourcePackages.tryGetResourceType("test-excludePackages:index/ExcludedResource", null); + + if (resourceType.isPresent()) { + fail("Test resource was found"); + } else { + assertThat(resourceType).isNotPresent(); + } + } finally { + // Clear the system property after the test + System.clearProperty("pulumi.resourcepackages.excludes"); + } + } + + @ResourceType(type = "test-excludePackages:index/ExcludedResource") + private static class ExcludedResource extends ComponentResource { + public ExcludedResource(String type, String name, @Nullable ResourceArgs args, @Nullable ComponentResourceOptions options) { + super(type, name, args, options); + } + } + +} diff --git a/sdk/java/pulumi/src/test/java/com/pulumi/serialization/internal/ResourcePackagesTest.java b/sdk/java/pulumi/src/test/java/com/pulumi/serialization/internal/ResourcePackagesTest.java index d57dad630a2..cff02215526 100644 --- a/sdk/java/pulumi/src/test/java/com/pulumi/serialization/internal/ResourcePackagesTest.java +++ b/sdk/java/pulumi/src/test/java/com/pulumi/serialization/internal/ResourcePackagesTest.java @@ -122,4 +122,5 @@ public AComponentResource(String type, String name, @Nullable ResourceArgs args, super(type, name, args, options); } } + }