Repository: camel
Updated Branches:
  refs/heads/master bddf183bd -> 6663813ee


CAMEL-8041: Camel commands should be reusable.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/55d9d82e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/55d9d82e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/55d9d82e

Branch: refs/heads/master
Commit: 55d9d82ea6ff8270898c709d56f6c8a08f37b36c
Parents: bddf183
Author: Claus Ibsen <davscl...@apache.org>
Authored: Thu Nov 13 07:44:44 2014 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Thu Nov 13 07:44:44 2014 +0100

----------------------------------------------------------------------
 parent/pom.xml                                  |   7 +-
 platforms/commands/commands-core/pom.xml        |  76 +++++++
 .../camel/commands/AbstractCamelCommand.java    |  34 ++++
 .../camel/commands/AbstractContextCommand.java  |  63 ++++++
 .../camel/commands/AbstractRouteCommand.java    | 100 +++++++++
 .../org/apache/camel/commands/CamelCommand.java |  37 ++++
 .../apache/camel/commands/CamelController.java  | 128 ++++++++++++
 .../camel/commands/ContextListCommand.java      | 118 +++++++++++
 .../camel/commands/internal/RegexUtil.java      |  69 +++++++
 .../src/main/resources/LICENSE.txt              | 203 +++++++++++++++++++
 .../commands-core/src/main/resources/NOTICE.txt |  11 +
 .../camel/commands/internal/RegexUtilTest.java  |  52 +++++
 platforms/commands/pom.xml                      |  35 ++++
 platforms/karaf/commands/pom.xml                |   4 +
 .../karaf/commands/CamelCommandSupport.java     |   1 +
 .../camel/karaf/commands/CamelController.java   | 128 ------------
 .../camel/karaf/commands/ContextList.java       |  95 +--------
 .../completers/CamelCompleterSupport.java       |   3 +-
 .../commands/internal/CamelControllerImpl.java  |   2 +-
 .../features/src/main/resources/features.xml    |   1 +
 platforms/pom.xml                               |   1 +
 21 files changed, 945 insertions(+), 223 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 6efd4ec..cc66de3 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -1486,7 +1486,12 @@
         <version>${project.version}</version>
       </dependency>
 
-      <!-- camel karaf -->
+      <!-- camel commands -->
+      <dependency>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>commands-core</artifactId>
+        <version>${project.version}</version>
+      </dependency>      
       <dependency>
         <groupId>org.apache.camel.karaf</groupId>
         <artifactId>camel-karaf-commands</artifactId>

http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/platforms/commands/commands-core/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/pom.xml 
b/platforms/commands/commands-core/pom.xml
new file mode 100644
index 0000000..817e769
--- /dev/null
+++ b/platforms/commands/commands-core/pom.xml
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>commands</artifactId>
+    <version>2.15-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>commands-core</artifactId>
+  <packaging>bundle</packaging>
+  <name>Camel :: Platforms :: Commands :: Core</name>
+  <description>Core Camel Commands</description>
+
+  <properties>
+    <camel.osgi.export.pkg>org.apache.camel.commands.*</camel.osgi.export.pkg>
+  </properties>
+
+  <dependencies>
+
+    <!-- camel -->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+
+    <!-- Test -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Private-Package>
+              org.apache.camel.commands.internal
+            </Private-Package>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelCommand.java
----------------------------------------------------------------------
diff --git 
a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelCommand.java
 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelCommand.java
