Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
0002047: Add extension service that can read extensions from database
  • Loading branch information
erilong committed Nov 5, 2014
1 parent dc3d987 commit ded7dda
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
Expand Up @@ -43,6 +43,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import bsh.EvalError;
import bsh.Interpreter;

/**
* This service registers {@link IExtensionPoint}s defined both by SymmetricDS
* and others found in the {@link ApplicationContext}.
Expand Down Expand Up @@ -93,16 +96,21 @@ public void refresh() {
if (extension.getExtensionType().equalsIgnoreCase(Extension.EXTENSION_TYPE_JAVA)) {
try {
Object ext = SimpleClassCompiler.getInstance().getCompiledClass(extension.getExtensionText());
if (ext instanceof IExtensionPoint) {
registerExtension(extension.getExtensionId(), (IExtensionPoint) ext);
} else {
log.error("Missing IExtensionPoint interface for extension " + extension.getExtensionId());
}
registerExtension(extension.getExtensionId(), (IExtensionPoint) ext);
} catch (Exception e) {
log.error("Error while compiling extension " + extension.getExtensionId(), e);
log.error("Error while compiling Java extension " + extension.getExtensionId(), e);
}
} else if (extension.getExtensionType().equalsIgnoreCase(Extension.EXTENSION_TYPE_BSH)) {
// TODO: implement BSH wrapper interface
try {
Interpreter interpreter = new Interpreter();
interpreter.eval(extension.getExtensionText());
Object ext = interpreter.getInterface(Class.forName(extension.getInterfaceName()));
registerExtension(extension.getExtensionId(), (IExtensionPoint) ext);
} catch (EvalError e) {
log.error("Error while parsing BSH extension " + extension.getExtensionId(), e);
} catch (ClassNotFoundException e) {
log.error("Interface class not found for BSH extension " + extension.getExtensionId(), e);
}
} else {
log.error("Skipping extension " + extension.getExtensionId() + ", unknown extension type " + extension.getExtensionType());
}
Expand All @@ -111,6 +119,9 @@ public void refresh() {
}

protected boolean registerExtension(String name, IExtensionPoint ext) {
if (! (ext instanceof IExtensionPoint)) {
log.error("Missing IExtensionPoint interface for extension " + name);
}
return registerExtension(name, ext, true);
}

Expand Down
Expand Up @@ -96,6 +96,9 @@ public Object getCompiledClass(String javaCode) throws Exception {
}

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
if (compiler == null) {
throw new SimpleClassCompilerException("Missing Java compiler: the JDK is required for compiling classes.");
}
JavaFileManager fileManager = new ClassFileManager(compiler.getStandardFileManager(null, null, null));
DiagnosticCollector<JavaFileObject> diag = new DiagnosticCollector<JavaFileObject>();
List<JavaFileObject> javaFiles = new ArrayList<JavaFileObject>();
Expand Down
Expand Up @@ -30,6 +30,10 @@ public class SimpleClassCompilerException extends RuntimeException {
private static final long serialVersionUID = 1L;

List<Diagnostic<? extends JavaFileObject>> diagnostics;

public SimpleClassCompilerException(String message) {
super(message);
}

public SimpleClassCompilerException(List<Diagnostic<? extends JavaFileObject>> diagnostics) {
this.diagnostics = diagnostics;
Expand Down

0 comments on commit ded7dda

Please sign in to comment.