Klasse Program und Upgrade so angepasst, dass man auch ein SQL Skript NACH einer Java Klasse ausführen kann. Aufruf system.exit ist jetzt abhängig von Parameter im Konstruktor.
git-svn-id: https://svn.libreccm.org/ccm/trunk@907 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
dc0c1ceb6a
commit
c286cc5fdb
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue