You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/11/13 11:32:01 UTC
[7/9] camel git commit: CAMEL-8041: Camel commands should be reusable.
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/c30e4559
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c30e4559
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c30e4559
Branch: refs/heads/master
Commit: c30e45598d386003b51272a3027c73c2f7524d2b
Parents: acd55f5
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Nov 13 10:58:07 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Nov 13 10:58:07 2014 +0100
----------------------------------------------------------------------
.../camel/commands/AbstractContextCommand.java | 6 +-
.../camel/commands/ComponentListCommand.java | 8 +--
.../apache/camel/commands/RestShowCommand.java | 2 +-
.../camel/commands/internal/RegexUtil.java | 52 +++++++--------
.../commands/internal/CamelControllerImpl.java | 10 ++-
.../karaf/commands/internal/RegexUtil.java | 69 --------------------
.../camel/karaf/commands/RegexUtilTest.java | 53 ---------------
7 files changed, 41 insertions(+), 159 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/c30e4559/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
index 7212b15..9facb48 100644
--- 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
@@ -43,12 +43,12 @@ public abstract class AbstractContextCommand extends AbstractCamelCommand {
}
// 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());
+// ClassLoader oldClassloader = Thread.currentThread().getContextClassLoader();
+// Thread.currentThread().setContextClassLoader(camelContext.getApplicationContextClassLoader());
try {
return performContextCommand(camelController, camelContext, out, err);
} finally {
- Thread.currentThread().setContextClassLoader(oldClassloader);
+// Thread.currentThread().setContextClassLoader(oldClassloader);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/c30e4559/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ComponentListCommand.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ComponentListCommand.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ComponentListCommand.java
index 8f613c1..290260e 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ComponentListCommand.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ComponentListCommand.java
@@ -91,10 +91,10 @@ public class ComponentListCommand extends AbstractContextCommand {
return null;
} else {
// some of the options is optional so we need to start from 1
- int maxNameLen = 1;
- int maxStatusLen = 1;
- int maxMavenLen = 1;
- int maxDescriptionLen = 1;
+ int maxNameLen = 0;
+ int maxStatusLen = 0;
+ int maxMavenLen = 0;
+ int maxDescriptionLen = 0;
for (final Map<String, String> component : components) {
http://git-wip-us.apache.org/repos/asf/camel/blob/c30e4559/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RestShowCommand.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RestShowCommand.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RestShowCommand.java
index 889246d..fb0dde2 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RestShowCommand.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RestShowCommand.java
@@ -34,7 +34,7 @@ public class RestShowCommand extends AbstractContextCommand {
protected Object performContextCommand(CamelController camelController, CamelContext camelContext, PrintStream out, PrintStream err) throws Exception {
List<RestDefinition> rests = camelController.getRestDefinitions(context);
if (rests == null || rests.isEmpty()) {
- out.print("There are no REST services in CamelContext with name: " + context);
+ out.println("There are no REST services in CamelContext with name: " + context);
return null;
}
// use a routes definition to dump the rests
http://git-wip-us.apache.org/repos/asf/camel/blob/c30e4559/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
index 45d0ee8..4c05f22 100644
--- 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
@@ -35,32 +35,32 @@ public final class RegexUtil {
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;
+ 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/c30e4559/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 1e733e9..f695f6a 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
@@ -209,7 +209,9 @@ public class CamelControllerImpl implements CamelController {
return o1.getUrl().compareTo(o2.getUrl());
}
});
- answer.put(camelContextName, services);
+ if (!services.isEmpty()) {
+ answer.put(camelContextName, services);
+ }
}
} else {
// already sorted by camel context
@@ -222,7 +224,9 @@ public class CamelControllerImpl implements CamelController {
return o1.getUrl().compareTo(o2.getUrl());
}
});
- answer.put(camelContext.getName(), services);
+ if (!services.isEmpty()) {
+ answer.put(camelContext.getName(), services);
+ }
}
}
return answer;
@@ -278,7 +282,7 @@ public class CamelControllerImpl implements CamelController {
}
}
- Map<String, String> row = new HashMap<>();
+ Map<String, String> row = new HashMap<String, String>();
row.put("name", name);
row.put("status", status);
if (description != null) {
http://git-wip-us.apache.org/repos/asf/camel/blob/c30e4559/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/RegexUtil.java
----------------------------------------------------------------------
diff --git a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/RegexUtil.java b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/RegexUtil.java
deleted file mode 100644
index 82b8717..0000000
--- a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/RegexUtil.java
+++ /dev/null
@@ -1,69 +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.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/c30e4559/platforms/karaf/commands/src/test/java/org/apache/camel/karaf/commands/RegexUtilTest.java
----------------------------------------------------------------------
diff --git a/platforms/karaf/commands/src/test/java/org/apache/camel/karaf/commands/RegexUtilTest.java b/platforms/karaf/commands/src/test/java/org/apache/camel/karaf/commands/RegexUtilTest.java
deleted file mode 100644
index 31dc455..0000000
--- a/platforms/karaf/commands/src/test/java/org/apache/camel/karaf/commands/RegexUtilTest.java
+++ /dev/null
@@ -1,53 +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.regex.Pattern;
-
-import org.apache.camel.karaf.commands.internal.RegexUtil;
-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));
- }
-
-}