提交 ed04a08d authored 作者: Thomas Mueller's avatar Thomas Mueller

Server.createTcpServer, createPgServer, createWebServer: invalid arguments are now detected.

上级 6cf432c7
...@@ -77,7 +77,7 @@ public class Backup extends Tool { ...@@ -77,7 +77,7 @@ public class Backup extends Tool {
showUsage(); showUsage();
return; return;
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} }
try { try {
......
...@@ -80,7 +80,7 @@ public class ChangeFileEncryption extends Tool { ...@@ -80,7 +80,7 @@ public class ChangeFileEncryption extends Tool {
showUsage(); showUsage();
return; return;
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} }
if ((encryptPassword == null && decryptPassword == null) || cipher == null) { if ((encryptPassword == null && decryptPassword == null) || cipher == null) {
......
...@@ -146,7 +146,7 @@ ShutdownHandler { ...@@ -146,7 +146,7 @@ ShutdownHandler {
} else if ("-webPort".equals(arg)) { } else if ("-webPort".equals(arg)) {
i++; i++;
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} else if ("-tool".equals(arg)) { } else if ("-tool".equals(arg)) {
startDefaultServers = false; startDefaultServers = false;
...@@ -177,7 +177,7 @@ ShutdownHandler { ...@@ -177,7 +177,7 @@ ShutdownHandler {
} else if ("-tcpShutdownForce".equals(arg)) { } else if ("-tcpShutdownForce".equals(arg)) {
tcpShutdownForce = true; tcpShutdownForce = true;
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} else if (arg.startsWith("-pg")) { } else if (arg.startsWith("-pg")) {
if ("-pg".equals(arg)) { if ("-pg".equals(arg)) {
...@@ -190,7 +190,7 @@ ShutdownHandler { ...@@ -190,7 +190,7 @@ ShutdownHandler {
} else if ("-pgPort".equals(arg)) { } else if ("-pgPort".equals(arg)) {
i++; i++;
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} else if ("-properties".equals(arg)) { } else if ("-properties".equals(arg)) {
i++; i++;
...@@ -201,7 +201,7 @@ ShutdownHandler { ...@@ -201,7 +201,7 @@ ShutdownHandler {
} else if ("-baseDir".equals(arg)) { } else if ("-baseDir".equals(arg)) {
i++; i++;
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} }
if (startDefaultServers) { if (startDefaultServers) {
......
...@@ -93,7 +93,7 @@ public class ConvertTraceFile extends Tool { ...@@ -93,7 +93,7 @@ public class ConvertTraceFile extends Tool {
showUsage(); showUsage();
return; return;
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} }
try { try {
......
...@@ -72,7 +72,7 @@ public class CreateCluster extends Tool { ...@@ -72,7 +72,7 @@ public class CreateCluster extends Tool {
showUsage(); showUsage();
return; return;
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} }
if (urlSource == null || urlTarget == null || serverList == null) { if (urlSource == null || urlTarget == null || serverList == null) {
......
...@@ -58,7 +58,7 @@ public class DeleteDbFiles extends Tool { ...@@ -58,7 +58,7 @@ public class DeleteDbFiles extends Tool {
showUsage(); showUsage();
return; return;
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} }
process(dir, db, quiet); process(dir, db, quiet);
......
...@@ -167,7 +167,7 @@ public class Recover extends Tool implements DataHandler { ...@@ -167,7 +167,7 @@ public class Recover extends Tool implements DataHandler {
showUsage(); showUsage();
return; return;
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} }
process(dir, db); process(dir, db);
......
...@@ -66,7 +66,7 @@ public class Restore extends Tool { ...@@ -66,7 +66,7 @@ public class Restore extends Tool {
showUsage(); showUsage();
return; return;
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} }
execute(zipFileName, dir, db, false); execute(zipFileName, dir, db, false);
......
...@@ -126,7 +126,7 @@ public class RunScript extends Tool { ...@@ -126,7 +126,7 @@ public class RunScript extends Tool {
showUsage(); showUsage();
return; return;
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} }
if (url == null) { if (url == null) {
......
...@@ -88,7 +88,7 @@ public class Script extends Tool { ...@@ -88,7 +88,7 @@ public class Script extends Tool {
showUsage(); showUsage();
return; return;
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} }
if (url == null) { if (url == null) {
......
...@@ -44,6 +44,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler { ...@@ -44,6 +44,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
* @param args the command line arguments * @param args the command line arguments
*/ */
public Server(Service service, String... args) throws SQLException { public Server(Service service, String... args) throws SQLException {
verifyArgs(args);
this.service = service; this.service = service;
try { try {
service.init(args); service.init(args);
...@@ -115,6 +116,75 @@ public class Server extends Tool implements Runnable, ShutdownHandler { ...@@ -115,6 +116,75 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
new Server().runTool(args); new Server().runTool(args);
} }
private void verifyArgs(String... args) throws SQLException {
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg == null) {
continue;
} else if ("-?".equals(arg) || "-help".equals(arg)) {
// ok
} else if (arg.startsWith("-web")) {
if ("-web".equals(arg)) {
// ok
} else if ("-webAllowOthers".equals(arg)) {
// no parameters
} else if ("-webDaemon".equals(arg)) {
// no parameters
} else if ("-webSSL".equals(arg)) {
// no parameters
} else if ("-webPort".equals(arg)) {
i++;
} else {
throwUnsupportedOption(arg);
}
} else if ("-browser".equals(arg)) {
// ok
} else if (arg.startsWith("-tcp")) {
if ("-tcp".equals(arg)) {
// ok
} else if ("-tcpAllowOthers".equals(arg)) {
// no parameters
} else if ("-tcpDaemon".equals(arg)) {
// no parameters
} else if ("-tcpSSL".equals(arg)) {
// no parameters
} else if ("-tcpPort".equals(arg)) {
i++;
} else if ("-tcpPassword".equals(arg)) {
i++;
} else if ("-tcpShutdown".equals(arg)) {
i++;
} else if ("-tcpShutdownForce".equals(arg)) {
// ok
} else {
throwUnsupportedOption(arg);
}
} else if (arg.startsWith("-pg")) {
if ("-pg".equals(arg)) {
// ok
} else if ("-pgAllowOthers".equals(arg)) {
// no parameters
} else if ("-pgDaemon".equals(arg)) {
// no parameters
} else if ("-pgPort".equals(arg)) {
i++;
} else {
throwUnsupportedOption(arg);
}
} else if ("-properties".equals(arg)) {
i++;
} else if ("-trace".equals(arg)) {
// no parameters
} else if ("-ifExists".equals(arg)) {
// no parameters
} else if ("-baseDir".equals(arg)) {
i++;
} else {
throwUnsupportedOption(arg);
}
}
}
public void runTool(String... args) throws SQLException { public void runTool(String... args) throws SQLException {
boolean tcpStart = false, pgStart = false, webStart = false; boolean tcpStart = false, pgStart = false, webStart = false;
boolean browserStart = false; boolean browserStart = false;
...@@ -142,7 +212,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler { ...@@ -142,7 +212,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
} else if ("-webPort".equals(arg)) { } else if ("-webPort".equals(arg)) {
i++; i++;
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} else if ("-browser".equals(arg)) { } else if ("-browser".equals(arg)) {
startDefaultServers = false; startDefaultServers = false;
...@@ -168,7 +238,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler { ...@@ -168,7 +238,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
} else if ("-tcpShutdownForce".equals(arg)) { } else if ("-tcpShutdownForce".equals(arg)) {
tcpShutdownForce = true; tcpShutdownForce = true;
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} else if (arg.startsWith("-pg")) { } else if (arg.startsWith("-pg")) {
if ("-pg".equals(arg)) { if ("-pg".equals(arg)) {
...@@ -181,7 +251,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler { ...@@ -181,7 +251,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
} else if ("-pgPort".equals(arg)) { } else if ("-pgPort".equals(arg)) {
i++; i++;
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} else if ("-properties".equals(arg)) { } else if ("-properties".equals(arg)) {
i++; i++;
...@@ -192,9 +262,10 @@ public class Server extends Tool implements Runnable, ShutdownHandler { ...@@ -192,9 +262,10 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
} else if ("-baseDir".equals(arg)) { } else if ("-baseDir".equals(arg)) {
i++; i++;
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} }
verifyArgs(args);
if (startDefaultServers) { if (startDefaultServers) {
tcpStart = true; tcpStart = true;
pgStart = true; pgStart = true;
......
...@@ -136,7 +136,7 @@ public class Shell extends Tool implements Runnable { ...@@ -136,7 +136,7 @@ public class Shell extends Tool implements Runnable {
showUsage(); showUsage();
return; return;
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} }
if (url != null) { if (url != null) {
......
...@@ -50,8 +50,18 @@ public abstract class Tool { ...@@ -50,8 +50,18 @@ public abstract class Tool {
* @param option the unsupported option * @param option the unsupported option
* @return this method never returns normally * @return this method never returns normally
*/ */
protected SQLException throwUnsupportedOption(String option) throws SQLException { protected SQLException showUsageAndThrowUnsupportedOption(String option) throws SQLException {
showUsage(); showUsage();
throw throwUnsupportedOption(option);
}
/**
* Throw a SQLException saying this command line option is not supported.
*
* @param option the unsupported option
* @return this method never returns normally
*/
protected SQLException throwUnsupportedOption(String option) throws SQLException {
throw new SQLException("Unsupported option: " + option); throw new SQLException("Unsupported option: " + option);
} }
......
...@@ -113,7 +113,7 @@ public class FileShell extends Tool { ...@@ -113,7 +113,7 @@ public class FileShell extends Tool {
showUsage(); showUsage();
return; return;
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} }
promptLoop(); promptLoop();
......
...@@ -170,12 +170,12 @@ public class FtpServer extends Tool implements Service { ...@@ -170,12 +170,12 @@ public class FtpServer extends Tool implements Service {
} else if ("-ftpTask".equals(arg)) { } else if ("-ftpTask".equals(arg)) {
// no parameters // no parameters
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} else if ("-trace".equals(arg)) { } else if ("-trace".equals(arg)) {
// no parameters // no parameters
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} }
Server server = new Server(this, args); Server server = new Server(this, args);
......
...@@ -69,7 +69,7 @@ public class FileViewer extends Tool { ...@@ -69,7 +69,7 @@ public class FileViewer extends Tool {
showUsage(); showUsage();
return; return;
} else { } else {
throwUnsupportedOption(arg); showUsageAndThrowUnsupportedOption(arg);
} }
} }
if (file == null) { if (file == null) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论