Skip to content

Commit

Permalink
Exclude Non-Loadable Packages from ClassLoader. Fixes #issue 1385 (#1384
Browse files Browse the repository at this point in the history
)

We encountered an issue with the package loader that loads every package
indiscriminately, instead of using the Maven class loader's smart
loading. This is a known problem, and while some packages have already
been excluded, the process requires a merge request for each exclusion.
Therefore, we identified the need for a faster and more dynamic
exclusion mechanism.

This fix introduces a system property string containing a
comma-separated list of packages to exclude. By setting this property,
the specified packages will be excluded from the loaded packages.

Fixes #1385
  • Loading branch information
andreaspartisia authored Aug 28, 2024
1 parent 55af7cd commit a1ab305
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 3 deletions.
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
Expand Down
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);
}
}

}

0 comments on commit a1ab305

Please sign in to comment.