Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude Non-Loadable Packages from ClassLoader. Fixes #issue 1385 #1384

Merged
merged 10 commits into from
Aug 28, 2024
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion pulumi
Submodule pulumi updated 376 files
41 changes: 40 additions & 1 deletion sdk/java/pulumi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Class<Resource>> 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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,5 @@ public AComponentResource(String type, String name, @Nullable ResourceArgs args,
super(type, name, args, options);
}
}

}