Skip to content

Commit 1ecc9da

Browse files
authored
Remove commons lang as a compile time dependency (#594)
1 parent 61ed6df commit 1ecc9da

File tree

6 files changed

+65
-4
lines changed

6 files changed

+65
-4
lines changed

pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,18 @@
8484
<artifactId>slf4j-api</artifactId>
8585
<version>${version.slf4j}</version>
8686
</dependency>
87+
<!--
88+
Commons lang slated for removal but kept for projects that accidentally depend on it
89+
through accidental transitive runtime dependencies.
90+
91+
For projects that depend on it for compile they will get an immediate failure as the
92+
scope is now runtime instead of compile.
93+
-->
8794
<dependency>
8895
<groupId>org.apache.commons</groupId>
8996
<artifactId>commons-lang3</artifactId>
9097
<version>${version.common-lang3}</version>
98+
<scope>runtime</scope>
9199
</dependency>
92100
<dependency>
93101
<groupId>org.jruby.joni</groupId>

src/main/java/com/networknt/schema/BaseJsonValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import com.fasterxml.jackson.databind.JsonNode;
2727
import com.fasterxml.jackson.databind.node.ObjectNode;
2828
import com.networknt.schema.ValidationContext.DiscriminatorContext;
29-
import org.apache.commons.lang3.StringUtils;
29+
import com.networknt.schema.utils.StringUtils;
3030
import org.slf4j.Logger;
3131

3232
public abstract class BaseJsonValidator implements JsonValidator {

src/main/java/com/networknt/schema/JsonMetaSchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.networknt.schema;
1818

1919
import com.fasterxml.jackson.databind.JsonNode;
20-
import org.apache.commons.lang3.StringUtils;
20+
import com.networknt.schema.utils.StringUtils;
2121
import org.slf4j.Logger;
2222
import org.slf4j.LoggerFactory;
2323

src/main/java/com/networknt/schema/ValidationMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.networknt.schema;
1818

19-
import org.apache.commons.lang3.StringUtils;
19+
import com.networknt.schema.utils.StringUtils;
2020

2121
import java.text.MessageFormat;
2222
import java.util.Arrays;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.networknt.schema.utils;
2+
3+
public final class StringUtils {
4+
5+
private StringUtils() {
6+
}
7+
8+
public static boolean isBlank(final CharSequence cs) {
9+
int strLen = length(cs);
10+
if (strLen == 0) {
11+
return true;
12+
}
13+
for (int i = 0; i < strLen; i++) {
14+
if (!Character.isWhitespace(cs.charAt(i))) {
15+
return false;
16+
}
17+
}
18+
return true;
19+
}
20+
21+
public static boolean isNotBlank(final CharSequence cs) {
22+
return !isBlank(cs);
23+
}
24+
25+
private static int length(final CharSequence cs) {
26+
return cs == null ? 0 : cs.length();
27+
}
28+
29+
// The following was borrowed from Apache Commons Lang 3
30+
public static boolean equals(final CharSequence cs1, final CharSequence cs2) {
31+
if (cs1 == cs2) {
32+
return true;
33+
}
34+
if (cs1 == null || cs2 == null) {
35+
return false;
36+
}
37+
if (cs1.length() != cs2.length()) {
38+
return false;
39+
}
40+
if (cs1 instanceof String && cs2 instanceof String) {
41+
return cs1.equals(cs2);
42+
}
43+
// Step-wise comparison
44+
final int length = cs1.length();
45+
for (int i = 0; i < length; i++) {
46+
if (cs1.charAt(i) != cs2.charAt(i)) {
47+
return false;
48+
}
49+
}
50+
return true;
51+
}
52+
53+
}

src/test/java/com/networknt/schema/BaseSuiteJsonSchemaTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.fasterxml.jackson.databind.node.ArrayNode;
2222
import io.undertow.Undertow;
2323
import io.undertow.server.handlers.resource.FileResourceManager;
24-
import org.apache.commons.lang3.StringUtils;
24+
import com.networknt.schema.utils.StringUtils;
2525
import org.junit.jupiter.api.AfterAll;
2626
import org.junit.jupiter.api.BeforeAll;
2727

0 commit comments

Comments
 (0)