felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1736036 - in /felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline: Expander.java Shell.java
Date Mon, 21 Mar 2016 16:57:36 GMT
Author: gnodet
Date: Mon Mar 21 16:57:36 2016
New Revision: 1736036

URL: http://svn.apache.org/viewvc?rev=1736036&view=rev
Log:
Configure the expander correctly

Added:
    felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Expander.java
Modified:
    felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Shell.java

Added: felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Expander.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Expander.java?rev=1736036&view=auto
==============================================================================
--- felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Expander.java (added)
+++ felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Expander.java Mon Mar
21 16:57:36 2016
@@ -0,0 +1,57 @@
+/*
+ * 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.felix.gogo.jline;
+
+import java.util.Collection;
+import java.util.stream.Collectors;
+
+import org.apache.felix.gogo.runtime.Closure;
+import org.apache.felix.gogo.runtime.CommandSessionImpl;
+import org.apache.felix.service.command.CommandSession;
+import org.jline.reader.impl.DefaultExpander;
+
+public class Expander extends DefaultExpander {
+
+    private final CommandSession session;
+
+    public Expander(CommandSession session) {
+        this.session = session;
+    }
+
+    @Override
+    public String expandVar(String word) {
+        try {
+            Object o = org.apache.felix.gogo.runtime.Expander.expand(
+                    word,
+                    new Closure((CommandSessionImpl) session, null, null));
+            if (o instanceof Collection) {
+                return ((Collection<Object>) o).stream()
+                        .map(String::valueOf)
+                        .collect(Collectors.joining(" "));
+            }
+            else if (o != null) {
+                return o.toString();
+            }
+        } catch (Exception e) {
+            // ignore
+        }
+        return word;
+    }
+
+}

Modified: felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Shell.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Shell.java?rev=1736036&r1=1736035&r2=1736036&view=diff
==============================================================================
--- felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Shell.java (original)
+++ felix/trunk/gogo/jline/src/main/java/org/apache/felix/gogo/jline/Shell.java Mon Mar 21
16:57:36 2016
@@ -42,7 +42,6 @@ import java.util.concurrent.atomic.Atomi
 import org.apache.felix.gogo.runtime.Closure;
 import org.apache.felix.gogo.runtime.CommandProxy;
 import org.apache.felix.gogo.runtime.CommandSessionImpl;
-import org.apache.felix.gogo.runtime.Expander;
 import org.apache.felix.gogo.runtime.Job;
 import org.apache.felix.gogo.runtime.Job.Status;
 import org.apache.felix.gogo.runtime.Reflective;
@@ -140,7 +139,7 @@ public class Shell {
         Object prompt = session.get(name);
         if (prompt != null) {
             try {
-                Object o = Expander.expand(
+                Object o = org.apache.felix.gogo.runtime.Expander.expand(
                         prompt.toString(),
                         new Closure((CommandSessionImpl) session, null, null));
                 if (o != null) {
@@ -291,6 +290,7 @@ public class Shell {
                     .highlighter(new Highlighter(session))
                     .history(new FileHistory(new File(System.getProperty("user.home"), ".gogo.history")))
                     .parser(new Parser())
+                    .expander(new Expander(newSession))
                     .build();
             newSession.put(Shell.VAR_READER, reader);
             newSession.put(Shell.VAR_COMPLETIONS, new HashMap());



Mime
View raw message