You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sqoop.apache.org by bl...@apache.org on 2012/05/21 19:36:55 UTC

svn commit: r1341121 - in /sqoop/branches/sqoop2/client: ./ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/sqoop/ src/main/java/org/apache/sqoop/client/ src/main/java/org/apache/sqoop/client/core/ src/main/java/org/apache/sqoop/c...

Author: blee
Date: Mon May 21 17:36:54 2012
New Revision: 1341121

URL: http://svn.apache.org/viewvc?rev=1341121&view=rev
Log:
SQOOP-365  Proposal for next major revision of Sqoop.

Added:
    sqoop/branches/sqoop2/client/src/main/java/org/
    sqoop/branches/sqoop2/client/src/main/java/org/apache/
    sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/
    sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/
    sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/core/
    sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/core/ClientError.java   (with props)
    sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/core/Environment.java   (with props)
    sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/request/
    sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/request/Request.java   (with props)
    sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/request/VersionRequest.java   (with props)
    sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/
    sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/HelpCommand.java   (with props)
    sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SetCommand.java   (with props)
    sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SetServerFunction.java   (with props)
    sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopCommand.java   (with props)
    sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopFunction.java   (with props)
    sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java   (with props)
Modified:
    sqoop/branches/sqoop2/client/pom.xml

Modified: sqoop/branches/sqoop2/client/pom.xml
URL: http://svn.apache.org/viewvc/sqoop/branches/sqoop2/client/pom.xml?rev=1341121&r1=1341120&r2=1341121&view=diff
==============================================================================
--- sqoop/branches/sqoop2/client/pom.xml (original)
+++ sqoop/branches/sqoop2/client/pom.xml Mon May 21 17:36:54 2012
@@ -34,13 +34,38 @@ limitations under the License.
   <dependencies>
     <dependency>
       <groupId>org.apache.sqoop</groupId>
-      <artifactId>sqoop-core</artifactId>
+      <artifactId>sqoop-common</artifactId>
       <version>2.0.0-SNAPSHOT</version>
     </dependency>
     <dependency>
-      <groupId>org.apache.sqoop</groupId>
-      <artifactId>sqoop-common</artifactId>
-      <version>2.0.0-SNAPSHOT</version>
+      <groupId>commons-cli</groupId>
+      <artifactId>commons-cli</artifactId>
+      <version>1.3-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+      <version>2.6</version>
+    </dependency>
+    <dependency>
+      <groupId>com.sun.jersey</groupId>
+      <artifactId>jersey-client</artifactId>
+      <version>1.11</version>
+    </dependency>
+    <dependency>
+      <groupId>jline</groupId>
+      <artifactId>jline</artifactId>
+      <version>0.9.94</version>
+    </dependency>
+    <dependency>
+      <groupId>org.fusesource.jansi</groupId>
+      <artifactId>jansi</artifactId>
+      <version>1.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.groovy</groupId>
+      <artifactId>groovy-all</artifactId>
+      <version>1.8.5</version>
     </dependency>
   </dependencies>
 </project>

