You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2020/02/07 19:18:28 UTC
[camel] 01/02: Break dependency between camel-tooling-model and
camel-tooling-util
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 6ce1bac3529aabce6aed88d356623c9f1042b27b
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Fri Feb 7 20:07:29 2020 +0100
Break dependency between camel-tooling-model and camel-tooling-util
---
tooling/camel-tooling-model/pom.xml | 4 -
.../org/apache/camel/tooling/model/BaseModel.java | 2 -
.../camel/tooling/model/BaseOptionModel.java | 2 -
.../org/apache/camel/tooling/model}/Strings.java | 160 +--------------------
.../apache/camel/tooling/model}/StringsTest.java | 16 +--
.../org/apache/camel/tooling/util/Strings.java | 135 -----------------
.../org/apache/camel/tooling/util/StringsTest.java | 31 ----
7 files changed, 2 insertions(+), 348 deletions(-)
diff --git a/tooling/camel-tooling-model/pom.xml b/tooling/camel-tooling-model/pom.xml
index 1c53756..6ab2b85 100644
--- a/tooling/camel-tooling-model/pom.xml
+++ b/tooling/camel-tooling-model/pom.xml
@@ -45,10 +45,6 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-util-json</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-tooling-util</artifactId>
- </dependency>
<!-- testing -->
<dependency>
diff --git a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/BaseModel.java b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/BaseModel.java
index 087b1e3..6051963 100644
--- a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/BaseModel.java
+++ b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/BaseModel.java
@@ -20,8 +20,6 @@ import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
-import org.apache.camel.tooling.util.Strings;
-
public abstract class BaseModel<O extends BaseOptionModel> {
protected String name;
diff --git a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/BaseOptionModel.java b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/BaseOptionModel.java
index 2ec4745..1aff346 100644
--- a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/BaseOptionModel.java
+++ b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/BaseOptionModel.java
@@ -18,8 +18,6 @@ package org.apache.camel.tooling.model;
import java.util.List;
-import org.apache.camel.tooling.util.Strings;
-
@SuppressWarnings("unused")
public abstract class BaseOptionModel {
diff --git a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/Strings.java b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/Strings.java
similarity index 59%
copy from tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/Strings.java
copy to tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/Strings.java
index 949df76..d087382 100644
--- a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/Strings.java
+++ b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/Strings.java
@@ -14,9 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.tooling.util;
-
-import java.util.Collection;
+package org.apache.camel.tooling.model;
/**
* Some String helper methods
@@ -27,10 +25,6 @@ public final class Strings {
//Helper class
}
- public static boolean isEmpty(String s) {
- return s == null || s.trim().isEmpty();
- }
-
/**
* Returns true if the given text is null or empty string or has <tt>null</tt> as the value
*/
@@ -38,158 +32,6 @@ public final class Strings {
return text == null || text.length() == 0 || "null".equals(text);
}
- public static String safeNull(String text) {
- if (isNullOrEmpty(text)) {
- return "";
- } else {
- return text;
- }
- }
-
- /**
- * Returns the value or the defaultValue if it is null
- */
- public static String getOrElse(String text, String defaultValue) {
- return (text != null) ? text : defaultValue;
- }
-
- /**
- * Returns the string after the given token
- *
- * @param text the text
- * @param after the token
- * @return the text after the token, or <tt>null</tt> if text does not contain the token
- */
- public static String after(String text, String after) {
- int index = text.indexOf(after);
- if (index < 0) {
- return null;
- }
- return text.substring(index + after.length());
- }
-
- /**
- * Returns the canonical class name by removing any generic type information.
- */
- public static String canonicalClassName(String className) {
- // remove generics
- int pos = className.indexOf('<');
- if (pos != -1) {
- return className.substring(0, pos);
- } else {
- return className;
- }
- }
-
- /**
- * Returns the text wrapped double quotes
- */
- public static String doubleQuote(String text) {
- return quote(text, "\"");
- }
-
- /**
- * Returns the text wrapped single quotes
- */
- public static String singleQuote(String text) {
- return quote(text, "'");
- }
-
- /**
- * Wraps the text in the given quote text
- *
- * @param text the text to wrap in quotes
- * @param quote the quote text added to the prefix and postfix of the text
- *
- * @return the text wrapped in the given quotes
- */
- public static String quote(String text, String quote) {
- return quote + text + quote;
- }
-
- /**
- * Clips the text between the start and end markers
- */
- public static String between(String text, String after, String before) {
- text = after(text, after);
- if (text == null) {
- return null;
- }
- return before(text, before);
- }
-
- /**
- * Capitalizes the name as a title
- *
- * @param name the name
- * @return as a title
- */
- public static String asTitle(String name) {
- StringBuilder sb = new StringBuilder();
- for (char c : name.toCharArray()) {
- boolean upper = Character.isUpperCase(c);
- boolean first = sb.length() == 0;
- if (first) {
- sb.append(Character.toUpperCase(c));
- } else if (upper) {
- char prev = sb.charAt(sb.length() - 1);
- if (!Character.isUpperCase(prev)) {
- // append space if previous is not upper
- sb.append(' ');
- }
- sb.append(c);
- } else {
- sb.append(Character.toLowerCase(c));
- }
- }
- return sb.toString().trim();
- }
-
- public static String before(String text, String before) {
- int index = text.indexOf(before);
- if (index < 0) {
- return null;
- }
- return text.substring(0, index);
- }
-
- public static String indentCollection(String indent, Collection<String> list) {
- StringBuilder sb = new StringBuilder();
- for (String text : list) {
- sb.append(indent).append(text);
- }
- return sb.toString();
- }
-
- /**
- * Converts the value to use title style instead of dash cased
- */
- public static String camelDashToTitle(String value) {
- StringBuilder sb = new StringBuilder(value.length());
- boolean dash = false;
-
- for (char c : value.toCharArray()) {
- if ('-' == c) {
- dash = true;
- continue;
- }
-
- if (dash) {
- sb.append(' ');
- sb.append(Character.toUpperCase(c));
- } else {
- // upper case first
- if (sb.length() == 0) {
- sb.append(Character.toUpperCase(c));
- } else {
- sb.append(c);
- }
- }
- dash = false;
- }
- return sb.toString();
- }
-
public static String cutLastZeroDigit(String version) {
String answer = version;
// cut last digit so its not 2.18.0 but 2.18
diff --git a/tooling/camel-tooling-util/src/test/java/org/apache/camel/tooling/util/StringsTest.java b/tooling/camel-tooling-model/src/test/java/org/apache/camel/tooling/model/StringsTest.java
similarity index 83%
copy from tooling/camel-tooling-util/src/test/java/org/apache/camel/tooling/util/StringsTest.java
copy to tooling/camel-tooling-model/src/test/java/org/apache/camel/tooling/model/StringsTest.java
index 1583b8e..3c490e6 100644
--- a/tooling/camel-tooling-util/src/test/java/org/apache/camel/tooling/util/StringsTest.java
+++ b/tooling/camel-tooling-model/src/test/java/org/apache/camel/tooling/model/StringsTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.tooling.util;
+package org.apache.camel.tooling.model;
import java.util.stream.Stream;
@@ -23,8 +23,6 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
-import static org.apache.camel.tooling.util.Strings.asTitle;
-import static org.apache.camel.tooling.util.Strings.between;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.params.provider.Arguments.arguments;
@@ -45,18 +43,6 @@ public class StringsTest {
}
@Test
- public void testBetween() {
- assertEquals("org.apache.camel.model.OnCompletionDefinition", between("java.util.List<org.apache.camel.model.OnCompletionDefinition>", "<", ">"));
- }
-
- @Test
- public void testAsTitle() {
- assertEquals("Broker URL", asTitle("brokerURL"));
- assertEquals("Expose All Queues", asTitle("exposeAllQueues"));
- assertEquals("Reply To Concurrent Consumers", asTitle("replyToConcurrentConsumers"));
- }
-
- @Test
public void testWrap() {
assertEquals("Hello WorldFoo Nar", wrap("HelloWorldFooNar", 8));
assertEquals("UseMessageIDAs CorrelationID", wrap("useMessageIDAsCorrelationID", 25));
diff --git a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/Strings.java b/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/Strings.java
index 949df76..08c27ca 100644
--- a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/Strings.java
+++ b/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/Strings.java
@@ -190,139 +190,4 @@ public final class Strings {
return sb.toString();
}
- public static String cutLastZeroDigit(String version) {
- String answer = version;
- // cut last digit so its not 2.18.0 but 2.18
- String[] parts = version.split("\\.");
- if (parts.length == 3 && parts[2].equals("0")) {
- answer = parts[0] + "." + parts[1];
- }
- return answer;
- }
-
- /**
- * To wrap long camel cased texts by words.
- *
- * @param option the option which is camel cased.
- * @param watermark a watermark to denote the size to cut after
- * @param lineSep the new line to use when breaking into a new line
- */
- public static String wrapCamelCaseWords(String option, int watermark, String lineSep) {
- String text = option.replaceAll("(?=[A-Z][a-z])", " ");
- text = wrapWords(text, "", lineSep, watermark, false);
- return Character.toUpperCase(text.charAt(0)) + text.substring(1);
- }
-
- /**
- * To wrap a big line by words.
- * @param line the big line
- * @param wordSep the word separator
- * @param lineSep the new line to use when breaking into a new line
- * @param watermark a watermark to denote the size to cut after
- * @param wrapLongWords whether to wrap long words
- */
- public static String wrapWords(String line, String wordSep, String lineSep, int watermark, boolean wrapLongWords) {
- if (line == null) {
- return null;
- } else {
- if (lineSep == null) {
- lineSep = System.lineSeparator();
- }
- if (wordSep == null) {
- wordSep = "";
- }
-
- if (watermark < 1) {
- watermark = 1;
- }
-
- int inputLineLength = line.length();
- int offset = 0;
- StringBuilder sb = new StringBuilder(inputLineLength + 32);
- int currentLength = 0;
- while (offset < inputLineLength) {
- if (line.charAt(offset) == ' ') {
- offset++;
- continue;
- }
- int next = line.indexOf(' ', offset);
- if (next < 0) {
- next = inputLineLength;
- if (wrapLongWords && inputLineLength - offset > watermark) {
- if (currentLength > 0) {
- sb.append(wordSep);
- currentLength += wordSep.length();
- }
- sb.append(line, offset, watermark - currentLength);
- sb.append(lineSep);
- offset += watermark - currentLength;
- }
- }
- if (currentLength + (currentLength > 0 ? wordSep.length() : 0) + next - offset <= watermark) {
- if (currentLength > 0) {
- sb.append(wordSep);
- currentLength += wordSep.length();
- }
- sb.append(line, offset, next);
- currentLength += next - offset;
- offset = next + 1;
- } else {
- sb.append(lineSep);
- sb.append(line, offset, next);
- currentLength = next - offset;
- offset = next + 1;
- }
- }
- /*
- while (inputLineLength - offset > watermark) {
- if (line.charAt(offset) == ' ') {
- ++offset;
- } else {
- int spaceToWrapAt = line.lastIndexOf(' ', watermark + offset);
- int spaces = 0;
- for (int i = offset; i < spaceToWrapAt; i++) {
- spaces += line.charAt(i) == ' ' ? 1 : 0;
- }
- if (spaceToWrapAt >= offset) {
- sb.append(line, offset, spaceToWrapAt);
- sb.append(newLine);
- offset = spaceToWrapAt + 1;
- } else if (wrapLongWords) {
- sb.append(line, offset, watermark + offset);
- sb.append(newLine);
- offset += watermark;
- } else {
- spaceToWrapAt = line.indexOf(' ', watermark + offset);
- if (spaceToWrapAt >= 0) {
- sb.append(line, offset, spaceToWrapAt);
- sb.append(newLine);
- offset = spaceToWrapAt + 1;
- } else {
- sb.append(line, offset, line.length());
- offset = inputLineLength;
- }
- }
- }
- }
-
- sb.append(line, offset, line.length());
- */
- return sb.toString();
- }
- }
-
- /**
- * Returns the base class name, i.e. without package and generic related
- * information.
- *
- * @param className The class name which base class is to be computed.
- * @return the base class name, i.e. without package and generic related
- * information.
- */
- public static String getClassShortName(String className) {
- if (className != null) {
- return className.replaceAll("<.*>", "").replaceAll(".*[.]([^.]+)", "$1");
- }
- return className;
- }
}
diff --git a/tooling/camel-tooling-util/src/test/java/org/apache/camel/tooling/util/StringsTest.java b/tooling/camel-tooling-util/src/test/java/org/apache/camel/tooling/util/StringsTest.java
index 1583b8e..67413b2 100644
--- a/tooling/camel-tooling-util/src/test/java/org/apache/camel/tooling/util/StringsTest.java
+++ b/tooling/camel-tooling-util/src/test/java/org/apache/camel/tooling/util/StringsTest.java
@@ -30,20 +30,6 @@ import static org.junit.jupiter.params.provider.Arguments.arguments;
public class StringsTest {
- static Stream<Arguments> getClassShortNameTypeVarations() {
- return Stream.of(arguments("String", "String"), arguments("String", "java.lang.String"), arguments("List", "List<String>"), arguments("List", "java.util.List<String>"),
- arguments("List", "List<java.lang.String>"), arguments("List", "java.util.List.List<org.apache.camel.Exchange>"),
- arguments("List", "java.util.List<Map<String,Integer>>"), arguments("List", "java.util.List<Map<java.lang.String,Integer>>"),
- arguments("List", "java.util.List<Map<String,java.lang.Integer>>"), arguments("List", "java.util.List<Map<java.lang.String,java.lang.Integer>>"),
- arguments("List", "java.util.List<java.util.Map<java.lang.String,java.lang.Integer>>"));
- }
-
- @ParameterizedTest
- @MethodSource("getClassShortNameTypeVarations")
- public void getClassShortName(String expectedBaseClassName, String className) {
- assertEquals(expectedBaseClassName, Strings.getClassShortName(className));
- }
-
@Test
public void testBetween() {
assertEquals("org.apache.camel.model.OnCompletionDefinition", between("java.util.List<org.apache.camel.model.OnCompletionDefinition>", "<", ">"));
@@ -56,21 +42,4 @@ public class StringsTest {
assertEquals("Reply To Concurrent Consumers", asTitle("replyToConcurrentConsumers"));
}
- @Test
- public void testWrap() {
- assertEquals("Hello WorldFoo Nar", wrap("HelloWorldFooNar", 8));
- assertEquals("UseMessageIDAs CorrelationID", wrap("useMessageIDAsCorrelationID", 25));
- assertEquals("ReplyToCacheLevelName", wrap("replyToCacheLevelName", 25));
- assertEquals("AllowReplyManagerQuick Stop", wrap("allowReplyManagerQuickStop", 25));
- assertEquals("AcknowledgementModeName", wrap("acknowledgementModeName", 25));
- assertEquals("ReplyToCacheLevelName", wrap("replyToCacheLevelName", 25));
- assertEquals("ReplyToOnTimeoutMax ConcurrentConsumers", wrap("replyToOnTimeoutMaxConcurrentConsumers", 25));
- assertEquals("ReplyToOnTimeoutMax ConcurrentConsumers", wrap("replyToOnTimeoutMaxConcurrentConsumers", 23));
- assertEquals("ReplyToMaxConcurrent Consumers", wrap("replyToMaxConcurrentConsumers", 23));
-
- }
-
- private String wrap(String str, int watermark) {
- return Strings.wrapCamelCaseWords(str, watermark, " ");
- }
}