Skip to content

Commit

Permalink
Fixes #4108: Remove org.apache.commons.collections* imports (#4129) (#…
Browse files Browse the repository at this point in the history
…4219)

* Fixes #4108: Remove org.apache.commons.collections* imports

* removed unused methods
  • Loading branch information
vga91 committed Nov 5, 2024
1 parent 5eb1c10 commit 7dfef90
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 39 deletions.
1 change: 0 additions & 1 deletion docs/asciidoc/modules/ROOT/partials/xls-dependencies.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Alternatively, you can download these jars from Maven Repository (putting them i
* https://repo1.maven.org/maven2/org/apache/poi/poi/5.1.0/poi-5.1.0.jar[poi-5.1.0.jar^]
.Additional for XLSX files:
* https://repo1.maven.org/maven2/org/apache/commons/commons-collections4/4.4/commons-collections4-4.4.jar[commons-collections4-4.4.jar^]
* https://repo1.maven.org/maven2/org/apache/poi/poi-ooxml/5.1.0/poi-ooxml-5.1.0.jar[poi-ooxml-5.1.0.jar^]
* https://repo1.maven.org/maven2/org/apache/poi/poi-ooxml-lite/5.1.0/poi-ooxml-lite-5.1.0.jar[poi-ooxml-lite-5.1.0.jar^]
* https://repo1.maven.org/maven2/org/apache/xmlbeans/xmlbeans/5.0.2/xmlbeans-5.0.2.jar[xmlbeans-5.0.2.jar^]
Expand Down
21 changes: 15 additions & 6 deletions extended/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ dependencies {
implementation project(':common')
implementation group: 'com.unboundid', name: 'unboundid-ldapsdk', version: '6.0.11'
implementation group: 'org.jsoup', name: 'jsoup', version: '1.15.3'
implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
implementation group: 'org.apache.commons', name: 'commons-csv', version: '1.10.0', {
exclude group: 'org.apache.commons', module: 'commons-io'
exclude group: 'org.apache.commons', module: 'commons-lang3'
Expand All @@ -102,8 +101,12 @@ dependencies {
// same version as the one included in neo4j `lib`
compileOnly group: 'org.neo4j.driver', name: 'neo4j-java-driver', version: '5.25.0'

compileOnly group: 'org.apache.poi', name: 'poi', version: '5.1.0'
compileOnly group: 'org.apache.poi', name: 'poi-ooxml', version: '5.1.0'
compileOnly group: 'org.apache.poi', name: 'poi', version: '5.1.0', {
exclude group: 'org.apache.commons', module: 'commons-collections4'
}
compileOnly group: 'org.apache.poi', name: 'poi-ooxml', version: '5.1.0', {
exclude group: 'org.apache.commons', module: 'commons-collections4'
}
compileOnly group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '4.10.0', {
exclude group: 'com.google.guava', module: 'guava'
}
Expand Down Expand Up @@ -134,8 +137,12 @@ dependencies {
// These dependencies affect the tests only, they will not be packaged in the resulting .jar
testImplementation project(':test-utils')
testImplementation project(':core')
testImplementation group: 'org.apache.poi', name: 'poi', version: '5.1.0'
testImplementation group: 'org.apache.poi', name: 'poi-ooxml', version: '5.1.0'
testImplementation group: 'org.apache.poi', name: 'poi', version: '5.1.0', {
exclude group: 'org.apache.commons', module: 'commons-collections4'
}
testImplementation group: 'org.apache.poi', name: 'poi-ooxml', version: '5.1.0', {
exclude group: 'org.apache.commons', module: 'commons-collections4'
}
testImplementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '4.10.0'
testImplementation group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '5.4.0'
testImplementation group: 'com.github.stefanbirkner', name: 'system-rules', version: '1.19.0'
Expand All @@ -154,7 +161,9 @@ dependencies {
testImplementation group: 'org.zapodot', name: 'embedded-ldap-junit', version: '0.9.0'
testImplementation group: 'org.mockito', name: 'mockito-core', version: '5.4.0'
testImplementation group: 'org.apache.parquet', name: 'parquet-hadoop', version: '1.13.1', withoutServers
testImplementation group: 'com.opencsv', name: 'opencsv', version: '5.7.1'
testImplementation group: 'com.opencsv', name: 'opencsv', version: '5.7.1', {
exclude group: 'org.apache.commons', module: 'commons-collections4'
}

configurations.all {
exclude group: 'org.slf4j', module: 'slf4j-nop'
Expand Down
4 changes: 2 additions & 2 deletions extended/src/main/java/apoc/agg/Rollup.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package apoc.agg;

import apoc.Extended;
import apoc.util.ExtendedListUtils;
import apoc.util.Util;
import org.apache.commons.collections4.ListUtils;
import org.neo4j.graphdb.Entity;
import org.neo4j.procedure.Description;
import org.neo4j.procedure.Name;
Expand Down Expand Up @@ -106,7 +106,7 @@ public void aggregate(
for (int i = 0; i <= groupKey.size(); i++) {
// add NULL_ROLLUP to remaining elements,
// e.g. `[<firstGroupKey>, `NULL_ROLLUP`, `NULL_ROLLUP`]`
List<Object> partialKey = ListUtils.union(groupKey.subList(0, i), Collections.nCopies(groupKey.size() - i, NULL_ROLLUP));
List<Object> partialKey = ExtendedListUtils.union(groupKey.subList(0, i), Collections.nCopies(groupKey.size() - i, NULL_ROLLUP));
if (!rolledUpData.containsKey(partialKey)) {
rolledUpData.put(partialKey, new HashMap<>());
}
Expand Down
2 changes: 1 addition & 1 deletion extended/src/main/java/apoc/coll/CollExtended.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package apoc.coll;

import apoc.Extended;
import org.apache.commons.collections4.CollectionUtils;
import apoc.util.CollectionUtils;
import org.neo4j.procedure.Description;
import org.neo4j.procedure.Name;
import org.neo4j.procedure.UserFunction;
Expand Down
9 changes: 4 additions & 5 deletions extended/src/main/java/apoc/dv/VirtualizedResource.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package apoc.dv;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import apoc.util.ExtendedMapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;

Expand Down Expand Up @@ -70,11 +69,11 @@ private void validateQueryParams(Object queryParams) {
throw new IllegalArgumentException("Query Params cannot be null");
}
final int actualSize;
if (queryParams instanceof Collection) {
actualSize = CollectionUtils.size(queryParams);
if (queryParams instanceof Collection collection) {
actualSize = collection.size();
} else if (queryParams instanceof Map) {
final Map<String, Object> parameterMap = (Map<String, Object>) queryParams;
actualSize = MapUtils.size(parameterMap);
actualSize = ExtendedMapUtils.size(parameterMap);
Set<String> setParams = params.stream()
.collect(Collectors.toSet());
final Set<String> actualParams = parameterMap.keySet().stream().map(p -> "$" + p).collect(Collectors.toSet());
Expand Down
4 changes: 2 additions & 2 deletions extended/src/main/java/apoc/export/xls/ExportXlsHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import apoc.export.util.ProgressReporter;
import apoc.result.ExportProgressInfo;
import apoc.result.ProgressInfo;
import org.apache.commons.collections4.ListUtils;
import apoc.util.ExtendedListUtils;
import org.apache.commons.lang3.tuple.Triple;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
Expand Down Expand Up @@ -144,7 +144,7 @@ private static void dumpSubGraph(SubGraph subgraph, XlsExportConfig config, Prog
List<String> keys = triple.getRight();
Row row = sheet.getRow(0);
int cellNum = 0;
for (String key: ListUtils.union(magicKeys,keys)) {
for (String key: ExtendedListUtils.union(magicKeys,keys)) {
sheet.autoSizeColumn(cellNum);
Cell cell = row.createCell(cellNum++);
cell.setCellValue(key);
Expand Down
26 changes: 26 additions & 0 deletions extended/src/main/java/apoc/util/ExtendedListUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package apoc.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class ExtendedListUtils {

/**
* Returns a new list containing the second list appended to the
* first list. The {@link List#addAll(Collection)} operation is
* used to append the two given lists into a new list.
*
* @param <E> the element type
* @param list1 the first list
* @param list2 the second list
* @return a new list containing the union of those lists
* @throws NullPointerException if either list is null
*/
public static <E> List<E> union(final List<? extends E> list1, final List<? extends E> list2) {
final ArrayList<E> result = new ArrayList<>(list1.size() + list2.size());
result.addAll(list1);
result.addAll(list2);
return result;
}
}
14 changes: 14 additions & 0 deletions extended/src/main/java/apoc/util/ExtendedMapUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package apoc.util;

import java.util.Map;

public class ExtendedMapUtils {

public static int size(final Map<?, ?> map) {
return map == null ? 0 : map.size();
}

public static boolean isEmpty(final Map<?,?> map) {
return map == null || map.isEmpty();
}
}
4 changes: 2 additions & 2 deletions extended/src/main/java/apoc/uuid/UuidHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import apoc.Pools;
import apoc.SystemPropertyKeys;
import apoc.util.Util;
import org.apache.commons.collections4.IterableUtils;
import apoc.util.collection.Iterables;
import org.apache.commons.lang3.tuple.Pair;
import org.neo4j.dbms.api.DatabaseManagementService;
import org.neo4j.graphdb.GraphDatabaseService;
Expand Down Expand Up @@ -147,7 +147,7 @@ public Void beforeCommit(TransactionData txData, Transaction transaction, GraphD
final String propertyName = config.getUuidProperty();
List<Node> nodes = config.isAddToSetLabels()
? StreamSupport.stream(txData.assignedLabels().spliterator(), false).map(LabelEntry::node).collect(Collectors.toList())
: IterableUtils.toList(txData.createdNodes());
: Iterables.asList(txData.createdNodes());
try {
nodes.forEach(node -> {
if (node.hasLabel(Label.label(label)) && !node.hasProperty(propertyName)) {
Expand Down
2 changes: 1 addition & 1 deletion extended/src/main/java/apoc/vectordb/ChromaDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import apoc.ml.RestAPIConfig;
import apoc.result.ListResult;
import apoc.result.MapResult;
import org.apache.commons.collections4.CollectionUtils;
import apoc.util.CollectionUtils;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.security.URLAccessChecker;
Expand Down
4 changes: 2 additions & 2 deletions extended/src/main/java/apoc/vectordb/VectorDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import apoc.SystemPropertyKeys;
import apoc.ml.RestAPIConfig;
import apoc.result.ObjectResult;
import apoc.util.ExtendedMapUtils;
import apoc.util.JsonUtil;
import apoc.util.SystemDbUtil;
import apoc.util.Util;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.neo4j.graphdb.Entity;
import org.neo4j.graphdb.GraphDatabaseService;
Expand Down Expand Up @@ -134,7 +134,7 @@ private static Entity handleMapping(Transaction tx, VectorMappingConfig mapping,
if (mapping.getEntityKey() == null) {
return null;
}
if (MapUtils.isEmpty(metadata)) {
if (ExtendedMapUtils.isEmpty(metadata)) {
throw new RuntimeException("To use mapping config, the metadata should not be empty. Make sure you execute `YIELD metadata` on the procedure");
}
Map<String, Object> metaProps = new HashMap<>(metadata);
Expand Down
4 changes: 2 additions & 2 deletions extended/src/main/java/apoc/vectordb/VectorDbUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import apoc.ExtendedSystemPropertyKeys;
import apoc.SystemPropertyKeys;
import apoc.util.ExtendedMapUtils;
import apoc.util.Util;
import org.apache.commons.collections.MapUtils;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
Expand Down Expand Up @@ -84,7 +84,7 @@ private static Map<String, Object> getSystemDbProps(String hostOrKey, VectorDbHa
*/
private static void getMapping(Map<String, Object> config, Map<String, Object> props) {
Map mappingConfVal = (Map) config.get(MAPPING_KEY);
if ( MapUtils.isEmpty(mappingConfVal) ) {
if ( ExtendedMapUtils.isEmpty(mappingConfVal) ) {
String mappingStoreVal = (String) props.get(MAPPING_KEY);
if (mappingStoreVal != null) {
config.put( MAPPING_KEY, Util.fromJson(mappingStoreVal, Map.class) );
Expand Down
20 changes: 5 additions & 15 deletions extra-dependencies/xls/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,9 @@ jar {
}

dependencies {
implementation group: 'org.apache.poi', name: 'poi', version: '5.1.0', {
exclude group: 'org.apache.logging.log4j'
}
implementation group: 'org.apache.poi', name: 'poi-ooxml-lite', version: '5.1.0', {
exclude group: 'org.apache.logging.log4j'
}
implementation group: 'org.apache.poi', name: 'poi-ooxml', version: '5.1.0' , {
exclude group: 'org.apache.commons', module: 'commons-compress'
exclude group: 'org.apache.logging.log4j'
}
implementation group: 'org.apache.xmlbeans', name: 'xmlbeans', version: '5.0.2', {
exclude group: 'org.apache.logging.log4j'
}
implementation group: 'com.github.virtuald', name: 'curvesapi', version: '1.06'
implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
implementation group: 'org.apache.poi', name: 'poi', version: '5.2.5', commonExclusions
implementation group: 'org.apache.poi', name: 'poi-ooxml-lite', version: '5.2.5', commonExclusions
implementation group: 'org.apache.poi', name: 'poi-ooxml', version: '5.2.5' , commonExclusions
implementation group: 'org.apache.xmlbeans', name: 'xmlbeans', version: '5.2.1', commonExclusions
implementation group: 'com.github.virtuald', name: 'curvesapi', version: '1.08', commonExclusions
}

0 comments on commit 7dfef90

Please sign in to comment.