From 54a136c7fe8b02db0a312b623812f17d360e8359 Mon Sep 17 00:00:00 2001 From: Navneet Verma Date: Tue, 5 Sep 2023 22:24:24 -0700 Subject: [PATCH] Resolving apache commons dependency forcefully to make sure that there is no jarhell Signed-off-by: Navneet Verma --- build.gradle | 8 +++++++- .../neuralsearch/processor/TextEmbeddingProcessor.java | 2 +- .../processor/combination/ScoreCombinationUtil.java | 4 +--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 0961eb890..8b2cf0907 100644 --- a/build.gradle +++ b/build.gradle @@ -144,7 +144,7 @@ dependencies { zipArchive group: 'org.opensearch.plugin', name:'opensearch-ml-plugin', version: "${opensearch_build}" compileOnly fileTree(dir: knnJarDirectory, include: '*.jar') api group: 'org.opensearch', name:'opensearch-ml-client', version: "${opensearch_build}" - implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.10' + compileOnly group: 'org.apache.commons', name: 'commons-lang3', version: '3.10' // ml-common excluded reflection for runtime so we need to add it by ourselves. // https://github.com/opensearch-project/ml-commons/commit/464bfe34c66d7a729a00dd457f03587ea4e504d9 // TODO: Remove following three lines of dependencies if ml-common include them in their jar @@ -153,6 +153,12 @@ dependencies { runtimeOnly group: 'org.opensearch', name: 'common-utils', version: "${opensearch_build}" } +// Resolving apache commons dependency forcefully to make sure that there is no jarhell and multiple dependency coming +// for apache commons lang3 +configurations.all { + resolutionStrategy.force 'org.apache.commons:commons-lang3:3.10' +} + // In order to add the jar to the classpath, we need to unzip the // k-NN zip and then copy it into a directory that we specify as a dependency. task extractKnnJar(type: Copy) { diff --git a/src/main/java/org/opensearch/neuralsearch/processor/TextEmbeddingProcessor.java b/src/main/java/org/opensearch/neuralsearch/processor/TextEmbeddingProcessor.java index 878a410a8..31f883140 100644 --- a/src/main/java/org/opensearch/neuralsearch/processor/TextEmbeddingProcessor.java +++ b/src/main/java/org/opensearch/neuralsearch/processor/TextEmbeddingProcessor.java @@ -16,7 +16,7 @@ import lombok.extern.log4j.Log4j2; -import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang.StringUtils; import org.opensearch.core.action.ActionListener; import org.opensearch.env.Environment; import org.opensearch.index.mapper.MapperService; diff --git a/src/main/java/org/opensearch/neuralsearch/processor/combination/ScoreCombinationUtil.java b/src/main/java/org/opensearch/neuralsearch/processor/combination/ScoreCombinationUtil.java index ed82a62ea..195f9c155 100644 --- a/src/main/java/org/opensearch/neuralsearch/processor/combination/ScoreCombinationUtil.java +++ b/src/main/java/org/opensearch/neuralsearch/processor/combination/ScoreCombinationUtil.java @@ -16,8 +16,6 @@ import lombok.extern.log4j.Log4j2; -import org.apache.commons.lang3.Range; - import com.google.common.math.DoubleMath; /** @@ -118,7 +116,7 @@ protected void validateIfWeightsMatchScores(final float[] scores, final List weightsList) { - boolean isOutOfRange = weightsList.stream().anyMatch(weight -> !Range.between(0.0f, 1.0f).contains(weight)); + boolean isOutOfRange = weightsList.stream().anyMatch(weight -> !(weight >= 0.0f && weight < 1.0f)); if (isOutOfRange) { throw new IllegalArgumentException( String.format(