From c286cc5fdbc35d5c2dbc448393a96e8aa9756660 Mon Sep 17 00:00:00 2001 From: pb Date: Sat, 14 May 2011 10:34:05 +0000 Subject: [PATCH] =?UTF-8?q?Klasse=20Program=20und=20Upgrade=20so=20angepas?= =?UTF-8?q?st,=20dass=20man=20auch=20ein=20SQL=20Skript=20NACH=20einer=20J?= =?UTF-8?q?ava=20Klasse=20ausf=C3=BChren=20kann.=20Aufruf=20system.exit=20?= =?UTF-8?q?ist=20jetzt=20abh=C3=A4ngig=20von=20Parameter=20im=20Konstrukto?= =?UTF-8?q?r.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.libreccm.org/ccm/trunk@907 8810af33-2d31-482b-a856-94f89814c4df --- .../src/com/arsdigita/packaging/Program.java | 34 +++++++++++++++++-- .../src/com/arsdigita/packaging/Upgrade.java | 14 ++++++-- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/ccm-core/src/com/arsdigita/packaging/Program.java b/ccm-core/src/com/arsdigita/packaging/Program.java index 5b307d5a2..0a64254eb 100755 --- a/ccm-core/src/com/arsdigita/packaging/Program.java +++ b/ccm-core/src/com/arsdigita/packaging/Program.java @@ -84,8 +84,14 @@ public abstract class Program { private String m_version; private String m_usage; private boolean m_verbose = false; + /** Whether to produce out marked by debug while running the CLI program.*/ private boolean m_debug = false; + /** Whether to initialize the CCM system before running the CLI program. */ private boolean m_startup = true; + /** True skips system.exit after processing finished so another program may + be invoked by a calling cammand script. Especially usefule for upgrade + script when a sql script has to be executed afer a jave class. */ + private boolean m_concatenate = false; private Options m_options; @@ -103,11 +109,11 @@ public abstract class Program { public Program(String name, String version, String usage) { - this(name, version, usage, true); + this(name, version, usage, true, false); } /** - * Creates a new program. The conventions for the + * Creates a new program. The conventions for the * usage parameter follow the GNU style guidelines. * For example, if there are multiple source files * and one destination, it would be "SOURCE... DEST" @@ -120,10 +126,30 @@ public abstract class Program { String version, String usage, boolean startup) { + this(name, version, usage, startup, false); + } + + /** + * Creates a new program. The conventions for the + * usage parameter follow the GNU style guidelines. + * For example, if there are multiple source files + * and one destination, it would be "SOURCE... DEST" + * @param name the program name + * @param version the version string + * @param usage for any non-option command line arguments + * @param startup true to perform standard WAF startup + * @param concatenate false invokes System.exit when processing finished + */ + public Program(String name, + String version, + String usage, + boolean startup, + boolean concatenate) { m_name = name; m_version = version; m_usage = usage; m_startup = startup; + m_concatenate = concatenate; m_options = new Options(); m_options.addOption @@ -243,7 +269,9 @@ public abstract class Program { doRun(cmdLine); - System.exit(0); + if(!m_concatenate) { + System.exit(0); + } } catch (Throwable t) { System.err.println("Error: " + t.getClass() + ":" + t.getMessage()); diff --git a/ccm-core/src/com/arsdigita/packaging/Upgrade.java b/ccm-core/src/com/arsdigita/packaging/Upgrade.java index 131826bf6..a7d8c0193 100755 --- a/ccm-core/src/com/arsdigita/packaging/Upgrade.java +++ b/ccm-core/src/com/arsdigita/packaging/Upgrade.java @@ -156,12 +156,15 @@ class Upgrade extends Command { "that your 'to' and 'from' versions match " + "the intended upgrade exactly"); return false; + } else { + System.out.println("Number of scripts: " + m_scripts.size() ); } Iterator iter = m_scripts.iterator(); - while (iter.hasNext()) { + final String[] parts = (String[]) iter.next(); + final String classname = parts[0]; final String sql = parts[1]; @@ -173,8 +176,8 @@ class Upgrade extends Command { final Method method; try { - method = clacc.getMethod - ("main", new Class[] {String[].class}); + method = clacc.getMethod("main", + new Class[] {String[].class}); } catch (NoSuchMethodException nsme) { throw new UncheckedWrapperException(nsme); } catch (SecurityException se) { @@ -191,6 +194,7 @@ class Upgrade extends Command { } } } + try { method.invoke(null, new Object[] {ll.toArray(new String[] {})}); } catch (IllegalAccessException iae) { @@ -198,6 +202,7 @@ class Upgrade extends Command { } catch (InvocationTargetException ite) { throw new UncheckedWrapperException(ite); } + } else if (sql != null) { final SchemaLoader loader = new SchemaLoader(sql); @@ -217,6 +222,7 @@ class Upgrade extends Command { } else { throw new IllegalStateException(); } + } return true; @@ -225,6 +231,7 @@ class Upgrade extends Command { private class Parser extends DefaultHandler { private String m_version; + @Override public final void startElement(final String uri, final String lname, final String qname, @@ -261,6 +268,7 @@ class Upgrade extends Command { } } + @Override public final void endElement(final String uri, final String lname, final String qname) {