http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectionFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectionFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectionFunction.java
index af325d5..4fe20c1 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectionFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectionFunction.java
@@ -21,55 +21,36 @@ import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.OptionBuilder;
import org.apache.sqoop.client.core.Constants;
import org.apache.sqoop.client.utils.TableDisplayer;
-import org.apache.sqoop.json.ConnectionBean;
import org.apache.sqoop.model.MConnection;
-import org.codehaus.groovy.tools.shell.IO;
-import java.io.PrintWriter;
import java.text.DateFormat;
-import java.text.MessageFormat;
import java.util.LinkedList;
import java.util.List;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
import static org.apache.sqoop.client.utils.FormDisplayer.*;
-import static org.apache.sqoop.client.core.RequestCache.*;
/**
*
*/
public class ShowConnectionFunction extends SqoopFunction {
-
-
- private IO io;
-
-
@SuppressWarnings("static-access")
- protected ShowConnectionFunction(IO io) {
- this.io = io;
-
+ protected ShowConnectionFunction() {
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants
- .RES_SHOW_PROMPT_DISPLAY_ALL_CONNS))
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_CONNS))
.withLongOpt(Constants.OPT_ALL)
.create(Constants.OPT_ALL_CHAR));
this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_XID)
- .withDescription(getResource().getString(Constants
- .RES_SHOW_PROMPT_DISPLAY_CONN_XID))
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_CONN_XID))
.withLongOpt(Constants.OPT_XID)
.create(Constants.OPT_XID_CHAR));
}
- public void printHelp(PrintWriter out) {
- out.println(getResource().getString(Constants.RES_SHOW_CONN_USAGE));
- super.printHelp(out);
- }
-
- public Object execute(List<String> args) {
- CommandLine line = parseOptions(this, 1, args);
+ public Object executeFunction(CommandLine line) {
if (line.hasOption(Constants.OPT_ALL)) {
- showConnection(null);
+ showConnections();
} else if (line.hasOption(Constants.OPT_XID)) {
- showConnection(line.getOptionValue(Constants.OPT_XID));
+ showConnection(getLong(line, Constants.OPT_XID));
} else {
showSummary();
}
@@ -78,13 +59,12 @@ public class ShowConnectionFunction extends SqoopFunction {
}
private void showSummary() {
- ConnectionBean connectionBean = readConnection(null);
- List<MConnection> connections = connectionBean.getConnections();
+ List<MConnection> connections = client.getConnections();
List<String> header = new LinkedList<String>();
- header.add(getResource().getString(Constants.RES_TABLE_HEADER_ID));
- header.add(getResource().getString(Constants.RES_TABLE_HEADER_NAME));
- header.add(getResource().getString(Constants.RES_TABLE_HEADER_CONNECTOR));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_ID));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_NAME));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_CONNECTOR));
List<String> ids = new LinkedList<String>();
List<String> names = new LinkedList<String>();
@@ -96,40 +76,43 @@ public class ShowConnectionFunction extends SqoopFunction {
connectors.add(String.valueOf(connection.getConnectorId()));
}
- TableDisplayer.display(io, header, ids, names, connectors);
+ TableDisplayer.display(header, ids, names, connectors);
}
- private void showConnection(String xid) {
- ConnectionBean connectionBean = readConnection(xid);
+ private void showConnections() {
+ List<MConnection> connections = client.getConnections();
- List<MConnection> connections = connectionBean.getConnections();
+ printlnResource(Constants.RES_SHOW_PROMPT_CONNS_TO_SHOW, connections.size());
- String s = MessageFormat.format(getResource().getString(Constants
- .RES_SHOW_PROMPT_CONNS_TO_SHOW), connections.size());
+ for (MConnection connection : connections) {
+ displayConnection(connection);
+ }
+ }
+
+ private void showConnection(Long xid) {
+ MConnection connection = client.getConnection(xid);
- io.out.println(s);
+ printlnResource(Constants.RES_SHOW_PROMPT_CONNS_TO_SHOW, 1);
+
+ displayConnection(connection);
+ }
+ private void displayConnection(MConnection connection) {
DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
- for (MConnection connection : connections) {
- s = MessageFormat.format(
- getResource().getString(Constants.RES_SHOW_PROMPT_CONN_INFO),
- connection.getPersistenceId(),
- connection.getName(),
- formatter.format(connection.getCreationDate()),
- formatter.format(connection.getLastUpdateDate())
- );
- io.out.println(s);
-
- long connectorId = connection.getConnectorId();
-
- // Display connector part
- displayForms(io,
- connection.getConnectorPart().getForms(),
- connectionBean.getConnectorBundle(connectorId));
- displayForms(io,
- connection.getFrameworkPart().getForms(),
- connectionBean.getFrameworkBundle());
- }
+ printlnResource(Constants.RES_SHOW_PROMPT_CONN_INFO,
+ connection.getPersistenceId(),
+ connection.getName(),
+ formatter.format(connection.getCreationDate()),
+ formatter.format(connection.getLastUpdateDate())
+ );
+
+ long connectorId = connection.getConnectorId();
+
+ // Display connector part
+ displayForms(connection.getConnectorPart().getForms(),
+ client.getResourceBundle(connectorId));
+ displayForms(connection.getFrameworkPart().getForms(),
+ client.getFrameworkResourceBundle());
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectorFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectorFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectorFunction.java
index c2464d2..19a8123 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectorFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectorFunction.java
@@ -17,59 +17,37 @@
*/
package org.apache.sqoop.client.shell;
-import java.io.PrintWriter;
-import java.text.MessageFormat;
import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
-import java.util.ResourceBundle;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.OptionBuilder;
-import org.apache.commons.lang.StringEscapeUtils;
import org.apache.sqoop.client.core.Constants;
import org.apache.sqoop.client.utils.TableDisplayer;
-import org.apache.sqoop.json.ConnectorBean;
import org.apache.sqoop.model.MConnector;
-import org.codehaus.groovy.tools.shell.IO;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
import static org.apache.sqoop.client.utils.FormDisplayer.*;
-import static org.apache.sqoop.client.core.RequestCache.*;
@SuppressWarnings("serial")
-public class ShowConnectorFunction extends SqoopFunction
-{
-
- private IO io;
-
-
+public class ShowConnectorFunction extends SqoopFunction {
@SuppressWarnings("static-access")
- protected ShowConnectorFunction(IO io) {
- this.io = io;
-
+ protected ShowConnectorFunction() {
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants
- .RES_SHOW_PROMPT_DISPLAY_ALL_CONNECTORS))
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_CONNECTORS))
.withLongOpt(Constants.OPT_ALL)
.create(Constants.OPT_ALL_CHAR));
this.addOption(OptionBuilder.hasArg().withArgName("cid")
- .withDescription(getResource().getString(Constants
- .RES_SHOW_PROMPT_DISPLAY_CONNECTOR_CID))
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_CONNECTOR_CID))
.withLongOpt(Constants.OPT_CID)
.create(Constants.OPT_CID_CHAR));
}
- public void printHelp(PrintWriter out) {
- out.println(getResource().getString(Constants.RES_SHOW_CONNECTOR_USAGE));
- super.printHelp(out);
- }
-
- public Object execute(List<String> args) {
- CommandLine line = parseOptions(this, 1, args);
+ public Object executeFunction(CommandLine line) {
if (line.hasOption(Constants.OPT_ALL)) {
- showConnector(null);
+ showConnectors();
} else if (line.hasOption(Constants.OPT_CID)) {
- showConnector(line.getOptionValue(Constants.OPT_CID));
+ showConnector(getLong(line, Constants.OPT_CID));
} else {
showSummary();
}
@@ -78,14 +56,13 @@ public class ShowConnectorFunction extends SqoopFunction
}
private void showSummary() {
- ConnectorBean connectorBean = readConnector(null);
- List<MConnector> connectors = connectorBean.getConnectors();
+ List<MConnector> connectors = client.getConnectors();
List<String> header = new LinkedList<String>();
- header.add(getResource().getString(Constants.RES_TABLE_HEADER_ID));
- header.add(getResource().getString(Constants.RES_TABLE_HEADER_NAME));
- header.add(getResource().getString(Constants.RES_TABLE_HEADER_VERSION));
- header.add(getResource().getString(Constants.RES_TABLE_HEADER_CLASS));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_ID));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_NAME));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_VERSION));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_CLASS));
List<String> ids = new LinkedList<String>();
List<String> uniqueNames = new LinkedList<String>();
@@ -99,25 +76,34 @@ public class ShowConnectorFunction extends SqoopFunction
classes.add(connector.getClassName());
}
- TableDisplayer.display(io, header, ids, uniqueNames, versions, classes);
+ TableDisplayer.display(header, ids, uniqueNames, versions, classes);
}
- private void showConnector(String cid) {
- ConnectorBean connectorBean = readConnector(cid);
- List<MConnector> connectors = connectorBean.getConnectors();
- Map<Long, ResourceBundle> bundles = connectorBean.getResourceBundles();
- String s = MessageFormat.format(getResource().getString(Constants
- .RES_SHOW_PROMPT_CONNECTORS_TO_SHOW), connectors.size());
- io.out.println(s);
+ private void showConnectors() {
+ List<MConnector> connectors = client.getConnectors();
+
+ printlnResource(Constants.RES_SHOW_PROMPT_CONNECTORS_TO_SHOW, connectors.size());
+
for (MConnector connector : connectors) {
- s = MessageFormat.format(getResource().getString(Constants
- .RES_SHOW_PROMPT_CONNECTOR_INFO), connector.getPersistenceId(),
- connector.getUniqueName(), connector.getClassName(),
- connector.getVersion());
- io.out.println(StringEscapeUtils.unescapeJava(s));
- displayFormMetadataDetails(io, connector, bundles.get(connector.getPersistenceId()));
+ displayConnector(connector);
}
+ }
+
+ private void showConnector(Long cid) {
+ MConnector connector = client.getConnector(cid);
+
+ printlnResource(Constants.RES_SHOW_PROMPT_CONNECTORS_TO_SHOW, 1);
+
+ displayConnector(connector);
+ }
- io.out.println();
+ private void displayConnector(MConnector connector) {
+ printlnResource(Constants.RES_SHOW_PROMPT_CONNECTOR_INFO,
+ connector.getPersistenceId(),
+ connector.getUniqueName(),
+ connector.getClassName(),
+ connector.getVersion()
+ );
+ displayFormMetadataDetails(connector, client.getResourceBundle(connector.getPersistenceId()));
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/ShowFrameworkFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/ShowFrameworkFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/ShowFrameworkFunction.java
index 31de8dc..d37b73a 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/ShowFrameworkFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/ShowFrameworkFunction.java
@@ -17,41 +17,26 @@
*/
package org.apache.sqoop.client.shell;
-import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.cli.CommandLine;
import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.json.FrameworkBean;
import org.apache.sqoop.model.MFramework;
-import org.codehaus.groovy.tools.shell.IO;
-import java.io.PrintWriter;
-import java.text.MessageFormat;
-import java.util.List;
import java.util.ResourceBundle;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
import static org.apache.sqoop.client.utils.FormDisplayer.*;
-import static org.apache.sqoop.client.core.RequestCache.*;
/**
*
*/
public class ShowFrameworkFunction extends SqoopFunction {
-
- private IO io;
-
@SuppressWarnings("static-access")
- protected ShowFrameworkFunction(IO io) {
- this.io = io;
- }
-
- public void printHelp(PrintWriter out) {
- out.println(getResource().getString(Constants.RES_SHOW_FRAMEWORK_USAGE));
- super.printHelp(out);
+ protected ShowFrameworkFunction() {
}
- public Object execute(List<String> args) {
- if (args.size() != 1) {
- printHelp(io.out);
- io.out.println();
+ public Object executeFunction(CommandLine line) {
+ if (line.getArgs().length != 1) {
+ printlnResource(Constants.RES_SHOW_FRAMEWORK_USAGE);
return null;
}
@@ -61,16 +46,10 @@ public class ShowFrameworkFunction extends SqoopFunction {
}
private void showFramework() {
- FrameworkBean frameworkBean = readFramework();
-
- MFramework framework = frameworkBean.getFramework();
- ResourceBundle bundle = frameworkBean.getResourceBundle();
- io.out.println(StringEscapeUtils.unescapeJava(
- MessageFormat.format(getResource().getString(Constants.RES_SHOW_PROMPT_FRAMEWORK_OPTS),
- framework.getPersistenceId())));
-
- displayFormMetadataDetails(io, framework, bundle);
+ MFramework framework = client.getFramework();
+ ResourceBundle bundle = client.getFrameworkResourceBundle();
- io.out.println();
+ printlnResource(Constants.RES_SHOW_PROMPT_FRAMEWORK_OPTS, framework.getPersistenceId());
+ displayFormMetadataDetails(framework, bundle);
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/ShowJobFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/ShowJobFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/ShowJobFunction.java
index 0d67133..5505d51 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/ShowJobFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/ShowJobFunction.java
@@ -21,53 +21,36 @@ import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.OptionBuilder;
import org.apache.sqoop.client.core.Constants;
import org.apache.sqoop.client.utils.TableDisplayer;
-import org.apache.sqoop.json.JobBean;
import org.apache.sqoop.model.MJob;
-import org.codehaus.groovy.tools.shell.IO;
-import java.io.PrintWriter;
import java.text.DateFormat;
-import java.text.MessageFormat;
import java.util.LinkedList;
import java.util.List;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
import static org.apache.sqoop.client.utils.FormDisplayer.*;
-import static org.apache.sqoop.client.core.RequestCache.*;
/**
*
*/
public class ShowJobFunction extends SqoopFunction {
-
- private IO io;
-
@SuppressWarnings("static-access")
- protected ShowJobFunction(IO io) {
- this.io = io;
-
+ protected ShowJobFunction() {
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants
- .RES_SHOW_PROMPT_DISPLAY_ALL_JOBS))
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_JOBS))
.withLongOpt(Constants.OPT_ALL)
.create(Constants.OPT_ALL_CHAR));
this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_JID)
- .withDescription(getResource().getString(Constants
- .RES_SHOW_PROMPT_DISPLAY_JOB_JID))
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_JOB_JID))
.withLongOpt(Constants.OPT_JID)
.create(Constants.OPT_JID_CHAR));
}
- public void printHelp(PrintWriter out) {
- out.println(getResource().getString(Constants.RES_SHOW_JOB_USAGE));
- super.printHelp(out);
- }
-
- public Object execute(List<String> args) {
- CommandLine line = parseOptions(this, 1, args);
+ public Object executeFunction(CommandLine line) {
if (line.hasOption(Constants.OPT_ALL)) {
- showJob(null);
+ showJobs();
} else if (line.hasOption(Constants.OPT_JID)) {
- showJob(line.getOptionValue(Constants.OPT_JID));
+ showJob(getLong(line, Constants.OPT_JID));
} else {
showSummary();
}
@@ -76,14 +59,13 @@ public class ShowJobFunction extends SqoopFunction {
}
private void showSummary() {
- JobBean jobBean = readJob(null);
- List<MJob> jobs = jobBean.getJobs();
+ List<MJob> jobs = client.getJobs();
List<String> header = new LinkedList<String>();
- header.add(getResource().getString(Constants.RES_TABLE_HEADER_ID));
- header.add(getResource().getString(Constants.RES_TABLE_HEADER_NAME));
- header.add(getResource().getString(Constants.RES_TABLE_HEADER_TYPE));
- header.add(getResource().getString(Constants.RES_TABLE_HEADER_CONNECTOR));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_ID));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_NAME));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_TYPE));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_CONNECTOR));
List<String> ids = new LinkedList<String>();
List<String> names = new LinkedList<String>();
@@ -97,37 +79,40 @@ public class ShowJobFunction extends SqoopFunction {
connectors.add(String.valueOf(job.getConnectorId()));
}
- TableDisplayer.display(io, header, ids, names, types, connectors);
+ TableDisplayer.display(header, ids, names, types, connectors);
}
- private void showJob(String jid) {
- JobBean jobBean = readJob(jid);
+ private void showJobs() {
+ List<MJob> jobs = client.getJobs();
+ printlnResource(Constants.RES_SHOW_PROMPT_JOBS_TO_SHOW, jobs.size());
- List<MJob> jobs = jobBean.getJobs();
- String s = MessageFormat.format(getResource().getString(Constants.RES_SHOW_PROMPT_JOBS_TO_SHOW), jobs.size());
- io.out.println(s);
+ for (MJob job : jobs) {
+ displayJob(job);
+ }
+ }
+
+ private void showJob(Long jid) {
+ MJob job = client.getJob(jid);
+ printlnResource(Constants.RES_SHOW_PROMPT_JOBS_TO_SHOW, 1);
+
+ displayJob(job);
+ }
+ private void displayJob(MJob job) {
DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
- for (MJob job : jobs) {
- s = MessageFormat.format(
- getResource().getString(Constants.RES_SHOW_PROMPT_JOB_INFO),
- job.getPersistenceId(),
- job.getName(),
- formatter.format(job.getCreationDate()),
- formatter.format(job.getLastUpdateDate())
- );
- io.out.println(s);
-
- long connectorId = job.getConnectorId();
-
- // Display connector part
- displayForms(io,
- job.getConnectorPart().getForms(),
- jobBean.getConnectorBundle(connectorId));
- displayForms(io,
- job.getFrameworkPart().getForms(),
- jobBean.getFrameworkBundle());
- }
+ printlnResource(
+ Constants.RES_SHOW_PROMPT_JOB_INFO,
+ job.getPersistenceId(),
+ job.getName(),
+ formatter.format(job.getCreationDate()),
+ formatter.format(job.getLastUpdateDate())
+ );
+
+ // Display connector part
+ displayForms(job.getConnectorPart().getForms(),
+ client.getResourceBundle(job.getConnectorId()));
+ displayForms(job.getFrameworkPart().getForms(),
+ client.getFrameworkResourceBundle());
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/ShowOptionFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/ShowOptionFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/ShowOptionFunction.java
index d8af0b2..890ede1 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/ShowOptionFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/ShowOptionFunction.java
@@ -20,47 +20,34 @@ package org.apache.sqoop.client.shell;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.OptionBuilder;
import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.core.Environment;
-import org.codehaus.groovy.tools.shell.IO;
-import java.util.List;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
/**
* Show client internal options
*/
public class ShowOptionFunction extends SqoopFunction {
-
- private IO io;
-
/**
* Construct new object.
- *
- * @param io Shell's associated IO object
*/
@SuppressWarnings("static-access")
- protected ShowOptionFunction(IO io) {
- this.io = io;
-
+ protected ShowOptionFunction() {
this.addOption(OptionBuilder
.hasArg().withArgName(Constants.OPT_NAME)
- .withDescription(getResource().getString(Constants.RES_SET_PROMPT_OPT_NAME))
+ .withDescription(resource.getString(Constants.RES_SET_PROMPT_OPT_NAME))
.withLongOpt(Constants.OPT_NAME)
.create(Constants.OPT_NAME_CHAR));
}
/**
* Execute this function from parsed command line.
- *
- * @param args Arguments passed to this function.
- * @return Null
*/
- public Object execute(List<String> args) {
- if (args.size() == 1) {
+ public Object executeFunction(CommandLine line) {
+ if (line.getArgs().length == 1) {
printAllOptions();
return null;
}
- CommandLine line = parseOptions(this, 1, args);
if (line.hasOption(Constants.OPT_NAME)) {
String optionName = line.getOptionValue(Constants.OPT_NAME);
@@ -83,7 +70,7 @@ public class ShowOptionFunction extends SqoopFunction {
* Print verbose option.
*/
private void printVerbose() {
- io.out.print("Verbose = ");
- io.out.println(Environment.isVerboose());
+ print("Verbose = ");
+ println(String.valueOf(isVerboose()));
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/ShowServerFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/ShowServerFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/ShowServerFunction.java
index e1f6fa6..110f67e 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/ShowServerFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/ShowServerFunction.java
@@ -17,62 +17,40 @@
*/
package org.apache.sqoop.client.shell;
-import java.io.PrintWriter;
-import java.text.MessageFormat;
-import java.util.List;
-
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.OptionBuilder;
import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.core.Environment;
-import org.codehaus.groovy.tools.shell.IO;
-
-@SuppressWarnings("serial")
-public class ShowServerFunction extends SqoopFunction
-{
-
- private IO io;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
+@SuppressWarnings("serial")
+public class ShowServerFunction extends SqoopFunction {
@SuppressWarnings("static-access")
- protected ShowServerFunction(IO io) {
- this.io = io;
-
+ protected ShowServerFunction() {
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants
- .RES_SHOW_PROMPT_DISPLAY_ALL_SERVERS))
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_SERVERS))
.withLongOpt(Constants.OPT_ALL)
.create(Constants.OPT_ALL_CHAR));
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants
- .RES_SHOW_PROMPT_DISPLAY_SERVER_HOST))
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_SERVER_HOST))
.withLongOpt(Constants.OPT_HOST)
.create(Constants.OPT_HOST_CHAR));
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants
- .RES_SHOW_PROMPT_DISPLAY_SERVER_PORT))
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_SERVER_PORT))
.withLongOpt(Constants.OPT_PORT)
.create(Constants.OPT_PORT_CHAR));
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants
- .RES_SHOW_PROMPT_DISPLAY_SERVER_WEBAPP))
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_SERVER_WEBAPP))
.withLongOpt(Constants.OPT_WEBAPP)
.create(Constants.OPT_WEBAPP_CHAR));
}
- public void printHelp(PrintWriter out) {
- out.println(getResource().getString(Constants.RES_SHOW_SERVER_USAGE));
- super.printHelp(out);
- }
-
- public Object execute(List<String> args) {
- if (args.size() == 1) {
- printHelp(io.out);
- io.out.println();
+ public Object executeFunction(CommandLine line) {
+ if (line.getArgs().length == 1) {
+ printlnResource(Constants.RES_SHOW_SERVER_USAGE);
return null;
}
- CommandLine line = parseOptions(this, 1, args);
if (line.hasOption(Constants.OPT_ALL)) {
showServer(true, true, true, true);
@@ -94,27 +72,17 @@ public class ShowServerFunction extends SqoopFunction
return null;
}
- private void showServer(boolean host, boolean port, boolean webapp,
- boolean version) {
- String s;
+ private void showServer(boolean host, boolean port, boolean webapp, boolean version) {
if (host) {
- s = MessageFormat.format(getResource().getString(Constants
- .RES_SHOW_PROMPT_SERVER_HOST), Environment.getServerHost());
- io.out.println(s);
+ printlnResource(Constants.RES_SHOW_PROMPT_SERVER_HOST, getServerHost());
}
if (port) {
- s = MessageFormat.format(getResource().getString(Constants
- .RES_SHOW_PROMPT_SERVER_PORT), Environment.getServerPort());
- io.out.println(s);
+ printlnResource(Constants.RES_SHOW_PROMPT_SERVER_PORT, getServerPort());
}
if (webapp) {
- s = MessageFormat.format(getResource().getString(Constants
- .RES_SHOW_PROMPT_SERVER_WEBAPP), Environment.getServerWebapp());
- io.out.println(s);
+ printlnResource(Constants.RES_SHOW_PROMPT_SERVER_WEBAPP, getServerWebapp());
}
-
- io.out.println();
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/ShowVersionFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/ShowVersionFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/ShowVersionFunction.java
index 0dfc6c8..1038116 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/ShowVersionFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/ShowVersionFunction.java
@@ -17,69 +17,48 @@
*/
package org.apache.sqoop.client.shell;
-import java.io.PrintWriter;
-import java.text.MessageFormat;
import java.util.Arrays;
-import java.util.List;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.OptionBuilder;
-import org.apache.commons.lang.StringEscapeUtils;
import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.core.Environment;
import org.apache.sqoop.client.request.VersionRequest;
import org.apache.sqoop.common.VersionInfo;
import org.apache.sqoop.json.VersionBean;
-import org.codehaus.groovy.tools.shell.IO;
-
-@SuppressWarnings("serial")
-public class ShowVersionFunction extends SqoopFunction
-{
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
- private IO io;
+@SuppressWarnings("serial")
+public class ShowVersionFunction extends SqoopFunction {
private VersionRequest versionRequest;
@SuppressWarnings("static-access")
- protected ShowVersionFunction(IO io) {
- this.io = io;
-
+ protected ShowVersionFunction() {
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants
- .RES_SHOW_PROMPT_DISPLAY_ALL_VERSIONS))
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_VERSIONS))
.withLongOpt(Constants.OPT_ALL)
.create(Constants.OPT_ALL_CHAR));
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants
- .RES_SHOW_PROMPT_DISPLAY_VERSION_SERVER))
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_VERSION_SERVER))
.withLongOpt(Constants.OPT_SERVER)
.create(Constants.OPT_SERVER_CHAR));
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants
- .RES_SHOW_PROMPT_DISPLAY_VERSION_CLIENT))
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_VERSION_CLIENT))
.withLongOpt(Constants.OPT_CLIENT)
.create(Constants.OPT_CLIENT_CHAR));
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants
- .RES_SHOW_PROMPT_DISPLAY_VERSION_PROTOCOL))
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_VERSION_PROTOCOL))
.withLongOpt(Constants.OPT_PROTOCOL)
.create(Constants.OPT_PROTOCOL_CHAR));
}
- public void printHelp(PrintWriter out) {
- out.println(getResource().getString(Constants.RES_SHOW_VERSION_USAGE));
- super.printHelp(out);
- }
-
- public Object execute(List<String> args) {
- if (args.size() == 1) {
- printHelp(io.out);
- io.out.println();
+ public Object executeFunction(CommandLine line) {
+ if (line.getArgs().length == 1) {
+ printlnResource(Constants.RES_SHOW_VERSION_USAGE);
return null;
}
- CommandLine line = parseOptions(this, 1, args);
if (line.hasOption(Constants.OPT_ALL)) {
showVersion(true, true, true);
@@ -104,17 +83,14 @@ public class ShowVersionFunction extends SqoopFunction
private void showVersion(boolean server, boolean client, boolean protocol) {
// Print out client string if needed
- String s;
if (client) {
- s = MessageFormat.format(
- getResource().getString(Constants.RES_SHOW_PROMPT_VERSION_CLIENT_SERVER),
+ printlnResource(Constants.RES_SHOW_PROMPT_VERSION_CLIENT_SERVER,
Constants.OPT_CLIENT,
VersionInfo.getVersion(),
VersionInfo.getRevision(),
VersionInfo.getUser(),
VersionInfo.getDate()
);
- io.out.println(StringEscapeUtils.unescapeJava(s));
}
// If only client version was required we do not need to continue
@@ -125,29 +101,22 @@ public class ShowVersionFunction extends SqoopFunction
if (versionRequest == null) {
versionRequest = new VersionRequest();
}
- VersionBean versionBean =
- versionRequest.doGet(Environment.getServerUrl());
+ VersionBean versionBean = versionRequest.doGet(getServerUrl());
if (server) {
- s = MessageFormat.format(
- getResource().getString(Constants.RES_SHOW_PROMPT_VERSION_CLIENT_SERVER),
+ printlnResource(Constants.RES_SHOW_PROMPT_VERSION_CLIENT_SERVER,
Constants.OPT_SERVER,
versionBean.getVersion(),
versionBean.getRevision(),
versionBean.getUser(),
versionBean.getDate()
);
- io.out.println(StringEscapeUtils.unescapeJava(s));
}
if (protocol) {
- s = MessageFormat.format(
- getResource().getString(Constants.RES_SHOW_PROMPT_VERSION_PROTOCOL),
+ printlnResource(Constants.RES_SHOW_PROMPT_VERSION_PROTOCOL,
Arrays.toString(versionBean.getProtocols())
);
- io.out.println(StringEscapeUtils.unescapeJava(s));
}
-
- io.out.println();
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/SqoopCommand.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/SqoopCommand.java b/client/src/main/java/org/apache/sqoop/client/shell/SqoopCommand.java
index df9350f..2188482 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/SqoopCommand.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/SqoopCommand.java
@@ -24,7 +24,6 @@ import groovy.lang.Script;
import java.util.*;
import org.apache.sqoop.client.core.ClientError;
-import org.apache.sqoop.client.core.Constants;
import org.apache.sqoop.common.SqoopException;
import org.codehaus.groovy.tools.shell.ComplexCommandSupport;
import org.codehaus.groovy.tools.shell.Shell;
@@ -38,13 +37,6 @@ public abstract class SqoopCommand extends ComplexCommandSupport
private String usage;
private String help;
- private static final ResourceBundle clientResource =
- ResourceBundle.getBundle(Constants.RESOURCE_NAME);
-
- protected ResourceBundle getResource() {
- return clientResource;
- }
-
@SuppressWarnings("unchecked")
protected SqoopCommand(Shell shell, String name, String shortcut,
String[] funcs, String descriptionPrefix, String descriptionPostfix) {
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/SqoopFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/SqoopFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/SqoopFunction.java
index 5632bac..bf26761 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/SqoopFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/SqoopFunction.java
@@ -17,10 +17,8 @@
*/
package org.apache.sqoop.client.shell;
-import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
-import java.util.ResourceBundle;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
@@ -29,26 +27,26 @@ import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.sqoop.client.core.ClientError;
-import org.apache.sqoop.client.core.Constants;
import org.apache.sqoop.common.SqoopException;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
+
@SuppressWarnings("serial")
-public class SqoopFunction extends Options
-{
- private static final ResourceBundle clientResource =
- ResourceBundle.getBundle(Constants.RESOURCE_NAME);
+abstract public class SqoopFunction extends Options {
- public void printHelp(PrintWriter out) {
+ public void printHelp() {
HelpFormatter formatter = new HelpFormatter();
- formatter.printOptions(out, formatter.getWidth(), this, 0, 4);
+ formatter.printOptions(getIo().out, formatter.getWidth(), this, 0, 4);
}
- protected ResourceBundle getResource() {
- return clientResource;
+ public abstract Object executeFunction(CommandLine line);
+
+ public Object execute(List<String> args) {
+ CommandLine line = parseOptions(this, 1, args);
+ return executeFunction(line);
}
- protected CommandLine parseOptions(Options options,
- int start, List<String> arglist) {
+ protected CommandLine parseOptions(Options options, int start, List<String> arglist) {
Iterator<String> iterator = arglist.iterator();
int i = 0;
for (; i < start; i ++) {
@@ -69,4 +67,8 @@ public class SqoopFunction extends Options
}
return line;
}
+
+ protected long getLong(CommandLine line, String parameterName) {
+ return Long.parseLong(line.getOptionValue(parameterName));
+ }
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java b/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java
index b4d352c..83f1c4f 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java
@@ -21,13 +21,10 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
-import java.text.MessageFormat;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.ResourceBundle;
import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.core.Environment;
import org.apache.sqoop.client.utils.ThrowableDisplayer;
import org.codehaus.groovy.runtime.MethodClosure;
import org.codehaus.groovy.tools.shell.Command;
@@ -35,6 +32,8 @@ import org.codehaus.groovy.tools.shell.CommandRegistry;
import org.codehaus.groovy.tools.shell.Groovysh;
import org.codehaus.groovy.tools.shell.IO.Verbosity;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
+
/**
* Main entry point to Sqoop client.
*
@@ -48,15 +47,10 @@ public final class SqoopShell {
*/
private static final String RC_FILE = ".sqoop2rc";
-
-
- private static final ResourceBundle clientResource =
- ResourceBundle.getBundle(Constants.RESOURCE_NAME);
/**
* Banner message that is displayed in interactive mode after client start.
*/
-
/**
* Hash of commands that we want to have in history in all cases.
*/
@@ -74,15 +68,12 @@ public final class SqoopShell {
* @param args Command line arguments
* @throws Exception
*/
- public static void main (String[] args) throws Exception
- {
+ public static void main (String[] args) throws Exception {
System.setProperty("groovysh.prompt", Constants.SQOOP_PROMPT);
Groovysh shell = new Groovysh();
// Install our error hook (exception handling)
- shell.setErrorHook(
- new MethodClosure(ThrowableDisplayer.class, "errorHook"));
- ThrowableDisplayer.setIo(shell.getIo());
+ shell.setErrorHook(new MethodClosure(ThrowableDisplayer.class, "errorHook"));
CommandRegistry registry = shell.getRegistry();
@SuppressWarnings("unchecked")
@@ -105,8 +96,11 @@ public final class SqoopShell {
shell.register(new CloneCommand(shell));
shell.register(new SubmissionCommand(shell));
+ // Configure shared shell io object
+ setIo(shell.getIo());
+
// We're running in batch mode by default
- Environment.setInteractive(false);
+ setInteractive(false);
// Let's see if user do have resource file with initial commands that he
// would like to apply.
@@ -114,21 +108,19 @@ public final class SqoopShell {
File rcFile = new File(homeDir, RC_FILE);
if(rcFile.exists()) {
- shell.getIo().out.println(MessageFormat.format(clientResource.getString
- (Constants.RES_SQOOP_PROMPT_SHELL_LOADRC), RC_FILE));
+ printlnResource(Constants.RES_SQOOP_PROMPT_SHELL_LOADRC, RC_FILE);
interpretFileContent(rcFile, shell);
- shell.getIo().out.println(clientResource.getString(Constants.RES_SQOOP_PROMPT_SHELL_LOADEDRC));
+ printlnResource(Constants.RES_SQOOP_PROMPT_SHELL_LOADEDRC);
}
if (args.length == 0) {
// Interactive mode:
- shell.getIo().setVerbosity(Verbosity.QUIET);
- shell.getIo().out.println(clientResource.getString(Constants
- .RES_SQOOP_SHELL_BANNER));
- shell.getIo().out.println();
+ getIo().setVerbosity(Verbosity.QUIET);
+ printlnResource(Constants.RES_SQOOP_SHELL_BANNER);
+ println();
// Switch to interactive mode
- Environment.setInteractive(true);
+ setInteractive(true);
shell.run(args);
} else {
@@ -163,13 +155,13 @@ public final class SqoopShell {
}
// Render shell and command to get user perception that it was run as usual
- shell.getIo().out.print(shell.renderPrompt());
- shell.getIo().out.println(line);
+ print(shell.renderPrompt());
+ println(line);
// Manually trigger command line parsing
Object result = shell.execute(line);
if (result != null) {
- shell.getIo().out.println(result);
+ println(result);
}
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/SubmissionCommand.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/SubmissionCommand.java b/client/src/main/java/org/apache/sqoop/client/shell/SubmissionCommand.java
index af4231d..993bbde 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/SubmissionCommand.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/SubmissionCommand.java
@@ -17,14 +17,13 @@
*/
package org.apache.sqoop.client.shell;
-import org.apache.sqoop.client.core.ClientError;
import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.common.SqoopException;
import org.codehaus.groovy.tools.shell.Shell;
import java.text.MessageFormat;
import java.util.List;
-import java.util.ResourceBundle;
+
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
/**
*
@@ -35,7 +34,6 @@ public class SubmissionCommand extends SqoopCommand {
private SubmissionStopFunction stopFunction;
private SubmissionStatusFunction statusFunction;
-
public SubmissionCommand(Shell shell) {
super(shell, Constants.CMD_SUBMISSION, Constants.CMD_SUBMISSION_SC,
new String[] {Constants.FN_START, Constants.FN_STOP,
@@ -44,32 +42,31 @@ public class SubmissionCommand extends SqoopCommand {
}
public Object executeCommand(List args) {
- String usageMsg = MessageFormat.format(getResource().getString(Constants
- .RES_SUBMISSION_USAGE), getUsage());
+ String usageMsg = MessageFormat.format(resource.getString(Constants.RES_SUBMISSION_USAGE), getUsage());
if (args.size() == 0) {
- io.out.println(usageMsg);
- io.out.println();
+ println(usageMsg);
return null;
}
String func = (String)args.get(0);
if (func.equals(Constants.FN_START)) {
if (startFunction == null) {
- startFunction = new SubmissionStartFunction(io);
+ startFunction = new SubmissionStartFunction();
}
return startFunction.execute(args);
} else if (func.equals(Constants.FN_STOP)) {
if (stopFunction == null) {
- stopFunction = new SubmissionStopFunction(io);
+ stopFunction = new SubmissionStopFunction();
}
return stopFunction.execute(args);
} else if (func.equals(Constants.FN_STATUS)) {
if (statusFunction == null) {
- statusFunction = new SubmissionStatusFunction(io);
+ statusFunction = new SubmissionStatusFunction();
}
return statusFunction.execute(args);
} else {
- throw new SqoopException(ClientError.CLIENT_0002, usageMsg);
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ return null;
}
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/SubmissionStartFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/SubmissionStartFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/SubmissionStartFunction.java
index ba05dbb..cefe0a2 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/SubmissionStartFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/SubmissionStartFunction.java
@@ -20,42 +20,32 @@ package org.apache.sqoop.client.shell;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.OptionBuilder;
import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.core.RequestCache;
import org.apache.sqoop.client.utils.SubmissionDisplayer;
import org.apache.sqoop.model.MSubmission;
-import org.codehaus.groovy.tools.shell.IO;
-import java.util.List;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
/**
*
*/
public class SubmissionStartFunction extends SqoopFunction {
-
- private IO io;
-
@SuppressWarnings("static-access")
- public SubmissionStartFunction(IO io) {
- this.io = io;
-
+ public SubmissionStartFunction() {
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants.RES_PROMPT_JOB_ID))
+ .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
.withLongOpt(Constants.OPT_JID)
.hasArg()
.create(Constants.OPT_JID_CHAR));
}
- public Object execute(List<String> args) {
- CommandLine line = parseOptions(this, 1, args);
+ public Object executeFunction(CommandLine line) {
if (!line.hasOption(Constants.OPT_JID)) {
- io.out.println(getResource().getString(Constants.RES_ARGS_JID_MISSING));
+ printlnResource(Constants.RES_ARGS_JID_MISSING);
return null;
}
- MSubmission submission =
- RequestCache.createSubmission(line.getOptionValue(Constants.OPT_JID));
-
- SubmissionDisplayer.display(io, submission);
+ MSubmission submission = client.startSubmission(getLong(line, Constants.OPT_JID));
+ SubmissionDisplayer.display(submission);
return null;
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/SubmissionStatusFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/SubmissionStatusFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/SubmissionStatusFunction.java
index dd63cd1..48db8ab 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/SubmissionStatusFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/SubmissionStatusFunction.java
@@ -20,42 +20,32 @@ package org.apache.sqoop.client.shell;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.OptionBuilder;
import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.core.RequestCache;
import org.apache.sqoop.client.utils.SubmissionDisplayer;
import org.apache.sqoop.model.MSubmission;
-import org.codehaus.groovy.tools.shell.IO;
-import java.util.List;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
/**
*
*/
public class SubmissionStatusFunction extends SqoopFunction {
-
- private IO io;
-
@SuppressWarnings("static-access")
- public SubmissionStatusFunction(IO io) {
- this.io = io;
-
+ public SubmissionStatusFunction() {
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants.RES_PROMPT_JOB_ID))
+ .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
.withLongOpt(Constants.OPT_JID)
.hasArg()
.create(Constants.OPT_JID_CHAR));
}
- public Object execute(List<String> args) {
- CommandLine line = parseOptions(this, 1, args);
+ public Object executeFunction(CommandLine line) {
if (!line.hasOption(Constants.OPT_JID)) {
- io.out.println(getResource().getString(Constants.RES_ARGS_JID_MISSING));
+ printlnResource(Constants.RES_ARGS_JID_MISSING);
return null;
}
- MSubmission submission =
- RequestCache.readSubmission(line.getOptionValue(Constants.OPT_JID));
-
- SubmissionDisplayer.display(io, submission);
+ MSubmission submission = client.getSubmissionStatus(getLong(line, Constants.OPT_JID));
+ SubmissionDisplayer.display(submission);
return null;
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/SubmissionStopFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/SubmissionStopFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/SubmissionStopFunction.java
index e71f8bf..8291a54 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/SubmissionStopFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/SubmissionStopFunction.java
@@ -20,42 +20,32 @@ package org.apache.sqoop.client.shell;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.OptionBuilder;
import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.core.RequestCache;
import org.apache.sqoop.client.utils.SubmissionDisplayer;
import org.apache.sqoop.model.MSubmission;
-import org.codehaus.groovy.tools.shell.IO;
-import java.util.List;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
/**
*
*/
public class SubmissionStopFunction extends SqoopFunction {
-
- private IO io;
-
@SuppressWarnings("static-access")
- public SubmissionStopFunction(IO io) {
- this.io = io;
-
+ public SubmissionStopFunction() {
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants.RES_PROMPT_JOB_ID))
+ .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
.withLongOpt(Constants.OPT_JID)
.hasArg()
.create(Constants.OPT_JID_CHAR));
}
- public Object execute(List<String> args) {
- CommandLine line = parseOptions(this, 1, args);
+ public Object executeFunction(CommandLine line) {
if (!line.hasOption(Constants.OPT_JID)) {
- io.out.println(getResource().getString(Constants.RES_ARGS_JID_MISSING));
+ printlnResource(Constants.RES_ARGS_JID_MISSING);
return null;
}
- MSubmission submission =
- RequestCache.deleteSubmission(line.getOptionValue(Constants.OPT_JID));
-
- SubmissionDisplayer.display(io, submission);
+ MSubmission submission = client.stopSubmission(getLong(line, Constants.OPT_JID));
+ SubmissionDisplayer.display(submission);
return null;
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/UpdateCommand.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/UpdateCommand.java b/client/src/main/java/org/apache/sqoop/client/shell/UpdateCommand.java
index 0057efb..f16745c 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/UpdateCommand.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/UpdateCommand.java
@@ -19,13 +19,12 @@ package org.apache.sqoop.client.shell;
import org.apache.sqoop.client.core.ClientError;
import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.core.Environment;
import org.apache.sqoop.common.SqoopException;
import org.codehaus.groovy.tools.shell.Shell;
-import java.text.MessageFormat;
import java.util.List;
-import java.util.ResourceBundle;
+
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
/**
*
@@ -42,30 +41,29 @@ public class UpdateCommand extends SqoopCommand {
}
public Object executeCommand(List args) {
- if(!Environment.isInteractive()) {
+ if(!isInteractive()) {
throw new SqoopException(ClientError.CLIENT_0007, "update");
}
- String usageMsg = MessageFormat.format(getResource().getString(Constants.RES_UPDATE_USAGE), getUsage());
if (args.size() == 0) {
- io.out.println(usageMsg);
- io.out.println();
+ printlnResource(Constants.RES_UPDATE_USAGE, getUsage());
return null;
}
String func = (String)args.get(0);
if (func.equals(Constants.FN_CONNECTION)) {
if (connectionFunction == null) {
- connectionFunction = new UpdateConnectionFunction(io);
+ connectionFunction = new UpdateConnectionFunction();
}
return connectionFunction.execute(args);
} else if (func.equals(Constants.FN_JOB)) {
if (jobFunction == null) {
- jobFunction = new UpdateJobFunction(io);
+ jobFunction = new UpdateJobFunction();
}
return jobFunction.execute(args);
} else {
- throw new SqoopException(ClientError.CLIENT_0002, usageMsg);
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ return null;
}
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/UpdateConnectionFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/UpdateConnectionFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/UpdateConnectionFunction.java
index dd0df24..95ada63 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/UpdateConnectionFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/UpdateConnectionFunction.java
@@ -23,48 +23,36 @@ import org.apache.commons.cli.OptionBuilder;
import org.apache.sqoop.client.core.ClientError;
import org.apache.sqoop.client.core.Constants;
import org.apache.sqoop.common.SqoopException;
-import org.apache.sqoop.json.ConnectionBean;
import org.apache.sqoop.model.MConnection;
import org.apache.sqoop.validation.Status;
-import org.codehaus.groovy.tools.shell.IO;
import java.io.IOException;
-import java.text.MessageFormat;
-import java.util.List;
import java.util.ResourceBundle;
import static org.apache.sqoop.client.utils.FormFiller.*;
-import static org.apache.sqoop.client.core.RequestCache.*;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
/**
*
*/
public class UpdateConnectionFunction extends SqoopFunction {
-
-
- private IO io;
-
-
@SuppressWarnings("static-access")
- public UpdateConnectionFunction(IO io) {
- this.io = io;
-
+ public UpdateConnectionFunction() {
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants.RES_PROMPT_CONN_ID))
+ .withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
.withLongOpt(Constants.OPT_XID)
.hasArg()
.create(Constants.OPT_XID_CHAR));
}
- public Object execute(List<String> args) {
- CommandLine line = parseOptions(this, 1, args);
+ public Object executeFunction(CommandLine line) {
if (!line.hasOption(Constants.OPT_XID)) {
- io.out.println(getResource().getString(Constants.RES_ARGS_XID_MISSING));
+ printlnResource(Constants.RES_ARGS_XID_MISSING);
return null;
}
try {
- updateConnection(line.getOptionValue(Constants.OPT_XID));
+ updateConnection(getLong(line, Constants.OPT_XID));
} catch (IOException ex) {
throw new SqoopException(ClientError.CLIENT_0005, ex);
}
@@ -72,44 +60,36 @@ public class UpdateConnectionFunction extends SqoopFunction {
return null;
}
- private void updateConnection(String connectionId) throws IOException {
- io.out.println(MessageFormat.format(getResource().getString(Constants
- .RES_UPDATE_UPDATING_CONN), connectionId));
+ private void updateConnection(Long connectionId) throws IOException {
+ printlnResource(Constants.RES_UPDATE_UPDATING_CONN, connectionId);
ConsoleReader reader = new ConsoleReader();
- ConnectionBean connectionBean = readConnection(connectionId);
+ MConnection connection = client.getConnection(connectionId);
- // TODO(jarcec): Check that we have expected data
- MConnection connection = connectionBean.getConnections().get(0);
- ResourceBundle frameworkBundle
- = connectionBean.getFrameworkBundle();
- ResourceBundle connectorBundle
- = connectionBean.getConnectorBundle(connection.getConnectorId());
+ ResourceBundle connectorBundle = client.getResourceBundle(connection.getConnectorId());
+ ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
Status status = Status.FINE;
- io.out.println(getResource().getString(Constants
- .RES_PROMPT_UPDATE_CONN_METADATA));
+ printlnResource(Constants.RES_PROMPT_UPDATE_CONN_METADATA);
do {
// Print error introduction if needed
if( !status.canProceed() ) {
- errorIntroduction(io);
+ errorIntroduction();
}
// Fill in data from user
- if(!fillConnection(io, reader, connection,
- connectorBundle, frameworkBundle)) {
+ if(!fillConnection(reader, connection, connectorBundle, frameworkBundle)) {
return;
}
// Try to create
- status = updateConnectionApplyValidations(connection);
+ status = client.updateConnection(connection);
} while(!status.canProceed());
- io.out.println(MessageFormat.format(getResource().getString(Constants
- .RES_UPDATE_CONN_SUCCESSFUL), status.name()));
+ printlnResource(Constants.RES_UPDATE_CONN_SUCCESSFUL, status.name());
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/UpdateJobFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/UpdateJobFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/UpdateJobFunction.java
index 4fac977..3f0ac7d 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/UpdateJobFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/UpdateJobFunction.java
@@ -23,48 +23,36 @@ import org.apache.commons.cli.OptionBuilder;
import org.apache.sqoop.client.core.ClientError;
import org.apache.sqoop.client.core.Constants;
import org.apache.sqoop.common.SqoopException;
-import org.apache.sqoop.json.JobBean;
import org.apache.sqoop.model.MJob;
import org.apache.sqoop.validation.Status;
-import org.codehaus.groovy.tools.shell.IO;
import java.io.IOException;
-import java.text.MessageFormat;
-import java.util.List;
import java.util.ResourceBundle;
import static org.apache.sqoop.client.utils.FormFiller.*;
-import static org.apache.sqoop.client.core.RequestCache.*;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
/**
*
*/
public class UpdateJobFunction extends SqoopFunction {
-
-
- private IO io;
-
-
@SuppressWarnings("static-access")
- public UpdateJobFunction(IO io) {
- this.io = io;
-
+ public UpdateJobFunction() {
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants.RES_PROMPT_JOB_ID))
+ .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
.withLongOpt(Constants.OPT_JID)
.hasArg()
.create(Constants.OPT_JID_CHAR));
}
- public Object execute(List<String> args) {
- CommandLine line = parseOptions(this, 1, args);
+ public Object executeFunction(CommandLine line) {
if (!line.hasOption(Constants.OPT_JID)) {
- io.out.println(getResource().getString(Constants.RES_ARGS_JID_MISSING));
+ printlnResource(Constants.RES_ARGS_JID_MISSING);
return null;
}
try {
- updateJob(line.getOptionValue(Constants.OPT_JID));
+ updateJob(getLong(line, Constants.OPT_JID));
} catch (IOException ex) {
throw new SqoopException(ClientError.CLIENT_0005, ex);
}
@@ -72,41 +60,35 @@ public class UpdateJobFunction extends SqoopFunction {
return null;
}
- private void updateJob(String jobId) throws IOException {
- io.out.println(MessageFormat.format(getResource().getString(Constants
- .RES_UPDATE_UPDATING_JOB), jobId));
+ private void updateJob(Long jobId) throws IOException {
+ printlnResource(Constants.RES_UPDATE_UPDATING_JOB, jobId);
ConsoleReader reader = new ConsoleReader();
- JobBean jobBean = readJob(jobId);
+ MJob job = client.getJob(jobId);
- // TODO(jarcec): Check that we have expected data
- MJob job = jobBean.getJobs().get(0);
- ResourceBundle frameworkBundle
- = jobBean.getFrameworkBundle();
- ResourceBundle connectorBundle
- = jobBean.getConnectorBundle(job.getConnectorId());
+ ResourceBundle connectorBundle = client.getResourceBundle(job.getConnectorId());
+ ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
Status status = Status.FINE;
- io.out.println(getResource().getString(Constants.RES_PROMPT_UPDATE_JOB_METADATA));
+ printlnResource(Constants.RES_PROMPT_UPDATE_JOB_METADATA);
do {
// Print error introduction if needed
if( !status.canProceed() ) {
- errorIntroduction(io);
+ errorIntroduction();
}
// Fill in data from user
- if(!fillJob(io, reader, job, connectorBundle, frameworkBundle)) {
+ if(!fillJob(reader, job, connectorBundle, frameworkBundle)) {
return;
}
// Try to create
- status = updateJobApplyValidations(job);
+ status = client.updateJob(job);
} while(!status.canProceed());
- io.out.println(MessageFormat.format(getResource().getString(Constants
- .RES_UPDATE_JOB_SUCCESSFUL), status.name()));
+ printlnResource(Constants.RES_UPDATE_JOB_SUCCESSFUL, status.name());
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/utils/FormDisplayer.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/utils/FormDisplayer.java b/client/src/main/java/org/apache/sqoop/client/utils/FormDisplayer.java
index 4d0442f..abd9643 100644
--- a/client/src/main/java/org/apache/sqoop/client/utils/FormDisplayer.java
+++ b/client/src/main/java/org/apache/sqoop/client/utils/FormDisplayer.java
@@ -27,181 +27,174 @@ import org.apache.sqoop.model.MJobForms;
import org.apache.sqoop.model.MMapInput;
import org.apache.sqoop.model.MStringInput;
import org.apache.sqoop.utils.StringUtils;
-import org.codehaus.groovy.tools.shell.IO;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
+
/**
* Convenience static methods for displaying form related information
*/
public final class FormDisplayer {
- public static void displayFormMetadataDetails(IO io,
- MFramework framework,
+ public static void displayFormMetadataDetails(MFramework framework,
ResourceBundle bundle) {
- io.out.print(" Supported job types: ");
- io.out.println(framework.getAllJobsForms().keySet().toString());
+ print(" Supported job types: ");
+ println(framework.getAllJobsForms().keySet().toString());
- displayFormsMetadata(io,
+ displayFormsMetadata(
framework.getConnectionForms().getForms(),
"Connection",
bundle);
for (MJobForms jobForms : framework.getAllJobsForms().values()) {
- io.out.print(" Forms for job type ");
- io.out.print(jobForms.getType().name());
- io.out.println(":");
+ print(" Forms for job type ");
+ print(jobForms.getType().name());
+ println(":");
- displayFormsMetadata(io, jobForms.getForms(), "Job", bundle);
+ displayFormsMetadata(jobForms.getForms(), "Job", bundle);
}
}
- public static void displayFormsMetadata(IO io,
- List<MForm> forms,
+ public static void displayFormsMetadata(List<MForm> forms,
String type,
ResourceBundle bundle) {
Iterator<MForm> fiter = forms.iterator();
int findx = 1;
while (fiter.hasNext()) {
- io.out.print(" ");
- io.out.print(type);
- io.out.print(" form ");
- io.out.print(findx++);
- io.out.println(":");
+ print(" ");
+ print(type);
+ print(" form ");
+ print(findx++);
+ println(":");
MForm form = fiter.next();
- io.out.print(" Name: ");
- io.out.println(form.getName());
+ print(" Name: ");
+ println(form.getName());
// Label
- io.out.print(" Label: ");
- io.out.println(bundle.getString(form.getLabelKey()));
+ print(" Label: ");
+ println(bundle.getString(form.getLabelKey()));
// Help text
- io.out.print(" Help: ");
- io.out.println(bundle.getString(form.getHelpKey()));
+ print(" Help: ");
+ println(bundle.getString(form.getHelpKey()));
List<MInput<?>> inputs = form.getInputs();
Iterator<MInput<?>> iiter = inputs.iterator();
int iindx = 1;
while (iiter.hasNext()) {
- io.out.print(" Input ");
- io.out.print(iindx++);
- io.out.println(":");
+ print(" Input ");
+ print(iindx++);
+ println(":");
MInput<?> input = iiter.next();
- io.out.print(" Name: ");
- io.out.println(input.getName());
- io.out.print(" Label: ");
- io.out.println(bundle.getString(input.getLabelKey()));
- io.out.print(" Help: ");
- io.out.println(bundle.getString(input.getHelpKey()));
- io.out.print(" Type: ");
- io.out.println(input.getType());
+ print(" Name: ");
+ println(input.getName());
+ print(" Label: ");
+ println(bundle.getString(input.getLabelKey()));
+ print(" Help: ");
+ println(bundle.getString(input.getHelpKey()));
+ print(" Type: ");
+ println(input.getType());
if (input.getType() == MInputType.STRING) {
- io.out.print(" Mask: ");
- io.out.println(((MStringInput)input).isMasked());
- io.out.print(" Size: ");
- io.out.println(((MStringInput)input).getMaxLength());
+ print(" Mask: ");
+ println(((MStringInput)input).isMasked());
+ print(" Size: ");
+ println(((MStringInput)input).getMaxLength());
} else if(input.getType() == MInputType.ENUM) {
- io.out.print(" Possible values: ");
- io.out.println(StringUtils.join(((MEnumInput)input).getValues(), ","));
+ print(" Possible values: ");
+ println(StringUtils.join(((MEnumInput)input).getValues(), ","));
}
}
}
}
- public static void displayForms(IO io,
- List<MForm> forms,
- ResourceBundle bundle) {
+ public static void displayForms(List<MForm> forms, ResourceBundle bundle) {
for(MForm form : forms) {
- displayForm(io, form, bundle);
+ displayForm(form, bundle);
}
}
- private static void displayForm(IO io, MForm form, ResourceBundle bundle) {
- io.out.print(" ");
- io.out.println(bundle.getString(form.getLabelKey()));
+ private static void displayForm(MForm form, ResourceBundle bundle) {
+ print(" ");
+ println(bundle.getString(form.getLabelKey()));
for (MInput<?> input : form.getInputs()) {
- io.out.print(" ");
- io.out.print(bundle.getString(input.getLabelKey()));
- io.out.print(": ");
+ print(" ");
+ print(bundle.getString(input.getLabelKey()));
+ print(": ");
if(!input.isEmpty()) {
// Based on the input type, let's perform specific load
switch (input.getType()) {
case STRING:
- displayInputString(io, (MStringInput) input);
+ displayInputString((MStringInput) input);
break;
case INTEGER:
- displayInputInteger(io, (MIntegerInput) input);
+ displayInputInteger((MIntegerInput) input);
break;
case MAP:
- displayInputMap(io, (MMapInput) input);
+ displayInputMap((MMapInput) input);
break;
case ENUM:
- displayInputEnum(io, (MEnumInput) input);
+ displayInputEnum((MEnumInput) input);
break;
default:
- io.out.println("Unsupported data type " + input.getType());
+ println("Unsupported data type " + input.getType());
return;
}
}
- io.out.println("");
+ println("");
}
}
/**
* Display content of String input.
*
- * @param io Shell's IO object
* @param input String input
*/
- private static void displayInputString(IO io, MStringInput input) {
+ private static void displayInputString(MStringInput input) {
if (input.isMasked()) {
- io.out.print("(This input is sensitive)");
+ print("(This input is sensitive)");
} else {
- io.out.print(input.getValue());
+ print(input.getValue());
}
}
/**
* Display content of Integer input.
*
- * @param io Shell's IO object
* @param input Integer input
*/
- private static void displayInputInteger(IO io, MIntegerInput input) {
- io.out.print(input.getValue());
+ private static void displayInputInteger(MIntegerInput input) {
+ print(input.getValue());
}
/**
* Display content of Map input
*
- * @param io Shell's IO object
* @param input Map input
*/
- private static void displayInputMap(IO io, MMapInput input) {
+ private static void displayInputMap(MMapInput input) {
for(Map.Entry<String, String> entry : input.getValue().entrySet()) {
- io.out.println();
- io.out.print(" ");
- io.out.print(entry.getKey());
- io.out.print(" = ");
- io.out.print(entry.getValue());
+ println();
+ print(" ");
+ print(entry.getKey());
+ print(" = ");
+ print(entry.getValue());
}
}
/**
* Display content of Enum input
*
- * @param io Shell's IO object
* @param input Enum input
*/
- private static void displayInputEnum(IO io, MEnumInput input) {
- io.out.print(input.getValue());
+ private static void displayInputEnum(MEnumInput input) {
+ print(input.getValue());
}
private FormDisplayer() {
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java b/client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java
index e3fe02f..f11b9d2 100644
--- a/client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java
+++ b/client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java
@@ -18,7 +18,6 @@
package org.apache.sqoop.client.utils;
import jline.ConsoleReader;
-import org.apache.sqoop.client.core.Environment;
import org.apache.sqoop.model.MConnection;
import org.apache.sqoop.model.MEnumInput;
import org.apache.sqoop.model.MForm;
@@ -28,7 +27,6 @@ import org.apache.sqoop.model.MMapInput;
import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MStringInput;
import org.apache.sqoop.model.MValidatedElement;
-import org.codehaus.groovy.tools.shell.IO;
import java.io.IOException;
import java.util.List;
@@ -36,6 +34,8 @@ import java.util.Map;
import java.util.HashMap;
import java.util.ResourceBundle;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
+
/**
* Convenient methods for retrieving user input.
*/
@@ -45,13 +45,11 @@ public final class FormFiller {
* Internal input that will be reused for loading names for connection and
* job objects.
*/
- private static MStringInput nameInput =
- new MStringInput("object-name", false, (short)25);
+ private static MStringInput nameInput = new MStringInput("object-name", false, (short)25);
/**
* Fill job object based on user input.
*
- * @param io Shell's io object
* @param reader Associated console reader object
* @param job Job that user is suppose to fill in
* @param connectorBundle Connector resource bundle
@@ -59,18 +57,16 @@ public final class FormFiller {
* @return True if we filled all inputs, false if user has stopped processing
* @throws IOException
*/
- public static boolean fillJob(IO io,
- ConsoleReader reader,
+ public static boolean fillJob(ConsoleReader reader,
MJob job,
ResourceBundle connectorBundle,
ResourceBundle frameworkBundle)
throws IOException {
- job.setName(getName(io, reader, job.getName()));
+ job.setName(getName(reader, job.getName()));
// Fill in data from user
- return fillForms(io,
- reader,
+ return fillForms(reader,
job.getConnectorPart().getForms(),
connectorBundle,
job.getFrameworkPart().getForms(),
@@ -80,7 +76,6 @@ public final class FormFiller {
/**
* Fill connection object based on user input.
*
- * @param io Shell's io object
* @param reader Associated console reader object
* @param connection Connection that user is suppose to fill in
* @param connectorBundle Connector resource bundle
@@ -88,26 +83,23 @@ public final class FormFiller {
* @return True if we filled all inputs, false if user has stopped processing
* @throws IOException
*/
- public static boolean fillConnection(IO io,
- ConsoleReader reader,
+ public static boolean fillConnection(ConsoleReader reader,
MConnection connection,
ResourceBundle connectorBundle,
ResourceBundle frameworkBundle)
throws IOException {
- connection.setName(getName(io, reader, connection.getName()));
+ connection.setName(getName(reader, connection.getName()));
// Fill in data from user
- return fillForms(io,
- reader,
+ return fillForms(reader,
connection.getConnectorPart().getForms(),
connectorBundle,
connection.getFrameworkPart().getForms(),
frameworkBundle);
}
- public static boolean fillForms(IO io,
- ConsoleReader reader,
+ public static boolean fillForms(ConsoleReader reader,
List<MForm> connectorForms,
ResourceBundle connectorBundle,
List<MForm> frameworkForms,
@@ -116,25 +108,24 @@ public final class FormFiller {
// Query connector forms
- if(!fillForms(io, connectorForms, reader, connectorBundle)) {
+ if(!fillForms(connectorForms, reader, connectorBundle)) {
return false;
}
// Query framework forms
- if(!fillForms(io, frameworkForms, reader, frameworkBundle)) {
+ if(!fillForms(frameworkForms, reader, frameworkBundle)) {
return false;
}
return true;
}
- public static boolean fillForms(IO io,
- List<MForm> forms,
+ public static boolean fillForms(List<MForm> forms,
ConsoleReader reader,
ResourceBundle bundle)
throws IOException {
for (MForm form : forms) {
- if(!fillForm(io, form, reader, bundle)) {
+ if(!fillForm(form, reader, bundle)) {
return false;
}
}
@@ -142,19 +133,18 @@ public final class FormFiller {
return true;
}
- public static boolean fillForm(IO io,
- MForm form,
+ public static boolean fillForm(MForm form,
ConsoleReader reader,
ResourceBundle bundle) throws IOException {
- io.out.println("");
- io.out.println(bundle.getString(form.getLabelKey()));
+ println("");
+ println(bundle.getString(form.getLabelKey()));
// Print out form validation
- printValidationMessage(io, form);
- io.out.println("");
+ printValidationMessage(form);
+ println("");
for (MInput input : form.getInputs()) {
- if(!fillInput(io, input, reader, bundle)) {
+ if(!fillInput(input, reader, bundle)) {
return false;
}
}
@@ -162,25 +152,24 @@ public final class FormFiller {
return true;
}
- public static boolean fillInput(IO io,
- MInput input,
+ public static boolean fillInput(MInput input,
ConsoleReader reader,
ResourceBundle bundle) throws IOException {
// Print out validation
- printValidationMessage(io, input);
+ printValidationMessage(input);
// Based on the input type, let's perform specific load
switch (input.getType()) {
case STRING:
- return fillInputString(io, (MStringInput) input, reader, bundle);
+ return fillInputString((MStringInput) input, reader, bundle);
case INTEGER:
- return fillInputInteger(io, (MIntegerInput) input, reader, bundle);
+ return fillInputInteger((MIntegerInput) input, reader, bundle);
case MAP:
- return fillInputMap(io, (MMapInput) input, reader, bundle);
+ return fillInputMap((MMapInput) input, reader, bundle);
case ENUM:
- return fillInputEnum(io, (MEnumInput) input, reader, bundle);
+ return fillInputEnum((MEnumInput) input, reader, bundle);
default:
- io.out.println("Unsupported data type " + input.getType());
+ println("Unsupported data type " + input.getType());
return true;
}
}
@@ -191,20 +180,18 @@ public final class FormFiller {
* Print out numbered list of all available options and let user choose one
* item from that.
*
- * @param io Shell's IO object
* @param input Input that we should read or edit
* @param reader Associated console reader
* @param bundle Resource bundle
* @return True if user with to continue with loading addtional inputs
* @throws IOException
*/
- private static boolean fillInputEnum(IO io,
- MEnumInput input,
+ private static boolean fillInputEnum(MEnumInput input,
ConsoleReader reader,
ResourceBundle bundle)
throws IOException {
// Prompt in enum case
- io.out.println(bundle.getString(input.getLabelKey()) + ": ");
+ println(bundle.getString(input.getLabelKey()) + ": ");
// Indexes
int i = -1;
@@ -214,7 +201,7 @@ public final class FormFiller {
for(String value : input.getValues()) {
i++;
- io.out.println(" " + i + " : " + value);
+ println(" " + i + " : " + value);
if(!input.isEmpty() && value.equals(input.getValue())) {
lastChoice = i;
@@ -242,14 +229,14 @@ public final class FormFiller {
index = Integer.valueOf(userTyped);
if(index < 0 || index >= input.getValues().length) {
- errorMessage(io, "Invalid index");
- return fillInputEnum(io, input, reader, bundle);
+ errorMessage("Invalid index");
+ return fillInputEnum(input, reader, bundle);
}
input.setValue(input.getValues()[index]);
} catch (NumberFormatException ex) {
- errorMessage(io, "Input is not valid integer number");
- return fillInputEnum(io, input, reader, bundle);
+ errorMessage("Input is not valid integer number");
+ return fillInputEnum(input, reader, bundle);
}
}
@@ -268,20 +255,18 @@ public final class FormFiller {
* Please note that following code do not supports equal sign in property
* name. It's however perfectly fine to have equal sign in value.
*
- * @param io Shell's IO object
* @param input Input that we should read or edit
* @param reader Associated console reader
* @param bundle Resource bundle
* @return True if user wish to continue with loading additional inputs
* @throws IOException
*/
- private static boolean fillInputMap(IO io,
- MMapInput input,
+ private static boolean fillInputMap(MMapInput input,
ConsoleReader reader,
ResourceBundle bundle)
throws IOException {
// Special prompt in Map case
- io.out.println(bundle.getString(input.getLabelKey()) + ": ");
+ println(bundle.getString(input.getLabelKey()) + ": ");
// Internal loading map
Map<String, String> values = input.getValue();
@@ -293,10 +278,9 @@ public final class FormFiller {
while(true) {
// Print all current items in each iteration
- io.out.println("There are currently " + values.size()
- + " values in the map:");
+ println("There are currently " + values.size() + " values in the map:");
for(Map.Entry<String, String> entry : values.entrySet()) {
- io.out.println(entry.getKey() + " = " + entry.getValue());
+ println(entry.getKey() + " = " + entry.getValue());
}
// Special prompt for Map entry
@@ -329,7 +313,7 @@ public final class FormFiller {
if(values.containsKey(key)) {
values.remove(key);
} else {
- errorMessage(io, "Don't know what to do with " + userTyped);
+ errorMessage("Don't know what to do with " + userTyped);
}
}
}
@@ -374,8 +358,7 @@ public final class FormFiller {
return input;
}
- private static boolean fillInputInteger(IO io,
- MIntegerInput input,
+ private static boolean fillInputInteger(MIntegerInput input,
ConsoleReader reader,
ResourceBundle bundle)
throws IOException {
@@ -398,8 +381,8 @@ public final class FormFiller {
value = Integer.valueOf(userTyped);
input.setValue(value);
} catch (NumberFormatException ex) {
- errorMessage(io, "Input is not valid integer number");
- return fillInputInteger(io, input, reader, bundle);
+ errorMessage("Input is not valid integer number");
+ return fillInputInteger(input, reader, bundle);
}
input.setValue(Integer.valueOf(userTyped));
@@ -411,15 +394,13 @@ public final class FormFiller {
/**
* Load string input from the user.
*
- * @param io Shell's IO object
* @param input Input that we should load in
* @param reader Associated console reader
* @param bundle Resource bundle for this input
* @return
* @throws IOException
*/
- public static boolean fillInputString(IO io,
- MStringInput input,
+ public static boolean fillInputString(MStringInput input,
ConsoleReader reader,
ResourceBundle bundle)
throws IOException {
@@ -451,9 +432,9 @@ public final class FormFiller {
// Check that it did not exceeds maximal allowance for given input
if(userTyped.length() > input.getMaxLength()) {
- errorMessage(io, "Size of input exceeds allowance for this input"
+ errorMessage("Size of input exceeds allowance for this input"
+ " field. Maximal allowed size is " + input.getMaxLength());
- return fillInputString(io, input, reader, bundle);
+ return fillInputString(input, reader, bundle);
}
}
@@ -468,7 +449,7 @@ public final class FormFiller {
reader.flushConsole();
}
- public static String getName(IO io, ConsoleReader reader,
+ public static String getName(ConsoleReader reader,
String name) throws IOException {
if(name == null) {
nameInput.setEmpty();
@@ -476,7 +457,7 @@ public final class FormFiller {
nameInput.setValue(name);
}
- fillInputString(io, nameInput, reader, Environment.getResourceBundle());
+ fillInputString(nameInput, reader, getResourceBundle());
return nameInput.getValue();
}
@@ -484,16 +465,15 @@ public final class FormFiller {
/**
* Print validation message in cases that it's not in state "FINE"
*
- * @param io IO object to print out the message
* @param element Validated element
*/
- public static void printValidationMessage(IO io, MValidatedElement element) {
+ public static void printValidationMessage(MValidatedElement element) {
switch (element.getValidationStatus()) {
case UNACCEPTABLE:
- errorMessage(io, element.getValidationMessage());
+ errorMessage(element.getValidationMessage());
break;
case ACCEPTABLE:
- warningMessage(io, element.getValidationMessage());
+ warningMessage(element.getValidationMessage());
break;
default:
// Simply ignore all other states for the moment
@@ -501,18 +481,17 @@ public final class FormFiller {
}
}
- public static void errorMessage(IO io, String message) {
- io.out.println("Error message: @|red " + message + " |@");
+ public static void errorMessage(String message) {
+ println("Error message: @|red " + message + " |@");
}
- public static void warningMessage(IO io, String message) {
- io.out.println("Warning message: @|yellow " + message + " |@");
+ public static void warningMessage(String message) {
+ println("Warning message: @|yellow " + message + " |@");
}
- public static void errorIntroduction(IO io) {
- io.out.println();
- io.out.println("@|red There are issues with entered data, please"
- + " revise your input:|@");
+ public static void errorIntroduction() {
+ println();
+ println("@|red There are issues with entered data, please revise your input:|@");
}
private FormFiller() {
|