Browse Source

Formatting

tags/release-2.6.0
Decebal Suiu 5 years ago
parent
commit
8feda969a0

+ 2
- 4
pf4j/src/main/java/org/pf4j/DependencyResolver.java View File

@@ -145,8 +145,7 @@ public class DependencyResolver {
} else {
boolean edgeAdded = false;
for (PluginDependency dependency : dependencies) {
// Don't register optional plugins in the dependency graph
// to avoid automatic disabling of the plugin,
// Don't register optional plugins in the dependency graph to avoid automatic disabling of the plugin,
// if an optional dependency is missing.
if (!dependency.isOptional()) {
edgeAdded = true;
@@ -155,8 +154,7 @@ public class DependencyResolver {
}
}

// Register the plugin without dependencies,
// if all of its dependencies are optional.
// Register the plugin without dependencies, if all of its dependencies are optional.
if (!edgeAdded) {
dependenciesGraph.addVertex(pluginId);
dependentsGraph.addVertex(pluginId);

+ 1
- 0
pf4j/src/main/java/org/pf4j/Extension.java View File

@@ -59,4 +59,5 @@ public @interface Extension {
* @return plugin IDs, that have to be available in order to load this extension
*/
String[] plugins() default {};

}

+ 1
- 2
pf4j/src/main/java/org/pf4j/PluginDependency.java View File

@@ -35,8 +35,7 @@ public class PluginDependency {
}
}

// A dependency is considered as optional,
// if the plugin id ends with a question mark.
// A dependency is considered as optional, if the plugin id ends with a question mark.
this.optional = this.pluginId.endsWith("?");
if (this.optional) {
this.pluginId = this.pluginId.substring(0, this.pluginId.length() - 1);

+ 5
- 2
pf4j/src/main/java/org/pf4j/asm/ExtensionInfo.java View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.pf4j.asm;

import org.objectweb.asm.ClassReader;
@@ -35,14 +34,16 @@ import java.util.List;
* @author Decebal Suiu
*/
public final class ExtensionInfo {

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

private final String className;

int ordinal = 0;
List<String> plugins = new ArrayList<>();
List<String> points = new ArrayList<>();

private ExtensionInfo(String className) {
super();
this.className = className;
}

@@ -93,10 +94,12 @@ public final class ExtensionInfo {
try (InputStream input = classLoader.getResourceAsStream(className.replace('.', '/') + ".class")) {
ExtensionInfo info = new ExtensionInfo(className);
new ClassReader(input).accept(new ExtensionVisitor(info), ClassReader.SKIP_DEBUG);

return info;
} catch (IOException e) {
log.error(e.getMessage(), e);
return null;
}
}

}

+ 14
- 9
pf4j/src/main/java/org/pf4j/asm/ExtensionVisitor.java View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.pf4j.asm;

import org.objectweb.asm.AnnotationVisitor;
@@ -21,6 +20,8 @@ import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.pf4j.Extension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;

@@ -38,8 +39,11 @@ import java.util.Arrays;
* @author Decebal Suiu
*/
class ExtensionVisitor extends ClassVisitor {
//private static final Logger log = LoggerFactory.getLogger(ExtensionVisitor.class);
private static final Logger log = LoggerFactory.getLogger(ExtensionVisitor.class);

private static final int ASM_VERSION = Opcodes.ASM7;

private final ExtensionInfo extensionInfo;

ExtensionVisitor(ExtensionInfo extensionInfo) {
@@ -63,24 +67,23 @@ class ExtensionVisitor extends ClassVisitor {

@Override
public void visit(String key, Object value) {
//log.debug("Load annotation attribute {} = {} ({})", name, value, value.getClass().getName());

log.debug("Load annotation attribute {} = {} ({})", name, value, value.getClass().getName());
if ("ordinal".equals(name)) {
extensionInfo.ordinal = Integer.parseInt(value.toString());
} else if ("plugins".equals(name)) {
if (value instanceof String) {
//log.debug("found plugin " + value);
log.debug("Found plugin {}", value);
extensionInfo.plugins.add((String) value);
} else if (value instanceof String[]) {
//log.debug("found plugins " + Arrays.toString((String[]) value));
log.debug("Found plugins {}", Arrays.toString((String[]) value));
extensionInfo.plugins.addAll(Arrays.asList((String[]) value));
} else {
//log.debug("found plugin " + value.toString());
log.debug("Found plugin {}", value.toString());
extensionInfo.plugins.add(value.toString());
}
} else if ("points".equals(name)) {
} else {
String pointClassName = ((Type) value).getClassName();
//log.debug("found point " + pointClassName);
log.debug("Found point " + pointClassName);
extensionInfo.points.add(pointClassName);
}

@@ -91,6 +94,8 @@ class ExtensionVisitor extends ClassVisitor {

return super.visitArray(name);
}

};
}

}

Loading…
Cancel
Save