karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject karaf git commit: [KARAF-5019] The source command doesn't work as before in karaf 4.1.0
Date Fri, 10 Mar 2017 17:30:12 GMT
Repository: karaf
Updated Branches:
  refs/heads/master 9275458dd -> 46aae23c5


[KARAF-5019] The source command doesn't work as before in karaf 4.1.0

Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/46aae23c
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/46aae23c
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/46aae23c

Branch: refs/heads/master
Commit: 46aae23c551435b709b61d6b5a89b79afd44c077
Parents: 9275458
Author: Guillaume Nodet <gnodet@apache.org>
Authored: Fri Mar 10 13:48:34 2017 +0100
Committer: Guillaume Nodet <gnodet@apache.org>
Committed: Fri Mar 10 13:50:20 2017 +0100

----------------------------------------------------------------------
 .../apache/karaf/config/command/MockCommandSession.java  | 10 ++++++++++
 .../apache/karaf/shell/commands/impl/ExecuteAction.java  |  8 +++++++-
 .../apache/karaf/shell/commands/impl/SourceAction.java   | 10 +++++-----
 .../java/org/apache/karaf/shell/api/console/Session.java |  5 +++++
 .../karaf/shell/impl/console/ConsoleSessionImpl.java     | 10 ++++++++++
 .../karaf/shell/impl/console/HeadlessSessionImpl.java    | 11 +++++++++++
 6 files changed, 48 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/46aae23c/config/src/test/java/org/apache/karaf/config/command/MockCommandSession.java
----------------------------------------------------------------------
diff --git a/config/src/test/java/org/apache/karaf/config/command/MockCommandSession.java
b/config/src/test/java/org/apache/karaf/config/command/MockCommandSession.java
index 7fa430b..33d3c24 100644
--- a/config/src/test/java/org/apache/karaf/config/command/MockCommandSession.java
+++ b/config/src/test/java/org/apache/karaf/config/command/MockCommandSession.java
@@ -19,6 +19,7 @@ package org.apache.karaf.config.command;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintStream;
+import java.nio.file.Path;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -88,6 +89,15 @@ class MockCommandSession implements Session {
     }
 
     @Override
+    public Path currentDir() {
+        return null;
+    }
+
+    @Override
+    public void currentDir(Path path) {
+    }
+
+    @Override
     public String resolveCommand(String name) {
         return null;
     }

http://git-wip-us.apache.org/repos/asf/karaf/blob/46aae23c/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/ExecuteAction.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/ExecuteAction.java
b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/ExecuteAction.java
index 3c60859..1c7ed6a 100644
--- a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/ExecuteAction.java
+++ b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/ExecuteAction.java
@@ -21,7 +21,9 @@ import java.util.List;
 import org.apache.karaf.shell.api.action.Action;
 import org.apache.karaf.shell.api.action.Argument;
 import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.console.Session;
 import org.apache.karaf.util.process.PumpStreamHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -38,9 +40,13 @@ public class ExecuteAction implements Action {
     @Argument(index = 0, name = "command", description = "Execution command with arguments",
required = true, multiValued = true)
     private List<String> args;
 
+    @Reference
+    Session session;
+
     @Override
     public Object execute() throws Exception {
-        ProcessBuilder builder = new ProcessBuilder(args);
+        ProcessBuilder builder = new ProcessBuilder(args)
+                .directory(session.currentDir().toFile());
 
         PumpStreamHandler handler = new PumpStreamHandler(System.in, System.out, System.err,
"Command" + args.toString());
 

http://git-wip-us.apache.org/repos/asf/karaf/blob/46aae23c/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/SourceAction.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/SourceAction.java
b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/SourceAction.java
index b1bf564..eab00eb 100644
--- a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/SourceAction.java
+++ b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/SourceAction.java
@@ -20,13 +20,13 @@ package org.apache.karaf.shell.commands.impl;
 
 import java.io.BufferedReader;
 import java.io.CharArrayWriter;
-import java.io.File;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.List;
 
 import org.apache.karaf.shell.api.action.Action;
@@ -66,11 +66,11 @@ public class SourceAction implements Action {
                 log.info("Printing URL: " + url);
                 reader = new BufferedReader(new InputStreamReader(url.openStream()));
             }
-            catch (MalformedURLException ignore) {
+            catch (MalformedURLException | IllegalArgumentException ignore) {
                 // fallback to a file
-                File file = new File(script.getPath());
+                Path file = session.currentDir().resolve(script.getPath());
                 log.info("Printing file: " + file);
-                reader = new BufferedReader(new FileReader(file));
+                reader = new BufferedReader(Files.newBufferedReader(file));
             }
 
             CharArrayWriter w = new CharArrayWriter();

http://git-wip-us.apache.org/repos/asf/karaf/blob/46aae23c/shell/core/src/main/java/org/apache/karaf/shell/api/console/Session.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/api/console/Session.java b/shell/core/src/main/java/org/apache/karaf/shell/api/console/Session.java
index b9b549f..9308140 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/api/console/Session.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/api/console/Session.java
@@ -22,6 +22,7 @@ import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintStream;
+import java.nio.file.Path;
 
 /**
  * A <code>Session</code> can be used to execute commands.
@@ -158,6 +159,10 @@ public interface Session extends Runnable, Closeable {
      */
     String resolveCommand(String name);
 
+    Path currentDir();
+
+    void currentDir(Path path);
+
     /**
      * Close this session. After the session is closed, it will throw
      * IllegalStateException when it is used.

http://git-wip-us.apache.org/repos/asf/karaf/blob/46aae23c/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
index 82b81b8..4a80b1e 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
@@ -268,6 +268,16 @@ public class ConsoleSessionImpl implements Session {
         return factory;
     }
 
+    @Override
+    public Path currentDir() {
+        return session.currentDir();
+    }
+
+    @Override
+    public void currentDir(Path path) {
+        session.currentDir(path);
+    }
+
     public void close() {
         if (running) {
             reader.getHistory().save();

http://git-wip-us.apache.org/repos/asf/karaf/blob/46aae23c/shell/core/src/main/java/org/apache/karaf/shell/impl/console/HeadlessSessionImpl.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/HeadlessSessionImpl.java
b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/HeadlessSessionImpl.java
index 7f951d3..e82f6f0 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/HeadlessSessionImpl.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/HeadlessSessionImpl.java
@@ -21,6 +21,7 @@ package org.apache.karaf.shell.impl.console;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintStream;
+import java.nio.file.Path;
 import java.util.EnumSet;
 import java.util.List;
 import java.util.Properties;
@@ -141,6 +142,16 @@ public class HeadlessSessionImpl implements Session {
     }
 
     @Override
+    public Path currentDir() {
+        return session.currentDir();
+    }
+
+    @Override
+    public void currentDir(Path path) {
+        session.currentDir(path);
+    }
+
+    @Override
     public void run() {
         throw new UnsupportedOperationException();
     }


Mime
View raw message