Merge pull request #22 from nikkiii/master.

Recursive plugin loading.
This commit is contained in:
Major-
2014-05-01 18:50:36 +01:00
50 changed files with 38 additions and 6 deletions
+4 -2
View File
@@ -1,5 +1,6 @@
package org.apollo.io;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -60,11 +61,12 @@ public final class PluginMetaDataParser {
/**
* Parses the XML and creates a meta data object.
*
* @param base The base path for this plugin
* @return The meta data object.
* @throws SAXException If a SAX error occurs.
* @throws IOException If an I/O error occurs.
*/
public PluginMetaData parse() throws IOException, SAXException {
public PluginMetaData parse(File base) throws IOException, SAXException {
XmlNode rootNode = parser.parse(is);
if (!rootNode.getName().equals("plugin")) {
throw new IOException("Root node must be named plugin.");
@@ -116,7 +118,7 @@ public final class PluginMetaDataParser {
}
}
return new PluginMetaData(id, name, description, authors, scripts, dependencies, version);
return new PluginMetaData(id, base, name, description, authors, scripts, dependencies, version);
}
}
+17 -3
View File
@@ -66,20 +66,34 @@ public final class PluginManager {
* @throws SAXException If a SAX error occurs.
*/
private Collection<PluginMetaData> findPlugins() throws IOException, SAXException {
return findPlugins(new File("./data/plugins"));
}
/**
* Finds plugins and loads their meta data.
*
* @param dir The directory to search
*
* @return A collection of plugin meta data objects.
* @throws IOException If an I/O error occurs.
* @throws SAXException If a SAX error occurs.
*/
private Collection<PluginMetaData> findPlugins(File dir) throws IOException, SAXException {
Collection<PluginMetaData> plugins = new ArrayList<PluginMetaData>();
File dir = new File("./data/plugins");
for (File plugin : dir.listFiles()) {
if (plugin.isDirectory() && !plugin.getName().startsWith(".")) {
File xml = new File(plugin, "plugin.xml");
if (xml.exists()) {
try (InputStream is = new FileInputStream(xml)) {
PluginMetaDataParser parser = new PluginMetaDataParser(is);
PluginMetaData meta = parser.parse();
PluginMetaData meta = parser.parse(plugin);
for (String author : meta.getAuthors()) {
authors.add(author);
}
plugins.add(meta);
}
} else {
plugins.addAll(findPlugins(plugin));
}
}
}
@@ -163,7 +177,7 @@ public final class PluginManager {
String[] scripts = plugin.getScripts();
for (String script : scripts) {
File scriptFile = new File("./data/plugins/" + plugin.getId() + "/" + script);
File scriptFile = new File(plugin.getBase(), script);
InputStream is = new FileInputStream(scriptFile);
env.parse(is, scriptFile.getAbsolutePath());
}
+17 -1
View File
@@ -1,5 +1,7 @@
package org.apollo.util.plugin;
import java.io.File;
/**
* Contains attributes which describe a plugin.
*
@@ -42,6 +44,11 @@ public final class PluginMetaData {
*/
private final double version;
/**
* The plugin's base folder
*/
private final File base;
/**
* Creates the plugin meta data.
*
@@ -53,9 +60,10 @@ public final class PluginMetaData {
* @param dependencies The plugin's dependencies.
* @param version The plugin's version.
*/
public PluginMetaData(String id, String name, String description, String[] authors, String[] scripts,
public PluginMetaData(String id, File base, String name, String description, String[] authors, String[] scripts,
String[] dependencies, double version) {
this.id = id;
this.base = base;
this.name = name;
this.description = description;
this.authors = authors;
@@ -127,4 +135,12 @@ public final class PluginMetaData {
return version;
}
/**
* Gets the plugin's base folder.
*
* @return The plugin's base folder (where plugin.xml is)
*/
public File getBase() {
return base;
}
}