diff --git a/dspace-api/src/main/java/org/dspace/app/launcher/ScriptLauncher.java b/dspace-api/src/main/java/org/dspace/app/launcher/ScriptLauncher.java new file mode 100644 index 0000000000..21378ff4d3 --- /dev/null +++ b/dspace-api/src/main/java/org/dspace/app/launcher/ScriptLauncher.java @@ -0,0 +1,203 @@ +/* + * ScriptLauncher.java + * + * Version: $Revision$ + * + * Date: $Date$ + * + * Copyright (c) 2002-2009, Duraspace. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of Duraspace nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + */package org.dspace.app.launcher; + +import org.dspace.core.ConfigurationManager; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.input.SAXBuilder; + +import java.util.List; +import java.lang.reflect.Method; + +/** + * A DSpace script launcher. + * + * @author Stuart Lewis + */ +public class ScriptLauncher +{ + /** + * Execute the DSpace script launcher + * + * @param args Any parameters required to be passed to the scripts it executes + * @throws Exception + */ + public static void main(String[] args) + { + // Check that there is at least one argument + if (args.length < 1) + { + System.err.println("You must provide at least one command argument"); + display(); + System.exit(1); + } + + // Parse the configuration file looking for the command entered + Document doc = getConfig(); + String request = args[0]; + Element root = doc.getRootElement(); + List commands = root.getChildren("command"); + for (Element command : commands) + { + if (request.equalsIgnoreCase(command.getChild("name").getValue())) + { + // Run each step + List steps = command.getChildren("step"); + for (Element step : steps) + { + // Instantiate the class + Class target = null; + String className = step.getChild("class").getValue(); + try + { + target = Class.forName(className, + true, + Thread.currentThread().getContextClassLoader()); + } + catch (ClassNotFoundException e) + { + System.err.println("Error in launcher.xml: Invalid class name: " + className); + System.exit(1); + } + + // Strip the leading argument from the args, and add the arguments + // Set false if the arguments should not be passed on + String[] useargs = args.clone(); + Class[] argTypes = {useargs.getClass()}; + boolean passargs = true; + if ((step.getAttribute("passuserargs") != null) && + ("false".equalsIgnoreCase(step.getAttribute("passuserargs").getValue()))) + { + passargs = false; + } + if ((args.length == 1) || (!passargs)) + { + useargs = new String[0]; + } + else + { + String[] argsnew = new String[useargs.length - 1]; + for (int i = 1; i < useargs.length; i++) + { + argsnew[i - 1] = useargs[i]; + } + useargs = argsnew; + } + + // Add any extra properties + List bits = step.getChildren("argument"); + if (step.getChild("argument") != null) + { + String[] argsnew = new String[useargs.length + bits.size()]; + int i = 0; + for (Element arg : bits) + { + argsnew[i++] = arg.getValue(); + } + for (; i < bits.size() + useargs.length; i++) + { + argsnew[i] = useargs[i - bits.size()]; + } + useargs = argsnew; + } + + // Run the main() method + try + { + Object[] arguments = {useargs}; + + // Useful for debugging, so left in the code... + /**System.out.print("About to execute: " + className); + for (String param : useargs) + { + System.out.print(" " + param); + } + System.out.println("");**/ + + Method main = target.getMethod("main", argTypes); + Object output = main.invoke(null, arguments); + } + catch (Exception e) + { + System.err.println("Exception: " + e.getMessage()); + System.exit(1); + } + } + System.exit(0); + } + } + + // The command wasn't found + System.err.println("Command not found: " + args[0]); + display(); + System.exit(1); + } + + public static Document getConfig() + { + // Load the launcher configuration file + String config = ConfigurationManager.getProperty("dspace.dir") + + System.getProperty("file.separator") + "config" + + System.getProperty("file.separator") + "launcher.xml"; + SAXBuilder saxBuilder = new SAXBuilder(); + Document doc = null; + try + { + doc = saxBuilder.build(config); + } + catch (Exception e) + { + System.err.println("Unable to load the launcher configuration file: [dspace]/config/launcher.xml"); + System.err.println(e.getMessage()); + System.exit(1); + } + return doc; + } + + public static void display() + { + Document doc = getConfig(); + List commands = doc.getRootElement().getChildren("command"); + System.out.println("Usage: dspace [command-name] {parameters}"); + for (Element command : commands) + { + System.out.println(" - " + command.getChild("name").getValue() + + ": " + command.getChild("description").getValue()); + } + } +} diff --git a/dspace/CHANGES b/dspace/CHANGES index 630e8d8467..714114d453 100644 --- a/dspace/CHANGES +++ b/dspace/CHANGES @@ -49,6 +49,7 @@ - [DS-316] Make SWORD app:accepts configurable - [DS-318] JSPUI: Left over text in edit item about format - [DS-319] Replace '/dspace/bin/dsrun org.dspace.browse.ItemCounter' with /dspace/bin/itemcounter + - [DS-321] DSpace command launcher - [DS-327] SWORD temp upload directory missing trailling slash - [DS-328] SWORD service documents do not include atom:generator element diff --git a/dspace/bin/dspace b/dspace/bin/dspace new file mode 100644 index 0000000000..7b0ad944c9 --- /dev/null +++ b/dspace/bin/dspace @@ -0,0 +1,48 @@ +#!/bin/sh + +########################################################################### +# +# dspace +# +# Version: $Revision$ +# +# Date: $Date$ +# +# Copyright (c) 2002-2009, Duraspace. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# - Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# - Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# - Neither the name of the Duraspace nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH +# DAMAGE. +# +########################################################################### + +# Script for running the DSpace launcher. + +# Get the DSPACE/bin directory +BINDIR=`dirname $0` + +$BINDIR/dsrun org.dspace.app.launcher.ScriptLauncher $@ diff --git a/dspace/bin/dspace.bat b/dspace/bin/dspace.bat new file mode 100644 index 0000000000..74cc3d06ca --- /dev/null +++ b/dspace/bin/dspace.bat @@ -0,0 +1,41 @@ +@REM ########################################################################### +@REM # +@REM # dspace.bat +@REM # +@REM # Version: $Revision$ +@REM # +@REM # Date: $Date$ +@REM # +@REM # Copyright (c) 2002-2009, Duraspace. All rights reserved. +@REM # +@REM # Redistribution and use in source and binary forms, with or without +@REM # modification, are permitted provided that the following conditions are +@REM # met: +@REM # +@REM # - Redistributions of source code must retain the above copyright +@REM # notice, this list of conditions and the following disclaimer. +@REM # +@REM # - Redistributions in binary form must reproduce the above copyright +@REM # notice, this list of conditions and the following disclaimer in the +@REM # documentation and/or other materials provided with the distribution. +@REM # +@REM # - Neither the name of the Duraspace nor the names of its +@REM # contributors may be used to endorse or promote products derived from +@REM # this software without specific prior written permission. +@REM # +@REM # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +@REM # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +@REM # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +@REM # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +@REM # HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +@REM # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +@REM # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +@REM # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +@REM # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +@REM # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +@REM # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH +@REM # DAMAGE. +@REM # +@REM ########################################################################### + +@call dsrun.bat org.dspace.app.launcher.ScriptLauncher %1 %2 %3 %4 %5 %6 %7 %8 %9 \ No newline at end of file diff --git a/dspace/config/launcher.xml b/dspace/config/launcher.xml new file mode 100644 index 0000000000..8ac6bd35ef --- /dev/null +++ b/dspace/config/launcher.xml @@ -0,0 +1,218 @@ + + + + + checker + Run the checksum checker + + org.dspace.app.checker.ChecksumChecker + + + + + cleanup + Remove deleted bitstreams from the assetstore + + org.dspace.storage.bitstore.Cleanup + + + + + create-administrator + Create a DSpace administrator account + + org.dspace.administer.CreateAdministrator + + + + + dsprop + View a DSpace property from dspace.cfg + + org.dspace.core.ConfigurationManager + + + + + export + Export items or collections + + org.dspace.app.itemexport.ItemExport + + + + + filter-media + Perform the media filtering to extract full text from docuemnts and to create thumbnails + + org.dspace.app.mediafilter.MediaFilterManager + + + + + generate-sitemaps + Generate search engine and html sitemaps + + org.dspace.app.sitemap.GenerateSitemaps + + + + + import + Import items into DSpace + + org.dspace.app.itemimport.ItemImport + + + + + index-init + Initialise the search and browse indexes + + org.dspace.browse.IndexBrowse + -f + -r + + + org.dspace.browse.ItemCounter + + + org.dspace.search.DSIndexer + -b + + + + + index-update + Update the search and browse indexes + + org.dspace.browse.IndexBrowse + -i + + + org.dspace.browse.ItemCounter + + + org.dspace.search.DSIndexer + + + + + itemcounter + Update the item strength counts in the user interface + + org.dspace.browse.ItemCounter + + + + + itemupdate + Item update tool for altering metadata and bitstream content in items + + org.dspace.app.itemimport.ItemUpdate + + + + + metadata-export + Export metadata for batch editing + + org.dspace.app.bulkedit.MetadataExport + + + + + metadata-import + Import metadata after batch editing + + org.dspace.app.bulkedit.MetadataImport + + + + + packager + Execute a packager + + org.dspace.app.packager.Packager + + + + + stat-general + Compile the general statistics + + org.dspace.app.statistics.CreateStatReport + -r stat-general + + + + + stat-initial + Compile the initial statistics + + org.dspace.app.statistics.CreateStatReport + -r stat-initial + + + + + stat-monthly + Compile the monthly statistics + + org.dspace.app.statistics.CreateStatReport + -r stat-monthly + + + + + stat-report-general + Create the general statistics report + + org.dspace.app.statistics.CreateStatReport + -r stat-report-general + + + + + stat-report-initial + Create the general statistics report + + org.dspace.app.statistics.CreateStatReport + -r stat-report-initial + + + + + stat-report-monthly + Create the monthly statistics report + + org.dspace.app.statistics.CreateStatReport + -r stat-report-monthly + + + + + structure-builder + Build DSpace commnity and collection structure + + org.dspace.administer.StructBuilder + + + + + sub-daily + Send daily subscription notices + + org.dspace.eperson.Subscribe + + + + + update-handle-prefix + Update handle records and metadata when moving from one handle to another + + org.dspace.handle.UpdateHandlePrefix + + + + \ No newline at end of file