提交 20037a4a authored 作者: Thomas Mueller's avatar Thomas Mueller

The API of the tools changed a bit.

上级 6ab81676
......@@ -70,9 +70,7 @@ public class Backup extends Tool {
showUsage();
return;
} else {
out.println("Unsupported option: " + arg);
showUsage();
return;
throwUnsupportedOption(arg);
}
}
process(zipFileName, dir, db, quiet);
......
......@@ -80,14 +80,12 @@ public class ChangeFileEncryption extends Tool {
showUsage();
return;
} else {
out.println("Unsupported option: " + arg);
showUsage();
return;
throwUnsupportedOption(arg);
}
}
if ((encryptPassword == null && decryptPassword == null) || cipher == null) {
showUsage();
return;
throw new SQLException("Encryption or decryption password not set, or cipher not set");
}
process(dir, db, cipher, decryptPassword, encryptPassword, quiet);
}
......
......@@ -30,9 +30,9 @@ import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import org.h2.util.Resources;
import org.h2.util.Tool;
import java.io.IOException;
import java.io.PrintStream;
//## AWT end ##
import java.sql.SQLException;
......@@ -41,20 +41,17 @@ import org.h2.server.ShutdownHandler;
import org.h2.util.StartBrowser;
/**
* This tool starts the H2 Console (web-) server, as well as the TCP and PG
* server. For JDK 1.6, a system tray icon is created, for platforms that
* support it. Otherwise, a small window opens.
* Starts the H2 Console (web-) server, as well as the TCP and PG server.
* @h2.resource
*
* @author Thomas Mueller, Ridvan Agar
*/
public class Console implements
public class Console extends Tool implements
//## AWT begin ##
ActionListener, MouseListener,
//## AWT end ##
ShutdownHandler {
private static final int EXIT_ERROR = 1;
//## AWT begin ##
Frame frame;
private Font font;
......@@ -65,50 +62,40 @@ ShutdownHandler {
private boolean isWindows;
/**
* The command line interface for this tool.
* The command line options are the same as in the Server tool,
* but this tool will always start the TCP, TCP and PG server.
* Options are case sensitive.
*
* The command line interface for this tool. The options must be split into
* strings like this: "-baseDir", "/temp/data",... By default, -tcp, -web,
* -browser and -pg are started. If there is a problem starting a service,
* the program terminates with an exit code of 1. Options are case
* sensitive. The following options are supported:
* <ul>
* <li>-help or -? (print the list of options) </li>
* <li>-web (start the Web Server and H2 Console) </li>
* <li>-tool (start the icon or window that allows to start a browser)</li>
* <li>-browser (start a browser and open a page to connect to the
* Web Server) </li>
* <li>-tcp (start the TCP Server) </li>
* <li>-pg (start the PG Server) </li>
* </ul>
* For each Server, additional options are available.
* Those options are the same as in the Server tool.
* When running without options, -tcp, -web, -browser and -pg are started.<br />
* Options are case sensitive. Supported options are:
* <table>
* <tr><td>[-help] or [-?]</td>
* <td>Print the list of options</td></tr>
* <tr><td>[-web]</td>
* <td>Start the web server with the H2 Console</td></tr>
* <tr><td>[-tool]</td>
* <td>Start the icon or window that allows to start a browser</td></tr>
* <tr><td>[-browser]</td>
* <td>Start a browser and open a page to connect to the web server</td></tr>
* <tr><td>[-tcp]</td>
* <td>Start the TCP server</td></tr>
* <tr><td>[-pg]</td>
* <td>Start the PG server</td></tr>
* </table>
* For each Server, additional options are available; for details, see the Server tool.<br />
* If a service can not be started, the program terminates with an exit code of 1.
* @h2.resource
*
* @param args the command line arguments
*/
public static void main(String[] args) {
int exitCode = new Console().run(args, System.out);
if (exitCode != 0) {
System.exit(exitCode);
}
}
private void showUsage(PrintStream out) {
out.println("Starts H2 Console");
out.println("By default, -web, -tool, -browser, -tcp, and -pg are started. Options are case sensitive.");
out.println("java "+getClass().getName());
out.println("-web Start the Web Server and H2 Console");
out.println("-tool Start the icon or window that allows to start a browser (includes -web)");
out.println("-browser Start a browser to connect to the H2 Console (includes -web)");
out.println("-tcp Start the TCP Server");
out.println("-pg Start the PG Server");
out.println("See also http://h2database.com/javadoc/" + getClass().getName().replace('.', '/') + ".html");
public static void main(String[] args) throws SQLException {
new Console().run(args);
}
private int run(String[] args, PrintStream out) {
/**
* This tool starts the H2 Console (web-) server, as well as the TCP and PG
* server. For JDK 1.6, a system tray icon is created, for platforms that
* support it. Otherwise, a small window opens.
*
* @param args the command line arguments
*/
public void run(String[] args) throws SQLException {
isWindows = SysProperties.getStringSetting("os.name", "").startsWith("Windows");
boolean tcpStart = false, pgStart = false, webStart = false, toolStart = false;
boolean browserStart = false;
......@@ -119,8 +106,8 @@ ShutdownHandler {
if (arg == null) {
continue;
} else if ("-?".equals(arg) || "-help".equals(arg)) {
showUsage(out);
return EXIT_ERROR;
showUsage();
return;
} else if ("-web".equals(arg)) {
startDefaultServers = false;
webStart = true;
......@@ -147,7 +134,6 @@ ShutdownHandler {
tcpStart = true;
pgStart = true;
}
int exitCode = 0;
if (webStart) {
try {
web = Server.createWebServer(args);
......@@ -199,17 +185,16 @@ ShutdownHandler {
StartBrowser.openURL(web.getURL());
}
if (!web.isRunning(true)) {
exitCode = EXIT_ERROR;
throw new SQLException("The web server is not running");
}
return exitCode;
}
private void printProblem(SQLException e, Server server) {
if (server == null) {
e.printStackTrace();
} else {
System.out.println(server.getStatus());
System.out.println("Root cause: " + e.getMessage());
out.println(server.getStatus());
out.println("Root cause: " + e.getMessage());
}
}
......
......@@ -92,9 +92,7 @@ public class ConvertTraceFile extends Tool {
showUsage();
return;
} else {
out.println("Unsupported option: " + arg);
showUsage();
return;
throwUnsupportedOption(arg);
}
}
try {
......
......@@ -69,14 +69,12 @@ public class CreateCluster extends Tool {
showUsage();
return;
} else {
out.println("Unsupported option: " + arg);
showUsage();
return;
throwUnsupportedOption(arg);
}
}
if (urlSource == null || urlTarget == null || user == null || serverList == null) {
if (urlSource == null || urlTarget == null || serverList == null) {
showUsage();
return;
throw new SQLException("Source URL, target URL, or server list not set");
}
process(urlSource, urlTarget, user, password, serverList);
}
......
......@@ -59,9 +59,7 @@ public class DeleteDbFiles extends Tool {
showUsage();
return;
} else {
out.println("Unsupported option: " + arg);
showUsage();
return;
throwUnsupportedOption(arg);
}
}
process(dir, db, quiet);
......
......@@ -106,6 +106,7 @@ public class Recover extends Tool implements DataHandler {
* a hardware problem.
*
* @param args the command line arguments
* @return the exit code
*/
public void run(String[] args) throws SQLException {
String dir = ".";
......@@ -124,9 +125,7 @@ public class Recover extends Tool implements DataHandler {
showUsage();
return;
} else {
out.println("Unsupported option: " + arg);
showUsage();
return;
throwUnsupportedOption(arg);
}
}
if (!SysProperties.PAGE_STORE && remove) {
......
......@@ -66,9 +66,7 @@ public class Restore extends Tool {
showUsage();
return;
} else {
out.println("Unsupported option: " + arg);
showUsage();
return;
throwUnsupportedOption(arg);
}
}
process(zipFileName, dir, db);
......
......@@ -127,14 +127,12 @@ public class RunScript extends Tool {
showUsage();
return;
} else {
out.println("Unsupported option: " + arg);
showUsage();
return;
throwUnsupportedOption(arg);
}
}
if (url == null || user == null || password == null || script == null) {
if (url == null) {
showUsage();
return;
throw new SQLException("URL not set");
}
long time = System.currentTimeMillis();
if (options != null) {
......
......@@ -89,14 +89,12 @@ public class Script extends Tool {
showUsage();
return;
} else {
out.println("Unsupported option: " + arg);
showUsage();
return;
throwUnsupportedOption(arg);
}
}
if (url == null) {
showUsage();
return;
throw new SQLException("URL not set");
}
if (options1 != null) {
processScript(url, user, password, file, options1, options2);
......
......@@ -6,13 +6,11 @@
*/
package org.h2.tools;
import java.io.PrintStream;
import java.sql.Connection;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.message.Message;
import org.h2.message.TraceSystem;
import org.h2.server.Service;
......@@ -25,11 +23,11 @@ import org.h2.util.StartBrowser;
import org.h2.util.Tool;
/**
* This tool can be used to start various database servers (listeners).
* Starts the H2 Console (web-) server, TCP, PG, and FTP server.
* @h2.resource
*/
public class Server implements Runnable, ShutdownHandler {
public class Server extends Tool implements Runnable, ShutdownHandler {
private static final int EXIT_ERROR = 1;
private Service service;
private Server web, tcp, pg, ftp;
private ShutdownHandler shutdownHandler;
......@@ -47,101 +45,70 @@ public class Server implements Runnable, ShutdownHandler {
}
}
private void showUsage(String a, PrintStream out) {
if (a != null) {
out.println("Unsupported option: " + a);
out.println();
}
out.println("Starts H2 Servers");
out.println("By default, -tcp, -web, -browser and -pg are started. Options are case sensitive.");
out.println("java "+getClass().getName());
out.println("-web Start the Web Server and H2 Console");
out.println("-webAllowOthers Allow other computers to connect");
out.println("-webPort <port> The port (default: " + Constants.DEFAULT_HTTP_PORT+")");
out.println("-webSSL Use encrypted HTTPS connections");
out.println("-browser Start a browser to connect to the H2 Console");
out.println("-tcp Start the TCP Server");
out.println("-tcpAllowOthers Allow other computers to connect");
out.println("-tcpPort <port> The port (default: " + TcpServer.DEFAULT_PORT+")");
out.println("-tcpSSL Use encrypted SSL connections");
out.println("-tcpPassword <pass> The password for shutting down a TCP Server");
out.println("-tcpShutdown <url> Shutdown the TCP Server; example: tcp://localhost:9094");
out.println("-tcpShutdownForce Don't wait for other connections to close");
out.println("-pg Start the PG Server");
out.println("-pgAllowOthers Allow other computers to connect");
out.println("-pgPort <port> The port (default: " + PgServer.DEFAULT_PORT+")");
out.println("-ftp Start the FTP Server");
out.println("-ftpPort <port> The port (default: " + Constants.DEFAULT_FTP_PORT+")");
out.println("-ftpDir <dir> The base directory (default: " + FtpServer.DEFAULT_ROOT + ")");
out.println("-ftpRead <user> The user name for reading (default: " + FtpServer.DEFAULT_READ+")");
out.println("-ftpWrite <user> The user name for writing (default: " + FtpServer.DEFAULT_WRITE+")");
out.println("-ftpWritePassword <p> The write password (default: " + FtpServer.DEFAULT_WRITE_PASSWORD+")");
out.println("-baseDir <dir> The base directory for H2 databases; for all servers");
out.println("-ifExists Only existing databases may be opened; for all servers");
out.println("-trace Print additional trace information; for all servers");
out.println("See also http://h2database.com/javadoc/" + getClass().getName().replace('.', '/') + ".html");
}
/**
* The command line interface for this tool. The options must be split into
* strings like this: "-baseDir", "/temp/data",... By default, -tcp, -web,
* -browser and -pg are started. If there is a problem starting a service,
* the program terminates with an exit code of 1. Options are case
* sensitive. The following options are supported:
* <ul>
* <li>-help or -? (print the list of options) </li>
* <li>-web (start the Web Server and H2 Console) </li>
* <li>-browser (start a browser and open a page to connect to the
* Web Server) </li>
* <li>-tcp (start the TCP Server) </li>
* <li>-tcpShutdown {url} (shutdown the running TCP Server,
* URL example: tcp://localhost:9094) </li>
* <li>-pg (start the PG Server) </li>
* <li>-ftp (start the FTP Server) </li>
* <li>-trace (print additional trace information; for all servers) </li>
* <li>-baseDir {directory} (sets the base directory for H2 databases;
* for all servers) </li>
* <li>-ifExists (only existing databases may be opened;
* for all servers) </li>
* </ul>
* For each Server, additional options are available:
* <ul>
* <li>-webPort {port} (the port of Web Server, default: 8082) </li>
* <li>-webSSL (HTTPS is to be be used) </li>
* <li>-webAllowOthers (enable remote connections)
* </li>
* <li>-tcpPort {port} (the port of TCP Server, default: 9092) </li>
* <li>-tcpSSL (SSL is to be used) </li>
* <li>-tcpAllowOthers (enable remote connections)
* </li>
* <li>-tcpPassword {password} (the password for shutting down a TCP
* Server) </li>
* <li>-tcpShutdownForce (don't wait for other connections to
* close) </li>
* <li>-pgPort {port} (the port of PG Server, default: 5435) </li>
* <li>-pgAllowOthers (enable remote connections)
* </li>
* <li>-ftpPort {port} </li>
* <li>-ftpDir {directory} </li>
* <li>-ftpRead {readUserName} </li>
* <li>-ftpWrite {writeUserName} </li>
* <li>-ftpWritePassword {password} </li>
* </ul>
* When running without options, -tcp, -web, -browser and -pg are started.<br />
* Options are case sensitive. Supported options are:
* <table>
* <tr><td>[-help] or [-?]</td>
* <td>Print the list of options</td></tr>
* <tr><td>[-web]</td>
* <td>Start the web server with the H2 Console</td></tr>
* <tr><td>[-webAllowOthers]</td>
* <td>Allow other computers to connect</td></tr>
* <tr><td>[-webPort &lt;port&gt;]</td>
* <td>The port (default: 8082)</td></tr>
* <tr><td>[-webSSL]</td>
* <td>Use encrypted (HTTPS) connections</td></tr>
* <tr><td>[-browser]</td>
* <td>Start a browser and open a page to connect to the web server</td></tr>
* <tr><td>[-tcp]</td>
* <td>Start the TCP server</td></tr>
* <tr><td>[-tcpAllowOthers]</td>
* <td>Allow other computers to connect</td></tr>
* <tr><td>[-tcpPort &lt;port&gt;]</td>
* <td>The port (default: 9092)</td></tr>
* <tr><td>[-tcpSSL]</td>
* <td>Use encrypted (SSL) connections</td></tr>
* <tr><td>[-tcpPassword &lt;pwd&gt;]</td>
* <td>The password for shutting down a TCP server</td></tr>
* <tr><td>[-tcpShutdown &lt;url&gt;]</td>
* <td>Stop the TCP server; example: tcp://localhost:9094</td></tr>
* <tr><td>[-tcpShutdownForce]</td>
* <td>Do not wait until all connections are closed</td></tr>
* <tr><td>[-pg]</td>
* <td>Start the PG server</td></tr>
* <tr><td>[-pgAllowOthers]</td>
* <td>Allow other computers to connect</td></tr>
* <tr><td>[-pgPort &lt;port&gt;]</td>
* <td>The port (default: 5435)</td></tr>
* <tr><td>[-ftp]</td>
* <td>Start the FTP server</td></tr>
* <tr><td>[-ftpPort &lt;port&gt;]</td>
* <td>The port (default: 8021)</td></tr>
* <tr><td>[-ftpDir &lt;dir&gt;]</td>
* <td>The base directory (default: ftp)</td></tr>
* <tr><td>[-ftpRead &lt;user&gt;]</td>
* <td>The user name for reading (default: guest)</td></tr>
* <tr><td>[-ftpWrite &lt;user&gt;]</td>
* <td>The user name for writing (default: sa)</td></tr>
* <tr><td>[-ftpWritePassword &lt;p&gt;]</td>
* <td>The write password (default: sa)</td></tr>
* <tr><td>[-baseDir &lt;dir&gt;]</td>
* <td>The base directory for H2 databases; for all servers</td></tr>
* <tr><td>[-ifExists]</td>
* <td>Only existing databases may be opened; for all servers</td></tr>
* <tr><td>[-trace]</td>
* <td>Print additional trace information; for all servers</td></tr>
* </table>
* @h2.resource
*
* @param args the command line arguments
* @throws SQLException
*/
public static void main(String[] args) throws SQLException {
int exitCode = new Server().run(args, System.out);
if (exitCode != 0) {
System.exit(exitCode);
}
new Server().run(args);
}
/**
* INTERNAL
*/
public int run(String[] args, PrintStream out) throws SQLException {
public void run(String[] args) throws SQLException {
boolean tcpStart = false, pgStart = false, webStart = false, ftpStart = false;
boolean browserStart = false;
boolean tcpShutdown = false, tcpShutdownForce = false;
......@@ -153,8 +120,8 @@ public class Server implements Runnable, ShutdownHandler {
if (arg == null) {
continue;
} else if ("-?".equals(arg) || "-help".equals(arg)) {
showUsage(null, out);
return EXIT_ERROR;
showUsage();
return;
} else if (arg.startsWith("-web")) {
if ("-web".equals(arg)) {
startDefaultServers = false;
......@@ -172,8 +139,7 @@ public class Server implements Runnable, ShutdownHandler {
} else if ("-webScript".equals(arg)) {
i++;
} else {
showUsage(arg, out);
return EXIT_ERROR;
throwUnsupportedOption(arg);
}
} else if ("-browser".equals(arg)) {
startDefaultServers = false;
......@@ -206,8 +172,7 @@ public class Server implements Runnable, ShutdownHandler {
tcpShutdownForce = true;
}
} else {
showUsage(arg, out);
return EXIT_ERROR;
throwUnsupportedOption(arg);
}
} else if (arg.startsWith("-pg")) {
if ("-pg".equals(arg)) {
......@@ -220,8 +185,7 @@ public class Server implements Runnable, ShutdownHandler {
} else if ("-pgPort".equals(arg)) {
i++;
} else {
showUsage(arg, out);
return EXIT_ERROR;
throwUnsupportedOption(arg);
}
} else if (arg.startsWith("-ftp")) {
if ("-ftp".equals(arg)) {
......@@ -240,8 +204,7 @@ public class Server implements Runnable, ShutdownHandler {
} else if ("-ftpTask".equals(arg)) {
// no parameters
} else {
showUsage(arg, out);
return EXIT_ERROR;
throwUnsupportedOption(arg);
}
} else if ("-trace".equals(arg)) {
// no parameters
......@@ -254,11 +217,9 @@ public class Server implements Runnable, ShutdownHandler {
} else if ("-baseDir".equals(arg)) {
i++;
} else {
showUsage(arg, out);
return EXIT_ERROR;
throwUnsupportedOption(arg);
}
}
int exitCode = 0;
if (startDefaultServers) {
tcpStart = true;
pgStart = true;
......@@ -270,58 +231,41 @@ public class Server implements Runnable, ShutdownHandler {
out.println("Shutting down TCP Server at " + tcpShutdownServer);
shutdownTcpServer(tcpShutdownServer, tcpPassword, tcpShutdownForce);
}
if (tcpStart) {
tcp = createTcpServer(args);
try {
tcp.start();
} catch (SQLException e) {
// ignore (status is displayed)
e.printStackTrace();
exitCode = EXIT_ERROR;
}
out.println(tcp.getStatus());
}
if (pgStart) {
pg = createPgServer(args);
try {
pg.start();
} catch (SQLException e) {
// ignore (status is displayed)
e.printStackTrace();
exitCode = EXIT_ERROR;
}
out.println(pg.getStatus());
}
if (webStart) {
web = createWebServer(args);
web.setShutdownHandler(this);
SQLException result = null;
try {
web.start();
} catch (SQLException e) {
// ignore (status is displayed)
e.printStackTrace();
exitCode = EXIT_ERROR;
result = e;
}
out.println(web.getStatus());
// start browser anyway (even if the server is already running)
// start browser in any case (even if the server is already running)
// because some people don't look at the output,
// but are wondering why nothing happens
if (browserStart) {
StartBrowser.openURL(web.getURL());
}
if (result != null) {
throw result;
}
}
if (tcpStart) {
tcp = createTcpServer(args);
tcp.start();
out.println(tcp.getStatus());
}
if (pgStart) {
pg = createPgServer(args);
pg.start();
out.println(pg.getStatus());
}
if (ftpStart) {
ftp = createFtpServer(args);
try {
ftp.start();
} catch (SQLException e) {
// ignore (status is displayed)
e.printStackTrace();
exitCode = EXIT_ERROR;
}
ftp.start();
out.println(ftp.getStatus());
}
return exitCode;
}
/**
......
......@@ -28,83 +28,71 @@ import org.h2.util.FileUtils;
import org.h2.util.JdbcDriverUtils;
import org.h2.util.JdbcUtils;
import org.h2.util.SortedProperties;
import org.h2.util.Tool;
/**
* Interactive command line tool to access a database using JDBC.
* @h2.resource
*/
public class Shell {
/**
* The system output stream.
*/
PrintStream out = System.out;
public class Shell extends Tool {
private PrintStream err = System.err;
private InputStream in = System.in;
private BufferedReader reader;
private Connection conn;
private Statement stat;
private boolean listMode;
private int maxColumnSize = 100;
// Windows: '\u00b3';
private char boxVertical = '|';
private BufferedReader reader;
/**
* The command line interface for this tool. The options must be split into
* strings like this: "-user", "sa",... Options are case sensitive. The
* following options are supported:
* <ul>
* <li>-help or -? (print the list of options) </li>
* <li>-url jdbc:h2:... (database URL) </li>
* <li>-user username </li>
* <li>-password password </li>
* <li>-driver driver the JDBC driver class name (not required for most
* databases) </li>
* </ul>
* Options are case sensitive. Supported options are:
* <table>
* <tr><td>[-help] or [-?]</td>
* <td>Print the list of options</td></tr>
* <tr><td>[-url &lt;url&gt;]</td>
* <td>The database URL (jdbc:h2:...)</td></tr>
* <tr><td>[-user &lt;user&gt;]</td>
* <td>The user name</td></tr>
* <tr><td>[-password &lt;pwd&gt;]</td>
* <td>The password</td></tr>
* <tr><td>[-driver &lt;class&gt;]</td>
* <td>The JDBC driver class to use (not required in most cases)</td></tr>
* </table>
* @h2.resource
*
* @param args the command line arguments
* @throws SQLException
*/
public static void main(String[] args) throws SQLException {
new Shell().run(args);
}
private void showUsage() {
println("An interactive command line database tool.");
println("java "+getClass().getName() + "\n" +
" [-url <url>] The database URL\n" +
" [-user <user>] The user name\n" +
" [-password <pwd>] The password\n" +
" [-driver <class>] The JDBC driver class to use (not required in most cases)");
println("See also http://h2database.com/javadoc/" + getClass().getName().replace('.', '/') + ".html");
/**
* Sets the standard error stream.
*
* @param out the new standard error stream
*/
public void setErr(PrintStream err) {
this.err = err;
}
/**
* Redirects the input and output. By default, System.in, out and err are
* used.
* Redirects the standard input. By default, System.in is used.
*
* @param in the input stream to use
* @param out the output stream to use
* @param err the output error stream to use
*/
public void setStreams(InputStream in, PrintStream out, PrintStream err) {
public void setIn(InputStream in) {
this.in = in;
this.out = out;
this.err = err;
}
/**
* Redirects the input and output. By default, System.in, out and err are
* used.
* Redirects the standard input. By default, System.in is used.
*
* @param reader the input stream reader to use
* @param out the output stream to use
* @param err the output error stream to use
*/
public void setStreams(BufferedReader reader, PrintStream out, PrintStream err) {
public void setInReader(BufferedReader reader) {
this.reader = reader;
this.out = out;
this.err = err;
}
/**
......@@ -117,19 +105,18 @@ public class Shell {
String user = "";
String password = "";
for (int i = 0; args != null && i < args.length; i++) {
if (args[i].equals("-url")) {
String arg = args[i];
if (arg.equals("-url")) {
url = args[++i];
} else if (args[i].equals("-user")) {
} else if (arg.equals("-user")) {
user = args[++i];
} else if (args[i].equals("-password")) {
} else if (arg.equals("-password")) {
password = args[++i];
} else if (args[i].equals("-driver")) {
} else if (arg.equals("-driver")) {
String driver = args[++i];
ClassUtils.loadUserClass(driver);
} else {
println("Unsupported option: " + args[i]);
showUsage();
return;
throwUnsupportedOption(arg);
}
}
if (url != null) {
......
......@@ -57,7 +57,9 @@ public class TestShell extends TestBase {
public void run() {
try {
Shell shell = new Shell();
shell.setStreams(toolIn, toolOut, toolOut);
shell.setIn(toolIn);
shell.setOut(toolOut);
shell.setErr(toolOut);
shell.run(new String[0]);
} catch (SQLException e) {
e.printStackTrace();
......
......@@ -162,8 +162,14 @@ public class TestTools extends TestBase {
ByteArrayOutputStream buff = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(buff);
server = new Server();
int gotCode = server.run(args, ps);
assertEquals(exitCode, gotCode);
server.setOut(ps);
int result = 0;
try {
server.run(args);
} catch (SQLException e) {
result = 1;
}
assertEquals(exitCode, result);
ps.flush();
String s = new String(buff.toByteArray());
return s;
......
......@@ -9,8 +9,10 @@ package org.h2.dev.util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.message.Message;
import org.h2.util.Tool;
......@@ -24,7 +26,7 @@ public class FileViewer extends Tool {
*
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
public static void main(String[] args) throws SQLException {
new FileViewer().run(args);
}
......@@ -42,7 +44,7 @@ public class FileViewer extends Tool {
// getClass().getName().replace('.', '/') + ".html");
}
public void run(String[] args) {
public void run(String[] args) throws SQLException {
String file = null;
String find = null;
boolean head = false, tail = false;
......@@ -69,9 +71,7 @@ public class FileViewer extends Tool {
showUsage();
return;
} else {
out.println("Unsupported option: " + arg);
showUsage();
return;
throwUnsupportedOption(arg);
}
}
if (file == null) {
......@@ -84,7 +84,7 @@ public class FileViewer extends Tool {
try {
process(file, find, head, tail, start, lines, quiet);
} catch (IOException e) {
e.printStackTrace();
throw Message.convert(e);
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论