< prev index next >
src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludePlugin.java
Print this page
@@ -25,10 +25,11 @@
package jdk.tools.jlink.internal.plugins;
import java.util.Map;
import java.util.function.Predicate;
import jdk.tools.jlink.plugin.Plugin;
+import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
import jdk.tools.jlink.plugin.ResourcePoolEntry;
/**
@@ -47,11 +48,17 @@
@Override
public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) {
in.transformAndCopy((resource) -> {
if (resource.type().equals(ResourcePoolEntry.Type.CLASS_OR_RESOURCE)) {
- resource = predicate.test(resource.path()) ? resource : null;
+ boolean shouldExclude = !predicate.test(resource.path());
+ // do not allow filtering module-info.class to avoid mutating module graph.
+ if (shouldExclude &&
+ resource.path().equals("/" + resource.moduleName() + "/module-info.class")) {
+ throw new PluginException("Cannot exclude " + resource.path());
+ }
+ return shouldExclude? null : resource;
}
return resource;
}, out);
return out.build();
}
< prev index next >