No more yml

This commit is contained in:
Nanne Baars
2016-10-12 15:21:39 -04:00
parent 22a76624e6
commit 7fe6e1bb6e
2 changed files with 62 additions and 16 deletions

View File

@ -5,9 +5,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import com.google.common.reflect.ClassPath;
import org.apache.commons.io.FileUtils;
import org.owasp.webgoat.lessons.AbstractLesson;
import org.owasp.webgoat.lessons.NewLesson;
import org.springframework.util.StringUtils;
import java.io.File;
@ -33,7 +33,8 @@ public class Plugin {
private PluginClassLoader classLoader;
private Class<AbstractLesson> lesson;
private YmlBasedLesson ymlBasedLesson;
private YmlBasedLesson ymlBasedLesson; //TODO REMOVE!
private Class<NewLesson> newLesson;
private Map<String, File> solutionLanguageFiles = new HashMap<>();
private Map<String, File> lessonPlansLanguageFiles = new HashMap<>();
private List<File> pluginFiles = Lists.newArrayList();
@ -64,11 +65,14 @@ public class Plugin {
if (AbstractLesson.class.isAssignableFrom(clazz)) {
this.lesson = clazz;
}
if (NewLesson.class.isAssignableFrom(clazz)) {
this.newLesson = clazz;
}
} catch (ClassNotFoundException ce) {
throw new PluginLoadingFailure("Class " + realClassName + " listed in jar but unable to load the class.", ce);
}
//New code all lessons should work as below
//TODO remove
readYmlLessonConfiguration();
}
@ -93,19 +97,6 @@ public class Plugin {
}
}
private Class findAttack(String id) {
try {
for (final ClassPath.ClassInfo info : ClassPath.from(this.classLoader).getTopLevelClasses()) {
if (info.getName().endsWith(id)) {
return info.load();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* <p>loadFiles.</p>
*
@ -176,6 +167,9 @@ public class Plugin {
if (lesson != null) {
return Optional.of(lesson.newInstance());
}
if (newLesson != null) {
return Optional.of(newLesson.newInstance());
}
} catch (IllegalAccessException | InstantiationException e) {
throw new PluginLoadingFailure("Unable to instantiate the lesson " + lesson.getName(), e);