You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2014/03/06 18:38:16 UTC
[1/6] git commit: The management/server bundle should not depend on
service/guard The service/guard service isn't actually used by JMX nor the
shell/core.
Repository: karaf
Updated Branches:
refs/heads/master c4313f627 -> 106856c4a
The management/server bundle should not depend on service/guard
The service/guard service isn't actually used by JMX nor the shell/core.
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/cb7e77d2
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/cb7e77d2
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/cb7e77d2
Branch: refs/heads/master
Commit: cb7e77d22d305aea71b89a4e2eef983d6e0aff64
Parents: c4313f6
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Thu Mar 6 10:31:45 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Thu Mar 6 10:31:45 2014 +0100
----------------------------------------------------------------------
management/server/pom.xml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/cb7e77d2/management/server/pom.xml
----------------------------------------------------------------------
diff --git a/management/server/pom.xml b/management/server/pom.xml
index e82b02f..3147278 100644
--- a/management/server/pom.xml
+++ b/management/server/pom.xml
@@ -102,7 +102,8 @@
<instructions>
<Export-Package>org.apache.karaf.management;version=${project.version};-split-package:=merge-first</Export-Package>
<Private-Package>
- org.apache.karaf.management.internal
+ org.apache.karaf.management.internal,
+ org.apache.karaf.service.guard.tools
</Private-Package>
</instructions>
</configuration>
[6/6] git commit: Cleanup imports
Posted by gn...@apache.org.
Cleanup imports
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/106856c4
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/106856c4
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/106856c4
Branch: refs/heads/master
Commit: 106856c4ad015b1a71e0a58ae0bad5cd75bde6f0
Parents: 0ba89bb
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Thu Mar 6 17:52:43 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Thu Mar 6 17:52:43 2014 +0100
----------------------------------------------------------------------
.../shell/impl/action/command/DefaultActionPreparator.java | 4 ++--
.../org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java | 1 -
.../org/apache/karaf/shell/impl/console/SessionFactoryImpl.java | 5 -----
.../org/apache/karaf/shell/impl/console/osgi/Activator.java | 2 +-
.../karaf/shell/impl/console/osgi/EventAdminListener.java | 1 -
.../impl/console/osgi/secured/SecuredSessionFactoryImpl.java | 3 ---
.../org/apache/karaf/shell/impl/console/standalone/Main.java | 3 +--
7 files changed, 4 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/106856c4/shell/core/src/main/java/org/apache/karaf/shell/impl/action/command/DefaultActionPreparator.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/action/command/DefaultActionPreparator.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/action/command/DefaultActionPreparator.java
index 9cd0343..689202c 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/action/command/DefaultActionPreparator.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/action/command/DefaultActionPreparator.java
@@ -45,10 +45,10 @@ import org.apache.karaf.shell.api.action.Argument;
import org.apache.karaf.shell.api.action.Command;
import org.apache.karaf.shell.api.action.Option;
import org.apache.karaf.shell.api.console.Session;
-import org.apache.karaf.shell.support.converter.DefaultConverter;
-import org.apache.karaf.shell.support.converter.GenericType;
import org.apache.karaf.shell.support.CommandException;
import org.apache.karaf.shell.support.NameScoping;
+import org.apache.karaf.shell.support.converter.DefaultConverter;
+import org.apache.karaf.shell.support.converter.GenericType;
import static org.apache.karaf.shell.support.ansi.SimpleAnsi.COLOR_DEFAULT;
import static org.apache.karaf.shell.support.ansi.SimpleAnsi.COLOR_RED;
http://git-wip-us.apache.org/repos/asf/karaf/blob/106856c4/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 0bf75f0..56114ad 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
@@ -52,7 +52,6 @@ import org.apache.karaf.shell.api.console.Registry;
import org.apache.karaf.shell.api.console.Session;
import org.apache.karaf.shell.api.console.SessionFactory;
import org.apache.karaf.shell.api.console.Terminal;
-import org.apache.karaf.shell.impl.console.parsing.Parser;
import org.apache.karaf.shell.support.ShellUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/karaf/blob/106856c4/shell/core/src/main/java/org/apache/karaf/shell/impl/console/SessionFactoryImpl.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/SessionFactoryImpl.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/SessionFactoryImpl.java
index 2f19499..be7aaea 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/SessionFactoryImpl.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/SessionFactoryImpl.java
@@ -20,16 +20,12 @@ package org.apache.karaf.shell.impl.console;
import java.io.InputStream;
import java.io.PrintStream;
-import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import org.apache.felix.gogo.runtime.CommandProcessorImpl;
-import org.apache.felix.service.command.CommandSession;
import org.apache.felix.service.command.Function;
import org.apache.felix.service.threadio.ThreadIO;
import org.apache.karaf.shell.api.console.Command;
@@ -40,7 +36,6 @@ import org.apache.karaf.shell.api.console.Terminal;
import org.apache.karaf.shell.impl.console.commands.ExitCommand;
import org.apache.karaf.shell.impl.console.commands.SubShellCommand;
import org.apache.karaf.shell.impl.console.commands.help.HelpCommand;
-import org.apache.karaf.shell.support.ShellUtil;
public class SessionFactoryImpl extends RegistryImpl implements SessionFactory, Registry {
http://git-wip-us.apache.org/repos/asf/karaf/blob/106856c4/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/Activator.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/Activator.java
index 94b45c0..e595081 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/Activator.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/Activator.java
@@ -22,8 +22,8 @@ import java.io.Closeable;
import org.apache.felix.gogo.runtime.threadio.ThreadIOImpl;
import org.apache.karaf.shell.api.console.SessionFactory;
-import org.apache.karaf.shell.impl.action.osgi.CommandExtender;
import org.apache.karaf.shell.impl.action.command.ManagerImpl;
+import org.apache.karaf.shell.impl.action.osgi.CommandExtender;
import org.apache.karaf.shell.impl.console.SessionFactoryImpl;
import org.apache.karaf.shell.impl.console.TerminalFactory;
import org.apache.karaf.shell.impl.console.osgi.secured.SecuredSessionFactoryImpl;
http://git-wip-us.apache.org/repos/asf/karaf/blob/106856c4/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/EventAdminListener.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/EventAdminListener.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/EventAdminListener.java
index 56905d2..73c741e 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/EventAdminListener.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/EventAdminListener.java
@@ -21,7 +21,6 @@ package org.apache.karaf.shell.impl.console.osgi;
import java.io.Closeable;
import java.util.HashMap;
import java.util.Map;
-import java.util.Properties;
import org.apache.felix.gogo.api.CommandSessionListener;
import org.apache.felix.service.command.CommandSession;
http://git-wip-us.apache.org/repos/asf/karaf/blob/106856c4/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SecuredSessionFactoryImpl.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SecuredSessionFactoryImpl.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SecuredSessionFactoryImpl.java
index 38b542e..567575d 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SecuredSessionFactoryImpl.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SecuredSessionFactoryImpl.java
@@ -23,12 +23,9 @@ import java.security.AccessController;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Dictionary;
-import java.util.Enumeration;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import javax.security.auth.Subject;
http://git-wip-us.apache.org/repos/asf/karaf/blob/106856c4/shell/core/src/main/java/org/apache/karaf/shell/impl/console/standalone/Main.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/standalone/Main.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/standalone/Main.java
index 842a248..73527b0 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/standalone/Main.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/standalone/Main.java
@@ -38,15 +38,14 @@ import java.util.List;
import org.apache.felix.gogo.runtime.threadio.ThreadIOImpl;
import org.apache.felix.service.threadio.ThreadIO;
import org.apache.karaf.shell.api.action.lifecycle.Manager;
-import org.apache.karaf.shell.api.console.Registry;
import org.apache.karaf.shell.api.console.Session;
import org.apache.karaf.shell.api.console.SessionFactory;
import org.apache.karaf.shell.api.console.Terminal;
import org.apache.karaf.shell.impl.action.command.ManagerImpl;
-import org.apache.karaf.shell.support.NameScoping;
import org.apache.karaf.shell.impl.console.JLineTerminal;
import org.apache.karaf.shell.impl.console.SessionFactoryImpl;
import org.apache.karaf.shell.impl.console.TerminalFactory;
+import org.apache.karaf.shell.support.NameScoping;
import org.apache.karaf.shell.support.ShellUtil;
import org.fusesource.jansi.AnsiConsole;
[2/6] git commit: [KARAF-2753] Fix potential parsing problem with
overrides
Posted by gn...@apache.org.
[KARAF-2753] Fix potential parsing problem with overrides
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/a33fd100
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/a33fd100
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/a33fd100
Branch: refs/heads/master
Commit: a33fd100e7a27ddf6cc652f8e9414f7b98a7227d
Parents: cb7e77d
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Thu Mar 6 12:03:14 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Thu Mar 6 12:15:13 2014 +0100
----------------------------------------------------------------------
.../karaf/features/internal/Overrides.java | 9 ++++----
.../karaf/features/internal/OverridesTest.java | 21 ++++++++++++++++++
.../features/internal/overrides.properties | 23 ++++++++++++++++++++
3 files changed, 48 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/a33fd100/features/core/src/main/java/org/apache/karaf/features/internal/Overrides.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/Overrides.java b/features/core/src/main/java/org/apache/karaf/features/internal/Overrides.java
index 8c7d468..dab988a 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/Overrides.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/Overrides.java
@@ -22,6 +22,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -47,7 +48,7 @@ public class Overrides {
private static final Logger LOGGER = LoggerFactory.getLogger(Overrides.class);
- private static final String OVERRIDE_RANGE = "range";
+ protected static final String OVERRIDE_RANGE = "range";
private static final String VENDOR_WARNING = "Bundle Vendor has changed, please check if this is intentional. Bundle: ";
/**
@@ -169,10 +170,8 @@ public class Overrides {
while ((line = reader.readLine()) != null) {
line = line.trim();
if (!line.isEmpty() && !line.startsWith("#")) {
- Clause[] cs = Parser.parseHeader(line);
- for (Clause c : cs) {
- overrides.add(c);
- }
+ Clause[] cs = Parser.parseClauses(new String[]{line});
+ Collections.addAll(overrides, cs);
}
}
} finally {
http://git-wip-us.apache.org/repos/asf/karaf/blob/a33fd100/features/core/src/test/java/org/apache/karaf/features/internal/OverridesTest.java
----------------------------------------------------------------------
diff --git a/features/core/src/test/java/org/apache/karaf/features/internal/OverridesTest.java b/features/core/src/test/java/org/apache/karaf/features/internal/OverridesTest.java
index 79e2015..99feb32 100644
--- a/features/core/src/test/java/org/apache/karaf/features/internal/OverridesTest.java
+++ b/features/core/src/test/java/org/apache/karaf/features/internal/OverridesTest.java
@@ -26,6 +26,7 @@ import java.io.Writer;
import java.util.Arrays;
import java.util.List;
+import org.apache.felix.utils.manifest.Clause;
import org.apache.karaf.features.BundleInfo;
import org.apache.karaf.features.internal.model.Bundle;
import org.junit.Before;
@@ -201,6 +202,26 @@ public class OverridesTest {
assertEquals(b100.toURI().toString(), out.getLocation());
}
+ @Test
+ public void testLoadOverrides() {
+ List<Clause> overrides = Overrides.loadOverrides(getClass().getResource("overrides.properties").toExternalForm());
+ assertEquals(2, overrides.size());
+
+ Clause karafAdminCommand = null;
+ Clause karafAdminCore = null;
+ for (Clause clause : overrides) {
+ if (clause.getName().equals("mvn:org.apache.karaf.admin/org.apache.karaf.admin.command/2.3.0.redhat-61033X")) {
+ karafAdminCommand = clause;
+ }
+ if (clause.getName().equals("mvn:org.apache.karaf.admin/org.apache.karaf.admin.core/2.3.0.redhat-61033X")) {
+ karafAdminCore = clause;
+ }
+ }
+ assertNotNull("Missing admin.command bundle override", karafAdminCommand);
+ assertNotNull("Missing admin.core bundle override", karafAdminCore);
+ assertNotNull("Missing range on admin.core override", karafAdminCore.getAttribute(Overrides.OVERRIDE_RANGE));
+ }
+
/**
* Copies the content of {@link java.io.InputStream} to {@link java.io.OutputStream}.
*
http://git-wip-us.apache.org/repos/asf/karaf/blob/a33fd100/features/core/src/test/resources/org/apache/karaf/features/internal/overrides.properties
----------------------------------------------------------------------
diff --git a/features/core/src/test/resources/org/apache/karaf/features/internal/overrides.properties b/features/core/src/test/resources/org/apache/karaf/features/internal/overrides.properties
new file mode 100644
index 0000000..d34fa7e
--- /dev/null
+++ b/features/core/src/test/resources/org/apache/karaf/features/internal/overrides.properties
@@ -0,0 +1,23 @@
+
+################################################################################
+#
+# 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.
+#
+################################################################################
+
+# Sample etc/overrides.properties file for testing purposes
+mvn:org.apache.karaf.admin/org.apache.karaf.admin.command/2.3.0.redhat-61033X
+mvn:org.apache.karaf.admin/org.apache.karaf.admin.core/2.3.0.redhat-61033X;range=[2.3.0,2.5)
[5/6] git commit: [KARAF-2805] Remove dependency from shell/core to
jaas/modules
Posted by gn...@apache.org.
[KARAF-2805] Remove dependency from shell/core to jaas/modules
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/0ba89bbf
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/0ba89bbf
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/0ba89bbf
Branch: refs/heads/master
Commit: 0ba89bbfcd839334338a86f9874de28c4fd8d0e6
Parents: e2bf5ce
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Thu Mar 6 17:52:08 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Thu Mar 6 17:52:08 2014 +0100
----------------------------------------------------------------------
shell/core/pom.xml | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/0ba89bbf/shell/core/pom.xml
----------------------------------------------------------------------
diff --git a/shell/core/pom.xml b/shell/core/pom.xml
index c14cc6e..47c1d34 100644
--- a/shell/core/pom.xml
+++ b/shell/core/pom.xml
@@ -169,6 +169,9 @@
<Main-Class>
org.apache.karaf.shell.impl.console.standalone.Main
</Main-Class>
+ <Embed-Dependency>
+ org.apache.karaf.jaas.modules;inline="org/apache/karaf/jaas/modules/JaasHelper.class"
+ </Embed-Dependency>
</instructions>
<unpackBundle>true</unpackBundle>
</configuration>
[3/6] git commit: [KARAF-2805] Command execution should trigger an
EventAdmin event
Posted by gn...@apache.org.
[KARAF-2805] Command execution should trigger an EventAdmin event
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/09be4b1f
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/09be4b1f
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/09be4b1f
Branch: refs/heads/master
Commit: 09be4b1f5a5a16d8be44222e11f58e02766b8185
Parents: a33fd10
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Thu Mar 6 12:16:21 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Thu Mar 6 13:29:08 2014 +0100
----------------------------------------------------------------------
.../shell/impl/console/osgi/Activator.java | 14 +++++
.../impl/console/osgi/EventAdminListener.java | 66 ++++++++++++++++++++
2 files changed, 80 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/09be4b1f/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/Activator.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/Activator.java
index 1dba465..94b45c0 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/Activator.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/Activator.java
@@ -18,6 +18,8 @@
*/
package org.apache.karaf.shell.impl.console.osgi;
+import java.io.Closeable;
+
import org.apache.felix.gogo.runtime.threadio.ThreadIOImpl;
import org.apache.karaf.shell.api.console.SessionFactory;
import org.apache.karaf.shell.impl.action.osgi.CommandExtender;
@@ -40,6 +42,8 @@ public class Activator implements BundleActivator {
private CommandExtender actionExtender;
+ private Closeable eventAdminListener;
+
private TerminalFactory terminalFactory;
private LocalConsoleManager localConsoleManager;
@@ -51,6 +55,13 @@ public class Activator implements BundleActivator {
sessionFactory = new SecuredSessionFactoryImpl(context, threadIO);
sessionFactory.getCommandProcessor().addConverter(new Converters(context));
sessionFactory.getCommandProcessor().addConstant(".context", context.getBundle(0).getBundleContext());
+ try {
+ EventAdminListener listener = new EventAdminListener(context);
+ sessionFactory.getCommandProcessor().addListener(listener);
+ eventAdminListener = listener;
+ } catch (NoClassDefFoundError error) {
+ // Ignore the listener if EventAdmin package isn't present
+ }
sessionFactory.register(new ManagerImpl(sessionFactory, sessionFactory));
@@ -74,5 +85,8 @@ public class Activator implements BundleActivator {
actionExtender.stop(context);
threadIO.stop();
terminalFactory.destroy();
+ if (eventAdminListener != null) {
+ eventAdminListener.close();
+ }
}
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/09be4b1f/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/EventAdminListener.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/EventAdminListener.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/EventAdminListener.java
new file mode 100644
index 0000000..56905d2
--- /dev/null
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/EventAdminListener.java
@@ -0,0 +1,66 @@
+/*
+ * 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.karaf.shell.impl.console.osgi;
+
+import java.io.Closeable;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.felix.gogo.api.CommandSessionListener;
+import org.apache.felix.service.command.CommandSession;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class EventAdminListener implements CommandSessionListener, Closeable
+{
+
+ private ServiceTracker<EventAdmin, EventAdmin> tracker;
+
+ public EventAdminListener(BundleContext bundleContext)
+ {
+ tracker = new ServiceTracker<EventAdmin, EventAdmin>(bundleContext, EventAdmin.class.getName(), null);
+ tracker.open();
+ }
+
+ public void close() {
+ tracker.close();
+ }
+
+ public void beforeExecute(CommandSession session, CharSequence command) {
+ if (command.toString().trim().length() > 0) {
+ EventAdmin admin = tracker.getService();
+ if (admin != null) {
+ Map<String, Object> props = new HashMap<String, Object>();
+ props.put("command", command.toString());
+ Event event = new Event("org/apache/karaf/shell/console/EXECUTING", props);
+ admin.postEvent(event);
+ }
+ }
+ }
+
+ public void afterExecute(CommandSession session, CharSequence command, Exception exception) {
+ }
+
+ public void afterExecute(CommandSession session, CharSequence command, Object result) {
+ }
+
+}
[4/6] git commit: [KARAF-2805] Fix completion in console so that the
CommandLine is actually useful
Posted by gn...@apache.org.
[KARAF-2805] Fix completion in console so that the CommandLine is actually useful
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/e2bf5cec
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/e2bf5cec
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/e2bf5cec
Branch: refs/heads/master
Commit: e2bf5cecae23ea514588f802c6dffac81074939c
Parents: 09be4b1
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Thu Mar 6 17:50:46 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Thu Mar 6 17:50:46 2014 +0100
----------------------------------------------------------------------
.../impl/action/command/ArgumentCompleter.java | 46 +--------------
.../shell/impl/console/CommandsCompleter.java | 59 +++++++++++++++++--
.../impl/console/commands/help/HelpCommand.java | 41 +------------
.../support/completers/ArgumentCommandLine.java | 61 ++++++++++++++++++++
.../support/completers/StringsCompleter.java | 6 +-
5 files changed, 123 insertions(+), 90 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/e2bf5cec/shell/core/src/main/java/org/apache/karaf/shell/impl/action/command/ArgumentCompleter.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/action/command/ArgumentCompleter.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/action/command/ArgumentCompleter.java
index 2868e6f..2e8fca3 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/action/command/ArgumentCompleter.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/action/command/ArgumentCompleter.java
@@ -35,6 +35,7 @@ import org.apache.karaf.shell.api.action.Option;
import org.apache.karaf.shell.api.console.CommandLine;
import org.apache.karaf.shell.api.console.Completer;
import org.apache.karaf.shell.api.console.Session;
+import org.apache.karaf.shell.support.completers.ArgumentCommandLine;
import org.apache.karaf.shell.support.completers.FileCompleter;
import org.apache.karaf.shell.support.completers.NullCompleter;
import org.apache.karaf.shell.support.completers.StringsCompleter;
@@ -275,14 +276,12 @@ public class ArgumentCompleter implements Completer {
comp = argsCompleters.get(indexArg >= argsCompleters.size() ? argsCompleters.size() - 1 : indexArg);
}
- int ret = comp.complete(session, new ArgumentCommandLine(list.getCursorArgument(), argpos), candidates);
+ int pos = comp.complete(session, list, candidates);
- if (ret == -1) {
+ if (pos == -1) {
return -1;
}
- int pos = ret + (list.getBufferPosition() - argpos);
-
/**
* Special case: when completing in the middle of a line, and the
* area under the cursor is a delimiter, then trim any delimiters
@@ -343,43 +342,4 @@ public class ArgumentCompleter implements Completer {
return Character.isWhitespace(buffer.charAt(pos));
}
- static class ArgumentCommandLine implements CommandLine {
- private final String argument;
- private final int position;
-
- ArgumentCommandLine(String argument, int position) {
- this.argument = argument;
- this.position = position;
- }
-
- @Override
- public int getCursorArgumentIndex() {
- return 0;
- }
-
- @Override
- public String getCursorArgument() {
- return argument;
- }
-
- @Override
- public int getArgumentPosition() {
- return position;
- }
-
- @Override
- public String[] getArguments() {
- return new String[] { argument };
- }
-
- @Override
- public int getBufferPosition() {
- return position;
- }
-
- @Override
- public String getBuffer() {
- return argument;
- }
- }
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/e2bf5cec/shell/core/src/main/java/org/apache/karaf/shell/impl/console/CommandsCompleter.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/CommandsCompleter.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/CommandsCompleter.java
index d73af34..2a513cb 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/CommandsCompleter.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/CommandsCompleter.java
@@ -36,6 +36,7 @@ import org.apache.karaf.shell.api.console.Completer;
import org.apache.karaf.shell.api.console.Session;
import org.apache.karaf.shell.api.console.SessionFactory;
import org.apache.karaf.shell.support.completers.AggregateCompleter;
+import org.apache.karaf.shell.support.completers.ArgumentCommandLine;
import org.apache.karaf.shell.support.completers.StringsCompleter;
/**
@@ -46,6 +47,12 @@ public class CommandsCompleter extends org.apache.karaf.shell.support.completers
private final SessionFactory factory;
private final Map<String, Completer> globalCompleters = new HashMap<String, Completer>();
private final Map<String, Completer> localCompleters = new HashMap<String, Completer>();
+ private final Completer aliasesCompleter = new SimpleCommandCompleter() {
+ @Override
+ protected Collection<String> getNames(Session session) {
+ return getAliases(session);
+ }
+ };
private final List<Command> commands = new ArrayList<Command>();
public CommandsCompleter(SessionFactory factory) {
@@ -95,7 +102,7 @@ public class CommandsCompleter extends org.apache.karaf.shell.support.completers
}
}
List<Completer> compl = new ArrayList<Completer>();
- compl.add(new StringsCompleter(getAliases(session)));
+ compl.add(aliasesCompleter);
compl.addAll(allCompleters[0].values());
int res = new AggregateCompleter(compl).complete(session, commandLine, candidates);
Collections.sort(candidates);
@@ -103,7 +110,7 @@ public class CommandsCompleter extends org.apache.karaf.shell.support.completers
}
List<Completer> compl = new ArrayList<Completer>();
- compl.add(new StringsCompleter(getAliases(session)));
+ compl.add(aliasesCompleter);
compl.addAll(allCompleters[0].values());
int res = new AggregateCompleter(compl).complete(session, commandLine, candidates);
Collections.sort(candidates);
@@ -205,13 +212,13 @@ public class CommandsCompleter extends org.apache.karaf.shell.support.completers
Completer cl = command.getCompleter(true);
if (cg == null) {
if (Session.SCOPE_GLOBAL.equals(command.getScope())) {
- cg = new StringsCompleter(new String[] { command.getName() });
+ cg = new FixedSimpleCommandCompleter(Arrays.asList(command.getName()));
} else {
- cg = new StringsCompleter(new String[] { key, command.getName() });
+ cg = new FixedSimpleCommandCompleter(Arrays.asList(key, command.getName()));
}
}
if (cl == null) {
- cl = new StringsCompleter(new String[] { command.getName() });
+ cl = new FixedSimpleCommandCompleter(Arrays.asList(command.getName()));
}
global.put(key, cg);
local.put(key, cl);
@@ -252,5 +259,47 @@ public class CommandsCompleter extends org.apache.karaf.shell.support.completers
return aliases;
}
+ static abstract class SimpleCommandCompleter implements Completer {
+
+ @Override
+ public int complete(Session session, CommandLine commandLine, List<String> candidates) {
+ String[] args = commandLine.getArguments();
+ int argIndex = commandLine.getCursorArgumentIndex();
+ StringsCompleter completer = new StringsCompleter(getNames(session));
+ if (argIndex == 0) {
+ int res = completer.complete(session, new ArgumentCommandLine(args[argIndex], commandLine.getArgumentPosition()), candidates);
+ if (res > -1) {
+ res += commandLine.getBufferPosition() - commandLine.getArgumentPosition();
+ }
+ return res;
+ } else if (!verifyCompleter(session, completer, args[0])) {
+ return -1;
+ }
+ return 0;
+ }
+
+ protected abstract Collection<String> getNames(Session session);
+
+ private boolean verifyCompleter(Session session, Completer completer, String argument) {
+ List<String> candidates = new ArrayList<String>();
+ return completer.complete(session, new ArgumentCommandLine(argument, argument.length()), candidates) != -1 && !candidates.isEmpty();
+ }
+
+ }
+
+ static class FixedSimpleCommandCompleter extends SimpleCommandCompleter {
+
+ private final Collection<String> names;
+
+ FixedSimpleCommandCompleter(Collection<String> names) {
+ this.names = names;
+ }
+
+ @Override
+ protected Collection<String> getNames(Session session) {
+ return names;
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/e2bf5cec/shell/core/src/main/java/org/apache/karaf/shell/impl/console/commands/help/HelpCommand.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/commands/help/HelpCommand.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/commands/help/HelpCommand.java
index 4afa149..3b9ae33 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/commands/help/HelpCommand.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/commands/help/HelpCommand.java
@@ -33,6 +33,7 @@ import org.apache.karaf.shell.api.console.Registry;
import org.apache.karaf.shell.api.console.Session;
import org.apache.karaf.shell.api.console.SessionFactory;
import org.apache.karaf.shell.support.CommandException;
+import org.apache.karaf.shell.support.completers.ArgumentCommandLine;
import org.apache.karaf.shell.support.completers.StringsCompleter;
import static org.apache.karaf.shell.support.ansi.SimpleAnsi.COLOR_DEFAULT;
@@ -182,44 +183,4 @@ public class HelpCommand implements Command {
return help;
}
- static class ArgumentCommandLine implements CommandLine {
- private final String argument;
- private final int position;
-
- ArgumentCommandLine(String argument, int position) {
- this.argument = argument;
- this.position = position;
- }
-
- @Override
- public int getCursorArgumentIndex() {
- return 0;
- }
-
- @Override
- public String getCursorArgument() {
- return argument;
- }
-
- @Override
- public int getArgumentPosition() {
- return position;
- }
-
- @Override
- public String[] getArguments() {
- return new String[] { argument };
- }
-
- @Override
- public int getBufferPosition() {
- return position;
- }
-
- @Override
- public String getBuffer() {
- return argument;
- }
- }
-
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/e2bf5cec/shell/core/src/main/java/org/apache/karaf/shell/support/completers/ArgumentCommandLine.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/support/completers/ArgumentCommandLine.java b/shell/core/src/main/java/org/apache/karaf/shell/support/completers/ArgumentCommandLine.java
new file mode 100644
index 0000000..663601a
--- /dev/null
+++ b/shell/core/src/main/java/org/apache/karaf/shell/support/completers/ArgumentCommandLine.java
@@ -0,0 +1,61 @@
+/*
+ * 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.karaf.shell.support.completers;
+
+import org.apache.karaf.shell.api.console.CommandLine;
+
+public class ArgumentCommandLine implements CommandLine {
+ private final String argument;
+ private final int position;
+
+ public ArgumentCommandLine(String argument, int position) {
+ this.argument = argument;
+ this.position = position;
+ }
+
+ @Override
+ public int getCursorArgumentIndex() {
+ return 0;
+ }
+
+ @Override
+ public String getCursorArgument() {
+ return argument;
+ }
+
+ @Override
+ public int getArgumentPosition() {
+ return position;
+ }
+
+ @Override
+ public String[] getArguments() {
+ return new String[] { argument };
+ }
+
+ @Override
+ public int getBufferPosition() {
+ return position;
+ }
+
+ @Override
+ public String getBuffer() {
+ return argument;
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/e2bf5cec/shell/core/src/main/java/org/apache/karaf/shell/support/completers/StringsCompleter.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/support/completers/StringsCompleter.java b/shell/core/src/main/java/org/apache/karaf/shell/support/completers/StringsCompleter.java
index 1317095..85b4fdf 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/support/completers/StringsCompleter.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/support/completers/StringsCompleter.java
@@ -82,9 +82,11 @@ public class StringsCompleter
// buffer could be null
assert candidates != null;
- String buffer = commandLine.getBuffer();
+ String buffer = commandLine.getCursorArgument();
if (buffer == null) {
buffer = "";
+ } else {
+ buffer = buffer.substring(0, commandLine.getArgumentPosition());
}
if (!caseSensitive) {
buffer = buffer.toLowerCase();
@@ -108,6 +110,6 @@ public class StringsCompleter
candidates.set(0, candidates.get(0) + " ");
}
- return candidates.isEmpty() ? -1 : 0;
+ return candidates.isEmpty() ? -1 : commandLine.getBufferPosition() - commandLine.getArgumentPosition();
}
}