5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-06 04:51:51 +08:00

SQOOP-495. Support for parameter substitution in the client shell.

(Vasanth kumar RJ via Jarek Jarcec Cecho)


git-svn-id: https://svn.apache.org/repos/asf/sqoop/branches/sqoop2@1362238 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jarek Jarcec Cecho 2012-07-16 20:26:48 +00:00
parent e19d63b625
commit 7c295b4f61
3 changed files with 30 additions and 2 deletions

View File

@ -31,7 +31,10 @@ public enum ClientError implements ErrorCode {
CLIENT_0002("The specified function is not recognized"),
/** An error has occurred when parsing options. */
CLIENT_0003("An error has occurred when parsing options");
CLIENT_0003("An error has occurred when parsing options"),
/** Unable to resolve the variables. */
CLIENT_0004("Unable to resolve the variables");
private final String message;

View File

@ -41,7 +41,7 @@ public Object execute(List args) {
io.out.println();
return null;
}
resolveVariables(args);
String func = (String)args.get(0);
if (func.equals("server")) {
if (serverFunction == null) {

View File

@ -17,9 +17,18 @@
*/
package org.apache.sqoop.client.shell;
import groovy.lang.GroovyShell;
import groovy.lang.MissingPropertyException;
import groovy.lang.Script;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.apache.sqoop.client.core.ClientError;
import org.apache.sqoop.common.SqoopException;
import org.codehaus.groovy.tools.shell.ComplexCommandSupport;
import org.codehaus.groovy.tools.shell.Shell;
@ -112,4 +121,20 @@ public String getHelp() {
return help;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void resolveVariables(List arg) {
List temp = new ArrayList();
GroovyShell gs = new GroovyShell(getBinding());
for(Object obj:arg) {
Script scr = gs.parse("\""+(String)obj+"\"");
try {
temp.add(scr.run().toString());
}
catch(MissingPropertyException e) {
throw new SqoopException(ClientError.CLIENT_0004, e.getMessage(), e);
}
}
Collections.copy(arg, temp);
}
}