Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove commons lang as a compile time dependency #594

Merged
merged 1 commit into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,18 @@
<artifactId>slf4j-api</artifactId>
<version>${version.slf4j}</version>
</dependency>
<!--
Commons lang slated for removal but kept for projects that accidentally depend on it
through accidental transitive runtime dependencies.

For projects that depend on it for compile they will get an immediate failure as the
scope is now runtime instead of compile.
-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${version.common-lang3}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jruby.joni</groupId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/networknt/schema/BaseJsonValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.networknt.schema.ValidationContext.DiscriminatorContext;
import org.apache.commons.lang3.StringUtils;
import com.networknt.schema.utils.StringUtils;
import org.slf4j.Logger;

public abstract class BaseJsonValidator implements JsonValidator {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/networknt/schema/JsonMetaSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.networknt.schema;

import com.fasterxml.jackson.databind.JsonNode;
import org.apache.commons.lang3.StringUtils;
import com.networknt.schema.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/networknt/schema/ValidationMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.networknt.schema;

import org.apache.commons.lang3.StringUtils;
import com.networknt.schema.utils.StringUtils;

import java.text.MessageFormat;
import java.util.Arrays;
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/com/networknt/schema/utils/StringUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.networknt.schema.utils;

public final class StringUtils {

private StringUtils() {
}

public static boolean isBlank(final CharSequence cs) {
int strLen = length(cs);
if (strLen == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if (!Character.isWhitespace(cs.charAt(i))) {
return false;
}
}
return true;
}

public static boolean isNotBlank(final CharSequence cs) {
return !isBlank(cs);
}

private static int length(final CharSequence cs) {
return cs == null ? 0 : cs.length();
}

// The following was borrowed from Apache Commons Lang 3
public static boolean equals(final CharSequence cs1, final CharSequence cs2) {
if (cs1 == cs2) {
return true;
}
if (cs1 == null || cs2 == null) {
return false;
}
if (cs1.length() != cs2.length()) {
return false;
}
if (cs1 instanceof String && cs2 instanceof String) {
return cs1.equals(cs2);
}
// Step-wise comparison
final int length = cs1.length();
for (int i = 0; i < length; i++) {
if (cs1.charAt(i) != cs2.charAt(i)) {
return false;
}
}
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.fasterxml.jackson.databind.node.ArrayNode;
import io.undertow.Undertow;
import io.undertow.server.handlers.resource.FileResourceManager;
import org.apache.commons.lang3.StringUtils;
import com.networknt.schema.utils.StringUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;

Expand Down