You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ph...@apache.org on 2013/10/01 23:18:08 UTC

svn commit: r1528219 - in /zookeeper/trunk: ./ src/java/lib/ src/java/main/org/apache/zookeeper/

Author: phunt
Date: Tue Oct  1 21:18:07 2013
New Revision: 1528219

URL: http://svn.apache.org/r1528219
Log:
ZOOKEEPER-1718. Support JLine 2 (Manikumar Reddy via phunt)

Added:
    zookeeper/trunk/src/java/lib/jline-2.11.LICENSE.txt
    zookeeper/trunk/src/java/main/org/apache/zookeeper/JLineZNodeCompleter.java
Removed:
    zookeeper/trunk/src/java/lib/jline-0.9.94.LICENSE.txt
    zookeeper/trunk/src/java/main/org/apache/zookeeper/JLineZNodeCompletor.java
Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/ivy.xml
    zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeperMain.java

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1528219&r1=1528218&r2=1528219&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Tue Oct  1 21:18:07 2013
@@ -395,6 +395,8 @@ BUGFIXES:
   ZOOKEEPER-1769. ZooInspector can't display node data/metadata/ACLs
   (Benjamin Jaton via phunt)
 
+  ZOOKEEPER-1718. Support JLine 2 (Manikumar Reddy via phunt)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports,

Modified: zookeeper/trunk/ivy.xml
URL: http://svn.apache.org/viewvc/zookeeper/trunk/ivy.xml?rev=1528219&r1=1528218&r2=1528219&view=diff
==============================================================================
--- zookeeper/trunk/ivy.xml (original)
+++ zookeeper/trunk/ivy.xml Tue Oct  1 21:18:07 2013
@@ -45,7 +45,7 @@
   
     <!-- transitive false turns off dependency checking, log4j deps seem borked -->
     <dependency org="log4j" name="log4j" rev="1.2.16" transitive="false" conf="default"/>
-    <dependency org="jline" name="jline" rev="0.9.94" transitive="false" conf="default"/>
+    <dependency org="jline" name="jline" rev="2.11" transitive="false" conf="default"/>
 
     <dependency org="org.jboss.netty" name="netty" conf="default" rev="3.2.5.Final">
       <artifact name="netty" type="jar" conf="default"/>

Added: zookeeper/trunk/src/java/lib/jline-2.11.LICENSE.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/lib/jline-2.11.LICENSE.txt?rev=1528219&view=auto
==============================================================================
--- zookeeper/trunk/src/java/lib/jline-2.11.LICENSE.txt (added)
+++ zookeeper/trunk/src/java/lib/jline-2.11.LICENSE.txt Tue Oct  1 21:18:07 2013
@@ -0,0 +1,35 @@
+Copyright (c) 2002-2012, the original author or authors.
+All rights reserved.
+
+http://www.opensource.org/licenses/bsd-license.php
+
+Redistribution and use in source and binary forms, with or
+without modification, are permitted provided that the following
+conditions are met:
+
+Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with
+the distribution.
+
+Neither the name of JLine nor the names of its contributors
+may be used to endorse or promote products derived from this
+software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+OF THE POSSIBILITY OF SUCH DAMAGE.
+

Added: zookeeper/trunk/src/java/main/org/apache/zookeeper/JLineZNodeCompleter.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/JLineZNodeCompleter.java?rev=1528219&view=auto
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/JLineZNodeCompleter.java (added)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/JLineZNodeCompleter.java Tue Oct  1 21:18:07 2013
@@ -0,0 +1,84 @@
+/**
+ * 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.zookeeper;
+
+import java.util.List;
+
+import jline.console.completer.Completer;
+
+class JLineZNodeCompleter implements Completer {
+    private ZooKeeper zk;
+
+    public JLineZNodeCompleter(ZooKeeper zk) {
+        this.zk = zk;
+    }
+
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    public int complete(String buffer, int cursor, List candidates) {
+        // Guarantee that the final token is the one we're expanding
+        buffer = buffer.substring(0,cursor);
+        String token = "";
+        if (!buffer.endsWith(" ")) {
+            String[] tokens = buffer.split(" ");
+            if (tokens.length != 0) {
+                token = tokens[tokens.length-1] ;
+            }
+        }
+
+        if (token.startsWith("/")){
+            return completeZNode( buffer, token, candidates);
+        }
+        return completeCommand(buffer, token, candidates);
+    }
+
+    private int completeCommand(String buffer, String token,
+            List<String> candidates)
+    {
+        for (String cmd : ZooKeeperMain.getCommands()) {
+            if (cmd.startsWith( token )) {
+                candidates.add(cmd);
+            }
+        }
+        return buffer.lastIndexOf(" ")+1;
+    }
+
+    private int completeZNode( String buffer, String token,
+            List<String> candidates)
+    {
+        String path = token;
+        int idx = path.lastIndexOf("/") + 1;
+        String prefix = path.substring(idx);
+        try {
+            // Only the root path can end in a /, so strip it off every other prefix
+            String dir = idx == 1 ? "/" : path.substring(0,idx-1);
+            List<String> children = zk.getChildren(dir, false);
+            for (String child : children) {
+                if (child.startsWith(prefix)) {
+                    candidates.add( child );
+                }
+            }
+        } catch( InterruptedException e) {
+            return 0;
+        }
+        catch( KeeperException e) {
+            return 0;
+        }
+        return candidates.size() == 0 ? buffer.length() : buffer.lastIndexOf("/") + 1;
+    }
+}

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeperMain.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeperMain.java?rev=1528219&r1=1528218&r2=1528219&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeperMain.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeperMain.java Tue Oct  1 21:18:07 2013
@@ -293,9 +293,9 @@ public class ZooKeeperMain {
             boolean jlinemissing = false;
             // only use jline if it's in the classpath
             try {
-                Class<?> consoleC = Class.forName("jline.ConsoleReader");
+                Class<?> consoleC = Class.forName("jline.console.ConsoleReader");
                 Class<?> completorC =
-                    Class.forName("org.apache.zookeeper.JLineZNodeCompletor");
+                    Class.forName("org.apache.zookeeper.JLineZNodeCompleter");
 
                 System.out.println("JLine support is enabled");
 
@@ -304,8 +304,8 @@ public class ZooKeeperMain {
 
                 Object completor =
                     completorC.getConstructor(ZooKeeper.class).newInstance(zk);
-                Method addCompletor = consoleC.getMethod("addCompletor",
-                        Class.forName("jline.Completor"));
+                Method addCompletor = consoleC.getMethod("addCompleter",
+                        Class.forName("jline.console.completer.Completer"));
                 addCompletor.invoke(console, completor);
 
                 String line;