mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 08:40:03 +00:00
@@ -1,5 +1,6 @@
|
|||||||
package org.apollo.io;
|
package org.apollo.io;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
@@ -60,11 +61,12 @@ public final class PluginMetaDataParser {
|
|||||||
/**
|
/**
|
||||||
* Parses the XML and creates a meta data object.
|
* Parses the XML and creates a meta data object.
|
||||||
*
|
*
|
||||||
|
* @param base The base path for this plugin
|
||||||
* @return The meta data object.
|
* @return The meta data object.
|
||||||
* @throws SAXException If a SAX error occurs.
|
* @throws SAXException If a SAX error occurs.
|
||||||
* @throws IOException If an I/O 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);
|
XmlNode rootNode = parser.parse(is);
|
||||||
if (!rootNode.getName().equals("plugin")) {
|
if (!rootNode.getName().equals("plugin")) {
|
||||||
throw new IOException("Root node must be named 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -66,20 +66,34 @@ public final class PluginManager {
|
|||||||
* @throws SAXException If a SAX error occurs.
|
* @throws SAXException If a SAX error occurs.
|
||||||
*/
|
*/
|
||||||
private Collection<PluginMetaData> findPlugins() throws IOException, SAXException {
|
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>();
|
Collection<PluginMetaData> plugins = new ArrayList<PluginMetaData>();
|
||||||
File dir = new File("./data/plugins");
|
|
||||||
for (File plugin : dir.listFiles()) {
|
for (File plugin : dir.listFiles()) {
|
||||||
if (plugin.isDirectory() && !plugin.getName().startsWith(".")) {
|
if (plugin.isDirectory() && !plugin.getName().startsWith(".")) {
|
||||||
File xml = new File(plugin, "plugin.xml");
|
File xml = new File(plugin, "plugin.xml");
|
||||||
if (xml.exists()) {
|
if (xml.exists()) {
|
||||||
try (InputStream is = new FileInputStream(xml)) {
|
try (InputStream is = new FileInputStream(xml)) {
|
||||||
PluginMetaDataParser parser = new PluginMetaDataParser(is);
|
PluginMetaDataParser parser = new PluginMetaDataParser(is);
|
||||||
PluginMetaData meta = parser.parse();
|
PluginMetaData meta = parser.parse(plugin);
|
||||||
for (String author : meta.getAuthors()) {
|
for (String author : meta.getAuthors()) {
|
||||||
authors.add(author);
|
authors.add(author);
|
||||||
}
|
}
|
||||||
plugins.add(meta);
|
plugins.add(meta);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
plugins.addAll(findPlugins(plugin));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,7 +177,7 @@ public final class PluginManager {
|
|||||||
String[] scripts = plugin.getScripts();
|
String[] scripts = plugin.getScripts();
|
||||||
|
|
||||||
for (String script : scripts) {
|
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);
|
InputStream is = new FileInputStream(scriptFile);
|
||||||
env.parse(is, scriptFile.getAbsolutePath());
|
env.parse(is, scriptFile.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.apollo.util.plugin;
|
package org.apollo.util.plugin;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains attributes which describe a plugin.
|
* Contains attributes which describe a plugin.
|
||||||
*
|
*
|
||||||
@@ -42,6 +44,11 @@ public final class PluginMetaData {
|
|||||||
*/
|
*/
|
||||||
private final double version;
|
private final double version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The plugin's base folder
|
||||||
|
*/
|
||||||
|
private final File base;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the plugin meta data.
|
* Creates the plugin meta data.
|
||||||
*
|
*
|
||||||
@@ -53,9 +60,10 @@ public final class PluginMetaData {
|
|||||||
* @param dependencies The plugin's dependencies.
|
* @param dependencies The plugin's dependencies.
|
||||||
* @param version The plugin's version.
|
* @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) {
|
String[] dependencies, double version) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
this.base = base;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.authors = authors;
|
this.authors = authors;
|
||||||
@@ -127,4 +135,12 @@ public final class PluginMetaData {
|
|||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the plugin's base folder.
|
||||||
|
*
|
||||||
|
* @return The plugin's base folder (where plugin.xml is)
|
||||||
|
*/
|
||||||
|
public File getBase() {
|
||||||
|
return base;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user