Repository: incubator-trafodion Updated Branches: refs/heads/master 3f1485fe6 -> d3c0bb9b1
TRAFODION-2462 jline not work will Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/5bba1331 Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/5bba1331 Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/5bba1331 Branch: refs/heads/master Commit: 5bba13319d03021106c8844fd86ebc2381f95eda Parents: bf3e8d0 Author: mashengchen <mashengc...@gmail.com> Authored: Sun May 14 05:37:44 2017 +0000 Committer: mashengchen <mashengc...@gmail.com> Committed: Sun May 14 05:37:44 2017 +0000 ---------------------------------------------------------------------- .../java/org/trafodion/ci/ConsoleReader.java | 148 ++++++++++--------- .../src/main/java/org/trafodion/ci/FCQuery.java | 12 +- .../java/org/trafodion/ci/ParseArguments.java | 19 ++- .../java/org/trafodion/ci/QueryWrapper.java | 22 ++- .../src/main/java/org/trafodion/ci/Session.java | 2 +- .../java/org/trafodion/ci/SessionInterface.java | 2 +- .../java/org/trafodion/ci/UserInterface.java | 7 +- core/conn/trafci/utils/trafci.cmd-tmpl | 14 +- core/conn/trafci/utils/trafci.sh-tmpl | 42 +++--- 9 files changed, 158 insertions(+), 110 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5bba1331/core/conn/trafci/src/main/java/org/trafodion/ci/ConsoleReader.java ---------------------------------------------------------------------- diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/ConsoleReader.java b/core/conn/trafci/src/main/java/org/trafodion/ci/ConsoleReader.java index 26009a1..4e421c4 100644 --- a/core/conn/trafci/src/main/java/org/trafodion/ci/ConsoleReader.java +++ b/core/conn/trafci/src/main/java/org/trafodion/ci/ConsoleReader.java @@ -52,21 +52,30 @@ public class ConsoleReader private MaskingThread mt=null; WCIUtils wcs=null; + private boolean isJline = false; jline.console.ConsoleReader cr = null; - ConsoleReader() - { - newLine=System.getProperty("line.separator"); - defaultEncoding=System.getProperty("file.encoding"); - - CTRLCHandler = new MySignalHandlerClass(); - try { - INTSignal=new Signal("INT"); - } catch (Exception e) {} - } + ConsoleReader() { + this(false); + } + + public ConsoleReader(boolean isJline) { + this.isJline = isJline; + newLine = System.getProperty("line.separator"); + defaultEncoding = System.getProperty("file.encoding"); + + CTRLCHandler = new MySignalHandlerClass(); + try { + INTSignal = new Signal("INT"); + } catch (Exception e) { + } + } public void setPrompt(String ps, boolean time, boolean ampmFmt) { + if (isJline) { + this.cr.setPrompt(ps); + } this.prompt = ps; this.time = time; this.ampmFmt = ampmFmt; @@ -110,9 +119,11 @@ public class ConsoleReader public void initialize() throws IOException { this.in=System.in; - cr = new jline.console.ConsoleReader(); - cr.setPrompt(this.prompt); - cr.setHandleUserInterrupt(true); + if (isJline) { + cr = new jline.console.ConsoleReader(); + cr.setPrompt(this.prompt); + cr.setHandleUserInterrupt(true); + } } public String getLine() throws IOException, UserInterruption @@ -123,69 +134,61 @@ public class ConsoleReader public String readLine() throws UnsupportedEncodingException, UserInterruption, IOException { -/* StringBuffer lineBuffer=null; - lineBuffer=new StringBuffer(); - int i=-1; - - try { - if (CTRLCHandler != null) - { - Signal.handle(INTSignal, CTRLCHandler); - } - } catch (Exception e) {} - - while (true) - { - queryInterrupted = false; - this.in.mark(1); - try{ - if ((i = this.in.read()) != -1) - { - if (queryInterrupted) - { - in.reset(); - throw new UserInterruption(); + if (!isJline) { + StringBuffer lineBuffer = null; + lineBuffer = new StringBuffer(); + int i = -1; + + try { + if (CTRLCHandler != null) { + Signal.handle(INTSignal, CTRLCHandler); + } + } catch (Exception e) { } - lineBuffer.append((char)i); - line = lineBuffer.toString(); - - if (!defaultEncoding.equalsIgnoreCase("Cp1047")) - { - byte[] ba=line.getBytes("ISO-8859-1"); // added for nls character support - line=new String(ba,defaultEncoding); + while (true) { + queryInterrupted = false; + this.in.mark(1); + try { + if ((i = this.in.read()) != -1) { + if (queryInterrupted) { + in.reset(); + throw new UserInterruption(); + } + + lineBuffer.append((char) i); + line = lineBuffer.toString(); + + if (!defaultEncoding.equalsIgnoreCase("Cp1047")) { + byte[] ba = line.getBytes("ISO-8859-1"); // added for nls character support + line = new String(ba, defaultEncoding); + } + + if (line != null && line.endsWith(newLine)) { + return line.substring(0, line.length() - newLine.length()); + } + } + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println(SessionError.OUT_OF_BOUNDS); + + if (doTrace) { + e.printStackTrace(); + } + } + + if (queryInterrupted) { + in.reset(); + throw new UserInterruption(); + } } - - if (line != null && line.endsWith(newLine)) - { - return line.substring(0,line.length() - newLine.length()); + } else { + String readLine = null; + try { + readLine = cr.readLine(); + } catch (UserInterruptException e) { } - } - }catch (ArrayIndexOutOfBoundsException e) - { - System.out.println(SessionError.OUT_OF_BOUNDS); - - if(doTrace) - { - e.printStackTrace(); - } - } - - if (queryInterrupted) - { - in.reset(); - throw new UserInterruption(); - - } - } -*/ - String readLine = null; - try { - readLine = cr.readLine(); - } catch (UserInterruptException e) { - // TODO Auto-generated catch block + return readLine; } - return readLine; } public boolean next() throws IOException, UserInterruption @@ -227,5 +230,8 @@ public class ConsoleReader return (num <= 0 ? true:false); } + public boolean isJline() { + return isJline; + } } http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5bba1331/core/conn/trafci/src/main/java/org/trafodion/ci/FCQuery.java ---------------------------------------------------------------------- diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/FCQuery.java b/core/conn/trafci/src/main/java/org/trafodion/ci/FCQuery.java index f67d5a7..10ca6de 100644 --- a/core/conn/trafci/src/main/java/org/trafodion/ci/FCQuery.java +++ b/core/conn/trafci/src/main/java/org/trafodion/ci/FCQuery.java @@ -78,7 +78,11 @@ public class FCQuery } if (sessObj.isLogCmdText()) { writer.writeln(sessObj.getSessionPrompt() + multiLineQry[lineNo]); // print the line to be edited - writer.write(fcPrompt); //print the fc prompt + if (reader.getConsoleReader().isJline()) { + reader.getConsoleReader().setPrompt(fcPrompt, false, false); + } else { + writer.write(fcPrompt); // print the fc prompt + } } //read the fc command fcCommand= reader.getLine().toCharArray(); @@ -129,7 +133,11 @@ public class FCQuery } if (sessObj.isLogCmdText()) { writer.writeln(sessObj.getSessionPrompt() + qryText ); - writer.write(fcPrompt); + if (reader.getConsoleReader().isJline()) { + reader.getConsoleReader().setPrompt(fcPrompt, false, false); + } else { + writer.write(fcPrompt); + } } fcCommand= reader.getLine().toCharArray(); http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5bba1331/core/conn/trafci/src/main/java/org/trafodion/ci/ParseArguments.java ---------------------------------------------------------------------- diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/ParseArguments.java b/core/conn/trafci/src/main/java/org/trafodion/ci/ParseArguments.java index 57944a0..eb2d0cc 100644 --- a/core/conn/trafci/src/main/java/org/trafodion/ci/ParseArguments.java +++ b/core/conn/trafci/src/main/java/org/trafodion/ci/ParseArguments.java @@ -168,7 +168,6 @@ public class ParseArguments printUsage(); throw new InvalidNumberOfArguments(); } - argsList=null; @@ -178,7 +177,6 @@ public class ParseArguments { String option=args[i++].trim(); String value=args[i].trim(); - if (option.equalsIgnoreCase("-u")|| option.equalsIgnoreCase("-user")) { userName=value; @@ -211,6 +209,9 @@ public class ParseArguments } } + else if (option.equalsIgnoreCase("-j")|| option.equalsIgnoreCase("-jline")) { + continue; + } else if (isLaunchConnect && (option.equalsIgnoreCase("-q")|| option.equalsIgnoreCase("-sql"))) { queryStr=value; @@ -338,8 +339,12 @@ public class ParseArguments if (!this.isLaunchConnect) breakConnectPrompt = "Command Interrupted - Please hit <Enter> ... "+SessionDefaults.lineSeperator; - crObj.setPrompt(breakConnectPrompt,false,false); - cwObj.print(prompt); + if (crObj.isJline()) { + crObj.setPrompt(prompt,false,false); + }else { + crObj.setPrompt(breakConnectPrompt,false,false); + cwObj.print(prompt); + } //set retry count to 0 if user hits a Ctrl+C while entering login parameters try @@ -428,7 +433,11 @@ public class ParseArguments if (!this.isLaunchConnect) breakConnectPrompt = "Command Interrupted - Please hit <Enter> ... "+SessionDefaults.lineSeperator; - crObj.setPrompt(breakConnectPrompt,false,false); + if (! crObj.isJline()) { + crObj.setPrompt(breakConnectPrompt,false,false); + } else { + crObj.setPrompt("",false,false); + } try http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5bba1331/core/conn/trafci/src/main/java/org/trafodion/ci/QueryWrapper.java ---------------------------------------------------------------------- diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/QueryWrapper.java b/core/conn/trafci/src/main/java/org/trafodion/ci/QueryWrapper.java index 2adc7e5..57e78fd 100644 --- a/core/conn/trafci/src/main/java/org/trafodion/ci/QueryWrapper.java +++ b/core/conn/trafci/src/main/java/org/trafodion/ci/QueryWrapper.java @@ -184,17 +184,23 @@ public abstract class QueryWrapper { if ((matchTrigStmt)&& (utils.rtrim(queryStr).equals(crTrigTerminator))) break; - else if ((!matchTrigStmt) && (queryStr.trim().toUpperCase().endsWith(sessObj.getSessionSQLTerminator()))) - {this.sessObj.getConsoleReader().cr.setPrompt("SQL>"); - break; - } + else if ((!matchTrigStmt) && (queryStr.trim().toUpperCase().endsWith(sessObj.getSessionSQLTerminator()))) { + if (this.sessObj.getConsoleReader().isJline()) { + this.sessObj.getConsoleReader().cr.setPrompt("SQL>"); + } + break; + } if (( (writer.getWriterMode() == SessionDefaults.CONSOLE_WRITE_MODE || writer.getWriterMode() == SessionDefaults.CONSOLE_SPOOL_WRITE_MODE)) ) { - if((reader.getReadMode() == SessionDefaults.OBEY_READ_MODE && !sessObj.isQuietEnabled()) || !(reader.getReadMode() == SessionDefaults.OBEY_READ_MODE) ) - {//writer.getConsoleWriter().print(sessObj.getSessionCprompt()); - this.sessObj.getConsoleReader().cr.setPrompt("+>"); - } + if((reader.getReadMode() == SessionDefaults.OBEY_READ_MODE && !sessObj.isQuietEnabled()) || !(reader.getReadMode() == SessionDefaults.OBEY_READ_MODE) ) + { + if (this.sessObj.getConsoleReader().isJline()) { + this.sessObj.getConsoleReader().cr.setPrompt("+>"); + } else { + writer.getConsoleWriter().print(sessObj.getSessionCprompt()); + } + } } try { http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5bba1331/core/conn/trafci/src/main/java/org/trafodion/ci/Session.java ---------------------------------------------------------------------- diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/Session.java b/core/conn/trafci/src/main/java/org/trafodion/ci/Session.java index 62d26f5..3e31e5a 100644 --- a/core/conn/trafci/src/main/java/org/trafodion/ci/Session.java +++ b/core/conn/trafci/src/main/java/org/trafodion/ci/Session.java @@ -558,7 +558,7 @@ static { switch (this.mode) { case SessionDefaults.SQL_MODE: - //prompt = sessionSQLPrompt; + prompt = sessionSQLPrompt; break; default: prompt = sessionSQLPrompt; http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5bba1331/core/conn/trafci/src/main/java/org/trafodion/ci/SessionInterface.java ---------------------------------------------------------------------- diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/SessionInterface.java b/core/conn/trafci/src/main/java/org/trafodion/ci/SessionInterface.java index 49db0b0..0243eb1 100644 --- a/core/conn/trafci/src/main/java/org/trafodion/ci/SessionInterface.java +++ b/core/conn/trafci/src/main/java/org/trafodion/ci/SessionInterface.java @@ -415,7 +415,7 @@ public class SessionInterface implements SessionDefaults if (!OS_EOF) { if(!sessObj.isSessionStartup()) { - if (!userPressedCtrlC && sessObj.isLogCmdText() && sessObj.isLogCmdEcho() ) + if (!userPressedCtrlC && sessObj.isLogCmdText() && sessObj.isLogCmdEcho() && !reader.getConsoleReader().isJline() ) { writer.write(sessObj.getSessionPrompt()); } http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5bba1331/core/conn/trafci/src/main/java/org/trafodion/ci/UserInterface.java ---------------------------------------------------------------------- diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/UserInterface.java b/core/conn/trafci/src/main/java/org/trafodion/ci/UserInterface.java index 0638b79..e1345f4 100644 --- a/core/conn/trafci/src/main/java/org/trafodion/ci/UserInterface.java +++ b/core/conn/trafci/src/main/java/org/trafodion/ci/UserInterface.java @@ -54,8 +54,8 @@ public class UserInterface { int exitCode = 0; boolean doTrace = Boolean.getBoolean(SessionDefaults.PROP_TRACE); String mySQRoot = System.getenv("TRAF_HOME"); - - + //to decide using jline + boolean isJline = "yes".equalsIgnoreCase(System.getProperty("jline")) ? true : false; /* handle AWT exceptions */ try { @@ -78,7 +78,7 @@ public class UserInterface { e1.printStackTrace(); System.exit(SessionDefaults.abruptExit); } - crObj = new ConsoleReader(); + crObj = new ConsoleReader(isJline); try { crObj.initialize(); @@ -92,6 +92,7 @@ public class UserInterface { banner(); + System.out.println("using jline: "+ isJline); // parse the arguments ParseArguments paObj = new ParseArguments(crObj, cwObj); http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5bba1331/core/conn/trafci/utils/trafci.cmd-tmpl ---------------------------------------------------------------------- diff --git a/core/conn/trafci/utils/trafci.cmd-tmpl b/core/conn/trafci/utils/trafci.cmd-tmpl index 167fb54..1be77af 100644 --- a/core/conn/trafci/utils/trafci.cmd-tmpl +++ b/core/conn/trafci/utils/trafci.cmd-tmpl @@ -33,6 +33,18 @@ set count=0 :set_args_loop set /a count+=1 + +set m=0 +set n=0 +if '%1'=='-j' set /a m=1 +if '%1'=='-jline' set /a n=1 +set /a x=m "|" n +if %x% EQU 1 ( + set extention_opts=-Djline=%2% + shift /1 + shift /1 +) + set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1 shift /1 if %count%==16 goto after_set_args_loop @@ -44,7 +56,7 @@ set binlocation=%~dp0 set driver=%binlocation:~0,2% %driver% cd %binlocation% -java -classpath %TRAFCI_CLASSPATH% org.trafodion.ci.UserInterface %CMD_LINE_ARGS% +java %extention_opts% -classpath %TRAFCI_CLASSPATH% org.trafodion.ci.UserInterface %CMD_LINE_ARGS% if not %ERRORLEVEL% EQU -9999 goto end_loop echo. http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/5bba1331/core/conn/trafci/utils/trafci.sh-tmpl ---------------------------------------------------------------------- diff --git a/core/conn/trafci/utils/trafci.sh-tmpl b/core/conn/trafci/utils/trafci.sh-tmpl index 53ee1f2..cb03e0e 100644 --- a/core/conn/trafci/utils/trafci.sh-tmpl +++ b/core/conn/trafci/utils/trafci.sh-tmpl @@ -132,24 +132,22 @@ while [ $# -gt 0 ]; do # {{ USER_ARG=$1 shift; USER_OPTION="$1" + elif [ "ci$OPT_VALUE" = "ci-p" -o "ci$OPT_VALUE" = "ci-password" ]; then # {{{{{{{ + PASSWORD_ARG=$1 + shift; + PASSWORD_OPTION="$1" + elif [ "ci$OPT_VALUE" = "ci-r" -o "ci$OPT_VALUE" = "ci-role" ]; then # {{{{{{{{ + ROLE_ARG=$1 + shift; + ROLE_VALUE=$1 + UIMAINCLASS_PARAMS="$UIMAINCLASS_PARAMS $ROLE_ARG \"$ROLE_VALUE\"" + elif [ "ci$OPT_VALUE" = "ci-j" -o "ci$OPT_VALUE" = "ci-jline" ]; then + JLINE_ARG=$1 + shift; + JLINE_VALUE=$1 else - if [ "ci$OPT_VALUE" = "ci-p" -o "ci$OPT_VALUE" = "ci-password" ]; then # {{{{{{{ - PASSWORD_ARG=$1 - shift; - PASSWORD_OPTION="$1" - else - if [ "ci$OPT_VALUE" = "ci-r" -o "ci$OPT_VALUE" = "ci-role" ]; then # {{{{{{{{ - ROLE_ARG=$1 - shift; - ROLE_VALUE=$1 - UIMAINCLASS_PARAMS="$UIMAINCLASS_PARAMS $ROLE_ARG \"$ROLE_VALUE\"" - else - UIMAINCLASS_PARAMS="$UIMAINCLASS_PARAMS $1" + UIMAINCLASS_PARAMS="$UIMAINCLASS_PARAMS $1" - fi # End of check for Role }}}}}}}} - - fi # End of check for password }}}}}}} - fi # End of check for user }}}}}} fi # }}} End of IF the option is -q or -sql. @@ -176,12 +174,20 @@ if [ ! -z "$PASSWORD_ARG" ]; then jusercred_opts="$jusercred_opts $PASSWORD_ARG \"$PASSWORD_OPTION\"" fi +extention_opts="" +if [ ! -z "$JLINE_ARG" ]; then + extention_opts="-Djline=$JLINE_VALUE" +else + extention_opts="-Djline=no" +fi + #echo "***DEBUG*** jusercred_opts = $jusercred_opts" +#echo "***DEBUG*** extention_opts = $extention_opts" #echo "" #echo "***DEBUG*** running command = java $jcmd_opts $jusercred_opts $QUERY_OPTION \"$QUERY_ARG\" " if [ ! -z "$QUERY_OPTION" ]; then - eval java $jcmd_opts $jusercred_opts $QUERY_OPTION \'"$QUERY_ARG"\' + eval java $extention_opts $jcmd_opts $jusercred_opts $QUERY_OPTION \'"$QUERY_ARG"\' else - eval java $jcmd_opts $jusercred_opts + eval java $extention_opts $jcmd_opts $jusercred_opts fi