Added: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/core/ClientError.java
URL: http://svn.apache.org/viewvc/sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/core/ClientError.java?rev=1341121&view=auto
==============================================================================
--- sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/core/ClientError.java (added)
+++ sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/core/ClientError.java Mon May 21 17:36:54 2012
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.client.core;
+
+import org.apache.sqoop.common.ErrorCode;
+
+public enum ClientError implements ErrorCode {
+
+  /** An unknown error has occurred. */
+  CLIENT_0000("An unknown error has occurred"),
+
+  /** The specified command is not recognized. */
+  CLIENT_0001("The specified command is not recognized"),
+
+  /** The specified function is not recognized. */
+  CLIENT_0002("The specified function is not recognized"),
+
+  /** An error has occurred when parsing options. */
+  CLIENT_0003("An error has occurred when parsing options");
+
+  private final String message;
+
+  private ClientError(String message) {
+    this.message = message;
+  }
+
+  public String getCode() {
+    return name();
+  }
+
+  public String getMessage() {
+    return message;
+  }
+}

Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/core/ClientError.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/core/ClientError.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/core/Environment.java
URL: http://svn.apache.org/viewvc/sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/core/Environment.java?rev=1341121&view=auto
==============================================================================
--- sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/core/Environment.java (added)
+++ sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/core/Environment.java Mon May 21 17:36:54 2012
@@ -0,0 +1,67 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.client.core;
+
+public class Environment
+{
+  private Environment() {
+    // Disable explicit object creation
+  }
+
+  private static String serverHost;
+  private static String serverPort;
+  private static String serverWebapp;
+
+  private static String HOST_DEFAULT = "localhost";
+  private static String PORT_DEFAULT = "8080";
+  private static String WEBAPP_DEFAULT = "sqoop";
+
+  static {
+    serverHost = HOST_DEFAULT;
+    serverPort = PORT_DEFAULT;
+    serverWebapp = WEBAPP_DEFAULT;
+  }
+
+  public static void setServerHost(String host) {
+    serverHost = host;
+  }
+
+  public static String getServerHost() {
+    return serverHost;
+  }
+
+  public static void setServerPort(String port) {
+    serverPort = port;
+  }
+
+  public static String getServerPort() {
+    return serverPort;
+  }
+
+  public static void setServerWebapp(String webapp) {
+    serverWebapp = webapp;
+  }
+
+  public static String getServerWebapp() {
+    return serverWebapp;
+  }
+
+  public static String getServerUrl() {
+    return "http://" + serverHost + ":" + serverPort + "/" + serverWebapp + "/";
+  }
+}
\ No newline at end of file

Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/core/Environment.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/core/Environment.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/request/Request.java
URL: http://svn.apache.org/viewvc/sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/request/Request.java?rev=1341121&view=auto
==============================================================================
--- sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/request/Request.java (added)
+++ sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/request/Request.java Mon May 21 17:36:54 2012
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.client.request;
+
+import javax.ws.rs.core.MediaType;
+
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.WebResource.Builder;
+
+public class Request
+{
+  public String get(String url) {
+    Client client = Client.create();
+    WebResource resource = client.resource(url);
+    Builder builder = resource.accept(MediaType.APPLICATION_JSON_TYPE);
+    return builder.get(String.class);
+  }
+}
\ No newline at end of file

Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/request/Request.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/request/Request.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/request/VersionRequest.java
URL: http://svn.apache.org/viewvc/sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/request/VersionRequest.java?rev=1341121&view=auto
==============================================================================
--- sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/request/VersionRequest.java (added)
+++ sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/request/VersionRequest.java Mon May 21 17:36:54 2012
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.client.request;
+
+import org.apache.sqoop.json.VersionBean;
+import org.json.simple.JSONObject;
+import org.json.simple.JSONValue;
+
+public class VersionRequest extends Request
+{
+  public VersionBean versions(String url) {
+    String response = get(url + "version");
+    JSONObject jsonObject = (JSONObject)JSONValue.parse(response);
+
+    VersionBean versionBean = new VersionBean();
+    versionBean.restore(jsonObject);
+
+    return versionBean;
+  }
+}
\ No newline at end of file

Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/request/VersionRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/request/VersionRequest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/HelpCommand.java
URL: http://svn.apache.org/viewvc/sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/HelpCommand.java?rev=1341121&view=auto
==============================================================================
--- sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/HelpCommand.java (added)
+++ sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/HelpCommand.java Mon May 21 17:36:54 2012
@@ -0,0 +1,150 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.client.shell;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.sqoop.client.core.ClientError;
+import org.apache.sqoop.common.SqoopException;
+import org.codehaus.groovy.tools.shell.Command;
+import org.codehaus.groovy.tools.shell.CommandSupport;
+import org.codehaus.groovy.tools.shell.Shell;
+import org.codehaus.groovy.tools.shell.util.SimpleCompletor;
+
+public class HelpCommand extends CommandSupport
+{
+  protected HelpCommand(Shell shell) {
+    super(shell, "help", "\\h");
+  }
+
+  @Override
+  public String getDescription() {
+    return "Display this help message";
+  }
+
+  @Override
+  public String getUsage() {
+    return "[<command>]";
+  }
+
+  @Override
+  public String getHelp() {
+    return "Display the list of commands or "
+        + "the help text for @|bold command|@.";
+  }
+
+  @SuppressWarnings("rawtypes")
+  @Override
+  public Object execute(List args) {
+    if (args.size() == 0) {
+      list();
+    }
+    else {
+      help((String)args.get(0));
+    }
+    return null;
+  }
+
+  @SuppressWarnings("unchecked")
+  private void list() {
+    Iterator<Command> iterator;
+
+    // Figure out the max command name and shortcut length dynamically
+    int maxName = 0;
+    int maxShortcut = 0;
+    iterator = shell.getRegistry().commands().iterator();
+    while (iterator.hasNext()) {
+      Command command = iterator.next();
+      if (command.getHidden()) {
+        continue;
+      }
+
+      if (command.getName().length() > maxName) {
+        maxName = command.getName().length();
+      }
+        
+      if (command.getShortcut().length() > maxShortcut) {
+        maxShortcut = command.getShortcut().length();
+      }
+    }
+    
+    io.out.println("For information about @|green Sqoop|@, visit:");
+    io.out.println("  @|cyan http://incubator.apache.org/sqoop/|@ ");
+    io.out.println();
+
+    // List the commands we know about
+    io.out.println("Available commands:");
+    iterator = shell.getRegistry().commands().iterator();
+    while (iterator.hasNext()) {
+      Command command = iterator.next();
+      if (command.getHidden()) {
+        continue;
+      }
+
+      String paddedName =
+          StringUtils.rightPad(command.getName(), maxName);
+      String paddedShortcut =
+          StringUtils.rightPad(command.getShortcut(), maxShortcut);
+        
+      String description = command.getDescription();
+        
+      io.out.println("  @|bold " + paddedName + "|@  (@|bold "
+          + paddedShortcut + "|@) " + description);
+    }
+    
+    io.out.println();
+    io.out.println("For help on a specific command type:");
+    io.out.println("  help @|bold command|@ ");
+    io.out.println();
+  }
+
+  private void help(String name) {
+    Command command = shell.getRegistry().find(name);
+    if (command == null) {
+      String msg = "Unrecognized command " + name;
+      throw new SqoopException(ClientError.CLIENT_0001, msg);
+    }
+    
+    io.out.println("Usage: @|bold " + command.getName() + "|@ "
+        + command.getUsage());
+    io.out.println();
+    io.out.println(command.getHelp());
+    io.out.println();
+  }
+
+  @SuppressWarnings({ "rawtypes", "unchecked" })
+  protected List createCompletors() {
+    SimpleCompletor completor = new SimpleCompletor();
+    Iterator<Command> iterator = registry.iterator();
+    while (iterator.hasNext()) {
+      Command command = iterator.next();
+      if (command.getHidden()) {
+        continue;
+      }
+            
+      completor.add(command.getName());
+    }
+
+    List completors = new LinkedList();
+    completors.add(completor);
+    return completors;
+  }
+}
\ No newline at end of file

Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/HelpCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/HelpCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SetCommand.java
URL: http://svn.apache.org/viewvc/sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SetCommand.java?rev=1341121&view=auto
==============================================================================
--- sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SetCommand.java (added)
+++ sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SetCommand.java Mon May 21 17:36:54 2012
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.client.shell;
+
+import java.util.List;
+
+import org.apache.sqoop.client.core.ClientError;
+import org.apache.sqoop.common.SqoopException;
+import org.codehaus.groovy.tools.shell.Shell;
+
+public class SetCommand extends SqoopCommand
+{
+  private SetServerFunction serverFunction;
+
+  protected SetCommand(Shell shell) {
+    super(shell, "set", "\\st",
+        new String[] {"server", "client"},
+        "Set", "info");
+  }
+
+  @SuppressWarnings({ "rawtypes", "unchecked" })
+  @Override
+  public Object execute(List args) {
+    if (args.size() == 0) {
+      io.out.println("Usage: set " + getUsage());
+      io.out.println();
+      return null;
+    }
+
+    String func = (String)args.get(0);
+    if (func.equals("server")) {
+      if (serverFunction == null) {
+        serverFunction = new SetServerFunction(io);
+      }
+      return serverFunction.execute(args);
+
+    } else if (func.equals("client")) {
+      return null;
+
+    } else {
+      String msg = "Usage: set " + getUsage();
+      throw new SqoopException(ClientError.CLIENT_0002, msg);    
+    }
+  }
+}
\ No newline at end of file

Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SetCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SetCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SetServerFunction.java
URL: http://svn.apache.org/viewvc/sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SetServerFunction.java?rev=1341121&view=auto
==============================================================================
--- sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SetServerFunction.java (added)
+++ sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SetServerFunction.java Mon May 21 17:36:54 2012
@@ -0,0 +1,82 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.client.shell;
+
+import java.io.PrintWriter;
+import java.util.List;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.client.core.Environment;
+import org.codehaus.groovy.tools.shell.IO;
+
+@SuppressWarnings("serial")
+public class SetServerFunction extends SqoopFunction
+{
+  public static final String HOST = "host";
+  public static final String PORT = "port";
+  public static final String WEBAPP = "webapp";
+
+  private IO io;
+
+  @SuppressWarnings("static-access")
+  protected SetServerFunction(IO io) {
+    this.io = io;
+
+    this.addOption(OptionBuilder.hasArg().withArgName("host")
+        .withDescription(  "Host name to invoke server resources" )
+        .withLongOpt(HOST)
+        .create(HOST.charAt(0)));
+    this.addOption(OptionBuilder.hasArg().withArgName("port")
+        .withDescription(  "Port number to invoke server resources" )
+        .withLongOpt(PORT)
+        .create(PORT.charAt(0)));
+    this.addOption(OptionBuilder.hasArg().withArgName("webbapp")
+        .withDescription(  "Web app to invoke server resources" )
+        .withLongOpt(WEBAPP)
+        .create(WEBAPP.charAt(0)));
+  }
+
+  public void printHelp(PrintWriter out) {
+    out.println("Usage: set server");
+    super.printHelp(out);
+  }
+
+  public Object execute(List<String> args) {
+    if (args.size() == 1) {
+      printHelp(io.out);
+      io.out.println();
+      return null;
+    }
+
+    CommandLine line = parseOptions(this, 1, args);
+    if (line.hasOption(HOST)) {
+      Environment.setServerHost(line.getOptionValue(HOST));
+    }
+    if (line.hasOption(PORT)) {
+      Environment.setServerPort(line.getOptionValue(PORT));
+    }
+    if (line.hasOption(WEBAPP)) {
+      Environment.setServerWebapp(line.getOptionValue(WEBAPP));
+    }
+
+    io.out.println("Server is set successfully.");
+    io.out.println();
+    return null;
+  }
+}
\ No newline at end of file

Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SetServerFunction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SetServerFunction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopCommand.java
URL: http://svn.apache.org/viewvc/sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopCommand.java?rev=1341121&view=auto
==============================================================================
--- sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopCommand.java (added)
+++ sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopCommand.java Mon May 21 17:36:54 2012
@@ -0,0 +1,115 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.client.shell;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import org.codehaus.groovy.tools.shell.ComplexCommandSupport;
+import org.codehaus.groovy.tools.shell.Shell;
+
+public abstract class SqoopCommand extends ComplexCommandSupport
+{
+  private String descriptionPrefix;
+  private String descriptionPostfix;
+
+  private String description;
+  private String usage;
+  private String help;
+
+  @SuppressWarnings("unchecked")
+  protected SqoopCommand(Shell shell, String name, String shortcut,
+      String[] funcs, String descriptionPrefix, String descriptionPostfix) {
+    super(shell, name, shortcut);
+
+    this.functions = new LinkedList<String>();
+    for (String func : funcs) {
+      this.functions.add(func);
+    }
+
+    this.descriptionPrefix = descriptionPrefix;
+    this.descriptionPostfix = descriptionPostfix;
+  }
+
+  @Override
+  public String getDescription() {
+    if (description == null) {
+      StringBuilder sb = new StringBuilder();
+
+      if (descriptionPrefix != null) {
+        sb.append(descriptionPrefix);
+        sb.append(" ");
+      }
+
+      @SuppressWarnings("unchecked")
+      Iterator<String> iterator = functions.iterator();
+      int size = functions.size();
+      sb.append(iterator.next());
+      if (size > 1) {
+        for (int i = 1; i < (size - 1); i++) {
+          sb.append(", ");
+          sb.append(iterator.next());
+        }
+        sb.append(" or ");
+        sb.append(iterator.next());
+      }
+
+      if (descriptionPostfix != null) {
+        sb.append(" ");
+        sb.append(descriptionPostfix);
+      }
+
+      description = sb.toString();
+    }
+
+    return description;
+  }
+
+  @Override
+  public String getUsage() {
+    if (usage == null) {
+      StringBuilder sb = new StringBuilder();
+
+      sb.append("[");
+
+      @SuppressWarnings("unchecked")
+      Iterator<String> iterator = functions.iterator();
+      int size = functions.size();
+      sb.append(iterator.next());
+      for (int i = 1; i < size; i++) {
+        sb.append("|");
+        sb.append(iterator.next());
+      }
+
+      sb.append("]");
+
+      usage = sb.toString();
+    }
+
+    return usage;
+  }
+
+  @Override
+  public String getHelp() {
+    if (help == null) {
+      help = getDescription() + ".";
+    }
+
+    return help;
+  }
+}
\ No newline at end of file

Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopFunction.java
URL: http://svn.apache.org/viewvc/sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopFunction.java?rev=1341121&view=auto
==============================================================================
--- sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopFunction.java (added)
+++ sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopFunction.java Mon May 21 17:36:54 2012
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.client.shell;
+
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.DefaultParser;
+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.common.SqoopException;
+
+@SuppressWarnings("serial")
+public class SqoopFunction extends Options
+{
+  public void printHelp(PrintWriter out) {
+    HelpFormatter formatter = new HelpFormatter();
+    formatter.printOptions(out, formatter.getWidth(), this, 0, 4);
+  }
+
+  protected CommandLine parseOptions(Options options,
+      int start, List<String> arglist) {
+    Iterator<String> iterator = arglist.iterator();
+    int i = 0;
+    for (; i < start; i ++) {
+      iterator.next();
+    }
+
+    String[] args = new String[arglist.size() - start];
+    for (; i < arglist.size(); i ++) {
+      args[i - start] = iterator.next();
+    }
+
+    CommandLineParser parser = new DefaultParser();
+    CommandLine line;
+    try {
+      line = parser.parse(options, args);
+    } catch (ParseException e) {
+      throw new SqoopException(ClientError.CLIENT_0003, e.getMessage(), e);
+    }
+    return line;
+  }
+}
\ No newline at end of file

Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopFunction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopFunction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java
URL: http://svn.apache.org/viewvc/sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java?rev=1341121&view=auto
==============================================================================
--- sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java (added)
+++ sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java Mon May 21 17:36:54 2012
@@ -0,0 +1,90 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.client.shell;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import org.codehaus.groovy.tools.shell.Command;
+import org.codehaus.groovy.tools.shell.CommandRegistry;
+import org.codehaus.groovy.tools.shell.Groovysh;
+import org.codehaus.groovy.tools.shell.IO.Verbosity;
+
+public class SqoopShell
+{
+  private static final String banner =
+      "@|green Sqoop Shell:|@ Type '@|bold help|@' or '@|bold \\h|@' for help.";
+  
+  public static HashSet<String> commandsToKeep;
+  static {
+    commandsToKeep = new HashSet<String>();
+    commandsToKeep.add("exit");
+    commandsToKeep.add("history");
+  };
+
+  public static void main (String[] args) throws Exception
+  {
+    System.setProperty("groovysh.prompt", "sqoop");
+    Groovysh shell = new Groovysh();
+
+    CommandRegistry registry = shell.getRegistry();
+    @SuppressWarnings("unchecked")
+    Iterator<Command> iterator = registry.iterator();
+    while (iterator.hasNext()) {
+      Command command = iterator.next();
+      if (!commandsToKeep.contains(command.getName())) {
+        iterator.remove();
+        // remove from "names" set to avoid duplicate error.
+        registry.remove(command);
+      }
+    }
+
+    shell.register(new HelpCommand(shell));
+    shell.register(new SetCommand(shell));
+
+    if (args.length == 0) {
+      // Interactive mode:
+      shell.getIo().setVerbosity(Verbosity.QUIET);
+      shell.getIo().out.println(banner);
+      shell.getIo().out.println();
+      shell.run(args);
+
+    } else {
+      // Batch mode (with a script file):
+      File script = new File(args[0]);
+      if (!script.isAbsolute()) {
+        String userDir = System.getProperty("user.dir");
+        script = new File(userDir, args[0]);
+      }
+
+      BufferedReader in = new BufferedReader(new FileReader(script));
+      String line;
+      while ((line = in.readLine()) != null) {
+        shell.getIo().out.print(shell.renderPrompt());
+        shell.getIo().out.println(line);
+        Object result = shell.execute(line);
+        if (result != null) {
+          shell.getIo().out.println(result);
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain