Browse Source

Formatting

pull/219/head
Decebal Suiu 7 years ago
parent
commit
f80bc959c1
  1. 18
      pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java
  2. 6
      pf4j/src/main/java/org/pf4j/DefaultExtensionFactory.java
  3. 18
      pf4j/src/main/java/org/pf4j/ExtensionWrapper.java

18
pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java

@ -46,8 +46,8 @@ public abstract class AbstractExtensionFinder implements ExtensionFinder, Plugin
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> List<ExtensionWrapper<T>> find(Class<T> type) { public <T> List<ExtensionWrapper<T>> find(Class<T> type) {
log.debug("Finding extensions of extension point '{}'", type.getName()); log.debug("Finding extensions of extension point '{}'", type.getName());
Map<String, Set<String>> entries = getEntries(); Map<String, Set<String>> entries = getEntries();
List<ExtensionWrapper<T>> result = new ArrayList<>(); List<ExtensionWrapper<T>> result = new ArrayList<>();
@ -59,16 +59,16 @@ public abstract class AbstractExtensionFinder implements ExtensionFinder, Plugin
} }
if (entries.isEmpty()) { if (entries.isEmpty()) {
log.debug("No extensions found for extension point '{}'", type.getName()); log.debug("No extensions found for extension point '{}'", type.getName());
} else { } else {
log.debug("Found {} extensions for extension point '{}'", result.size(), type.getName()); log.debug("Found {} extensions for extension point '{}'", result.size(), type.getName());
} }
// sort by "ordinal" property // sort by "ordinal" property
Collections.sort(result); Collections.sort(result);
return result; return result;
} }
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -129,11 +129,11 @@ public abstract class AbstractExtensionFinder implements ExtensionFinder, Plugin
} }
@Override @Override
public List<ExtensionWrapper> find(String pluginId) { public List<ExtensionWrapper> find(String pluginId) {
log.debug("Finding extensions from plugin '{}'", pluginId); log.debug("Finding extensions from plugin '{}'", pluginId);
List<ExtensionWrapper> result = new ArrayList<>(); List<ExtensionWrapper> result = new ArrayList<>();
Set<String> classNames = findClassNames(pluginId); Set<String> classNames = findClassNames(pluginId);
if (classNames.isEmpty()) { if (classNames.isEmpty()) {
return result; return result;
} }
@ -182,7 +182,7 @@ public abstract class AbstractExtensionFinder implements ExtensionFinder, Plugin
} }
@Override @Override
public void pluginStateChanged(PluginStateEvent event) { public void pluginStateChanged(PluginStateEvent event) {
// TODO optimize (do only for some transitions) // TODO optimize (do only for some transitions)
// clear cache // clear cache
entries = null; entries = null;

6
pf4j/src/main/java/org/pf4j/DefaultExtensionFactory.java

@ -19,8 +19,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The default implementation for ExtensionFactory. * The default implementation for {@link ExtensionFactory}.
* It uses Class.newInstance() method. * It uses {@link Class#newInstance} method.
* *
* @author Decebal Suiu * @author Decebal Suiu
*/ */
@ -29,7 +29,7 @@ public class DefaultExtensionFactory implements ExtensionFactory {
private static final Logger log = LoggerFactory.getLogger(DefaultExtensionFactory.class); private static final Logger log = LoggerFactory.getLogger(DefaultExtensionFactory.class);
/** /**
* Creates an extension instance. If an error occurs than that error is logged and the method returns null. * Creates an extension instance. If an error occurs than that error is logged and the method returns {@code null}.
* @param extensionClass * @param extensionClass
* @return * @return
*/ */

18
pf4j/src/main/java/org/pf4j/ExtensionWrapper.java

@ -26,31 +26,31 @@ public class ExtensionWrapper<T> implements Comparable<ExtensionWrapper<T>> {
private final ExtensionFactory extensionFactory; private final ExtensionFactory extensionFactory;
private T extension; // cache private T extension; // cache
public ExtensionWrapper(ExtensionDescriptor descriptor, ExtensionFactory extensionFactory) { public ExtensionWrapper(ExtensionDescriptor descriptor, ExtensionFactory extensionFactory) {
this.descriptor = descriptor; this.descriptor = descriptor;
this.extensionFactory = extensionFactory; this.extensionFactory = extensionFactory;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public T getExtension() { public T getExtension() {
if (extension == null) { if (extension == null) {
extension = (T) extensionFactory.create(descriptor.extensionClass); extension = (T) extensionFactory.create(descriptor.extensionClass);
} }
return extension; return extension;
} }
public ExtensionDescriptor getDescriptor() { public ExtensionDescriptor getDescriptor() {
return descriptor; return descriptor;
} }
public int getOrdinal() { public int getOrdinal() {
return descriptor.ordinal; return descriptor.ordinal;
} }
@Override @Override
public int compareTo(ExtensionWrapper<T> o) { public int compareTo(ExtensionWrapper<T> o) {
return (getOrdinal() - o.getOrdinal()); return (getOrdinal() - o.getOrdinal());
} }
} }

Loading…
Cancel
Save