Browse Source

Little formatting

pull/388/head
Decebal Suiu 4 years ago
parent
commit
4d08bc8c51
  1. 41
      pf4j/src/main/java/org/pf4j/ClassLoadingStrategy.java
  2. 20
      pf4j/src/main/java/org/pf4j/PluginClassLoader.java

41
pf4j/src/main/java/org/pf4j/ClassLoadingStrategy.java

@ -20,38 +20,44 @@ import java.util.List;
/** /**
* {@link ClassLoadingStrategy} will be used to configure {@link PluginClassLoader} loading order * {@link ClassLoadingStrategy} will be used to configure {@link PluginClassLoader} loading order
* and contains all possible options supported by {@link PluginClassLoader} where * and contains all possible options supported by {@link PluginClassLoader} where:
* A=Application Source ( load classes from parent classLoader) * {@code
* P=Plugin Source ( load classes from this classloader) * A = Application Source (load classes from parent classLoader)
* D=Dependencies ( load classes from dependencies) * P = Plugin Source (load classes from this classloader)
* D = Dependencies (load classes from dependencies)
* }
*/ */
public class ClassLoadingStrategy { public class ClassLoadingStrategy {
/** /**
* application(parent)->plugin->dependencies * application(parent) -> plugin -> dependencies
*/ */
public static final ClassLoadingStrategy APD = new ClassLoadingStrategy(Arrays.asList(Source.APPLICATION, Source.PLUGIN, Source.DEPENDENCIES)); public static final ClassLoadingStrategy APD = new ClassLoadingStrategy(Arrays.asList(Source.APPLICATION, Source.PLUGIN, Source.DEPENDENCIES));
/** /**
* application(parent)->dependencies->plugin * application(parent) -> dependencies -> plugin
*/ */
public static final ClassLoadingStrategy ADP=new ClassLoadingStrategy(Arrays.asList(Source.APPLICATION,Source.DEPENDENCIES,Source.APPLICATION)); public static final ClassLoadingStrategy ADP = new ClassLoadingStrategy(Arrays.asList(Source.APPLICATION, Source.DEPENDENCIES, Source.APPLICATION));
/** /**
* plugin->application(parent)->dependencies * plugin -> application(parent) -> dependencies
*/ */
public static final ClassLoadingStrategy PAD=new ClassLoadingStrategy(Arrays.asList(Source.PLUGIN,Source.APPLICATION,Source.DEPENDENCIES)); public static final ClassLoadingStrategy PAD = new ClassLoadingStrategy(Arrays.asList(Source.PLUGIN, Source.APPLICATION, Source.DEPENDENCIES));
/** /**
* dependencies->application(parent)->plugin * dependencies -> application(parent) -> plugin
*/ */
public static final ClassLoadingStrategy DAP=new ClassLoadingStrategy(Arrays.asList(Source.DEPENDENCIES,Source.APPLICATION,Source.PLUGIN)); public static final ClassLoadingStrategy DAP = new ClassLoadingStrategy(Arrays.asList(Source.DEPENDENCIES, Source.APPLICATION, Source.PLUGIN));
/** /**
* dependencies->plugin->application(parent) * dependencies -> plugin -> application(parent)
*/ */
public static final ClassLoadingStrategy DPA=new ClassLoadingStrategy(Arrays.asList(Source.DEPENDENCIES,Source.PLUGIN,Source.APPLICATION)); public static final ClassLoadingStrategy DPA = new ClassLoadingStrategy(Arrays.asList(Source.DEPENDENCIES, Source.PLUGIN, Source.APPLICATION));
/** /**
* plugin->dependencies->application(parent) * plugin -> dependencies -> application(parent)
*/ */
public static final ClassLoadingStrategy PDA =new ClassLoadingStrategy(Arrays.asList(Source.PLUGIN, Source.DEPENDENCIES, Source.APPLICATION)); public static final ClassLoadingStrategy PDA = new ClassLoadingStrategy(Arrays.asList(Source.PLUGIN, Source.DEPENDENCIES, Source.APPLICATION));
private final List<Source> sources; private final List<Source> sources;
@ -64,6 +70,7 @@ public class ClassLoadingStrategy {
} }
public enum Source { public enum Source {
PLUGIN, APPLICATION,DEPENDENCIES; PLUGIN, APPLICATION, DEPENDENCIES;
} }
} }

20
pf4j/src/main/java/org/pf4j/PluginClassLoader.java

@ -62,7 +62,6 @@ public class PluginClassLoader extends URLClassLoader {
this(pluginManager, pluginDescriptor, parent, parentFirst ? ClassLoadingStrategy.APD : ClassLoadingStrategy.PDA); this(pluginManager, pluginDescriptor, parent, parentFirst ? ClassLoadingStrategy.APD : ClassLoadingStrategy.PDA);
} }
/** /**
* classloading according to {@code classLoadingStrategy} * classloading according to {@code classLoadingStrategy}
*/ */
@ -117,6 +116,7 @@ public class PluginClassLoader extends URLClassLoader {
log.trace("Found loaded class '{}'", className); log.trace("Found loaded class '{}'", className);
return loadedClass; return loadedClass;
} }
for (ClassLoadingStrategy.Source classLoadingSource : classLoadingStrategy.getSources()) { for (ClassLoadingStrategy.Source classLoadingSource : classLoadingStrategy.getSources()) {
Class<?> c = null; Class<?> c = null;
try { try {
@ -131,17 +131,16 @@ public class PluginClassLoader extends URLClassLoader {
c = loadClassFromDependencies(className); c = loadClassFromDependencies(className);
break; break;
} }
} catch (ClassNotFoundException ignored) { } catch (ClassNotFoundException ignored) {}
}
if (c != null) { if (c != null) {
log.trace("Found class '{}' in {} classpath", className,classLoadingSource); log.trace("Found class '{}' in {} classpath", className, classLoadingSource);
return c; return c;
} else { } else {
log.trace("Couldn't find class '{}' in {} classpath", className,classLoadingSource); log.trace("Couldn't find class '{}' in {} classpath", className, classLoadingSource);
} }
} }
throw new ClassNotFoundException(className); throw new ClassNotFoundException(className);
} }
} }
@ -170,15 +169,16 @@ public class PluginClassLoader extends URLClassLoader {
url = findResourceFromDependencies(name); url = findResourceFromDependencies(name);
break; break;
} }
if (url != null) { if (url != null) {
log.trace("Found resource '{}' in {} classpath", name,classLoadingSource); log.trace("Found resource '{}' in {} classpath", name, classLoadingSource);
return url; return url;
} else { } else {
log.trace("Couldn't find resource '{}' in {}.", name,classLoadingSource); log.trace("Couldn't find resource '{}' in {}", name, classLoadingSource);
} }
} }
return null;
return null;
} }
@Override @Override
@ -201,8 +201,8 @@ public class PluginClassLoader extends URLClassLoader {
break; break;
} }
} }
return Collections.enumeration(resources);
return Collections.enumeration(resources);
} }
protected Class<?> loadClassFromDependencies(String className) { protected Class<?> loadClassFromDependencies(String className) {

Loading…
Cancel
Save