new file mode 100644
index 0000000..03fa4e3
--- /dev/null
+++ 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelCommand.java
@@ -0,0 +1,34 @@
+/**
+ * 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.camel.commands;
+
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * Abstract base command for {@link org.apache.camel.commands.CamelCommand}
+ */
+public abstract class AbstractCamelCommand implements CamelCommand {
+
+    public String safeNull(String s) {
+        if (ObjectHelper.isEmpty(s)) {
+            return "";
+        } else {
+            return s;
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractContextCommand.java
----------------------------------------------------------------------
diff --git 
a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractContextCommand.java
 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractContextCommand.java
new file mode 100644
index 0000000..7e54b72
--- /dev/null
+++ 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractContextCommand.java
@@ -0,0 +1,63 @@
+/**
+ * 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.camel.commands;
+
+import java.io.PrintStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.Required;
+
+/**
+ * Abstract command for working with a single {@link 
org.apache.camel.CamelContext}
+ */
+public abstract class AbstractContextCommand extends AbstractCamelCommand {
+
+    /**
+     * The name of the Camel context.
+     */
+    @Required
+    public abstract String getContext();
+
+    @Override
+    public Object execute(CamelController camelController, PrintStream out, 
PrintStream err) throws Exception {
+        CamelContext camelContext = 
camelController.getCamelContext(getContext());
+        if (camelContext == null) {
+            err.println("Camel context " + getContext() + " not found.");
+            return null;
+        }
+
+        // Setting thread context classloader to the bundle classloader to 
enable legacy code that relies on it
+        ClassLoader oldClassloader = 
Thread.currentThread().getContextClassLoader();
+        
Thread.currentThread().setContextClassLoader(camelContext.getApplicationContextClassLoader());
+        try {
+            performContextCommand(camelContext, out, err);
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldClassloader);
+        }
+        return null;
+    }
+
+    /**
+     * Perform Context-specific command
+     *
+     * @param camelContext non-null {@link CamelContext}
+     * @param out          the output printer stream
+     * @param err          the error print stream
+     */
+    protected abstract void performContextCommand(CamelContext camelContext, 
PrintStream out, PrintStream err) throws Exception;
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractRouteCommand.java
----------------------------------------------------------------------
diff --git 
a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractRouteCommand.java
 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractRouteCommand.java
new file mode 100644
index 0000000..0a8a71d
--- /dev/null
+++ 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractRouteCommand.java
@@ -0,0 +1,100 @@
+/**
+ * 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.camel.commands;
+
+import java.io.PrintStream;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Route;
+import org.apache.camel.commands.internal.RegexUtil;
+import org.apache.camel.spi.Required;
+
+import static org.apache.camel.util.CamelContextHelper.getRouteStartupOrder;
+
+/**
+ * Abstract command for working with a one ore more routes.
+ */
+public abstract class AbstractRouteCommand extends AbstractCamelCommand {
+
+    /**
+     * The Camel route ID or a wildcard expression
+     */
+    @Required
+    public abstract String getRoute();
+
+    /**
+     * The name of the Camel context.
+     */
+    public abstract String getContext();
+
+    public Object execute(CamelController camelController, PrintStream out, 
PrintStream err) throws Exception {
+        List<Route> camelRoutes = camelController.getRoutes(getContext(), 
RegexUtil.wildcardAsRegex(getRoute()));
+        if (camelRoutes == null || camelRoutes.isEmpty()) {
+            err.println("Camel routes using " + getRoute() + " not found.");
+            return null;
+        }
+        // we want the routes sorted
+        Collections.sort(camelRoutes, new RouteComparator());
+
+        for (Route camelRoute : camelRoutes) {
+            CamelContext camelContext = 
camelRoute.getRouteContext().getCamelContext();
+            // Setting thread context classloader to the bundle classloader to 
enable legacy code that relies on it
+            ClassLoader oldClassloader = 
Thread.currentThread().getContextClassLoader();
+            
Thread.currentThread().setContextClassLoader(camelContext.getApplicationContextClassLoader());
+            try {
+                executeOnRoute(camelContext, camelRoute, out, err);
+            } finally {
+                Thread.currentThread().setContextClassLoader(oldClassloader);
+            }
+        }
+
+        return null;
+    }
+
+    public abstract void executeOnRoute(CamelContext camelContext, Route 
camelRoute, PrintStream out, PrintStream err) throws Exception;
+
+    /**
+     * To sort the routes.
+     */
+    private static final class RouteComparator implements Comparator<Route> {
+
+        @Override
+        public int compare(Route route1, Route route2) {
+            // sort by camel context first
+            CamelContext camel1 = route1.getRouteContext().getCamelContext();
+            CamelContext camel2 = route2.getRouteContext().getCamelContext();
+
+            if (camel1.getName().equals(camel2.getName())) {
+                // and then accordingly to startup order
+                Integer order1 = getRouteStartupOrder(camel1, route1.getId());
+                Integer order2 = getRouteStartupOrder(camel2, route2.getId());
+                if (order1 == 0 && order2 == 0) {
+                    // fallback and use name if not startup order was found
+                    return route1.getId().compareTo(route2.getId());
+                } else {
+                    return order1.compareTo(order2);
+                }
+            } else {
+                return camel1.getName().compareTo(camel2.getName());
+            }
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelCommand.java
----------------------------------------------------------------------
diff --git 
a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelCommand.java
 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelCommand.java
new file mode 100644
index 0000000..332c814
--- /dev/null
+++ 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelCommand.java
@@ -0,0 +1,37 @@
+/**
+ * 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.camel.commands;
+
+import java.io.PrintStream;
+
+/**
+ * A Camel command.
+ */
+public interface CamelCommand {
+
+    /**
+     * Executes the given command.
+     *
+     * @param camelController the Camel controller to access Camel information
+     * @param out             the output printer stream
+     * @param err             the error print stream
+     * @return response from command, or <tt>null</tt> if nothing to return
+     * @throws Exception is thrown if error executing command
+     */
+    Object execute(CamelController camelController, PrintStream out, 
PrintStream err) throws Exception;
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java
----------------------------------------------------------------------
diff --git 
a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java
 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java
new file mode 100644
index 0000000..645f865
--- /dev/null
+++ 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java
@@ -0,0 +1,128 @@
+/**
+ * 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.camel.commands;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Route;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+import org.apache.camel.spi.RestRegistry;
+
+/**
+ * CamelController interface defines the expected behaviors to manipulate 
Camel resources (context, route, etc).
+ */
+public interface CamelController {
+
+    /**
+     * Get the list of Camel context.
+     *
+     * @return the list of Camel contexts.
+     */
+    List<CamelContext> getCamelContexts();
+
+    /**
+     * Get a Camel context identified by the given name.
+     *
+     * @param name the Camel context name.
+     * @return the Camel context or null if not found.
+     */
+    CamelContext getCamelContext(String name);
+
+    /**
+     * Get all routes. If Camel context name is null, all routes from all 
contexts are listed.
+     *
+     * @param camelContextName the Camel context name. If null, all contexts 
are considered.
+     * @return the list of the Camel routes.
+     */
+    List<Route> getRoutes(String camelContextName);
+
+    /**
+     * Get all routes filtered by the regex.
+     *
+     * @param camelContextName the Camel context name. If null, all contexts 
are considered.
+     * @param filter           the filter which supports * and ? as wildcards
+     * @return the list of the Camel routes.
+     */
+    List<Route> getRoutes(String camelContextName, String filter);
+
+    /**
+     * Return the route with the given route ID.
+     *
+     * @param routeId          the route ID.
+     * @param camelContextName the Camel context name.
+     * @return the route.
+     */
+    Route getRoute(String routeId, String camelContextName);
+
+    /**
+     * Return the definition of a route identified by a ID and a Camel context.
+     *
+     * @param routeId          the route ID.
+     * @param camelContextName the Camel context.
+     * @return the <code>RouteDefinition</code>.
+     */
+    RouteDefinition getRouteDefinition(String routeId, String 
camelContextName);
+
+    /**
+     * Return the endpoints
+     *
+     * @param camelContextName the Camel context.
+     * @return the endpoints
+     */
+    List<Endpoint> getEndpoints(String camelContextName);
+
+    /**
+     * Return the definition of the REST services for the given Camel context.
+     *
+     * @param camelContextName the Camel context.
+     * @return the <code>RouteDefinition</code>.
+     */
+    List<RestDefinition> getRestDefinitions(String camelContextName);
+
+    /**
+     * Return the REST services
+     *
+     * @param camelContextName the Camel context.
+     * @return the REST services
+     */
+    Map<String, List<RestRegistry.RestService>> getRestServices(String 
camelContextName);
+
+    /**
+     * Explains an endpoint uri
+     *
+     * @param camelContextName the Camel context.
+     * @param uri              the endpoint uri
+     * @param allOptions       whether to explain all options, or only the 
explicit configured options from the uri
+     * @return a JSON schema with explanation of the options
+     * @throws java.lang.Exception is thrown if error loading resources to 
explain the endpoint
+     */
+    String explainEndpoint(String camelContextName, String uri, boolean 
allOptions) throws Exception;
+
+    /**
+     * Lists all components and include information
+     *
+     * @param camelContextName the Camel context.
+     * @return a list of key/value pairs with component information
+     * @throws java.lang.Exception is thrown if error loading resources to 
gather component information
+     */
+    List<Map<String, String>> listComponents(String camelContextName) throws 
Exception;
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ContextListCommand.java
----------------------------------------------------------------------
diff --git 
a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ContextListCommand.java
 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ContextListCommand.java
new file mode 100644
index 0000000..0cfe008
--- /dev/null
+++ 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ContextListCommand.java
@@ -0,0 +1,118 @@
+/**
+ * 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.camel.commands;
+
+import java.io.PrintStream;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+
+public class ContextListCommand extends AbstractCamelCommand {
+
+    private static final String CONTEXT_COLUMN_LABEL = "Context";
+    private static final String STATUS_COLUMN_LABEL = "Status";
+    private static final String UPTIME_COLUMN_LABEL = "Uptime";
+    private static final int DEFAULT_FORMAT_BUFFER_LENGTH = 24;
+    private static final String DEFAULT_FIELD_PREAMBLE = " ";
+    private static final String DEFAULT_FIELD_POSTAMBLE = " ";
+    private static final String DEFAULT_HEADER_PREAMBLE = " ";
+    private static final String DEFAULT_HEADER_POSTAMBLE = " ";
+    private static final int DEFAULT_COLUMN_WIDTH_INCREMENT = 0;
+    private static final int MAX_COLUMN_WIDTH = Integer.MAX_VALUE;
+    private static final int MIN_COLUMN_WIDTH = 12;
+
+    @Override
+    public Object execute(CamelController camelController, PrintStream out, 
PrintStream err) throws Exception {
+        final List<CamelContext> camelContexts = 
camelController.getCamelContexts();
+
+        final Map<String, Integer> columnWidths = 
computeColumnWidths(camelContexts);
+        final String headerFormat = buildFormatString(columnWidths, true);
+        final String rowFormat = buildFormatString(columnWidths, false);
+
+        out.println("Hello from commands-core");
+
+        if (camelContexts.size() > 0) {
+            out.println(String.format(headerFormat, CONTEXT_COLUMN_LABEL, 
STATUS_COLUMN_LABEL, UPTIME_COLUMN_LABEL));
+            out.println(String.format(headerFormat, "-------", "------", 
"------"));
+            for (final CamelContext camelContext : camelContexts) {
+                out.println(String.format(rowFormat, camelContext.getName(), 
camelContext.getStatus(), camelContext.getUptime()));
+            }
+        }
+
+        return null;
+    }
+
+    private static Map<String, Integer> computeColumnWidths(final 
Iterable<CamelContext> camelContexts) throws Exception {
+        if (camelContexts == null) {
+            throw new IllegalArgumentException("Unable to determine column 
widths from null Iterable<CamelContext>");
+        } else {
+            int maxNameLen = 0;
+            int maxStatusLen = 0;
+            int maxUptimeLen = 0;
+
+            for (final CamelContext camelContext : camelContexts) {
+                final String name = camelContext.getName();
+                maxNameLen = java.lang.Math.max(maxNameLen, name == null ? 0 : 
name.length());
+
+                final String status = camelContext.getStatus().toString();
+                maxStatusLen = java.lang.Math.max(maxStatusLen, status == null 
? 0 : status.length());
+
+                final String uptime = camelContext.getUptime();
+                maxUptimeLen = java.lang.Math.max(maxUptimeLen, uptime == null 
? 0 : uptime.length());
+            }
+
+            final Map<String, Integer> retval = new Hashtable<String, 
Integer>(3);
+            retval.put(CONTEXT_COLUMN_LABEL, maxNameLen);
+            retval.put(STATUS_COLUMN_LABEL, maxStatusLen);
+            retval.put(UPTIME_COLUMN_LABEL, maxUptimeLen);
+
+            return retval;
+        }
+    }
+
+    private static String buildFormatString(final Map<String, Integer> 
columnWidths, final boolean isHeader) {
+        final String fieldPreamble;
+        final String fieldPostamble;
+        final int columnWidthIncrement;
+
+        if (isHeader) {
+            fieldPreamble = DEFAULT_HEADER_PREAMBLE;
+            fieldPostamble = DEFAULT_HEADER_POSTAMBLE;
+        } else {
+            fieldPreamble = DEFAULT_FIELD_PREAMBLE;
+            fieldPostamble = DEFAULT_FIELD_POSTAMBLE;
+        }
+        columnWidthIncrement = DEFAULT_COLUMN_WIDTH_INCREMENT;
+
+        int contextLen = 
java.lang.Math.min(columnWidths.get(CONTEXT_COLUMN_LABEL) + 
columnWidthIncrement, MAX_COLUMN_WIDTH);
+        int statusLen = 
java.lang.Math.min(columnWidths.get(STATUS_COLUMN_LABEL) + 
columnWidthIncrement, MAX_COLUMN_WIDTH);
+        int uptimeLen = 
java.lang.Math.min(columnWidths.get(UPTIME_COLUMN_LABEL) + 
columnWidthIncrement, MAX_COLUMN_WIDTH);
+        contextLen = Math.max(MIN_COLUMN_WIDTH, contextLen);
+        statusLen = Math.max(MIN_COLUMN_WIDTH, statusLen);
+        // last row does not have min width
+
+        final StringBuilder retval = new 
StringBuilder(DEFAULT_FORMAT_BUFFER_LENGTH);
+        
retval.append(fieldPreamble).append("%-").append(contextLen).append('.').append(contextLen).append('s').append(fieldPostamble).append('
 ');
+        
retval.append(fieldPreamble).append("%-").append(statusLen).append('.').append(statusLen).append('s').append(fieldPostamble).append('
 ');
+        
retval.append(fieldPreamble).append("%-").append(uptimeLen).append('.').append(uptimeLen).append('s').append(fieldPostamble).append('
 ');
+
+        return retval.toString();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/internal/RegexUtil.java
----------------------------------------------------------------------
diff --git 
a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/internal/RegexUtil.java
 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/internal/RegexUtil.java
new file mode 100644
index 0000000..45d0ee8
--- /dev/null
+++ 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/internal/RegexUtil.java
@@ -0,0 +1,69 @@
+/**
+ * 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.camel.commands.internal;
+
+/**
+ * Util class.
+ */
+public final class RegexUtil {
+
+    private RegexUtil() {
+    }
+
+    /**
+     * convert a wild card containing * and ? to the equivalent regex
+     *
+     * @param wildcard wildcard string describing a file.
+     * @return regex string that could be fed to Pattern.compile
+     */
+    public static String wildcardAsRegex(String wildcard) {
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < wildcard.length(); i++) {
+            final char c = wildcard.charAt(i);
+            switch (c) {
+                case '*':
+                    sb.append(".*?");
+                    break;
+                case '?':
+                    sb.append(".");
+                    break;
+                // chars that have magic regex meaning. They need quoting to 
be taken literally
+                case '$':
+                case '(':
+                case ')':
+                case '+':
+                case '-':
+                case '.':
+                case '[':
+                case '\\':
+                case ']':
+                case '^':
+                case '{':
+                case '|':
+                case '}':
+                    sb.append('\\');
+                    sb.append(c);
+                    break;
+                default:
+                    sb.append(c);
+                    break;
+            }
+        }
+        return sb.toString();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/platforms/commands/commands-core/src/main/resources/LICENSE.txt
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/resources/LICENSE.txt 
b/platforms/commands/commands-core/src/main/resources/LICENSE.txt
new file mode 100644
index 0000000..6b0b127
--- /dev/null
+++ b/platforms/commands/commands-core/src/main/resources/LICENSE.txt
@@ -0,0 +1,203 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
+

http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/platforms/commands/commands-core/src/main/resources/NOTICE.txt
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/resources/NOTICE.txt 
b/platforms/commands/commands-core/src/main/resources/NOTICE.txt
new file mode 100644
index 0000000..2e215bf
--- /dev/null
+++ b/platforms/commands/commands-core/src/main/resources/NOTICE.txt
@@ -0,0 +1,11 @@
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the Apache Camel distribution.                    ==
+   =========================================================================
+
+   This product includes software developed by
+   The Apache Software Foundation (http://www.apache.org/).
+
+   Please read the different LICENSE files present in the licenses directory of
+   this distribution.

http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/internal/RegexUtilTest.java
----------------------------------------------------------------------
diff --git 
a/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/internal/RegexUtilTest.java
 
b/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/internal/RegexUtilTest.java
new file mode 100644
index 0000000..69bb871
--- /dev/null
+++ 
b/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/internal/RegexUtilTest.java
@@ -0,0 +1,52 @@
+/**
+ * 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.camel.commands.internal;
+
+import java.util.regex.Pattern;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class RegexUtilTest {
+
+    @Test
+    public void testWildcardAsRegex() throws Exception {
+        String testRouteId1 = "route.inbound.systema";
+        String testRouteId2 = "route.inbound.systemb";
+        String testRouteId3 = "route.outbound.systema";
+        String testRouteId4 = "route.outbound.systemb";
+        String testRouteId5 = "outbound.systemc";
+
+        
assertTrue(Pattern.matches(RegexUtil.wildcardAsRegex("route.inbound*"), 
testRouteId1));
+        assertTrue(!Pattern.matches(RegexUtil.wildcardAsRegex(".inbound*"), 
testRouteId2));
+        assertTrue(Pattern.matches(RegexUtil.wildcardAsRegex("*.inbound*"), 
testRouteId2));
+
+        assertTrue(Pattern.matches(RegexUtil.wildcardAsRegex("*outbound*"), 
testRouteId3));
+        assertTrue(Pattern.matches(RegexUtil.wildcardAsRegex("*outbound*"), 
testRouteId4));
+        assertTrue(Pattern.matches(RegexUtil.wildcardAsRegex("*outbound*"), 
testRouteId5));
+
+        assertTrue(Pattern.matches(RegexUtil.wildcardAsRegex("*"), 
testRouteId1));
+        assertTrue(Pattern.matches(RegexUtil.wildcardAsRegex("*"), 
testRouteId2));
+        assertTrue(Pattern.matches(RegexUtil.wildcardAsRegex("*"), 
testRouteId3));
+        assertTrue(Pattern.matches(RegexUtil.wildcardAsRegex("*"), 
testRouteId4));
+        assertTrue(Pattern.matches(RegexUtil.wildcardAsRegex("*"), 
testRouteId5));
+
+        
assertTrue(Pattern.matches(RegexUtil.wildcardAsRegex("route.inbound.systema"), 
testRouteId1));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/platforms/commands/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/commands/pom.xml b/platforms/commands/pom.xml
new file mode 100644
index 0000000..911090b
--- /dev/null
+++ b/platforms/commands/pom.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <!--
+    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.
+  -->
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>platforms</artifactId>
+    <version>2.15-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>commands</artifactId>
+  <packaging>pom</packaging>
+  <name>Camel :: Platforms :: Commands</name>
+
+  <modules>
+    <module>commands-core</module>
+  </modules>
+
+</project>

http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/platforms/karaf/commands/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/karaf/commands/pom.xml b/platforms/karaf/commands/pom.xml
index 5c5fd48..11aaa26 100644
--- a/platforms/karaf/commands/pom.xml
+++ b/platforms/karaf/commands/pom.xml
@@ -42,6 +42,10 @@
       <artifactId>camel-core</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>commands-core</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
     </dependency>

http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/CamelCommandSupport.java
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/CamelCommandSupport.java
 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/CamelCommandSupport.java
index 6076af2..d419256 100644
--- 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/CamelCommandSupport.java
+++ 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/CamelCommandSupport.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.karaf.commands;
 
+import org.apache.camel.commands.CamelController;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
 
 /**

http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/CamelController.java
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/CamelController.java
 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/CamelController.java
deleted file mode 100644
index 2495a0c..0000000
--- 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/CamelController.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/**
- * 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.camel.karaf.commands;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.Endpoint;
-import org.apache.camel.Route;
-import org.apache.camel.model.RouteDefinition;
-import org.apache.camel.model.rest.RestDefinition;
-import org.apache.camel.spi.RestRegistry;
-
-/**
- * CamelController interface defines the expected behaviors to manipulate 
Camel resources (context, route, etc).
- */
-public interface CamelController {
-
-    /**
-     * Get the list of Camel context.
-     *
-     * @return the list of Camel contexts.
-     */
-    List<CamelContext> getCamelContexts();
-
-    /**
-     * Get a Camel context identified by the given name.
-     *
-     * @param name the Camel context name.
-     * @return the Camel context or null if not found.
-     */
-    CamelContext getCamelContext(String name);
-
-    /**
-     * Get all routes. If Camel context name is null, all routes from all 
contexts are listed.
-     *
-     * @param camelContextName the Camel context name. If null, all contexts 
are considered.
-     * @return the list of the Camel routes.
-     */
-    List<Route> getRoutes(String camelContextName);
-
-    /**
-     * Get all routes filtered by the regex.
-     *
-     * @param camelContextName the Camel context name. If null, all contexts 
are considered.
-     * @param filter           the filter which supports * and ? as wildcards
-     * @return the list of the Camel routes.
-     */
-    List<Route> getRoutes(String camelContextName, String filter);
-
-    /**
-     * Return the route with the given route ID.
-     *
-     * @param routeId          the route ID.
-     * @param camelContextName the Camel context name.
-     * @return the route.
-     */
-    Route getRoute(String routeId, String camelContextName);
-
-    /**
-     * Return the definition of a route identified by a ID and a Camel context.
-     *
-     * @param routeId          the route ID.
-     * @param camelContextName the Camel context.
-     * @return the <code>RouteDefinition</code>.
-     */
-    RouteDefinition getRouteDefinition(String routeId, String 
camelContextName);
-
-    /**
-     * Return the endpoints
-     *
-     * @param camelContextName the Camel context.
-     * @return the endpoints
-     */
-    List<Endpoint> getEndpoints(String camelContextName);
-
-    /**
-     * Return the definition of the REST services for the given Camel context.
-     *
-     * @param camelContextName the Camel context.
-     * @return the <code>RouteDefinition</code>.
-     */
-    List<RestDefinition> getRestDefinitions(String camelContextName);
-
-    /**
-     * Return the REST services
-     *
-     * @param camelContextName the Camel context.
-     * @return the REST services
-     */
-    Map<String, List<RestRegistry.RestService>> getRestServices(String 
camelContextName);
-
-    /**
-     * Explains an endpoint uri
-     *
-     * @param camelContextName the Camel context.
-     * @param uri              the endpoint uri
-     * @param allOptions       whether to explain all options, or only the 
explicit configured options from the uri
-     * @return a JSON schema with explanation of the options
-     * @throws java.lang.Exception is thrown if error loading resources to 
explain the endpoint
-     */
-    String explainEndpoint(String camelContextName, String uri, boolean 
allOptions) throws Exception;
-
-    /**
-     * Lists all components and include information
-     *
-     * @param camelContextName the Camel context.
-     * @return a list of key/value pairs with component information
-     * @throws java.lang.Exception is thrown if error loading resources to 
gather component information
-     */
-    List<Map<String, String>> listComponents(String camelContextName) throws 
Exception;
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextList.java
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextList.java
 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextList.java
index ea69598..cef0589 100644
--- 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextList.java
+++ 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextList.java
@@ -16,12 +16,7 @@
  */
 package org.apache.camel.karaf.commands;
 
-import java.io.PrintStream;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.camel.CamelContext;
+import org.apache.camel.commands.ContextListCommand;
 import org.apache.felix.gogo.commands.Command;
 
 /**
@@ -30,91 +25,9 @@ import org.apache.felix.gogo.commands.Command;
 @Command(scope = "camel", name = "context-list", description = "Lists all 
Camel contexts.")
 public class ContextList extends CamelCommandSupport {
 
-    private static final String CONTEXT_COLUMN_LABEL = "Context";
-    private static final String STATUS_COLUMN_LABEL = "Status";
-    private static final String UPTIME_COLUMN_LABEL = "Uptime";
-    private static final int DEFAULT_FORMAT_BUFFER_LENGTH = 24;
-    private static final String DEFAULT_FIELD_PREAMBLE = " ";
-    private static final String DEFAULT_FIELD_POSTAMBLE = " ";
-    private static final String DEFAULT_HEADER_PREAMBLE = " ";
-    private static final String DEFAULT_HEADER_POSTAMBLE = " ";
-    private static final int DEFAULT_COLUMN_WIDTH_INCREMENT = 0;
-    private static final int MAX_COLUMN_WIDTH = Integer.MAX_VALUE;
-    private static final int MIN_COLUMN_WIDTH = 12;
-
+    @Override
     protected Object doExecute() throws Exception {
-        final List<CamelContext> camelContexts = 
camelController.getCamelContexts();
-
-        final Map<String, Integer> columnWidths = 
computeColumnWidths(camelContexts);
-        final String headerFormat = buildFormatString(columnWidths, true);
-        final String rowFormat = buildFormatString(columnWidths, false);
-        final PrintStream out = System.out;
-
-        if (camelContexts.size() > 0) {
-            out.println(String.format(headerFormat, CONTEXT_COLUMN_LABEL, 
STATUS_COLUMN_LABEL, UPTIME_COLUMN_LABEL));
-            out.println(String.format(headerFormat, "-------", "------", 
"------"));
-            for (final CamelContext camelContext : camelContexts) {
-                out.println(String.format(rowFormat, camelContext.getName(), 
camelContext.getStatus(), camelContext.getUptime()));
-            }
-        }
-
-        return null;
-    }
-
-    private static Map<String, Integer> computeColumnWidths(final 
Iterable<CamelContext> camelContexts) throws Exception {
-        if (camelContexts == null) {
-            throw new IllegalArgumentException("Unable to determine column 
widths from null Iterable<CamelContext>");
-        } else {
-            int maxNameLen = 0;
-            int maxStatusLen = 0;
-            int maxUptimeLen = 0;
-
-            for (final CamelContext camelContext : camelContexts) {
-                final String name = camelContext.getName();
-                maxNameLen = java.lang.Math.max(maxNameLen, name == null ? 0 : 
name.length());
-
-                final String status = camelContext.getStatus().toString();
-                maxStatusLen = java.lang.Math.max(maxStatusLen, status == null 
? 0 : status.length());
-
-                final String uptime = camelContext.getUptime();
-                maxUptimeLen = java.lang.Math.max(maxUptimeLen, uptime == null 
? 0 : uptime.length());
-            }
-
-            final Map<String, Integer> retval = new Hashtable<String, 
Integer>(3);
-            retval.put(CONTEXT_COLUMN_LABEL, maxNameLen);
-            retval.put(STATUS_COLUMN_LABEL, maxStatusLen);
-            retval.put(UPTIME_COLUMN_LABEL, maxUptimeLen);
-
-            return retval;
-        }
-    }
-
-    private static String buildFormatString(final Map<String, Integer> 
columnWidths, final boolean isHeader) {
-        final String fieldPreamble;
-        final String fieldPostamble;
-        final int columnWidthIncrement;
-
-        if (isHeader) {
-            fieldPreamble = DEFAULT_HEADER_PREAMBLE;
-            fieldPostamble = DEFAULT_HEADER_POSTAMBLE;
-        } else {
-            fieldPreamble = DEFAULT_FIELD_PREAMBLE;
-            fieldPostamble = DEFAULT_FIELD_POSTAMBLE;
-        }
-        columnWidthIncrement = DEFAULT_COLUMN_WIDTH_INCREMENT;
-
-        int contextLen = 
java.lang.Math.min(columnWidths.get(CONTEXT_COLUMN_LABEL) + 
columnWidthIncrement, MAX_COLUMN_WIDTH);
-        int statusLen = 
java.lang.Math.min(columnWidths.get(STATUS_COLUMN_LABEL) + 
columnWidthIncrement, MAX_COLUMN_WIDTH);
-        int uptimeLen = 
java.lang.Math.min(columnWidths.get(UPTIME_COLUMN_LABEL) + 
columnWidthIncrement, MAX_COLUMN_WIDTH);
-        contextLen = Math.max(MIN_COLUMN_WIDTH, contextLen);
-        statusLen = Math.max(MIN_COLUMN_WIDTH, statusLen);
-        // last row does not have min width
-
-        final StringBuilder retval = new 
StringBuilder(DEFAULT_FORMAT_BUFFER_LENGTH);
-        
retval.append(fieldPreamble).append("%-").append(contextLen).append('.').append(contextLen).append('s').append(fieldPostamble).append('
 ');
-        
retval.append(fieldPreamble).append("%-").append(statusLen).append('.').append(statusLen).append('s').append(fieldPostamble).append('
 ');
-        
retval.append(fieldPreamble).append("%-").append(uptimeLen).append('.').append(uptimeLen).append('s').append(fieldPostamble).append('
 ');
-
-        return retval.toString();
+        ContextListCommand command = new ContextListCommand();
+        return command.execute(camelController, System.out, System.err);
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/completers/CamelCompleterSupport.java
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/completers/CamelCompleterSupport.java
 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/completers/CamelCompleterSupport.java
index ff17d94..780eb1b 100644
--- 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/completers/CamelCompleterSupport.java
+++ 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/completers/CamelCompleterSupport.java
@@ -16,8 +16,7 @@
  */
 package org.apache.camel.karaf.commands.completers;
 
-import org.apache.camel.karaf.commands.CamelController;
-
+import org.apache.camel.commands.CamelController;
 import org.apache.karaf.shell.console.Completer;
 
 /**

http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java
 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java
index 0c8231a..1e733e9 100644
--- 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java
+++ 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java
@@ -28,7 +28,7 @@ import java.util.Properties;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Route;
-import org.apache.camel.karaf.commands.CamelController;
+import org.apache.camel.commands.CamelController;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.model.rest.RestDefinition;
 import org.apache.camel.spi.RestRegistry;

http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/platforms/karaf/features/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/platforms/karaf/features/src/main/resources/features.xml 
b/platforms/karaf/features/src/main/resources/features.xml
index b410c4c..249f814 100644
--- a/platforms/karaf/features/src/main/resources/features.xml
+++ b/platforms/karaf/features/src/main/resources/features.xml
@@ -36,6 +36,7 @@
   <feature name='camel-core' version='${project.version}' resolver='(obr)' 
start-level='50'>
     <feature version='${servicemix-specs-version}'>xml-specs-api</feature>
     <bundle>mvn:org.apache.camel/camel-core/${project.version}</bundle>
+    <bundle>mvn:org.apache.camel/commands-core/${project.version}</bundle>
     
<bundle>mvn:org.apache.camel.karaf/camel-karaf-commands/${project.version}</bundle>
   </feature>
   <feature name='camel-spring' version='${project.version}' resolver='(obr)' 
start-level='50'>

http://git-wip-us.apache.org/repos/asf/camel/blob/55d9d82e/platforms/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/pom.xml b/platforms/pom.xml
index fc41d6e..e699ca7 100644
--- a/platforms/pom.xml
+++ b/platforms/pom.xml
@@ -32,6 +32,7 @@
   <packaging>pom</packaging>
 
   <modules>
+    <module>commands</module>
     <module>karaf</module>
   </modules>
 </project>

Reply via email to