clean up course class
This commit is contained in:
parent
bb0d27d14b
commit
b0619ef5db
@ -1,8 +1,5 @@
|
||||
package org.owasp.webgoat.plugins;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@ -19,16 +16,18 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.lang.String.format;
|
||||
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
|
||||
import static org.owasp.webgoat.plugins.PluginFileUtils.createDirsIfNotExists;
|
||||
|
||||
/**
|
||||
* Extract the wpf file and collect the classes to load and files(lesson plans etc)
|
||||
* Extract the wpf file and place them in the system temp directory in the folder webgoat and collect the files
|
||||
* and classes.
|
||||
*/
|
||||
public class PluginExtractor {
|
||||
|
||||
private static final String DIRECTORY = "webgoat";
|
||||
private final Path pluginArchive;
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private final Map<String, byte[]> classes = new HashMap<String, byte[]>();
|
||||
private final List<Path> files = new ArrayList<>();
|
||||
private Path baseDirectory;
|
||||
@ -38,7 +37,7 @@ public class PluginExtractor {
|
||||
try {
|
||||
baseDirectory = createDirsIfNotExists(Paths.get(System.getProperty("java.io.tmpdir"), DIRECTORY));
|
||||
} catch (IOException io) {
|
||||
logger.error(String.format("Unable to create base directory: {}", pluginArchive.getFileName()), io);
|
||||
new Plugin.PluginLoadingFailure(format("Unable to create base directory: {}", pluginArchive.getFileName()), io);
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,7 +57,7 @@ public class PluginExtractor {
|
||||
}
|
||||
});
|
||||
} catch (IOException io) {
|
||||
logger.error(String.format("Unable to extract: %s", pluginArchive.getFileName()), io);
|
||||
new Plugin.PluginLoadingFailure(format("Unable to extract: %s", pluginArchive.getFileName()), io);
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,10 +78,5 @@ public class PluginExtractor {
|
||||
return FileSystems.newFileSystem(uri, new HashMap<String, Object>());
|
||||
}
|
||||
|
||||
public Path createDirsIfNotExists(Path p) throws IOException {
|
||||
if ( Files.notExists(p)) {
|
||||
Files.createDirectories(p);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package org.owasp.webgoat.plugins;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class PluginFileUtils {
|
||||
@ -19,4 +21,11 @@ public class PluginFileUtils {
|
||||
return hasParentDirectoryWithName(p.getParent(), s);
|
||||
}
|
||||
|
||||
public static Path createDirsIfNotExists(Path p) throws IOException {
|
||||
if ( Files.notExists(p)) {
|
||||
Files.createDirectories(p);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class PluginsLoader implements Runnable {
|
||||
plugin.loadFiles(extractor.getFiles(), reload);
|
||||
plugins.add(plugin);
|
||||
} catch (Plugin.PluginLoadingFailure e) {
|
||||
logger.error("Unable to load plugin, continue reading others...");
|
||||
logger.error("Unable to load plugin, continue loading others...");
|
||||
}
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
@ -431,9 +431,9 @@ public class Course {
|
||||
logger.info("Loading courses: " + path);
|
||||
this.webgoatContext = webgoatContext;
|
||||
loadLessionFromPlugin(context);
|
||||
//loadFiles(context, path);
|
||||
loadFiles(context, path);
|
||||
//loadLessons(path);
|
||||
//loadResources();
|
||||
loadResources();
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user