karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1529147 - in /karaf/branches/karaf-2.x: ./ assemblies/apache-karaf/ assemblies/apache-karaf/src/main/descriptors/ assemblies/apache-karaf/src/main/filtered-resources/etc/ assemblies/features/standard/src/main/resources/ client/ shell/conso...
Date Fri, 04 Oct 2013 12:47:12 GMT
Author: gnodet
Date: Fri Oct  4 12:47:11 2013
New Revision: 1529147

URL: http://svn.apache.org/r1529147
Log:
[KARAF-2501] Break some bundle dependencies in the console

Added:
    karaf/branches/karaf-2.x/shell/ssh/src/main/resources/karaf.key
      - copied, changed from r1529092, karaf/branches/karaf-2.x/shell/console/src/main/resources/karaf.key
Removed:
    karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/felix/gogo/runtime/Closure.java
    karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Activator.java
    karaf/branches/karaf-2.x/shell/console/src/main/resources/karaf.key
Modified:
    karaf/branches/karaf-2.x/assemblies/apache-karaf/pom.xml
    karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/descriptors/unix-bin-release.xml
    karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/descriptors/unix-minimal-bin-release.xml
    karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/descriptors/windows-bin-release.xml
    karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/descriptors/windows-minimal-bin-release.xml
    karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/filtered-resources/etc/startup.properties
    karaf/branches/karaf-2.x/assemblies/features/standard/src/main/resources/features.xml
    karaf/branches/karaf-2.x/client/pom.xml
    karaf/branches/karaf-2.x/pom.xml
    karaf/branches/karaf-2.x/shell/console/pom.xml
    karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/felix/gogo/commands/basic/DefaultActionPreparator.java
    karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/completer/CommandNamesCompleter.java
    karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/completer/CommandsCompleter.java
    karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/help/CommandListHelpProvider.java
    karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/help/SingleCommandHelpProvider.java
    karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java
    karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/ConsoleFactory.java
    karaf/branches/karaf-2.x/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafAgentFactory.java
    karaf/branches/karaf-2.x/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommandFactory.java
    karaf/branches/karaf-2.x/shell/ssh/src/main/resources/OSGI-INF/blueprint/shell-ssh.xml

Modified: karaf/branches/karaf-2.x/assemblies/apache-karaf/pom.xml
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/assemblies/apache-karaf/pom.xml?rev=1529147&r1=1529146&r2=1529147&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/assemblies/apache-karaf/pom.xml (original)
+++ karaf/branches/karaf-2.x/assemblies/apache-karaf/pom.xml Fri Oct  4 12:47:11 2013
@@ -235,6 +235,10 @@
             <artifactId>org.apache.felix.fileinstall</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.gogo.runtime</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.apache.mina</groupId>
             <artifactId>mina-core</artifactId>
         </dependency>

Modified: karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/descriptors/unix-bin-release.xml
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/descriptors/unix-bin-release.xml?rev=1529147&r1=1529146&r2=1529147&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/descriptors/unix-bin-release.xml
(original)
+++ karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/descriptors/unix-bin-release.xml
Fri Oct  4 12:47:11 2013
@@ -144,6 +144,8 @@
                 <include>org.apache.felix:org.apache.felix.configadmin</include>
                 <include>org.apache.felix:org.apache.felix.framework</include>
                 <include>org.apache.felix:org.apache.felix.fileinstall</include>
+                <include>org.apache.felix:org.apache.felix.framework.security</include>
+                <include>org.apache.felix:org.apache.felix.gogo.runtime</include>
             </includes>
         </dependencySet>
         <dependencySet>

Modified: karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/descriptors/unix-minimal-bin-release.xml
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/descriptors/unix-minimal-bin-release.xml?rev=1529147&r1=1529146&r2=1529147&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/descriptors/unix-minimal-bin-release.xml
(original)
+++ karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/descriptors/unix-minimal-bin-release.xml
Fri Oct  4 12:47:11 2013
@@ -128,6 +128,7 @@
                 <include>org.apache.felix:org.apache.felix.configadmin</include>
                 <include>org.apache.felix:org.apache.felix.framework</include>
                 <include>org.apache.felix:org.apache.felix.fileinstall</include>
