From 7c295b4f6103f525d4f9faa8ca2665b55a6f19a6 Mon Sep 17 00:00:00 2001 From: Jarek Jarcec Cecho Date: Mon, 16 Jul 2012 20:26:48 +0000 Subject: [PATCH] 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 --- .../apache/sqoop/client/core/ClientError.java | 5 +++- .../apache/sqoop/client/shell/SetCommand.java | 2 +- .../sqoop/client/shell/SqoopCommand.java | 25 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/client/src/main/java/org/apache/sqoop/client/core/ClientError.java b/client/src/main/java/org/apache/sqoop/client/core/ClientError.java index dc6bea7b..91d1aee4 100644 --- a/client/src/main/java/org/apache/sqoop/client/core/ClientError.java +++ b/client/src/main/java/org/apache/sqoop/client/core/ClientError.java @@ -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; diff --git a/client/src/main/java/org/apache/sqoop/client/shell/SetCommand.java b/client/src/main/java/org/apache/sqoop/client/shell/SetCommand.java index 1d32d966..377c827b 100644 --- a/client/src/main/java/org/apache/sqoop/client/shell/SetCommand.java +++ b/client/src/main/java/org/apache/sqoop/client/shell/SetCommand.java @@ -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) { 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 6b3c4ab2..c610fd47 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 @@ -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); + } } \ No newline at end of file