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 2013/12/18 12:36:08 UTC
git commit: [KARAF-2429] scr:list sorts components by id.
Updated Branches:
refs/heads/karaf-2.x b2cb0560d -> cf8ec8a70
[KARAF-2429] scr:list sorts components by id.
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/cf8ec8a7
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/cf8ec8a7
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/cf8ec8a7
Branch: refs/heads/karaf-2.x
Commit: cf8ec8a70087e9b9db0cd5b4df2aaaa69cd5692c
Parents: b2cb056
Author: Ioannis Canellos <io...@apache.org>
Authored: Fri Aug 2 16:52:45 2013 +0000
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Wed Dec 18 12:35:12 2013 +0100
----------------------------------------------------------------------
.../karaf/shell/scr/action/ListAction.java | 6 ++++
.../karaf/shell/scr/support/IdComparator.java | 33 ++++++++++++++++++++
2 files changed, 39 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/cf8ec8a7/shell/scr/src/main/java/org/apache/karaf/shell/scr/action/ListAction.java
----------------------------------------------------------------------
diff --git a/shell/scr/src/main/java/org/apache/karaf/shell/scr/action/ListAction.java b/shell/scr/src/main/java/org/apache/karaf/shell/scr/action/ListAction.java
index 3d34844..86e81cb 100644
--- a/shell/scr/src/main/java/org/apache/karaf/shell/scr/action/ListAction.java
+++ b/shell/scr/src/main/java/org/apache/karaf/shell/scr/action/ListAction.java
@@ -21,6 +21,9 @@ import org.apache.felix.scr.Component;
import org.apache.felix.scr.ScrService;
import org.apache.karaf.shell.scr.ScrCommandConstants;
import org.apache.karaf.shell.scr.ScrUtils;
+import org.apache.karaf.shell.scr.support.IdComparator;
+
+import java.util.Arrays;
/**
* Lists all the components currently installed.
@@ -30,6 +33,8 @@ import org.apache.karaf.shell.scr.ScrUtils;
description = "Displays a list of available components")
public class ListAction extends ScrActionSupport {
+ private final IdComparator idComparator = new IdComparator();
+
@Override
protected Object doScrAction(ScrService scrService) throws Exception {
if (logger.isDebugEnabled()) {
@@ -37,6 +42,7 @@ public class ListAction extends ScrActionSupport {
}
System.out.println(getBoldString(" ID State Component Name"));
Component[] components = scrService.getComponents();
+ Arrays.sort(components, idComparator);
for (Component component : ScrUtils.emptyIfNull(Component.class, components)) {
if (showHidden) {
// We display all because we are overridden
http://git-wip-us.apache.org/repos/asf/karaf/blob/cf8ec8a7/shell/scr/src/main/java/org/apache/karaf/shell/scr/support/IdComparator.java
----------------------------------------------------------------------
diff --git a/shell/scr/src/main/java/org/apache/karaf/shell/scr/support/IdComparator.java b/shell/scr/src/main/java/org/apache/karaf/shell/scr/support/IdComparator.java
new file mode 100644
index 0000000..764c6f4
--- /dev/null
+++ b/shell/scr/src/main/java/org/apache/karaf/shell/scr/support/IdComparator.java
@@ -0,0 +1,33 @@
+/*
+ * 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.scr.support;
+
+import org.apache.felix.scr.Component;
+
+import java.util.Comparator;
+
+public class IdComparator implements Comparator<Component> {
+ public int compare(Component left, Component right) {
+ if (left.getId() < right.getId()) {
+ return -1;
+ } else if (left.getId() == right.getId()) {
+ return 0;
+ } else {
+ return 1;
+ }
+ }
+}