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_version;
|
||||||
private String m_usage;
|
private String m_usage;
|
||||||
private boolean m_verbose = false;
|
private boolean m_verbose = false;
|
||||||
|
/** Whether to produce out marked by debug while running the CLI program.*/
|
||||||
private boolean m_debug = false;
|
private boolean m_debug = false;
|
||||||
|
/** Whether to initialize the CCM system before running the CLI program. */
|
||||||
private boolean m_startup = true;
|
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;
|
private Options m_options;
|
||||||
|
|
||||||
|
|
@ -103,11 +109,11 @@ public abstract class Program {
|
||||||
public Program(String name,
|
public Program(String name,
|
||||||
String version,
|
String version,
|
||||||
String usage) {
|
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.
|
* usage parameter follow the GNU style guidelines.
|
||||||
* For example, if there are multiple source files
|
* For example, if there are multiple source files
|
||||||
* and one destination, it would be "SOURCE... DEST"
|
* and one destination, it would be "SOURCE... DEST"
|
||||||
|
|
@ -120,10 +126,30 @@ public abstract class Program {
|
||||||
String version,
|
String version,
|
||||||
String usage,
|
String usage,
|
||||||
boolean startup) {
|
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_name = name;
|
||||||
m_version = version;
|
m_version = version;
|
||||||
m_usage = usage;
|
m_usage = usage;
|
||||||
m_startup = startup;
|
m_startup = startup;
|
||||||
|
m_concatenate = concatenate;
|
||||||
m_options = new Options();
|
m_options = new Options();
|
||||||
|
|
||||||
m_options.addOption
|
m_options.addOption
|
||||||
|
|
@ -243,7 +269,9 @@ public abstract class Program {
|
||||||
|
|
||||||
doRun(cmdLine);
|
doRun(cmdLine);
|
||||||
|
|
||||||
System.exit(0);
|
if(!m_concatenate) {
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
System.err.println("Error: " + t.getClass() +
|
System.err.println("Error: " + t.getClass() +
|
||||||
":" + t.getMessage());
|
":" + t.getMessage());
|
||||||
|
|
|
||||||
|
|
@ -156,12 +156,15 @@ class Upgrade extends Command {
|
||||||
"that your 'to' and 'from' versions match " +
|
"that your 'to' and 'from' versions match " +
|
||||||
"the intended upgrade exactly");
|
"the intended upgrade exactly");
|
||||||
return false;
|
return false;
|
||||||
|
} else {
|
||||||
|
System.out.println("Number of scripts: " + m_scripts.size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator iter = m_scripts.iterator();
|
Iterator iter = m_scripts.iterator();
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
|
|
||||||
final String[] parts = (String[]) iter.next();
|
final String[] parts = (String[]) iter.next();
|
||||||
|
|
||||||
final String classname = parts[0];
|
final String classname = parts[0];
|
||||||
final String sql = parts[1];
|
final String sql = parts[1];
|
||||||
|
|
||||||
|
|
@ -173,8 +176,8 @@ class Upgrade extends Command {
|
||||||
final Method method;
|
final Method method;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
method = clacc.getMethod
|
method = clacc.getMethod("main",
|
||||||
("main", new Class[] {String[].class});
|
new Class[] {String[].class});
|
||||||
} catch (NoSuchMethodException nsme) {
|
} catch (NoSuchMethodException nsme) {
|
||||||
throw new UncheckedWrapperException(nsme);
|
throw new UncheckedWrapperException(nsme);
|
||||||
} catch (SecurityException se) {
|
} catch (SecurityException se) {
|
||||||
|
|
@ -191,6 +194,7 @@ class Upgrade extends Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
method.invoke(null, new Object[] {ll.toArray(new String[] {})});
|
method.invoke(null, new Object[] {ll.toArray(new String[] {})});
|
||||||
} catch (IllegalAccessException iae) {
|
} catch (IllegalAccessException iae) {
|
||||||
|
|
@ -198,6 +202,7 @@ class Upgrade extends Command {
|
||||||
} catch (InvocationTargetException ite) {
|
} catch (InvocationTargetException ite) {
|
||||||
throw new UncheckedWrapperException(ite);
|
throw new UncheckedWrapperException(ite);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (sql != null) {
|
} else if (sql != null) {
|
||||||
final SchemaLoader loader = new SchemaLoader(sql);
|
final SchemaLoader loader = new SchemaLoader(sql);
|
||||||
|
|
||||||
|
|
@ -217,6 +222,7 @@ class Upgrade extends Command {
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -225,6 +231,7 @@ class Upgrade extends Command {
|
||||||
private class Parser extends DefaultHandler {
|
private class Parser extends DefaultHandler {
|
||||||
private String m_version;
|
private String m_version;
|
||||||
|
|
||||||
|
@Override
|
||||||
public final void startElement(final String uri,
|
public final void startElement(final String uri,
|
||||||
final String lname,
|
final String lname,
|
||||||
final String qname,
|
final String qname,
|
||||||
|
|
@ -261,6 +268,7 @@ class Upgrade extends Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final void endElement(final String uri,
|
public final void endElement(final String uri,
|
||||||
final String lname,
|
final String lname,
|
||||||
final String qname) {
|
final String qname) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue