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