From 24eaf561364641a0eda05fc0aa4fbae26ffe3189 Mon Sep 17 00:00:00 2001 From: yahavi Date: Sun, 16 Jun 2024 11:11:50 +0300 Subject: [PATCH] Remove commons-collections and add Multimaps --- .github/workflows/integrationTests.yml | 2 - .../build/api/multiMap/ListMultimap.java | 42 +++++ .../jfrog/build/api/multiMap/Multimap.java | 144 ++++++++++++++++++ .../jfrog/build/api/multiMap/SetMultimap.java | 33 ++++ .../build/api/multiMap/ListMultimapTest.java | 20 +++ .../build/api/multiMap/MultimapTest.java | 113 ++++++++++++++ .../build/api/multiMap/SetMultimapTest.java | 19 +++ .../docker/extractor/BuildDockerCreator.java | 12 +- .../docker/extractor/DockerPush.java | 12 +- .../docker/extractor/DockerExtractorTest.java | 9 +- .../extractor/go/extractor/GoPublish.java | 10 +- .../go/extractor/GoExtractorTest.java | 6 +- .../artifactory/task/ArtifactoryTask.java | 8 +- .../artifactory/task/helper/TaskHelper.java | 6 +- .../extractor/npm/extractor/NpmPublish.java | 10 +- .../npm/extractor/NpmExtractorTest.java | 19 ++- .../clientConfiguration/ArtifactSpecs.java | 8 +- .../ArtifactoryClientConfiguration.java | 4 +- .../artifactory/ArtifactoryManager.java | 4 +- .../artifactory/services/SetProperties.java | 15 +- .../deploy/DeployDetails.java | 18 +-- .../util/DeploymentUrlUtils.java | 4 +- .../util/PublishedItemsHelper.java | 14 +- .../spec/SingleSpecDeploymentProducer.java | 6 +- .../util/spec/SpecDeploymentProducer.java | 6 +- .../util/spec/SpecsHelper.java | 17 ++- .../util/spec/UploadSpecHelper.java | 12 +- .../client/DeploymentUrlUtilsTest.java | 6 +- .../util/PublishedItemsHelperTest.java | 36 ++--- build.gradle | 1 - 30 files changed, 492 insertions(+), 124 deletions(-) create mode 100644 build-info-api/src/main/java/org/jfrog/build/api/multiMap/ListMultimap.java create mode 100644 build-info-api/src/main/java/org/jfrog/build/api/multiMap/Multimap.java create mode 100644 build-info-api/src/main/java/org/jfrog/build/api/multiMap/SetMultimap.java create mode 100644 build-info-api/src/test/java/org/jfrog/build/api/multiMap/ListMultimapTest.java create mode 100644 build-info-api/src/test/java/org/jfrog/build/api/multiMap/MultimapTest.java create mode 100644 build-info-api/src/test/java/org/jfrog/build/api/multiMap/SetMultimapTest.java diff --git a/.github/workflows/integrationTests.yml b/.github/workflows/integrationTests.yml index ccf86093f..564c642f8 100644 --- a/.github/workflows/integrationTests.yml +++ b/.github/workflows/integrationTests.yml @@ -1,8 +1,6 @@ name: Integration Tests on: push: - branches: - - master # Triggers the workflow on labeled PRs only. pull_request_target: types: [ labeled ] diff --git a/build-info-api/src/main/java/org/jfrog/build/api/multiMap/ListMultimap.java b/build-info-api/src/main/java/org/jfrog/build/api/multiMap/ListMultimap.java new file mode 100644 index 000000000..234a9336c --- /dev/null +++ b/build-info-api/src/main/java/org/jfrog/build/api/multiMap/ListMultimap.java @@ -0,0 +1,42 @@ +package org.jfrog.build.api.multiMap; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.Map; + +/** + * A multimap that uses a {@link LinkedList} to store the values. + * + * @param + * @param + */ +public class ListMultimap extends Multimap { + + /** + * Default constructor. + */ + public ListMultimap() { + super(); + } + + /** + * Constructor that accepts a map. + * + * @param map the map + */ + public ListMultimap(Map map) { + super(map); + } + + /** + * Put a key-value pair into the multimap. + * + * @param key the key + * @param value the value + */ + public void put(Key key, Value value) { + Collection currentValue = multiMap.getOrDefault(key, new LinkedList<>()); + currentValue.add(value); + multiMap.put(key, currentValue); + } +} diff --git a/build-info-api/src/main/java/org/jfrog/build/api/multiMap/Multimap.java b/build-info-api/src/main/java/org/jfrog/build/api/multiMap/Multimap.java new file mode 100644 index 000000000..e355e417b --- /dev/null +++ b/build-info-api/src/main/java/org/jfrog/build/api/multiMap/Multimap.java @@ -0,0 +1,144 @@ +package org.jfrog.build.api.multiMap; + +import java.io.Serializable; +import java.util.*; + +public abstract class Multimap implements Serializable { + private static final long serialVersionUID = 1L; + + Multimap() { + } + + Multimap(Map map) { + map.forEach(this::put); + } + + Map> multiMap = new HashMap<>(); + + /** + * Put a key-value pair into the multimap. + * + * @param key the key + * @param value the value + */ + public abstract void put(Key key, Value value); + + /** + * Get all values for a key. + * + * @param key the key + * @return a collection of values for the key + */ + public Collection get(Key key) { + return multiMap.get(key); + } + + /** + * Put all key-value pairs from a map into the multimap. + * + * @param map the map + */ + public void putAll(Map map) { + for (Map.Entry entry : map.entrySet()) { + put(entry.getKey(), entry.getValue()); + } + } + + /** + * Put all key-value pairs from a multimap into the multimap. + * + * @param multimap the multimap + */ + public void putAll(Multimap multimap) { + for (Map.Entry> entry : multimap.multiMap.entrySet()) { + for (Value value : entry.getValue()) { + put(entry.getKey(), value); + } + } + } + + /** + * Put all values for a key into the multimap. + * + * @param key the key + * @param values the values + */ + public void putAll(Key key, Collection values) { + for (Value value : values) { + put(key, value); + } + } + + /** + * Get all key-value pairs in the multimap. + * + * @return a set of key-value pairs + */ + public Set> entries() { + Set> entries = new HashSet<>(); + for (Map.Entry> entry : multiMap.entrySet()) { + for (Value value : entry.getValue()) { + entries.add(new AbstractMap.SimpleEntry<>(entry.getKey(), value)); + } + } + return entries; + } + + /** + * Get the underlying map. + * + * @return the map + */ + public Map> asMap() { + return multiMap; + } + + /** + * Get all keys in the multimap. + * + * @return a set of keys + */ + public Set keySet() { + return multiMap.keySet(); + } + + /** + * Check if the multimap contains a value. + * + * @param value the value + * @return true if the multimap contains the value + */ + public boolean containsValue(Value value) { + for (Collection values : multiMap.values()) { + if (values.contains(value)) { + return true; + } + } + return false; + } + + /** + * Get the number of key-value pairs in the multimap. + * + * @return the number of key-value pairs + */ + public int size() { + return multiMap.size(); + } + + /** + * Check if the multimap is empty. + * + * @return true if the multimap is empty + */ + public boolean isEmpty() { + return multiMap.isEmpty(); + } + + /** + * Clear the multimap. + */ + public void clear() { + multiMap.clear(); + } +} diff --git a/build-info-api/src/main/java/org/jfrog/build/api/multiMap/SetMultimap.java b/build-info-api/src/main/java/org/jfrog/build/api/multiMap/SetMultimap.java new file mode 100644 index 000000000..6f57f48b4 --- /dev/null +++ b/build-info-api/src/main/java/org/jfrog/build/api/multiMap/SetMultimap.java @@ -0,0 +1,33 @@ +package org.jfrog.build.api.multiMap; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; + +/** + * A multimap that uses a {@link HashSet} to store the values. + * + * @param + * @param + */ +public class SetMultimap extends Multimap { + public SetMultimap() { + super(); + } + + public SetMultimap(Map map) { + super(map); + } + + /** + * Put a key-value pair into the multimap. + * + * @param key the key + * @param value the value + */ + public void put(Key key, Value value) { + Collection currentValue = multiMap.getOrDefault(key, new HashSet<>()); + currentValue.add(value); + multiMap.put(key, currentValue); + } +} diff --git a/build-info-api/src/test/java/org/jfrog/build/api/multiMap/ListMultimapTest.java b/build-info-api/src/test/java/org/jfrog/build/api/multiMap/ListMultimapTest.java new file mode 100644 index 000000000..8a2469dd7 --- /dev/null +++ b/build-info-api/src/test/java/org/jfrog/build/api/multiMap/ListMultimapTest.java @@ -0,0 +1,20 @@ +package org.jfrog.build.api.multiMap; + +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; + +@Test +public class ListMultimapTest { + + public void testPutDuplicated() { + Multimap multimap = new ListMultimap<>(); + multimap.put("key", "value"); + multimap.put("key", "value"); + String[] values = multimap.get("key").toArray(new String[0]); + + assertEquals(values.length, 2); + assertEquals(values[0], "value"); + assertEquals(values[1], "value"); + } +} diff --git a/build-info-api/src/test/java/org/jfrog/build/api/multiMap/MultimapTest.java b/build-info-api/src/test/java/org/jfrog/build/api/multiMap/MultimapTest.java new file mode 100644 index 000000000..ecfb9e44d --- /dev/null +++ b/build-info-api/src/test/java/org/jfrog/build/api/multiMap/MultimapTest.java @@ -0,0 +1,113 @@ +package org.jfrog.build.api.multiMap; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +public class MultimapTest { + + @DataProvider + private Object[][] testCases() { + return new Object[][]{ + {new ListMultimap()}, + {new SetMultimap()} + }; + } + + @Test(dataProvider = "testCases") + public void testPut(Multimap multimap) { + multimap.put("key", "value1"); + multimap.put("key", "value2"); + assertTrue(multimap.get("key").contains("value1")); + assertTrue(multimap.get("key").contains("value2")); + } + + @Test(dataProvider = "testCases") + public void testPutAllMultimap(Multimap multimap) { + Multimap otherMultimap = new ListMultimap<>(); + otherMultimap.put("key", "value1"); + otherMultimap.put("key", "value2"); + multimap.putAll(otherMultimap); + assertTrue(multimap.get("key").contains("value1")); + assertTrue(multimap.get("key").contains("value2")); + } + + @Test(dataProvider = "testCases") + public void testPutAllCollection(Multimap multimap) { + List otherCollection = new ArrayList<>(); + otherCollection.add("value1"); + otherCollection.add("value2"); + multimap.putAll("key", otherCollection); + assertTrue(multimap.get("key").contains("value1")); + assertTrue(multimap.get("key").contains("value2")); + } + + @Test(dataProvider = "testCases") + public void testPutAllMap(Multimap multimap) { + Map otherMap = new HashMap<>(); + otherMap.put("key1", "value1"); + otherMap.put("key2", "value2"); + multimap.putAll(otherMap); + assertTrue(multimap.get("key1").contains("value1")); + assertTrue(multimap.get("key2").contains("value2")); + } + + @Test(dataProvider = "testCases") + public void testEntries(Multimap multimap) { + multimap.put("key1", "value1"); + multimap.put("key2", "value2"); + assertTrue(multimap.entries().contains(new HashMap.SimpleEntry<>("key1", "value1"))); + assertTrue(multimap.entries().contains(new HashMap.SimpleEntry<>("key2", "value2"))); + } + + @Test(dataProvider = "testCases") + public void testAsMap(Multimap multimap) { + multimap.put("key1", "value1"); + multimap.put("key2", "value2"); + assertTrue(multimap.asMap().containsKey("key1")); + assertTrue(multimap.asMap().containsKey("key2")); + } + + @Test(dataProvider = "testCases") + public void testKeySet(Multimap multimap) { + multimap.put("key1", "value1"); + multimap.put("key2", "value2"); + assertTrue(multimap.keySet().contains("key1")); + assertTrue(multimap.keySet().contains("key2")); + } + + @Test(dataProvider = "testCases") + public void testContainsValue(Multimap multimap) { + multimap.put("key1", "value1"); + multimap.put("key2", "value2"); + assertTrue(multimap.containsValue("value1")); + assertTrue(multimap.containsValue("value2")); + } + + @Test(dataProvider = "testCases") + public void testSize(Multimap multimap) { + multimap.put("key1", "value1"); + multimap.put("key2", "value2"); + assertEquals(multimap.size(), 2); + } + + @Test(dataProvider = "testCases") + public void testIsEmpty(Multimap multimap) { + assertTrue(multimap.isEmpty()); + } + + @Test(dataProvider = "testCases") + public void testClear(Multimap multimap) { + multimap.put("key1", "value1"); + multimap.put("key2", "value2"); + multimap.clear(); + assertTrue(multimap.isEmpty()); + } +} diff --git a/build-info-api/src/test/java/org/jfrog/build/api/multiMap/SetMultimapTest.java b/build-info-api/src/test/java/org/jfrog/build/api/multiMap/SetMultimapTest.java new file mode 100644 index 000000000..ffc102f5e --- /dev/null +++ b/build-info-api/src/test/java/org/jfrog/build/api/multiMap/SetMultimapTest.java @@ -0,0 +1,19 @@ +package org.jfrog.build.api.multiMap; + +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; + +@Test +public class SetMultimapTest { + + public void testPutDuplicated() { + Multimap multimap = new SetMultimap<>(); + multimap.put("key", "value"); + multimap.put("key", "value"); + String[] values = multimap.get("key").toArray(new String[0]); + + assertEquals(values.length, 1); + assertEquals(values[0], "value"); + } +} diff --git a/build-info-extractor-docker/src/main/java/org/jfrog/build/extractor/docker/extractor/BuildDockerCreator.java b/build-info-extractor-docker/src/main/java/org/jfrog/build/extractor/docker/extractor/BuildDockerCreator.java index a514fb1cc..243818f08 100644 --- a/build-info-extractor-docker/src/main/java/org/jfrog/build/extractor/docker/extractor/BuildDockerCreator.java +++ b/build-info-extractor-docker/src/main/java/org/jfrog/build/extractor/docker/extractor/BuildDockerCreator.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.collections4.MultiValuedMap; -import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; +import org.jfrog.build.api.multiMap.ListMultimap; +import org.jfrog.build.api.multiMap.Multimap; import org.jfrog.build.api.util.Log; import org.jfrog.build.extractor.ci.BuildInfo; import org.jfrog.build.extractor.ci.Module; @@ -35,7 +35,7 @@ import static org.jfrog.build.extractor.packageManager.PackageManagerUtils.createArtifactoryClientConfiguration; public class BuildDockerCreator extends PackageManagerExtractor { - private final MultiValuedMap artifactProperties; + private final Multimap artifactProperties; private final ArtifactoryManagerBuilder artifactoryManagerBuilder; private final ImageFileType imageFileType; private final String sourceRepo; @@ -56,7 +56,7 @@ enum ImageFileType { * @param artifactProperties - Properties to be attached to the docker layers deployed to Artifactory. */ public BuildDockerCreator(ArtifactoryManagerBuilder artifactoryManagerBuilder, String imageFile, ImageFileType imageFileType, - MultiValuedMap artifactProperties, String sourceRepo, Log logger) { + Multimap artifactProperties, String sourceRepo, Log logger) { this.artifactoryManagerBuilder = artifactoryManagerBuilder; this.artifactProperties = artifactProperties; this.sourceRepo = sourceRepo; @@ -92,7 +92,7 @@ public static void main(String[] ignored) { BuildDockerCreator dockerBuildCreate = new BuildDockerCreator(artifactoryManagerBuilder, imageFile, imageFileType, - new ArrayListValuedHashMap<>(clientConfiguration.publisher.getMatrixParams()), + new ListMultimap<>(clientConfiguration.publisher.getMatrixParams()), clientConfiguration.publisher.getRepoKey(), clientConfiguration.getLog()); @@ -137,7 +137,7 @@ public BuildInfo execute() { /** * Update each layer's properties with artifactProperties. */ - private void setImageLayersProps(DockerLayers layers, MultiValuedMap artifactProperties, ArtifactoryManagerBuilder artifactoryManagerBuilder) throws IOException { + private void setImageLayersProps(DockerLayers layers, Multimap artifactProperties, ArtifactoryManagerBuilder artifactoryManagerBuilder) throws IOException { if (layers == null) { return; } diff --git a/build-info-extractor-docker/src/main/java/org/jfrog/build/extractor/docker/extractor/DockerPush.java b/build-info-extractor-docker/src/main/java/org/jfrog/build/extractor/docker/extractor/DockerPush.java index ebf669c68..05a97728c 100644 --- a/build-info-extractor-docker/src/main/java/org/jfrog/build/extractor/docker/extractor/DockerPush.java +++ b/build-info-extractor-docker/src/main/java/org/jfrog/build/extractor/docker/extractor/DockerPush.java @@ -1,9 +1,9 @@ package org.jfrog.build.extractor.docker.extractor; -import org.apache.commons.collections4.MultiValuedMap; -import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; +import org.jfrog.build.api.multiMap.ListMultimap; +import org.jfrog.build.api.multiMap.Multimap; import org.jfrog.build.api.util.Log; import org.jfrog.build.extractor.ci.BuildInfo; import org.jfrog.build.extractor.ci.Module; @@ -22,7 +22,7 @@ import static org.jfrog.build.extractor.packageManager.PackageManagerUtils.createArtifactoryClientConfiguration; public class DockerPush extends DockerCommand { - private final MultiValuedMap artifactProperties; + private final Multimap artifactProperties; /** @@ -37,7 +37,7 @@ public class DockerPush extends DockerCommand { * @param env - Environment variables to use during docker push execution. */ public DockerPush(ArtifactoryManagerBuilder artifactoryManagerBuilder, - String imageTag, String host, MultiValuedMap artifactProperties, String targetRepository, String username, + String imageTag, String host, Multimap artifactProperties, String targetRepository, String username, String password, Log logger, Map env) { super(artifactoryManagerBuilder, imageTag, host, targetRepository, username, password, logger, env); this.artifactProperties = artifactProperties; @@ -59,7 +59,7 @@ public static void main(String[] ignored) { DockerPush dockerPush = new DockerPush(artifactoryManagerBuilder, dockerHandler.getImageTag(), dockerHandler.getHost(), - new ArrayListValuedHashMap<>(clientConfiguration.publisher.getMatrixParams()), + new ListMultimap<>(clientConfiguration.publisher.getMatrixParams()), clientConfiguration.publisher.getRepoKey(), clientConfiguration.publisher.getUsername(), clientConfiguration.publisher.getPassword(), @@ -105,7 +105,7 @@ public BuildInfo execute() { /** * Update each layer's properties with artifactProperties. */ - private void setImageLayersProps(DockerLayers layers, MultiValuedMap artifactProperties, ArtifactoryManagerBuilder artifactoryManagerBuilder) throws IOException { + private void setImageLayersProps(DockerLayers layers, Multimap artifactProperties, ArtifactoryManagerBuilder artifactoryManagerBuilder) throws IOException { if (layers == null) { return; } diff --git a/build-info-extractor-docker/src/test/java/org/jfrog/build/extractor/docker/extractor/DockerExtractorTest.java b/build-info-extractor-docker/src/test/java/org/jfrog/build/extractor/docker/extractor/DockerExtractorTest.java index e31acf8c5..8591345c3 100644 --- a/build-info-extractor-docker/src/test/java/org/jfrog/build/extractor/docker/extractor/DockerExtractorTest.java +++ b/build-info-extractor-docker/src/test/java/org/jfrog/build/extractor/docker/extractor/DockerExtractorTest.java @@ -2,14 +2,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; -import org.apache.commons.collections4.MultiValuedMap; -import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; import org.apache.commons.compress.utils.Sets; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.SystemUtils; import org.jfrog.build.IntegrationTestsBase; -import org.jfrog.build.extractor.ci.Module; +import org.jfrog.build.api.multiMap.ListMultimap; +import org.jfrog.build.api.multiMap.Multimap; import org.jfrog.build.extractor.ci.*; import org.jfrog.build.extractor.docker.DockerJavaWrapper; import org.jfrog.build.extractor.executor.CommandExecutor; @@ -43,7 +42,7 @@ public class DockerExtractorTest extends IntegrationTestsBase { private static final String SHORT_IMAGE_TAG_VIRTUAL = "3"; private static final String EXPECTED_REMOTE_PATH_KANIKO = "hello-world/latest"; private static final String DOCKER_HOST = "BITESTS_ARTIFACTORY_DOCKER_HOST"; - private final MultiValuedMap artifactProperties; + private final Multimap artifactProperties; private String pullImageFromVirtual; private String virtualDomainName; private String host; @@ -56,7 +55,7 @@ public DockerExtractorTest() { localRepo1 = getKeyWithTimestamp(DOCKER_LOCAL_REPO); remoteRepo = getKeyWithTimestamp(DOCKER_REMOTE_REPO); virtualRepo = getKeyWithTimestamp(DOCKER_VIRTUAL_REPO); - artifactProperties = new ArrayListValuedHashMap() {{ + artifactProperties = new ListMultimap() {{ put("build.name", "docker-push-test"); put("build.number", "1"); put("build.timestamp", "321"); diff --git a/build-info-extractor-go/src/main/java/org/jfrog/build/extractor/go/extractor/GoPublish.java b/build-info-extractor-go/src/main/java/org/jfrog/build/extractor/go/extractor/GoPublish.java index 4283ada4a..cb4efa352 100644 --- a/build-info-extractor-go/src/main/java/org/jfrog/build/extractor/go/extractor/GoPublish.java +++ b/build-info-extractor-go/src/main/java/org/jfrog/build/extractor/go/extractor/GoPublish.java @@ -1,12 +1,12 @@ package org.jfrog.build.extractor.go.extractor; import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.collections4.MultiValuedMap; -import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; import org.apache.commons.compress.archivers.zip.ZipFile; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.jfrog.build.api.builder.ModuleType; +import org.jfrog.build.api.multiMap.ListMultimap; +import org.jfrog.build.api.multiMap.Multimap; import org.jfrog.build.api.util.FileChecksumCalculator; import org.jfrog.build.api.util.Log; import org.jfrog.build.client.ArtifactoryUploadResponse; @@ -47,7 +47,7 @@ public class GoPublish extends GoCommand { private static final String PKG_MOD_FILE_EXTENSION = "mod"; private static final String PKG_INFO_FILE_EXTENSION = "info"; - private final MultiValuedMap properties; + private final Multimap properties; private final List artifactList = new ArrayList<>(); private final String deploymentRepo; private final String version; @@ -62,7 +62,7 @@ public class GoPublish extends GoCommand { * @param version - The package's version. * @param logger - The logger. */ - public GoPublish(ArtifactoryManagerBuilder artifactoryManagerBuilder, MultiValuedMap properties, String repo, Path path, String version, String module, Log logger) throws IOException { + public GoPublish(ArtifactoryManagerBuilder artifactoryManagerBuilder, Multimap properties, String repo, Path path, String version, String module, Log logger) throws IOException { super(artifactoryManagerBuilder, path, module, logger); this.goDriver = new GoDriver(GO_CLIENT_CMD, null, path.toFile(), logger); this.moduleName = goDriver.getModuleName(); @@ -94,7 +94,7 @@ public static void main(String[] ignored) { GoPublish goPublish = new GoPublish( artifactoryManagerBuilder, - new ArrayListValuedHashMap<>(clientConfiguration.publisher.getMatrixParams()), + new ListMultimap<>(clientConfiguration.publisher.getMatrixParams()), clientConfiguration.publisher.getRepoKey(), Paths.get(packageManagerHandler.getPath() != null ? packageManagerHandler.getPath() : ".").toAbsolutePath(), clientConfiguration.goHandler.getGoPublishedVersion(), diff --git a/build-info-extractor-go/src/test/java/org/jfrog/build/extractor/go/extractor/GoExtractorTest.java b/build-info-extractor-go/src/test/java/org/jfrog/build/extractor/go/extractor/GoExtractorTest.java index a66af038b..850b4a892 100644 --- a/build-info-extractor-go/src/test/java/org/jfrog/build/extractor/go/extractor/GoExtractorTest.java +++ b/build-info-extractor-go/src/test/java/org/jfrog/build/extractor/go/extractor/GoExtractorTest.java @@ -1,11 +1,11 @@ package org.jfrog.build.extractor.go.extractor; -import org.apache.commons.collections4.MultiMapUtils; -import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.jfrog.build.IntegrationTestsBase; +import org.jfrog.build.api.multiMap.ListMultimap; +import org.jfrog.build.api.multiMap.Multimap; import org.jfrog.build.extractor.ci.*; import org.jfrog.build.extractor.clientConfiguration.ArtifactoryManagerBuilder; import org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails; @@ -175,7 +175,7 @@ public void goRunTest(Project project, String args, ArtifactoryManagerBuilder ar @Test public void goRunPublishTest() { Path projectDir = null; - MultiValuedMap properties = MultiMapUtils.newListValuedHashMap(); + Multimap properties = new ListMultimap<>(); try { // Run Go build on project1 locally Project project = Project.PROJECT_1; diff --git a/build-info-extractor-gradle/src/main/groovy/org/jfrog/gradle/plugin/artifactory/task/ArtifactoryTask.java b/build-info-extractor-gradle/src/main/groovy/org/jfrog/gradle/plugin/artifactory/task/ArtifactoryTask.java index 8f2f63d3e..2e6079ca9 100644 --- a/build-info-extractor-gradle/src/main/groovy/org/jfrog/gradle/plugin/artifactory/task/ArtifactoryTask.java +++ b/build-info-extractor-gradle/src/main/groovy/org/jfrog/gradle/plugin/artifactory/task/ArtifactoryTask.java @@ -1,8 +1,6 @@ package org.jfrog.gradle.plugin.artifactory.task; import groovy.lang.Closure; -import org.apache.commons.collections4.MultiMapUtils; -import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.lang3.StringUtils; import org.gradle.api.Action; import org.gradle.api.DefaultTask; @@ -17,6 +15,8 @@ import org.gradle.api.tasks.Optional; import org.gradle.api.tasks.*; import org.gradle.util.ConfigureUtil; +import org.jfrog.build.api.multiMap.ListMultimap; +import org.jfrog.build.api.multiMap.Multimap; import org.jfrog.build.extractor.clientConfiguration.ArtifactSpecs; import org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration; import org.jfrog.gradle.plugin.artifactory.ArtifactoryPluginUtil; @@ -162,10 +162,10 @@ public void setCiServerBuild() { public final Set deployDetails = new TreeSet<>(); - private final MultiValuedMap properties = MultiMapUtils.newListValuedHashMap(); + private final Multimap properties = new ListMultimap<>(); @Input - public MultiValuedMap getProperties() { + public Multimap getProperties() { return properties; } diff --git a/build-info-extractor-gradle/src/main/groovy/org/jfrog/gradle/plugin/artifactory/task/helper/TaskHelper.java b/build-info-extractor-gradle/src/main/groovy/org/jfrog/gradle/plugin/artifactory/task/helper/TaskHelper.java index ff476410e..4ef7dbc2a 100644 --- a/build-info-extractor-gradle/src/main/groovy/org/jfrog/gradle/plugin/artifactory/task/helper/TaskHelper.java +++ b/build-info-extractor-gradle/src/main/groovy/org/jfrog/gradle/plugin/artifactory/task/helper/TaskHelper.java @@ -1,11 +1,11 @@ package org.jfrog.gradle.plugin.artifactory.task.helper; -import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.lang3.StringUtils; import org.gradle.api.Project; import org.gradle.api.Task; import org.gradle.api.logging.Logger; import org.gradle.api.logging.Logging; +import org.jfrog.build.api.multiMap.Multimap; import org.jfrog.build.extractor.clientConfiguration.ArtifactSpec; import org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration; import org.jfrog.gradle.plugin.artifactory.ArtifactoryPluginUtil; @@ -70,12 +70,12 @@ protected Map getPropsToAdd(PublishArtifactInfo artifact, String .name(project.getName()).version(project.getVersion().toString()) .classifier(artifact.getClassifier()) .type(artifact.getType()).build(); - MultiValuedMap artifactSpecsProperties = artifactoryTask.artifactSpecs.getProperties(spec); + Multimap artifactSpecsProperties = artifactoryTask.artifactSpecs.getProperties(spec); addProps(propsToAdd, artifactSpecsProperties); return propsToAdd; } - private void addProps(Map target, MultiValuedMap props) { + private void addProps(Map target, Multimap props) { for (Map.Entry entry : props.entries()) { // Make sure all GString are now Java Strings String key = entry.getKey(); diff --git a/build-info-extractor-npm/src/main/java/org/jfrog/build/extractor/npm/extractor/NpmPublish.java b/build-info-extractor-npm/src/main/java/org/jfrog/build/extractor/npm/extractor/NpmPublish.java index 44e0c4f25..ba21efc22 100644 --- a/build-info-extractor-npm/src/main/java/org/jfrog/build/extractor/npm/extractor/NpmPublish.java +++ b/build-info-extractor-npm/src/main/java/org/jfrog/build/extractor/npm/extractor/NpmPublish.java @@ -1,13 +1,13 @@ package org.jfrog.build.extractor.npm.extractor; -import org.apache.commons.collections4.MultiValuedMap; -import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.jfrog.build.api.builder.ModuleType; +import org.jfrog.build.api.multiMap.ListMultimap; +import org.jfrog.build.api.multiMap.Multimap; import org.jfrog.build.api.util.Log; import org.jfrog.build.client.ArtifactoryUploadResponse; import org.jfrog.build.extractor.builder.ArtifactBuilder; @@ -39,7 +39,7 @@ */ @SuppressWarnings({"unused", "WeakerAccess"}) public class NpmPublish extends NpmCommand { - private final MultiValuedMap properties; + private final Multimap properties; private Artifact deployedArtifact; private boolean tarballProvided; private final String module; @@ -54,7 +54,7 @@ public class NpmPublish extends NpmCommand { * @param logger - The logger. * @param env - Environment variables to use during npm execution. */ - public NpmPublish(ArtifactoryManagerBuilder artifactoryManagerBuilder, MultiValuedMap properties, Path path, String deploymentRepository, Log logger, Map env, String module) { + public NpmPublish(ArtifactoryManagerBuilder artifactoryManagerBuilder, Multimap properties, Path path, String deploymentRepository, Log logger, Map env, String module) { super(artifactoryManagerBuilder, deploymentRepository, logger, path, env); this.properties = properties; this.module = module; @@ -70,7 +70,7 @@ public static void main(String[] ignored) { ArtifactoryManagerBuilder artifactoryManagerBuilder = new ArtifactoryManagerBuilder().setClientConfiguration(clientConfiguration, clientConfiguration.publisher); ArtifactoryClientConfiguration.PackageManagerHandler npmHandler = clientConfiguration.packageManagerHandler; NpmPublish npmPublish = new NpmPublish(artifactoryManagerBuilder, - new ArrayListValuedHashMap<>(clientConfiguration.publisher.getMatrixParams()), + new ListMultimap<>(clientConfiguration.publisher.getMatrixParams()), Paths.get(npmHandler.getPath() != null ? npmHandler.getPath() : "."), clientConfiguration.publisher.getRepoKey(), clientConfiguration.getLog(), diff --git a/build-info-extractor-npm/src/test/java/org/jfrog/build/extractor/npm/extractor/NpmExtractorTest.java b/build-info-extractor-npm/src/test/java/org/jfrog/build/extractor/npm/extractor/NpmExtractorTest.java index a1702849d..b0282c8ef 100644 --- a/build-info-extractor-npm/src/test/java/org/jfrog/build/extractor/npm/extractor/NpmExtractorTest.java +++ b/build-info-extractor-npm/src/test/java/org/jfrog/build/extractor/npm/extractor/NpmExtractorTest.java @@ -1,12 +1,11 @@ package org.jfrog.build.extractor.npm.extractor; -import org.apache.commons.collections4.MultiMapUtils; -import org.apache.commons.collections4.MultiValuedMap; -import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.jfrog.build.IntegrationTestsBase; +import org.jfrog.build.api.multiMap.ListMultimap; +import org.jfrog.build.api.multiMap.Multimap; import org.jfrog.build.extractor.builder.DependencyBuilder; import org.jfrog.build.extractor.ci.BuildInfo; import org.jfrog.build.extractor.ci.Dependency; @@ -208,17 +207,17 @@ private void runNpmTest(Project project, Dependency[] expectedDependencies, Stri @DataProvider private Object[][] npmPublishProvider() { return new Object[][]{ - {Project.A, MultiMapUtils.emptyMultiValuedMap(), Project.A.getTargetPath(), ""}, - {Project.A, new ArrayListValuedHashMap() {{ + {Project.A, new ListMultimap<>(), Project.A.getTargetPath(), ""}, + {Project.A, new ListMultimap() {{ put("a", "b"); }}, Project.A.getTargetPath(), ""}, - {Project.B, MultiMapUtils.emptyMultiValuedMap(), Project.B.getTargetPath(), Project.B.getPackedFileName()}, - {Project.B, new ArrayListValuedHashMap() {{ + {Project.B, new ListMultimap<>(), Project.B.getTargetPath(), Project.B.getPackedFileName()}, + {Project.B, new ListMultimap() {{ put("a", "b"); put("c", "d"); }}, Project.B.getTargetPath(), Project.B.getPackedFileName()}, - {Project.C, MultiMapUtils.emptyMultiValuedMap(), Project.C.getTargetPath(), ""}, - {Project.C, new ArrayListValuedHashMap() {{ + {Project.C, new ListMultimap<>(), Project.C.getTargetPath(), ""}, + {Project.C, new ListMultimap() {{ put("a", "b"); put("a", "d"); }}, Project.C.getTargetPath(), ""} @@ -227,7 +226,7 @@ private Object[][] npmPublishProvider() { @SuppressWarnings("unused") @Test(dataProvider = "npmPublishProvider") - public void npmPublishTest(Project project, MultiValuedMap props, String targetPath, String packageName) { + public void npmPublishTest(Project project, Multimap props, String targetPath, String packageName) { Path projectDir = null; try { // Run npm publish diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/ArtifactSpecs.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/ArtifactSpecs.java index 273e158f9..06231d65c 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/ArtifactSpecs.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/ArtifactSpecs.java @@ -1,8 +1,8 @@ package org.jfrog.build.extractor.clientConfiguration; -import org.apache.commons.collections4.MultiMapUtils; -import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.lang3.StringUtils; +import org.jfrog.build.api.multiMap.ListMultimap; +import org.jfrog.build.api.multiMap.Multimap; import java.util.LinkedList; import java.util.Map; @@ -41,8 +41,8 @@ public ArtifactSpecs(String specsNotation) { * @param spec * @return */ - public MultiValuedMap getProperties(ArtifactSpec spec) { - MultiValuedMap props = MultiMapUtils.newListValuedHashMap(); + public Multimap getProperties(ArtifactSpec spec) { + Multimap props = new ListMultimap<>(); for (ArtifactSpec matcherSpec : this) { if (matcherSpec.matches(spec)) { Map matcherSpecProperties = matcherSpec.getProperties(); diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/ArtifactoryClientConfiguration.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/ArtifactoryClientConfiguration.java index 256938efa..445e066b9 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/ArtifactoryClientConfiguration.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/ArtifactoryClientConfiguration.java @@ -1,7 +1,7 @@ package org.jfrog.build.extractor.clientConfiguration; -import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.lang3.StringUtils; +import org.jfrog.build.api.multiMap.Multimap; import org.jfrog.build.api.util.CommonUtils; import org.jfrog.build.api.util.Log; import org.jfrog.build.extractor.ci.BuildInfo; @@ -883,7 +883,7 @@ public void addMatrixParams(Map vars) { } } - public void addMatrixParams(MultiValuedMap vars) { + public void addMatrixParams(Multimap vars) { for (Map.Entry entry : vars.entries()) { addMatrixParam(entry.getKey(), entry.getValue()); } diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/client/artifactory/ArtifactoryManager.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/client/artifactory/ArtifactoryManager.java index a4ea612cd..9ca6a9d1d 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/client/artifactory/ArtifactoryManager.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/client/artifactory/ArtifactoryManager.java @@ -1,12 +1,12 @@ package org.jfrog.build.extractor.clientConfiguration.client.artifactory; -import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.lang3.StringUtils; import org.apache.http.Header; import org.jfrog.build.api.dependency.BuildPatternArtifacts; import org.jfrog.build.api.dependency.BuildPatternArtifactsRequest; import org.jfrog.build.api.dependency.PatternResultFileSet; import org.jfrog.build.api.dependency.PropertySearchResult; +import org.jfrog.build.api.multiMap.Multimap; import org.jfrog.build.api.release.Distribution; import org.jfrog.build.api.release.Promotion; import org.jfrog.build.api.search.AqlSearchResult; @@ -72,7 +72,7 @@ public void setProperties(String relativePath, String properties, boolean encode setPropertiesService.execute(jfrogHttpClient); } - public void setProperties(String relativePath, MultiValuedMap properties, boolean encodeProperties) throws IOException { + public void setProperties(String relativePath, Multimap properties, boolean encodeProperties) throws IOException { SetProperties setPropertiesService = new SetProperties(relativePath, properties, encodeProperties, log); setPropertiesService.execute(jfrogHttpClient); } diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/client/artifactory/services/SetProperties.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/client/artifactory/services/SetProperties.java index d0e648cd4..41be473df 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/client/artifactory/services/SetProperties.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/client/artifactory/services/SetProperties.java @@ -1,11 +1,12 @@ package org.jfrog.build.extractor.clientConfiguration.client.artifactory.services; -import org.apache.commons.collections4.MultiMapUtils; -import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpEntity; import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpRequestBase; +import org.jfrog.build.api.multiMap.ListMultimap; +import org.jfrog.build.api.multiMap.Multimap; +import org.jfrog.build.api.multiMap.SetMultimap; import org.jfrog.build.api.util.Log; import org.jfrog.build.client.JFrogHttpClient; import org.jfrog.build.extractor.clientConfiguration.client.VoidJFrogService; @@ -19,12 +20,12 @@ public class SetProperties extends VoidJFrogService { public static final String SET_PROPERTIES_ENDPOINT = "api/storage/"; - private final MultiValuedMap propertiesMap; + private final Multimap propertiesMap; private final boolean encodeProperties; private final String relativePath; private final String propertiesString; - private SetProperties(String relativePath, String propertiesString, MultiValuedMap propertiesMap, boolean encodeProperties, Log log) { + private SetProperties(String relativePath, String propertiesString, Multimap propertiesMap, boolean encodeProperties, Log log) { super(log); this.relativePath = relativePath; this.propertiesMap = propertiesMap; @@ -36,7 +37,7 @@ public SetProperties(String relativePath, String propertiesString, boolean encod this(relativePath, propertiesString, null, encodeProperties, log); } - public SetProperties(String relativePath, MultiValuedMap propertiesMap, boolean encodeProperties, Log log) { + public SetProperties(String relativePath, Multimap propertiesMap, boolean encodeProperties, Log log) { this(relativePath, null, propertiesMap, encodeProperties, log); } @@ -80,8 +81,8 @@ protected void ensureRequirements(JFrogHttpClient client) throws IOException { } } - private MultiValuedMap mapPropsString(String props) { - MultiValuedMap propsMap = MultiMapUtils.newListValuedHashMap(); + private Multimap mapPropsString(String props) { + Multimap propsMap = new ListMultimap<>(); String[] propsList = props.split(";"); for (String prop : propsList) { if (isNotEmpty(prop)) { diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/deploy/DeployDetails.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/deploy/DeployDetails.java index 27af64a9c..ad3b3d45a 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/deploy/DeployDetails.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/deploy/DeployDetails.java @@ -1,9 +1,9 @@ package org.jfrog.build.extractor.clientConfiguration.deploy; -import org.apache.commons.collections4.MultiMapUtils; -import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.lang3.StringUtils; import org.jfrog.build.api.BuildFileBean; +import org.jfrog.build.api.multiMap.ListMultimap; +import org.jfrog.build.api.multiMap.Multimap; import org.jfrog.build.api.producerConsumer.ProducerConsumerItem; import java.io.File; @@ -45,7 +45,7 @@ public class DeployDetails implements Comparable, Serializable, P /** * Properties to attach to the deployed file as matrix params. */ - MultiValuedMap properties; + Multimap properties; /** * Target deploy repository. */ @@ -74,7 +74,7 @@ public File getFile() { return file; } - public MultiValuedMap getProperties() { + public Multimap getProperties() { return properties; } @@ -164,7 +164,7 @@ public DeployDetails build() { public Builder bean(BuildFileBean bean) { Properties beanProperties = bean.getProperties(); if (beanProperties != null) { - MultiValuedMap multimap = MultiMapUtils.newListValuedHashMap(); + Multimap multimap = new ListMultimap<>(); beanProperties.forEach((key, value) -> multimap.put((String) key, (String) value)); deployDetails.properties = multimap; } @@ -215,7 +215,7 @@ public Builder packageType(PackageType packageType) { public Builder addProperty(String key, String value) { if (deployDetails.properties == null) { - deployDetails.properties = MultiMapUtils.newListValuedHashMap(); + deployDetails.properties = new ListMultimap<>(); } deployDetails.properties.put(key, value); return this; @@ -223,16 +223,16 @@ public Builder addProperty(String key, String value) { public Builder addProperties(Map propertiesToAdd) { if (deployDetails.properties == null) { - deployDetails.properties = MultiMapUtils.newListValuedHashMap(); + deployDetails.properties = new ListMultimap<>(); } deployDetails.properties.putAll(propertiesToAdd); return this; } - public Builder addProperties(MultiValuedMap propertiesToAdd) { + public Builder addProperties(Multimap propertiesToAdd) { if (deployDetails.properties == null) { - deployDetails.properties = MultiMapUtils.newListValuedHashMap(); + deployDetails.properties = new ListMultimap<>(); } deployDetails.properties.putAll(propertiesToAdd); diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/DeploymentUrlUtils.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/DeploymentUrlUtils.java index 9cf71f1bc..7cc6b5e25 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/DeploymentUrlUtils.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/DeploymentUrlUtils.java @@ -1,7 +1,7 @@ package org.jfrog.build.extractor.clientConfiguration.util; -import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.lang3.StringUtils; +import org.jfrog.build.api.multiMap.Multimap; import org.jfrog.build.api.util.CommonUtils; import org.jfrog.build.extractor.UrlUtils; import org.jfrog.build.extractor.clientConfiguration.ClientProperties; @@ -66,7 +66,7 @@ public static String encodePath(String unescaped) { } - public static String buildMatrixParamsString(MultiValuedMap matrixParams, boolean encodeProperties) + public static String buildMatrixParamsString(Multimap matrixParams, boolean encodeProperties) throws UnsupportedEncodingException { StringBuilder matrix = new StringBuilder(); if (matrixParams != null && !matrixParams.isEmpty()) { diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/PublishedItemsHelper.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/PublishedItemsHelper.java index 1ead29be1..b7ab1b71e 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/PublishedItemsHelper.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/PublishedItemsHelper.java @@ -16,10 +16,10 @@ package org.jfrog.build.extractor.clientConfiguration.util; -import org.apache.commons.collections4.MultiMapUtils; -import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; +import org.jfrog.build.api.multiMap.Multimap; +import org.jfrog.build.api.multiMap.SetMultimap; import org.jfrog.build.extractor.clientConfiguration.util.spec.UploadSpecHelper; import java.io.File; @@ -45,8 +45,8 @@ public class PublishedItemsHelper { * then the value is treated as a source only (target will be ""). * @return a Map containing the sources as keys and targets as values */ - public static MultiValuedMap getPublishedItemsPatternPairs(String publishedItemsPropertyValue) { - MultiValuedMap patternPairMap = MultiMapUtils.newSetValuedHashMap(); + public static Multimap getPublishedItemsPatternPairs(String publishedItemsPropertyValue) { + Multimap patternPairMap = new SetMultimap<>(); if (StringUtils.isNotBlank(publishedItemsPropertyValue)) { List patternPairs = parsePatternsFromProperty(publishedItemsPropertyValue); @@ -148,9 +148,9 @@ public static String removeDoubleDotsFromPattern(String pattern) { * @throws IOException in case of any file system exception */ @Deprecated - public static MultiValuedMap buildPublishingData(File checkoutDir, String pattern, String targetPath) + public static Multimap buildPublishingData(File checkoutDir, String pattern, String targetPath) throws IOException { - final MultiValuedMap filePathsMap = MultiMapUtils.newSetValuedHashMap(); + final Multimap filePathsMap = new SetMultimap<>(); File patternAbsolutePath = getAbsolutePath(checkoutDir, pattern); if (patternAbsolutePath.isFile()) { // The given pattern is an absolute path of just one file, let's add it to our result map @@ -211,7 +211,7 @@ public static MultiValuedMap buildPublishingData(File checkoutDir, * @return a Multimap containing the targets as keys and the files as values */ @Deprecated - public static MultiValuedMap wildCardBuildPublishingData( + public static Multimap wildCardBuildPublishingData( File checkoutDir, String pattern, String targetPath, boolean flat, boolean isRecursive, boolean regexp) { if (!regexp) { pattern = PathsUtils.pathToRegExp(pattern); diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/spec/SingleSpecDeploymentProducer.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/spec/SingleSpecDeploymentProducer.java index 1d63adcbe..279100b8d 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/spec/SingleSpecDeploymentProducer.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/spec/SingleSpecDeploymentProducer.java @@ -1,9 +1,9 @@ package org.jfrog.build.extractor.clientConfiguration.util.spec; -import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; +import org.jfrog.build.api.multiMap.Multimap; import org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails; import org.jfrog.build.extractor.clientConfiguration.util.PathsUtils; import org.jfrog.build.extractor.producerConsumer.ProducerConsumerExecutor; @@ -26,7 +26,7 @@ public class SingleSpecDeploymentProducer { private FilesGroup spec; private File workspace; - private MultiValuedMap buildProperties; + private Multimap buildProperties; private Pattern regexpPattern; private Pattern regexpExcludePattern; @@ -42,7 +42,7 @@ public class SingleSpecDeploymentProducer { private int separatorsCount; private Set symlinkSet = new HashSet<>(); - SingleSpecDeploymentProducer(FilesGroup spec, File workspace, MultiValuedMap buildProperties) { + SingleSpecDeploymentProducer(FilesGroup spec, File workspace, Multimap buildProperties) { this.spec = spec; this.workspace = workspace; this.buildProperties = buildProperties; diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/spec/SpecDeploymentProducer.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/spec/SpecDeploymentProducer.java index 79948e93a..f6a04151a 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/spec/SpecDeploymentProducer.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/spec/SpecDeploymentProducer.java @@ -1,6 +1,6 @@ package org.jfrog.build.extractor.clientConfiguration.util.spec; -import org.apache.commons.collections4.MultiValuedMap; +import org.jfrog.build.api.multiMap.Multimap; import org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails; import org.jfrog.build.extractor.producerConsumer.ProducerRunnableBase; import org.jfrog.filespecs.FileSpec; @@ -23,9 +23,9 @@ public class SpecDeploymentProducer extends ProducerRunnableBase { private FileSpec spec; private File workspace; - private MultiValuedMap buildProperties; + private Multimap buildProperties; - SpecDeploymentProducer(FileSpec spec, File workspace, MultiValuedMap buildProperties) { + SpecDeploymentProducer(FileSpec spec, File workspace, Multimap buildProperties) { this.spec = spec; this.workspace = workspace; this.buildProperties = buildProperties; diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/spec/SpecsHelper.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/spec/SpecsHelper.java index ad2b7eba9..b50c34776 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/spec/SpecsHelper.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/spec/SpecsHelper.java @@ -1,9 +1,10 @@ package org.jfrog.build.extractor.clientConfiguration.util.spec; -import org.apache.commons.collections4.MultiMapUtils; -import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; +import org.jfrog.build.api.multiMap.ListMultimap; +import org.jfrog.build.api.multiMap.Multimap; +import org.jfrog.build.api.multiMap.SetMultimap; import org.jfrog.build.api.util.Log; import org.jfrog.build.extractor.builder.ArtifactBuilder; import org.jfrog.build.extractor.ci.Artifact; @@ -57,8 +58,8 @@ public List uploadArtifactsBySpec(String uploadSpec, File workspace, return uploadArtifactsBySpec(uploadSpec, DEFAULT_NUMBER_OF_THREADS, workspace, createMultiMap(buildProperties), artifactoryManagerBuilder); } - private static MultiValuedMap createMultiMap(Map input) { - MultiValuedMap multimap = MultiMapUtils.newListValuedHashMap(); + private static Multimap createMultiMap(Map input) { + Multimap multimap = new ListMultimap<>(); for (Map.Entry entry : input.entrySet()) { multimap.put(entry.getKey(), entry.getValue()); } @@ -78,7 +79,7 @@ private static MultiValuedMap createMultiMap(Map input) { * checksums or in case of any file system exception */ public List uploadArtifactsBySpec(String uploadSpec, int numberOfThreads, File workspace, - MultiValuedMap buildProperties, + Multimap buildProperties, ArtifactoryManagerBuilder artifactoryManagerBuilder) throws Exception { FileSpec fileSpec = FileSpec.fromString(uploadSpec); FileSpecsValidation.validateUploadFileSpec(fileSpec, this.log); @@ -153,13 +154,13 @@ public boolean editPropertiesBySpec(String spec, ArtifactoryManager artifactoryM * @param props Spec's properties * @return created properties map */ - public static MultiValuedMap getPropertiesMap(String props) { - MultiValuedMap propertiesMap = MultiMapUtils.newListValuedHashMap(); + public static Multimap getPropertiesMap(String props) { + Multimap propertiesMap = new ListMultimap<>(); fillPropertiesMap(props, propertiesMap); return propertiesMap; } - public static void fillPropertiesMap(String props, MultiValuedMap propertiesMap) { + public static void fillPropertiesMap(String props, Multimap propertiesMap) { if (StringUtils.isBlank(props)) { return; } diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/spec/UploadSpecHelper.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/spec/UploadSpecHelper.java index 396b8aae3..ef8f0e32f 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/spec/UploadSpecHelper.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/spec/UploadSpecHelper.java @@ -1,11 +1,11 @@ package org.jfrog.build.extractor.clientConfiguration.util.spec; -import org.apache.commons.collections4.MultiValuedMap; -import org.apache.commons.collections4.multimap.HashSetValuedHashMap; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; +import org.jfrog.build.api.multiMap.Multimap; +import org.jfrog.build.api.multiMap.SetMultimap; import org.jfrog.build.api.util.FileChecksumCalculator; import org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails; import org.jfrog.build.extractor.clientConfiguration.util.PathsUtils; @@ -38,7 +38,7 @@ public class UploadSpecHelper { */ public static DeployDetails buildDeployDetails(String targetPath, File artifactFile, String uploadTarget, String explode, String props, - MultiValuedMap buildProperties) + Multimap buildProperties) throws IOException, NoSuchAlgorithmException { String path = UploadSpecHelper.wildcardCalculateTargetPath(targetPath, artifactFile); path = StringUtils.replace(path, "//", "/"); @@ -151,9 +151,9 @@ protected static String getUploadPath(File file, Pattern pathPattern, String tar return PathsUtils.reformatRegexp(sourcePath, fileTargetPath.replace('\\', '/'), pathPattern); } - public static MultiValuedMap getUploadPathsMap(List files, File workspaceDir, String targetPath, - boolean isFlat, Pattern regexPattern, boolean isAbsolutePath) { - MultiValuedMap filePathsMap = new HashSetValuedHashMap<>(); + public static Multimap getUploadPathsMap(List files, File workspaceDir, String targetPath, + boolean isFlat, Pattern regexPattern, boolean isAbsolutePath) { + Multimap filePathsMap = new SetMultimap<>(); boolean isTargetDirectory = StringUtils.endsWith(targetPath, "/"); for (File file : files) { diff --git a/build-info-extractor/src/test/java/org/jfrog/build/extractor/client/DeploymentUrlUtilsTest.java b/build-info-extractor/src/test/java/org/jfrog/build/extractor/client/DeploymentUrlUtilsTest.java index d4eadf916..b23f6a831 100644 --- a/build-info-extractor/src/test/java/org/jfrog/build/extractor/client/DeploymentUrlUtilsTest.java +++ b/build-info-extractor/src/test/java/org/jfrog/build/extractor/client/DeploymentUrlUtilsTest.java @@ -1,7 +1,7 @@ package org.jfrog.build.extractor.client; -import org.apache.commons.collections4.MultiMapUtils; -import org.apache.commons.collections4.MultiValuedMap; +import org.jfrog.build.api.multiMap.ListMultimap; +import org.jfrog.build.api.multiMap.Multimap; import org.jfrog.build.extractor.clientConfiguration.ClientProperties; import org.jfrog.build.extractor.clientConfiguration.util.DeploymentUrlUtils; import org.testng.Assert; @@ -36,7 +36,7 @@ public void getDeploymentUrlWithEncodingNeeded() throws UnsupportedEncodingExcep public void testKeyWithMultiValuesParam() throws UnsupportedEncodingException { - MultiValuedMap params = MultiMapUtils.newListValuedHashMap(); + Multimap params = new ListMultimap<>(); params.put("key", "valueA"); params.put("key", "valueB"); params.put("keyA", "valueA"); diff --git a/build-info-extractor/src/test/java/org/jfrog/build/extractor/util/PublishedItemsHelperTest.java b/build-info-extractor/src/test/java/org/jfrog/build/extractor/util/PublishedItemsHelperTest.java index 8272d0f16..7272fb82b 100644 --- a/build-info-extractor/src/test/java/org/jfrog/build/extractor/util/PublishedItemsHelperTest.java +++ b/build-info-extractor/src/test/java/org/jfrog/build/extractor/util/PublishedItemsHelperTest.java @@ -1,7 +1,7 @@ package org.jfrog.build.extractor.util; -import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.io.FilenameUtils; +import org.jfrog.build.api.multiMap.Multimap; import org.jfrog.build.extractor.clientConfiguration.util.PublishedItemsHelper; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -32,9 +32,9 @@ public void setup() { } public void testDoubleDotWithStartWildcard() throws IOException { - MultiValuedMap pairs = getPublishedItemsPatternPairs("../../saas/**/*.xml=>target/xml"); + Multimap pairs = getPublishedItemsPatternPairs("../../saas/**/*.xml=>target/xml"); for (final Map.Entry entry : pairs.entries()) { - MultiValuedMap buildPublishingData = getBuildPublishingData(entry); + Multimap buildPublishingData = getBuildPublishingData(entry); assertEquals(buildPublishingData.size(), 2, "Expected to find 2 files"); for (Map.Entry fileEntry : buildPublishingData.entries()) { String targetPath = PublishedItemsHelper.calculateTargetPath(fileEntry.getKey(), fileEntry.getValue()); @@ -45,10 +45,10 @@ public void testDoubleDotWithStartWildcard() throws IOException { } public void testAbsolutePath() throws IOException { - MultiValuedMap pairs = getPublishedItemsPatternPairs( + Multimap pairs = getPublishedItemsPatternPairs( absoluteFile.getAbsolutePath() + "=>jaja/gululu"); for (final Map.Entry entry : pairs.entries()) { - MultiValuedMap buildPublishingData = getBuildPublishingData(entry); + Multimap buildPublishingData = getBuildPublishingData(entry); assertEquals(buildPublishingData.size(), 1, "Expected to find 1 files"); assertTrue(buildPublishingData.containsValue(absoluteFile), "Expected to find the absolute file"); for (Map.Entry fileEntry : buildPublishingData.entries()) { @@ -59,9 +59,9 @@ public void testAbsolutePath() throws IOException { } public void testAbsolutePathSameWorkspace() throws IOException { - MultiValuedMap pairs = getPublishedItemsPatternPairs(checkoutDir.getAbsolutePath() + "/inner/*.gradle" + "=>test/props"); + Multimap pairs = getPublishedItemsPatternPairs(checkoutDir.getAbsolutePath() + "/inner/*.gradle" + "=>test/props"); for (final Map.Entry entry : pairs.entries()) { - MultiValuedMap buildPublishingData = getBuildPublishingData(entry); + Multimap buildPublishingData = getBuildPublishingData(entry); assertEquals(buildPublishingData.size(), 1, "Expected to find 1 file"); for (Map.Entry fileEntry : buildPublishingData.entries()) { String targetPath = PublishedItemsHelper.calculateTargetPath(fileEntry.getKey(), fileEntry.getValue()); @@ -72,14 +72,14 @@ public void testAbsolutePathSameWorkspace() throws IOException { public void testMultiPatterns() throws IOException { String pattern = "**/multi1/*=>test/multi1, **multi2/*=>test/multi2"; - MultiValuedMap pairs = getPublishedItemsPatternPairs(pattern); + Multimap pairs = getPublishedItemsPatternPairs(pattern); assertEquals(pairs.keySet().size(), 2, "Expected to find 2 keys"); } public void testAllWorkspace() throws IOException { - MultiValuedMap pairs = getPublishedItemsPatternPairs("**"); + Multimap pairs = getPublishedItemsPatternPairs("**"); for (final Map.Entry entry : pairs.entries()) { - MultiValuedMap buildPublishingData = getBuildPublishingData(entry); + Multimap buildPublishingData = getBuildPublishingData(entry); assertEquals(buildPublishingData.size(), 6, "Expected to find 6 files"); } } @@ -87,17 +87,17 @@ public void testAllWorkspace() throws IOException { public void testAbsolutePathWithDoubleStar() throws IOException { File resourceAsFile = getResourceAsFile("/root/workspace"); String fileAbsolutePath = FilenameUtils.separatorsToUnix(resourceAsFile.getAbsolutePath()); - MultiValuedMap pairs = getPublishedItemsPatternPairs(fileAbsolutePath + "/ant/**"); + Multimap pairs = getPublishedItemsPatternPairs(fileAbsolutePath + "/ant/**"); for (final Map.Entry entry : pairs.entries()) { - MultiValuedMap buildPublishingData = getBuildPublishingData(entry); + Multimap buildPublishingData = getBuildPublishingData(entry); assertEquals(buildPublishingData.size(), 7, "Expected to find 7 files"); } } public void testAllSpecificFilesFromCheckoutDir() throws IOException { - MultiValuedMap pairs = getPublishedItemsPatternPairs("**/*.blabla=>blabla"); + Multimap pairs = getPublishedItemsPatternPairs("**/*.blabla=>blabla"); for (final Map.Entry entry : pairs.entries()) { - MultiValuedMap buildPublishingData = getBuildPublishingData(entry); + Multimap buildPublishingData = getBuildPublishingData(entry); assertEquals(buildPublishingData.size(), 2, "Expected to find 2 files"); for (Map.Entry fileEntry : buildPublishingData.entries()) { String targetPath = PublishedItemsHelper.calculateTargetPath(fileEntry.getKey(), fileEntry.getValue()); @@ -107,9 +107,9 @@ public void testAllSpecificFilesFromCheckoutDir() throws IOException { } public void testEmptyTargetPath() throws IOException { - MultiValuedMap pairs = getPublishedItemsPatternPairs("../../**/**/*.xml"); + Multimap pairs = getPublishedItemsPatternPairs("../../**/**/*.xml"); for (final Map.Entry entry : pairs.entries()) { - MultiValuedMap buildPublishingData = getBuildPublishingData(entry); + Multimap buildPublishingData = getBuildPublishingData(entry); assertEquals(buildPublishingData.size(), 2, "Expected to find 2 files"); for (Map.Entry fileEntry : buildPublishingData.entries()) { String targetPath = PublishedItemsHelper.calculateTargetPath(fileEntry.getKey(), fileEntry.getValue()); @@ -118,11 +118,11 @@ public void testEmptyTargetPath() throws IOException { } } - private MultiValuedMap getPublishedItemsPatternPairs(String pattern) { + private Multimap getPublishedItemsPatternPairs(String pattern) { return PublishedItemsHelper.getPublishedItemsPatternPairs(pattern); } - private MultiValuedMap getBuildPublishingData(Map.Entry entry) throws IOException { + private Multimap getBuildPublishingData(Map.Entry entry) throws IOException { return PublishedItemsHelper.buildPublishingData(checkoutDir, entry.getKey(), entry.getValue()); } diff --git a/build.gradle b/build.gradle index ecfd84151..8ab75ceab 100644 --- a/build.gradle +++ b/build.gradle @@ -134,7 +134,6 @@ subprojects { implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: jacksonVersion implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: jacksonVersion implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: jacksonVersion - implementation group: 'org.apache.commons', name: 'commons-collections4', version: commonsCollections4Version implementation group: 'org.apache.commons', name: 'commons-compress', version: commonsCompressVersion implementation("org.apache.httpcomponents:httpclient:$httpClientVersion") {