}
public JdrReport collect() throws OperationFailedException {
try {
this.env.setZip(new JdrZipFile(new JdrEnvironment(this.env)));
}
catch (Exception e) {
ROOT_LOGGER.error(ROOT_LOGGER.couldNotCreateZipfile(), e);
throw new OperationFailedException(JdrLogger.ROOT_LOGGER.couldNotCreateZipfile());
}
List<JdrCommand> commands = new ArrayList<JdrCommand>();
ByteArrayOutputStream versionStream = new ByteArrayOutputStream();
PrintWriter versionWriter = new PrintWriter(new OutputStreamWriter(versionStream));
versionWriter.println("JDR: " + Namespace.CURRENT.getUriString());
try {
InputStream is = this.getClass().getClassLoader().getResourceAsStream("plugins.properties");
Properties plugins = new Properties();
plugins.load(is);
for (String pluginName : plugins.stringPropertyNames()) {
Class pluginClass = Class.forName(pluginName);
JdrPlugin plugin = (JdrPlugin) pluginClass.newInstance();
commands.addAll(plugin.getCommands());
versionWriter.println(plugin.getPluginId());
}
versionWriter.close();
this.env.getZip().add(new ByteArrayInputStream(versionStream.toByteArray()), "version.txt");
} catch (Exception e) {
ROOT_LOGGER.error(ROOT_LOGGER.couldNotConfigureJDR(), e);
throw new OperationFailedException(ROOT_LOGGER.couldNotConfigureJDR());
}
if (commands.size() < 1) {
ROOT_LOGGER.error(JdrLogger.ROOT_LOGGER.noCommandsToRun());
throw new OperationFailedException(JdrLogger.ROOT_LOGGER.noCommandsToRun());
}
JdrReport report = new JdrReport();
StringBuilder skips = new StringBuilder();
report.setStartTime();
for( JdrCommand command : commands ) {
command.setEnvironment(new JdrEnvironment(this.env));
try {
command.execute();
} catch (Throwable t) {
String message = "Skipping command " + command.toString();
ROOT_LOGGER.debugf(message);