+                <include>org.apache.felix:org.apache.felix.gogo.runtime</include>
             </includes>
         </dependencySet>
         <dependencySet>

Modified: karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/descriptors/windows-bin-release.xml
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/descriptors/windows-bin-release.xml?rev=1529147&r1=1529146&r2=1529147&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/descriptors/windows-bin-release.xml
(original)
+++ karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/descriptors/windows-bin-release.xml
Fri Oct  4 12:47:11 2013
@@ -144,6 +144,8 @@
                 <include>org.apache.felix:org.apache.felix.configadmin</include>
                 <include>org.apache.felix:org.apache.felix.framework</include>
                 <include>org.apache.felix:org.apache.felix.fileinstall</include>
+                <include>org.apache.felix:org.apache.felix.framework.security</include>
+                <include>org.apache.felix:org.apache.felix.gogo.runtime</include>
             </includes>
         </dependencySet>
         <dependencySet>

Modified: karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/descriptors/windows-minimal-bin-release.xml
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/descriptors/windows-minimal-bin-release.xml?rev=1529147&r1=1529146&r2=1529147&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/descriptors/windows-minimal-bin-release.xml
(original)
+++ karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/descriptors/windows-minimal-bin-release.xml
Fri Oct  4 12:47:11 2013
@@ -129,6 +129,7 @@
                 <include>org.apache.felix:org.apache.felix.configadmin</include>
                 <include>org.apache.felix:org.apache.felix.framework</include>
                 <include>org.apache.felix:org.apache.felix.fileinstall</include>
+                <include>org.apache.felix:org.apache.felix.gogo.runtime</include>
             </includes>
         </dependencySet>
         <dependencySet>

Modified: karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/filtered-resources/etc/startup.properties
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/filtered-resources/etc/startup.properties?rev=1529147&r1=1529146&r2=1529147&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/filtered-resources/etc/startup.properties
(original)
+++ karaf/branches/karaf-2.x/assemblies/apache-karaf/src/main/filtered-resources/etc/startup.properties
Fri Oct  4 12:47:11 2013
@@ -41,6 +41,7 @@ org/apache/aries/blueprint/org.apache.ar
 org/apache/aries/blueprint/org.apache.aries.blueprint.core/${aries.blueprint.core.version}/org.apache.aries.blueprint.core-${aries.blueprint.core.version}.jar=20
 org/apache/aries/blueprint/org.apache.aries.blueprint.cm/${aries.blueprint.cm.version}/org.apache.aries.blueprint.cm-${aries.blueprint.cm.version}.jar=20
 
+org/apache/felix/org.apache.felix.gogo.runtime/${felix.gogo.version}/org.apache.felix.gogo.runtime-${felix.gogo.version}.jar=25
 org/apache/karaf/shell/org.apache.karaf.shell.console/${project.version}/org.apache.karaf.shell.console-${project.version}.jar=25
 
 org/apache/karaf/shell/org.apache.karaf.shell.osgi/${project.version}/org.apache.karaf.shell.osgi-${project.version}.jar=30

Modified: karaf/branches/karaf-2.x/assemblies/features/standard/src/main/resources/features.xml
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/assemblies/features/standard/src/main/resources/features.xml?rev=1529147&r1=1529146&r2=1529147&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/assemblies/features/standard/src/main/resources/features.xml
(original)
+++ karaf/branches/karaf-2.x/assemblies/features/standard/src/main/resources/features.xml
Fri Oct  4 12:47:11 2013
@@ -32,6 +32,7 @@
         <bundle start-level="20">mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.api/${aries.blueprint.api.version}</bundle>
         <bundle start-level="20">mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.core/${aries.blueprint.core.version}</bundle>
         <bundle start-level="20">mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.cm/${aries.blueprint.cm.version}</bundle>
+        <bundle start-level="30">mvn:org.apache.felix/org.apache.felix.gogo.runtime/${felix.gogo.version}</bundle>
         <bundle start-level="30">mvn:org.apache.karaf.shell/org.apache.karaf.shell.console/${project.version}</bundle>
         <bundle start-level="30">mvn:org.apache.karaf.shell/org.apache.karaf.shell.osgi/${project.version}</bundle>
         <bundle start-level="30">mvn:org.apache.karaf.shell/org.apache.karaf.shell.log/${project.version}</bundle>

