Skip to content

Commit

Permalink
[fix][*][*]: incorrect version and load class with prefix `com.alipay…
Browse files Browse the repository at this point in the history
….antchain.bridge.plugins.spi&commons` and `org.slf4j` from AppClzLoader instead of plugin clz loader
  • Loading branch information
zouxyan committed Apr 11, 2024
1 parent 5b4ce04 commit 575c5c6
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 6 deletions.
2 changes: 1 addition & 1 deletion antchain-bridge-bcdns/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>antchain-bridge-bcdns</artifactId>
<version>0.2.3</version>
<version>0.2.2</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
2 changes: 1 addition & 1 deletion antchain-bridge-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>antchain-bridge-commons</artifactId>
<version>0.2.3</version>
<version>0.2.2</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
2 changes: 1 addition & 1 deletion antchain-bridge-plugin-lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>antchain-bridge-plugin-lib</artifactId>
<version>0.2.3</version>
<version>0.2.2</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
2 changes: 1 addition & 1 deletion antchain-bridge-plugin-manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>antchain-bridge-plugin-manager</artifactId>
<version>0.2.3</version>
<version>0.2.2</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,21 @@
import org.pf4j.PluginClassLoader;
import org.pf4j.PluginDescriptor;
import org.pf4j.PluginManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PrefixBannedPluginClassloader extends PluginClassLoader {

private static final Logger log = LoggerFactory.getLogger(PrefixBannedPluginClassloader.class);

private static final String JAVA_PACKAGE_PREFIX = "java.";

private static final String PLUGIN_PACKAGE_PREFIX = "org.pf4j.";

private static final String ACB_SPI_PACKAGE_PREFIX = "com.alipay.antchain.bridge.plugins.spi";

private static final String ACB_COMMONS_PACKAGE_PREFIX = "com.alipay.antchain.bridge.plugins.commons";

/**
* Banned the dependency with the prefix path to read the resource
*/
Expand Down Expand Up @@ -134,4 +142,61 @@ public Enumeration<URL> getResources(String name) throws IOException {

return Collections.enumeration(resources);
}

@Override
public Class<?> loadClass(String className) throws ClassNotFoundException {
synchronized (getClassLoadingLock(className)) {
// first check whether it's a system class, delegate to the system loader
if (className.startsWith(JAVA_PACKAGE_PREFIX)) {
return findSystemClass(className);
}

// if the class is part of the plugin engine use parent class loader
if (
(className.startsWith(PLUGIN_PACKAGE_PREFIX) && !className.startsWith("org.pf4j.demo") && !className.startsWith("org.pf4j.test")) ||
className.startsWith(ACB_SPI_PACKAGE_PREFIX) ||
className.startsWith(ACB_COMMONS_PACKAGE_PREFIX) ||
className.startsWith("org.slf4j.")
) {
// log.trace("Delegate the loading of PF4J class '{}' to parent", className);
return getParent().loadClass(className);
}

log.trace("Received request to load class '{}'", className);

// second check whether it's already been loaded
Class<?> loadedClass = findLoadedClass(className);
if (loadedClass != null) {
log.trace("Found loaded class '{}'", className);
return loadedClass;
}

for (ClassLoadingStrategy.Source classLoadingSource : classLoadingStrategy.getSources()) {
Class<?> c = null;
try {
switch (classLoadingSource) {
case APPLICATION:
c = super.loadClass(className);
break;
case PLUGIN:
c = findClass(className);
break;
case DEPENDENCIES:
c = loadClassFromDependencies(className);
break;
}
} catch (ClassNotFoundException ignored) {
}

if (c != null) {
log.trace("Found class '{}' in {} classpath", className, classLoadingSource);
return c;
} else {
log.trace("Couldn't find class '{}' in {} classpath", className, classLoadingSource);
}
}

throw new ClassNotFoundException(className);
}
}
}
2 changes: 1 addition & 1 deletion antchain-bridge-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>antchain-bridge-spi</artifactId>
<version>0.2.3</version>
<version>0.2.2</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<packaging>pom</packaging>
<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>antchain-bridge-sdk</artifactId>
<version>0.2.3</version>
<version>0.2.2</version>

<modules>
<module>antchain-bridge-commons</module>
Expand Down

0 comments on commit 575c5c6

Please sign in to comment.