Refactoring creation of the lesson moving it towards the plugin
This commit is contained in:
parent
4865a4b606
commit
3e9331d46e
@ -124,9 +124,12 @@ public class Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AbstractLesson getLesson() {
|
||||||
public Class<AbstractLesson> getLesson() {
|
try {
|
||||||
return lesson;
|
return lesson.newInstance();
|
||||||
|
} catch (IllegalAccessException | InstantiationException e) {
|
||||||
|
throw new PluginLoadingFailure("Unable to instantiate the lesson " + lesson.getName(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<File> getLessonSolution(String language) {
|
public Optional<File> getLessonSolution(String language) {
|
||||||
|
@ -1,15 +1,21 @@
|
|||||||
package org.owasp.webgoat.plugins;
|
package org.owasp.webgoat.plugins;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class PluginClassLoader extends ClassLoader {
|
public class PluginClassLoader extends ClassLoader {
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(Plugin.class);
|
||||||
private final byte[] classFile;
|
private final byte[] classFile;
|
||||||
|
|
||||||
public PluginClassLoader(ClassLoader parent, byte[] classFile) {
|
public PluginClassLoader(ClassLoader parent, String nameOfClass, byte[] classFile) {
|
||||||
super(parent);
|
super(parent);
|
||||||
|
logger.debug("Creating class loader for {}", nameOfClass);
|
||||||
this.classFile = classFile;
|
this.classFile = classFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class findClass(String name) {
|
public Class findClass(String name) {
|
||||||
|
logger.debug("Finding class " + name);
|
||||||
return defineClass(name, classFile, 0, classFile.length);
|
return defineClass(name, classFile, 0, classFile.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,12 +304,8 @@ public class Course {
|
|||||||
List<Plugin> plugins = new PluginsLoader(Paths.get(pluginPath), Paths.get(targetPath)).loadPlugins(true);
|
List<Plugin> plugins = new PluginsLoader(Paths.get(pluginPath), Paths.get(targetPath)).loadPlugins(true);
|
||||||
for (Plugin plugin : plugins) {
|
for (Plugin plugin : plugins) {
|
||||||
try {
|
try {
|
||||||
Class<AbstractLesson> c = plugin.getLesson();
|
AbstractLesson lesson = plugin.getLesson();
|
||||||
Object o = c.newInstance();
|
|
||||||
|
|
||||||
AbstractLesson lesson = (AbstractLesson) o;
|
|
||||||
lesson.setWebgoatContext(webgoatContext);
|
lesson.setWebgoatContext(webgoatContext);
|
||||||
|
|
||||||
lesson.update(properties);
|
lesson.update(properties);
|
||||||
|
|
||||||
if (!lesson.getHidden()) {
|
if (!lesson.getHidden()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user