Modified: karaf/branches/karaf-2.x/client/pom.xml
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/client/pom.xml?rev=1529147&r1=1529146&r2=1529147&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/client/pom.xml (original)
+++ karaf/branches/karaf-2.x/client/pom.xml Fri Oct  4 12:47:11 2013
@@ -82,7 +82,7 @@
                             META-INF;-split-package:=merge-first
                         </Private-Package>
                         <Include-Resource>
-                            ../shell/console/src/main/resources/karaf.key,
+                            ../shell/ssh/src/main/resources/karaf.key,
                             {maven-resources}
                         </Include-Resource>
                         <Import-Package>!*</Import-Package>

Modified: karaf/branches/karaf-2.x/pom.xml
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/pom.xml?rev=1529147&r1=1529146&r2=1529147&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/pom.xml (original)
+++ karaf/branches/karaf-2.x/pom.xml Fri Oct  4 12:47:11 2013
@@ -574,6 +574,11 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.felix</groupId>
+                <artifactId>org.apache.felix.gogo.runtime</artifactId>
+                <version>${felix.gogo.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.felix</groupId>
                 <artifactId>org.apache.felix.fileinstall</artifactId>
                 <version>${felix.fileinstall.version}</version>
                 <exclusions>

Modified: karaf/branches/karaf-2.x/shell/console/pom.xml
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/shell/console/pom.xml?rev=1529147&r1=1529146&r2=1529147&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/shell/console/pom.xml (original)
+++ karaf/branches/karaf-2.x/shell/console/pom.xml Fri Oct  4 12:47:11 2013
@@ -115,15 +115,14 @@
                 <configuration>
                     <instructions>
                         <Import-Package>
+                            !org.apache.felix.gogo.runtime.*,
                             org.osgi.service.event;resolution:=optional,
                             org.apache.karaf.branding;resolution:=optional,
                             org.apache.sshd.agent*;resolution:=optional,
                             *
                         </Import-Package>
                         <Export-Package>
-                            org.apache.felix.gogo*;version=${felix.gogo.version};-split-package:=merge-first,
-                            org.apache.felix.service.command;version=${felix.gogo.version};status=provisional;mandatory:=status,
-                            org.apache.felix.service.threadio;version=${felix.gogo.version};status=provisional;mandatory:=status,
+                            org.apache.felix.gogo.commands.*;version=${felix.gogo.version};-split-package:=merge-first,
                             org.apache.karaf.shell.console*;version=${project.version},
                             org.fusesource.jansi;version=${jansi.version};-split-package:=merge-first,
                             jline*;version=${jline.version},
@@ -140,17 +139,21 @@
                             META-INF/native/windows64/jansi.dll;osname=Win32;processor=x86-64,
                             *
                         </Bundle-NativeCode>
+                        <!--
                         <Bundle-Activator>
                             org.apache.karaf.shell.console.jline.Activator
                         </Bundle-Activator>
+                        -->
                         <Main-Class>
                             org.apache.karaf.shell.console.Main
                         </Main-Class>
+                        <!--
                         <Export-Service>
                             org.apache.felix.service.threadio.ThreadIO,
                             org.apache.felix.service.command.CommandProcessor,
                             org.apache.felix.service.command.Converter
                         </Export-Service>
+                        -->
                     </instructions>
                     <unpackBundle>true</unpackBundle>
                 </configuration>

Modified: karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/felix/gogo/commands/basic/DefaultActionPreparator.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/felix/gogo/commands/basic/DefaultActionPreparator.java?rev=1529147&r1=1529146&r2=1529147&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/felix/gogo/commands/basic/DefaultActionPreparator.java
(original)
+++ karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/felix/gogo/commands/basic/DefaultActionPreparator.java
Fri Oct  4 12:47:11 2013
@@ -79,6 +79,17 @@ public class DefaultActionPreparator imp
         Map<Option, Field> options = new HashMap<Option, Field>();
         Map<Argument, Field> arguments = new HashMap<Argument, Field>();
         List<Argument> orderedArguments = new ArrayList<Argument>();
+        // It's a shame, but gogo converts string to numbers if possible
+        // and blueprint does not do the opposite conversion, so transform
+        // them back before preparing
+        List<Object> newParams = new ArrayList<Object>(params.size());
+        for (Object o : params) {
+            if (o instanceof Number) {
+                o = o.toString();
+            }
+            newParams.add(o);
+        }
+        params = newParams;
         // Introspect
         for (Class type = action.getClass(); type != null; type = type.getSuperclass()) {
             for (Field field : type.getDeclaredFields()) {

Modified: karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/completer/CommandNamesCompleter.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/completer/CommandNamesCompleter.java?rev=1529147&r1=1529146&r2=1529147&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/completer/CommandNamesCompleter.java
(original)
+++ karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/completer/CommandNamesCompleter.java
Fri Oct  4 12:47:11 2013
@@ -24,7 +24,6 @@ import java.util.List;
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArraySet;
 
-import org.apache.felix.gogo.runtime.CommandSessionImpl;
 import org.apache.felix.service.command.CommandProcessor;
 import org.apache.felix.service.command.CommandSession;
 import org.apache.karaf.shell.console.Completer;
@@ -39,6 +38,8 @@ import org.osgi.framework.ServiceListene
  */
 public class CommandNamesCompleter implements Completer {
 
+    public static final String COMMANDS = ".commands";
+
     private CommandSession session;
     private final Set<String> commands = new CopyOnWriteArraySet<String>();
 
@@ -69,7 +70,7 @@ public class CommandNamesCompleter imple
 
     protected void checkData() {
         if (commands.isEmpty()) {
-            Set<String> names = new HashSet<String>((Set<String>) session.get(CommandSessionImpl.COMMANDS));
+            Set<String> names = new HashSet<String>((Set<String>) session.get(COMMANDS));
             for (String name : names) {
                 commands.add(name);
                 if (name.indexOf(':') > 0) {

Modified: karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/completer/CommandsCompleter.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/completer/CommandsCompleter.java?rev=1529147&r1=1529146&r2=1529147&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/completer/CommandsCompleter.java
(original)
+++ karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/completer/CommandsCompleter.java
Fri Oct  4 12:47:11 2013
@@ -26,9 +26,6 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.felix.gogo.commands.basic.AbstractCommand;
-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.service.command.CommandSession;
 import org.apache.felix.service.command.Function;
 import org.apache.karaf.shell.console.Completer;
@@ -44,6 +41,8 @@ import org.slf4j.LoggerFactory;
  */
 public class CommandsCompleter implements Completer {
 
+    public static final String COMMANDS = ".commands";
+
     private static final Logger LOGGER = LoggerFactory.getLogger(CommandsCompleter.class);
 
     private CommandSession session;
@@ -72,7 +71,7 @@ public class CommandsCompleter implement
     protected synchronized void checkData() {
         // Copy the set to avoid concurrent modification exceptions
         // TODO: fix that in gogo instead
-        Set<String> names = new HashSet<String>((Set<String>) session.get(CommandSessionImpl.COMMANDS));
+        Set<String> names = new HashSet<String>((Set<String>) session.get(COMMANDS));
         if (!names.equals(commands)) {
             commands.clear();
             completers.clear();
@@ -107,7 +106,7 @@ public class CommandsCompleter implement
         Set<String> aliases = new HashSet<String>();
         for (String var : vars) {
             Object content = session.get(var);
-            if (content instanceof Closure)  {
+            if ("org.apache.felix.gogo.runtime.Closure".equals(content.getClass().getName()))
 {
                 aliases.add(var);
             }
         }
@@ -116,7 +115,7 @@ public class CommandsCompleter implement
 
     protected Function unProxy(Function function) {
         try {
-            if (function instanceof CommandProxy) {
+            if ("org.apache.felix.gogo.runtime.CommandProxy".equals(function.getClass().getName()))
{
                 Field contextField = function.getClass().getDeclaredField("context");
                 Field referenceField = function.getClass().getDeclaredField("reference");
                 contextField.setAccessible(true);

Modified: karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/help/CommandListHelpProvider.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/help/CommandListHelpProvider.java?rev=1529147&r1=1529146&r2=1529147&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/help/CommandListHelpProvider.java
(original)
+++ karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/help/CommandListHelpProvider.java
Fri Oct  4 12:47:11 2013
@@ -31,7 +31,6 @@ import org.apache.felix.gogo.commands.Ac
 import org.apache.felix.gogo.commands.Command;
 import org.apache.felix.gogo.commands.basic.AbstractCommand;
 import org.apache.felix.gogo.commands.basic.DefaultActionPreparator;
-import org.apache.felix.gogo.runtime.CommandSessionImpl;
 import org.apache.felix.service.command.CommandSession;
 import org.apache.felix.service.command.Function;
 import org.apache.karaf.shell.console.HelpProvider;
@@ -42,6 +41,8 @@ import org.osgi.framework.ServiceReferen
 
 public class CommandListHelpProvider implements HelpProvider {
 
+    public static final String COMMANDS = ".commands";
+
     public String getHelp(CommandSession session, String path) {
         if (path.indexOf('|') > 0) {
             if (path.startsWith("command-list|")) {
@@ -57,7 +58,7 @@ public class CommandListHelpProvider imp
     }
 
     private SortedMap<String, String> getCommandDescriptions(CommandSession session,
String command) {
-        Set<String> names = (Set<String>) session.get(CommandSessionImpl.COMMANDS);
+        Set<String> names = (Set<String>) session.get(COMMANDS);
         SortedMap<String,String> commands = new TreeMap<String,String>();
         for (String name : names) {
             if (command != null && !name.startsWith(command)) {

Modified: karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/help/SingleCommandHelpProvider.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/help/SingleCommandHelpProvider.java?rev=1529147&r1=1529146&r2=1529147&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/help/SingleCommandHelpProvider.java
(original)
+++ karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/help/SingleCommandHelpProvider.java
Fri Oct  4 12:47:11 2013
@@ -22,13 +22,14 @@ import java.io.ByteArrayOutputStream;
 import java.io.PrintStream;
 import java.util.Set;
 
-import org.apache.felix.gogo.runtime.CommandSessionImpl;
 import org.apache.felix.service.command.CommandSession;
 import org.apache.felix.service.threadio.ThreadIO;
 import org.apache.karaf.shell.console.HelpProvider;
 
 public class SingleCommandHelpProvider implements HelpProvider {
 
+    public static final String COMMANDS = ".commands";
+
     private ThreadIO io;
 
     public void setIo(ThreadIO io) {
@@ -43,7 +44,7 @@ public class SingleCommandHelpProvider i
                 return null;
             }
         }
-        Set<String> names = (Set<String>) session.get(CommandSessionImpl.COMMANDS);
+        Set<String> names = (Set<String>) session.get(COMMANDS);
         if (path != null && names.contains(path)) {
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             io.setStreams(new ByteArrayInputStream(new byte[0]), new PrintStream(baos, true),
new PrintStream(baos, true));

Modified: karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java?rev=1529147&r1=1529146&r2=1529147&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java
(original)
+++ karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java
Fri Oct  4 12:47:11 2013
@@ -39,8 +39,6 @@ import jline.UnsupportedTerminal;
 import jline.console.ConsoleReader;
 import jline.console.history.PersistentHistory;
 import org.apache.felix.gogo.commands.CommandException;
-import org.apache.felix.gogo.runtime.CommandNotFoundException;
-import org.apache.felix.gogo.runtime.Parser;
 import org.apache.felix.service.command.CommandProcessor;
 import org.apache.felix.service.command.CommandSession;
 import org.apache.felix.service.command.Converter;
@@ -192,7 +190,8 @@ public class Console implements Runnable
 
     private void logException(Throwable t) {
         try {
-            if (t instanceof CommandNotFoundException) {
+            boolean isCommandNotFound = "org.apache.felix.gogo.runtime.CommandNotFoundException".equals(t.getClass().getName());
+            if (isCommandNotFound) {
                 LOGGER.debug("Unknown command entered", t);
             } else if (t instanceof CommandException) {
                 LOGGER.debug("Command exception (Undefined option, ...)", t);
@@ -202,12 +201,12 @@ public class Console implements Runnable
             session.put(LAST_EXCEPTION, t);
             if (t instanceof CommandException) {
                 session.getConsole().println(((CommandException) t).getNiceHelp());
-            } else if (t instanceof CommandNotFoundException) {
+            } else if (isCommandNotFound) {
                 String str = Ansi.ansi()
                         .fg(Ansi.Color.RED)
                         .a("Command not found: ")
                         .a(Ansi.Attribute.INTENSITY_BOLD)
-                        .a(((CommandNotFoundException) t).getCommand())
+                        .a(t.getClass().getMethod("getCommand").invoke(t))
                         .a(Ansi.Attribute.INTENSITY_BOLD_OFF)
                         .fg(Ansi.Color.DEFAULT).toString();
                 session.getConsole().println(str);
@@ -216,7 +215,7 @@ public class Console implements Runnable
                 session.getConsole().print(Ansi.ansi().fg(Ansi.Color.RED).toString());
                 t.printStackTrace(session.getConsole());
                 session.getConsole().print(Ansi.ansi().fg(Ansi.Color.DEFAULT).toString());
-            } else if (!(t instanceof CommandException) && !(t instanceof CommandNotFoundException))
{
+            } else if (!(t instanceof CommandException) && !isCommandNotFound) {
                 session.getConsole().print(Ansi.ansi().fg(Ansi.Color.RED).toString());
                 session.getConsole().println("Error executing command: "
                     + (t.getMessage() != null ? t.getMessage() : t.getClass().getName()));
@@ -254,11 +253,16 @@ public class Console implements Runnable
                 }                                
             }
             try {
-                new Parser(command).program();
+                Class<?> cl = CommandSession.class.getClassLoader().loadClass("org.apache.felix.gogo.runtime.Parser");
+                Object parser = cl.getConstructor(CharSequence.class).newInstance(command);
+                cl.getMethod("program").invoke(parser);
                 loop = false;
             } catch (Exception e) {
                 loop = true;
                 first = false;
+            } catch (Throwable t) {
+                // Reflection problem ? just quit
+                loop = false;
             }
         }
         return command;

Modified: karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/ConsoleFactory.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/ConsoleFactory.java?rev=1529147&r1=1529146&r2=1529147&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/ConsoleFactory.java
(original)
+++ karaf/branches/karaf-2.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/ConsoleFactory.java
Fri Oct  4 12:47:11 2013
@@ -27,7 +27,6 @@ import java.net.URL;
 import java.security.KeyPair;
 import java.nio.charset.Charset;
 import java.security.PrivilegedExceptionAction;
-import java.util.Hashtable;
 import java.util.List;
 import javax.security.auth.Subject;
 
@@ -54,7 +53,6 @@ public class ConsoleFactory {
     Console console;
     private boolean start;
     private ServiceRegistration registration;
-    private SshAgent local;
 
     public void setBundleContext(BundleContext bundleContext) {
         this.bundleContext = bundleContext;
@@ -112,8 +110,6 @@ public class ConsoleFactory {
     }
 
     protected void doStart(String user) throws Exception {
-        String agentId = startAgent(user);
-
         final Terminal terminal = terminalFactory.getTerminal();
         // unwrap stream so it can be recognized by the terminal and wrapped to get 
         // special keys in windows
@@ -145,6 +141,10 @@ public class ConsoleFactory {
                                    encoding,
                                    callback);
         CommandSession session = console.getSession();
+        for (Object o : System.getProperties().keySet()) {
+            String key = o.toString();
+            session.put(key, System.getProperty(key));
+        }
         session.put("USER", user);
         session.put("APPLICATION", System.getProperty("karaf.name", "root"));
         session.put("#LINES", new Function() {
@@ -161,7 +161,8 @@ public class ConsoleFactory {
             session.put("LC_CTYPE", ctype);
         }
         session.put(".jline.terminal", terminal);
-        session.put(SshAgent.SSH_AUTHSOCKET_ENV_NAME, agentId);
+
+        registration = bundleContext.registerService(CommandSession.class, session, null);
 
         boolean delayconsole = Boolean.parseBoolean(System.getProperty("karaf.delay.console"));
         if (delayconsole) {
@@ -171,20 +172,6 @@ public class ConsoleFactory {
         }
     }
 
-    protected String startAgent(String user) {
-        try {
-            local = SshAgentLoader.load(bundleContext);
-            String agentId = "local:" + user;
-            Hashtable properties = new Hashtable();
-            properties.put("id", agentId);
-            registration = bundleContext.registerService(SshAgent.class.getName(), local,
properties);
-            return agentId;
-        } catch (Throwable e) {
-            LOGGER.warn("Error starting ssh agent for local console", e);
-            return null;
-        }
-    }
-
     protected void stop() throws Exception {
         if (registration != null) {
             registration.unregister();

Modified: karaf/branches/karaf-2.x/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafAgentFactory.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafAgentFactory.java?rev=1529147&r1=1529146&r2=1529147&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafAgentFactory.java
(original)
+++ karaf/branches/karaf-2.x/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafAgentFactory.java
Fri Oct  4 12:47:11 2013
@@ -19,25 +19,46 @@
 package org.apache.karaf.shell.ssh;
 
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.net.URL;
+import java.security.KeyPair;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
+import org.apache.felix.service.command.CommandSession;
 import org.apache.sshd.agent.SshAgent;
 import org.apache.sshd.agent.SshAgentFactory;
 import org.apache.sshd.agent.SshAgentServer;
 import org.apache.sshd.agent.common.AgentDelegate;
+import org.apache.sshd.agent.local.AgentImpl;
 import org.apache.sshd.agent.local.AgentServerProxy;
 import org.apache.sshd.agent.local.ChannelAgentForwarding;
 import org.apache.sshd.common.Channel;
 import org.apache.sshd.common.NamedFactory;
 import org.apache.sshd.common.Session;
 import org.apache.sshd.server.session.ServerSession;
+import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class KarafAgentFactory implements SshAgentFactory {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(KarafAgentFactory.class);
+
     private final Map<String, AgentServerProxy> proxies = new ConcurrentHashMap<String,
AgentServerProxy>();
     private final Map<String, SshAgent> locals = new ConcurrentHashMap<String, SshAgent>();
 
+    private BundleContext bundleContext;
+
+    public BundleContext getBundleContext() {
+        return bundleContext;
+    }
+
+    public void setBundleContext(BundleContext bundleContext) {
+        this.bundleContext = bundleContext;
+    }
+
     public NamedFactory<Channel> getChannelForwardingFactory() {
         return new ChannelAgentForwarding.Factory();
     }
@@ -75,23 +96,32 @@ public class KarafAgentFactory implement
         };
     }
 
-    public void registerAgent(SshAgent agent, Map<String, ?> properties) {
-        if (agent != null) {
-            Object id = properties.get("id");
-            if (id == null) {
-                throw new IllegalStateException("Local agent can't be registered with no
'id' property");
-            }
-            locals.put(id.toString(), agent);
+    public void registerCommandSession(CommandSession session) {
+        try {
+            String user = (String) session.get("USER");
+            SshAgent agent = new AgentImpl();
+            URL url = bundleContext.getBundle().getResource("karaf.key");
+            InputStream is = url.openStream();
+            ObjectInputStream r = new ObjectInputStream(is);
+            KeyPair keyPair = (KeyPair) r.readObject();
+            agent.addIdentity(keyPair, "karaf");
+            String agentId = "local:" + user;
+            session.put(SshAgent.SSH_AUTHSOCKET_ENV_NAME, agentId);
+            locals.put(agentId, agent);
+        } catch (Throwable e) {
+            LOGGER.warn("Error starting ssh agent for local console", e);
         }
     }
 
-    public void unregisterAgent(SshAgent agent, Map<String, ?> properties) {
-        if (agent != null) {
-            Object id = properties.get("id");
-            if (id == null) {
-                throw new IllegalStateException("Local agent can't be unregistered with no
'id' property");
+    public void unregisterCommandSession(CommandSession session) {
+        try {
+            String agentId = (String) session.get(SshAgent.SSH_AUTHSOCKET_ENV_NAME);
+            session.put(SshAgent.SSH_AUTHSOCKET_ENV_NAME, null);
+            if (agentId != null) {
+                locals.remove(agentId);
             }
-            locals.remove(id.toString());
+        } catch (Throwable e) {
+            LOGGER.warn("Error stopping ssh agent for local console", e);
         }
     }
 

Modified: karaf/branches/karaf-2.x/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommandFactory.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommandFactory.java?rev=1529147&r1=1529146&r2=1529147&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommandFactory.java
(original)
+++ karaf/branches/karaf-2.x/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommandFactory.java
Fri Oct  4 12:47:11 2013
@@ -123,7 +123,8 @@ public class ShellCommandFactory impleme
                     }
                 } catch (Throwable t) {
                     try {
-                        if (t instanceof CommandNotFoundException) {
+                        boolean isCommandNotFound = "org.apache.felix.gogo.runtime.CommandNotFoundException".equals(t.getClass().getName());
+                        if (isCommandNotFound) {
                             LOGGER.debug("Unknown command entered", t);
                         } else {
                             LOGGER.info("Exception caught while executing command", t);
@@ -131,12 +132,12 @@ public class ShellCommandFactory impleme
                         session.put(Console.LAST_EXCEPTION, t);
                         if (t instanceof CommandException) {
                             session.getConsole().println(((CommandException) t).getNiceHelp());
-                        } else if (t instanceof CommandNotFoundException) {
+                        } else if (isCommandNotFound) {
                             String str = Ansi.ansi()
                                     .fg(Ansi.Color.RED)
                                     .a("Command not found: ")
                                     .a(Ansi.Attribute.INTENSITY_BOLD)
-                                    .a(((CommandNotFoundException) t).getCommand())
+                                    .a(t.getClass().getMethod("getCommand").invoke(t))
                                     .a(Ansi.Attribute.INTENSITY_BOLD_OFF)
                                     .fg(Ansi.Color.DEFAULT).toString();
                             session.getConsole().println(str);
@@ -146,7 +147,7 @@ public class ShellCommandFactory impleme
                             t.printStackTrace(session.getConsole());
                             session.getConsole().print(Ansi.ansi().fg(Ansi.Color.DEFAULT).toString());
                         }
-                        else if (!(t instanceof CommandException) && !(t instanceof
CommandNotFoundException)) {
+                        else if (!(t instanceof CommandException) && !isCommandNotFound)
{
                             session.getConsole().print(Ansi.ansi().fg(Ansi.Color.RED).toString());
                             session.getConsole().println("Error executing command: "
                                     + (t.getMessage() != null ? t.getMessage() : t.getClass().getName()));

Modified: karaf/branches/karaf-2.x/shell/ssh/src/main/resources/OSGI-INF/blueprint/shell-ssh.xml
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/shell/ssh/src/main/resources/OSGI-INF/blueprint/shell-ssh.xml?rev=1529147&r1=1529146&r2=1529147&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/shell/ssh/src/main/resources/OSGI-INF/blueprint/shell-ssh.xml
(original)
+++ karaf/branches/karaf-2.x/shell/ssh/src/main/resources/OSGI-INF/blueprint/shell-ssh.xml
Fri Oct  4 12:47:11 2013
@@ -104,9 +104,11 @@
         <property name="agentFactory" ref="agentFactory" />
     </bean>
 
-    <bean id="agentFactory" class="org.apache.karaf.shell.ssh.KarafAgentFactory" />
-    <reference-list id="agents" interface="org.apache.sshd.agent.SshAgent" availability="optional"
activation="eager">
-        <reference-listener ref="agentFactory" bind-method="registerAgent" unbind-method="unregisterAgent"
/>
+    <bean id="agentFactory" class="org.apache.karaf.shell.ssh.KarafAgentFactory">
+        <property name="bundleContext" ref="blueprintBundleContext" />
+    </bean>
+    <reference-list id="commandSessions" interface="org.apache.felix.service.command.CommandSession"
availability="optional" activation="eager">
+        <reference-listener ref="agentFactory" bind-method="registerCommandSession" unbind-method="unregisterCommandSession"
/>
     </reference-list>
 
     <bean id="keyPairProvider" class="org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider">

Copied: karaf/branches/karaf-2.x/shell/ssh/src/main/resources/karaf.key (from r1529092, karaf/branches/karaf-2.x/shell/console/src/main/resources/karaf.key)
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/shell/ssh/src/main/resources/karaf.key?p2=karaf/branches/karaf-2.x/shell/ssh/src/main/resources/karaf.key&p1=karaf/branches/karaf-2.x/shell/console/src/main/resources/karaf.key&r1=1529092&r2=1529147&rev=1529147&view=diff
==============================================================================
    (empty)



Mime
View raw message