diff --git a/.github/workflows/integrationTests.yml b/.github/workflows/integrationTests.yml index ccf86093f..7cfd0d4a9 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 ] @@ -93,12 +91,9 @@ jobs: ${{ runner.os }}-maven- - name: Setup Artifactory - run: | - go install github.com/jfrog/jfrog-testing-infra/local-rt-setup@latest - ~/go/bin/local-rt-setup - env: - RTLIC: ${{secrets.RTLIC}} - GOPROXY: direct + uses: jfrog/.github/actions/install-local-artifactory@main + with: + RTLIC: ${{ secrets.RTLIC }} # Run tests - name: Run Tests @@ -189,12 +184,9 @@ jobs: ${{ runner.os }}-maven- - name: Setup Artifactory - run: | - go install github.com/jfrog/jfrog-testing-infra/local-rt-setup@latest - ~/go/bin/local-rt-setup - env: - RTLIC: ${{secrets.RTLIC}} - GOPROXY: direct + uses: jfrog/.github/actions/install-local-artifactory@main + with: + RTLIC: ${{ secrets.RTLIC }} # Run tests - name: Run Tests @@ -311,12 +303,9 @@ jobs: ${{ runner.os }}-maven- - name: Setup Artifactory - run: | - go install github.com/jfrog/jfrog-testing-infra/local-rt-setup@latest - ~/go/bin/local-rt-setup - env: - RTLIC: ${{secrets.RTLIC}} - GOPROXY: direct + uses: jfrog/.github/actions/install-local-artifactory@main + with: + RTLIC: ${{ secrets.RTLIC }} # Run tests - name: Run Tests @@ -341,14 +330,32 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} + # Prepare ubuntu by installing Mono and handle dotnet installation issues. + - name: Prepare ubuntu + if: matrix.os == 'ubuntu-latest' + run: | + # Install Mono + sudo apt-get update + sudo apt-get install -y apt-transport-https dirmngr gnupg ca-certificates + sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF + echo "deb https://download.mono-project.com/repo/ubuntu stable-focal main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list + sudo apt-get update + sudo apt-get install -y mono-complete + # Fixes dotnet installation issues, see https://github.com/jfrog/jfrog-cli/pull/2808 for more details. + echo "DOTNET_INSTALL_DIR=/usr/share/dotnet" >> $GITHUB_ENV + sudo mkdir -p /usr/share/dotnet + sudo chmod 777 /usr/share/dotnet + + - name: Install dotnet + uses: actions/setup-dotnet@v4 + with: + dotnet-version: "6.x" + - name: Install NuGet uses: nuget/setup-nuget@v2 with: nuget-version: 6.x - - name: Install dotnet - uses: actions/setup-dotnet@v2 - with: - dotnet-version: "3.x" + - name: Install Java uses: actions/setup-java@v3 with: @@ -370,12 +377,9 @@ jobs: ${{ runner.os }}-maven- - name: Setup Artifactory - run: | - go install github.com/jfrog/jfrog-testing-infra/local-rt-setup@latest - ~/go/bin/local-rt-setup - env: - RTLIC: ${{secrets.RTLIC}} - GOPROXY: direct + uses: jfrog/.github/actions/install-local-artifactory@main + with: + RTLIC: ${{ secrets.RTLIC }} # Run tests - name: Run Tests @@ -424,12 +428,9 @@ jobs: ${{ runner.os }}-maven- - name: Setup Artifactory - run: | - go install github.com/jfrog/jfrog-testing-infra/local-rt-setup@latest - ~/go/bin/local-rt-setup - env: - RTLIC: ${{secrets.RTLIC}} - GOPROXY: direct + uses: jfrog/.github/actions/install-local-artifactory@main + with: + RTLIC: ${{ secrets.RTLIC }} # Run tests - name: Run Tests diff --git a/build-info-api/src/main/java/org/jfrog/build/api/Artifact.java b/build-info-api/src/main/java/org/jfrog/build/api/Artifact.java index 10b9f7102..d053bfd48 100644 --- a/build-info-api/src/main/java/org/jfrog/build/api/Artifact.java +++ b/build-info-api/src/main/java/org/jfrog/build/api/Artifact.java @@ -10,6 +10,7 @@ public class Artifact extends BaseBuildFileBean { private String name; + private String originalDeploymentRepo; /** * Returns the name of the artifact @@ -29,6 +30,24 @@ public void setName(String name) { this.name = name; } + /** + * Returns the original deployment repository of the artifact + * + * @return repository name + */ + public String getOriginalDeploymentRepo() { + return originalDeploymentRepo; + } + + /** + * Sets the original deployment repository of the artifact + * + * @param originalDeploymentRepo repository name + */ + public void setOriginalDeploymentRepo(String originalDeploymentRepo) { + this.originalDeploymentRepo = originalDeploymentRepo; + } + @Override public boolean equals(Object o) { if (this == o) { diff --git a/build-info-api/src/main/java/org/jfrog/build/api/Issues.java b/build-info-api/src/main/java/org/jfrog/build/api/Issues.java index cdc873e68..29ec8902f 100644 --- a/build-info-api/src/main/java/org/jfrog/build/api/Issues.java +++ b/build-info-api/src/main/java/org/jfrog/build/api/Issues.java @@ -6,7 +6,6 @@ import java.io.Serializable; import java.util.HashSet; import java.util.Set; -import java.util.stream.Collectors; /** * @author Noam Y. Tenne 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..da1e0ce1a --- /dev/null +++ b/build-info-api/src/main/java/org/jfrog/build/api/multiMap/ListMultimap.java @@ -0,0 +1,39 @@ +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. + */ +public class ListMultimap<Key, Value> extends Multimap<Key, Value> { + + /** + * Default constructor. + */ + public ListMultimap() { + super(); + } + + /** + * Constructor that accepts a map. + * + * @param map the map + */ + public ListMultimap(Map<Key, Value> 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<Value> 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..3f70faa73 --- /dev/null +++ b/build-info-api/src/main/java/org/jfrog/build/api/multiMap/Multimap.java @@ -0,0 +1,163 @@ +package org.jfrog.build.api.multiMap; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +import java.io.Serializable; +import java.util.*; + +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") +@JsonSubTypes({ + @JsonSubTypes.Type(value = ListMultimap.class, name = "list"), + @JsonSubTypes.Type(value = SetMultimap.class, name = "set"), +}) +public abstract class Multimap<Key, Value> implements Serializable { + private static final long serialVersionUID = 1L; + Map<Key, Collection<Value>> multiMap = new HashMap<>(); + + /** + * Default constructor. + */ + Multimap() { + } + + /** + * Constructor that accepts a map. + * + * @param map the map + */ + Multimap(Map<Key, Value> map) { + map.forEach(this::put); + } + + /** + * 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<Value> 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<Key, Value> map) { + for (Map.Entry<Key, Value> 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<Key, Value> multimap) { + for (Map.Entry<Key, Collection<Value>> 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<Value> 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<Map.Entry<Key, Value>> entries() { + Set<Map.Entry<Key, Value>> entries = new HashSet<>(); + for (Map.Entry<Key, Collection<Value>> 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<Key, Collection<Value>> asMap() { + return multiMap; + } + + /** + * Get all keys in the multimap. + * + * @return a set of keys + */ + public Set<Key> 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<Value> 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() { + int size = 0; + for (Collection<Value> values : multiMap.values()) { + size += values.size(); + } + return 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..506d2232f --- /dev/null +++ b/build-info-api/src/main/java/org/jfrog/build/api/multiMap/SetMultimap.java @@ -0,0 +1,35 @@ +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. + */ +public class SetMultimap<Key, Value> extends Multimap<Key, Value> { + public SetMultimap() { + super(); + } + + /** + * Constructor that accepts a map. + * + * @param map the map + */ + public SetMultimap(Map<Key, Value> 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<Value> 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..7b2d4f115 --- /dev/null +++ b/build-info-api/src/test/java/org/jfrog/build/api/multiMap/ListMultimapTest.java @@ -0,0 +1,48 @@ +package org.jfrog.build.api.multiMap; + +import org.testng.annotations.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +@Test +public class ListMultimapTest { + + public void testDefaultConstructor() { + // Create a new multimap + Multimap<String, String> multimap = new ListMultimap<>(); + + // Assert that the multimap is empty + assertEquals(multimap.size(), 0); + } + + public void testConstructorWithMap() { + // Create a new map + Map<String, String> map = new HashMap<>(); + map.put("key", "value"); + + // Create a new multimap with the map + Multimap<String, String> multimap = new ListMultimap<>(map); + + // Assert that the multimap contains the value + assertTrue(multimap.containsValue("value")); + } + + public void testPutDuplicated() { + // Populate multimap with duplicated values + Multimap<String, String> multimap = new ListMultimap<>(); + multimap.put("key", "value"); + multimap.put("key", "value"); + + // Convert the collection to an array + String[] values = multimap.get("key").toArray(new String[0]); + + // Assert that the values were added + 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..1f74b66c1 --- /dev/null +++ b/build-info-api/src/test/java/org/jfrog/build/api/multiMap/MultimapTest.java @@ -0,0 +1,155 @@ +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<String, String>()}, + {new SetMultimap<String, String>()} + }; + } + + @Test(dataProvider = "testCases") + public void testPut(Multimap<String, String> multimap) { + // Populate multimap with values + multimap.put("key1", "value1"); + multimap.put("key2", "value2"); + multimap.put("key2", "value3"); + + // Assert that the values were added + assertTrue(multimap.get("key1").contains("value1")); + assertTrue(multimap.get("key2").contains("value2")); + assertTrue(multimap.get("key2").contains("value3")); + } + + @Test(dataProvider = "testCases") + public void testPutAllMultimap(Multimap<String, String> multimap) { + // Populate multimap with values + Multimap<String, String> otherMultimap = new ListMultimap<>(); + otherMultimap.put("key1", "value1"); + otherMultimap.put("key2", "value2"); + otherMultimap.put("key2", "value3"); + + // Add the values to the multimap + multimap.putAll(otherMultimap); + + // Assert that the values were added + assertTrue(multimap.get("key1").contains("value1")); + assertTrue(multimap.get("key2").contains("value2")); + assertTrue(multimap.get("key2").contains("value3")); + } + + @Test(dataProvider = "testCases") + public void testPutAllCollection(Multimap<String, String> multimap) { + // Populate multimap with values + List<String> otherCollection = new ArrayList<>(); + otherCollection.add("value1"); + otherCollection.add("value2"); + + // Add the values to the multimap + multimap.putAll("key", otherCollection); + + // Assert that the values were added + assertTrue(multimap.get("key").contains("value1")); + assertTrue(multimap.get("key").contains("value2")); + } + + @Test(dataProvider = "testCases") + public void testPutAllMap(Multimap<String, String> multimap) { + // Populate multimap with values + Map<String, String> otherMap = new HashMap<>(); + otherMap.put("key1", "value1"); + otherMap.put("key2", "value2"); + + // Add the values to the multimap + multimap.putAll(otherMap); + + // Assert that the values were added + assertTrue(multimap.get("key1").contains("value1")); + assertTrue(multimap.get("key2").contains("value2")); + } + + @Test(dataProvider = "testCases") + public void testEntries(Multimap<String, String> multimap) { + // Populate multimap with values + multimap.put("key1", "value1"); + multimap.put("key2", "value2"); + + // Assert that the entries were added + 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<String, String> multimap) { + // Populate multimap with values + multimap.put("key1", "value1"); + multimap.put("key2", "value2"); + + // Assert that the map contains the keys + assertTrue(multimap.asMap().containsKey("key1")); + assertTrue(multimap.asMap().containsKey("key2")); + } + + @Test(dataProvider = "testCases") + public void testKeySet(Multimap<String, String> multimap) { + // Populate multimap with values + multimap.put("key1", "value1"); + multimap.put("key2", "value2"); + + // Assert that the key set contains the keys + assertTrue(multimap.keySet().contains("key1")); + assertTrue(multimap.keySet().contains("key2")); + } + + @Test(dataProvider = "testCases") + public void testContainsValue(Multimap<String, String> multimap) { + // Populate multimap with values + multimap.put("key1", "value1"); + multimap.put("key2", "value2"); + + // Assert that the multimap contains the values + assertTrue(multimap.containsValue("value1")); + assertTrue(multimap.containsValue("value2")); + } + + @Test(dataProvider = "testCases") + public void testSize(Multimap<String, String> multimap) { + // Populate multimap with values + multimap.put("key1", "value1"); + multimap.put("key2", "value2"); + + // Assert that the size is correct + assertEquals(multimap.size(), 2); + } + + @Test(dataProvider = "testCases") + public void testIsEmpty(Multimap<String, String> multimap) { + assertTrue(multimap.isEmpty()); + } + + @Test(dataProvider = "testCases") + public void testClear(Multimap<String, String> multimap) { + // Populate multimap with values + multimap.put("key1", "value1"); + multimap.put("key2", "value2"); + + // Clear the multimap + multimap.clear(); + + // Assert that the multimap is empty + 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..d217e4c35 --- /dev/null +++ b/build-info-api/src/test/java/org/jfrog/build/api/multiMap/SetMultimapTest.java @@ -0,0 +1,47 @@ +package org.jfrog.build.api.multiMap; + +import org.testng.annotations.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +@Test +public class SetMultimapTest { + + public void testDefaultConstructor() { + // Create a new multimap + Multimap<String, String> multimap = new SetMultimap<>(); + + // Assert that the multimap is empty + assertEquals(multimap.size(), 0); + } + + public void testConstructorWithMap() { + // Create a new map + Map<String, String> map = new HashMap<>(); + map.put("key", "value"); + + // Create a new multimap with the map + Multimap<String, String> multimap = new SetMultimap<>(map); + + // Assert that the multimap contains the value + assertTrue(multimap.containsValue("value")); + } + + public void testPutDuplicated() { + // Populate multimap with duplicated values + Multimap<String, String> multimap = new SetMultimap<>(); + multimap.put("key", "value"); + multimap.put("key", "value"); + + // Convert the collection to an array + String[] values = multimap.get("key").toArray(new String[0]); + + // Assert that only one values was added + 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<String, String> artifactProperties; + private final Multimap<String, String> 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<String, String> artifactProperties, String sourceRepo, Log logger) { + Multimap<String, String> 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<String, String> artifactProperties, ArtifactoryManagerBuilder artifactoryManagerBuilder) throws IOException { + private void setImageLayersProps(DockerLayers layers, Multimap<String, String> 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<String, String> artifactProperties; + private final Multimap<String, String> 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<String, String> artifactProperties, String targetRepository, String username, + String imageTag, String host, Multimap<String, String> artifactProperties, String targetRepository, String username, String password, Log logger, Map<String, String> 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<String, String> artifactProperties, ArtifactoryManagerBuilder artifactoryManagerBuilder) throws IOException { + private void setImageLayersProps(DockerLayers layers, Multimap<String, String> 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<String, String> artifactProperties; + private final Multimap<String, String> 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<String, String>() {{ + artifactProperties = new ListMultimap<String, String>() {{ put("build.name", "docker-push-test"); put("build.number", "1"); put("build.timestamp", "321"); diff --git a/build-info-extractor-docker/src/test/resources/artifactory/Dockerfile b/build-info-extractor-docker/src/test/resources/artifactory/Dockerfile index c47054915..f386b4d0a 100644 --- a/build-info-extractor-docker/src/test/resources/artifactory/Dockerfile +++ b/build-info-extractor-docker/src/test/resources/artifactory/Dockerfile @@ -7,4 +7,4 @@ ENV JFROG_HOME=/jfrog_home WORKDIR /jfrog_home EXPOSE 8082 EXPOSE 8081 -CMD ["sh","-c","local-rt-setup; sleep infinity"] \ No newline at end of file +CMD ["sh","-c","local-rt-setup --rt-version 7.84.17; sleep infinity"] \ No newline at end of file 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<String, String> properties; + private final Multimap<String, String> properties; private final List<Artifact> 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<String, String> properties, String repo, Path path, String version, String module, Log logger) throws IOException { + public GoPublish(ArtifactoryManagerBuilder artifactoryManagerBuilder, Multimap<String, String> 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/main/java/org/jfrog/build/extractor/go/extractor/GoVersionUtils.java b/build-info-extractor-go/src/main/java/org/jfrog/build/extractor/go/extractor/GoVersionUtils.java index bfef3759e..6a302475c 100644 --- a/build-info-extractor-go/src/main/java/org/jfrog/build/extractor/go/extractor/GoVersionUtils.java +++ b/build-info-extractor-go/src/main/java/org/jfrog/build/extractor/go/extractor/GoVersionUtils.java @@ -1,11 +1,11 @@ package org.jfrog.build.extractor.go.extractor; +import com.github.zafarkhaja.semver.Version; import org.apache.commons.lang3.StringUtils; import org.jfrog.build.api.util.Log; import java.io.File; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import java.util.Optional; /** * @author BarakH @@ -14,27 +14,24 @@ public class GoVersionUtils { public static final String INCOMPATIBLE = "+incompatible"; public static final int ZERO_OR_ONE = 0; - protected static final Pattern VERSION_PATTERN = Pattern.compile("v(\\d*)\\.(\\d+)\\.(\\d+)"); + + private GoVersionUtils() { + } /** * @param version full version string * @return The major version as an integer or 0 if couldn't parse it */ - public static int getMajorVersion(String version, Log log) { + public static long getMajorVersion(String version, Log log) { if (StringUtils.isEmpty(version)) { return 0; } version = getCleanVersion(version); - Matcher matcher = VERSION_PATTERN.matcher(version); - if (matcher.matches()) { - String major = matcher.group(1); - if (!StringUtils.isEmpty(major)) { - try { - return Integer.parseInt(major); - } catch (NumberFormatException e) { - log.error("Failed to parse major version of " + version, e); - } - } + Optional<Version> parsedVersion = Version.tryParse(StringUtils.removeStart(version, "v")); + if (parsedVersion.isPresent()) { + return parsedVersion.get().majorVersion(); + } else { + log.debug("Failed to parse major version of " + version); } return 0; } @@ -86,7 +83,7 @@ public static boolean isCompatibleGoModuleNaming(String projectName, String vers if (StringUtils.isBlank(projectName) || StringUtils.isBlank(version)) { return false; } - int majorVersion = getMajorVersion(version, log); + long majorVersion = getMajorVersion(version, log); if (majorVersion >= 2) { return (projectName.endsWith("/v" + majorVersion) && !version.endsWith(INCOMPATIBLE)); } 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<String, String> properties = MultiMapUtils.newListValuedHashMap(); + Multimap<String, String> properties = new ListMultimap<>(); try { // Run Go build on project1 locally Project project = Project.PROJECT_1; diff --git a/build-info-extractor-go/src/test/java/org/jfrog/build/extractor/go/extractor/GoVersionUtilsTest.java b/build-info-extractor-go/src/test/java/org/jfrog/build/extractor/go/extractor/GoVersionUtilsTest.java new file mode 100644 index 000000000..b1410c2ce --- /dev/null +++ b/build-info-extractor-go/src/test/java/org/jfrog/build/extractor/go/extractor/GoVersionUtilsTest.java @@ -0,0 +1,179 @@ +package org.jfrog.build.extractor.go.extractor; + + +import org.jfrog.build.api.util.Log; +import org.jfrog.build.api.util.NullLog; +import org.testng.annotations.Test; + +import static org.testng.AssertJUnit.*; + +public class GoVersionUtilsTest { + + @Test + public void getMajorVersion_ValidVersion_ReturnsMajorVersion() { + Log log = new NullLog(); + assertEquals(GoVersionUtils.getMajorVersion("v0.0.4", log), 0); + assertEquals(GoVersionUtils.getMajorVersion("v1.2.3", log), 1); + assertEquals(GoVersionUtils.getMajorVersion("v2.2.3", log), 2); + assertEquals(GoVersionUtils.getMajorVersion("v10.20.30", log), 10); + assertEquals(GoVersionUtils.getMajorVersion("v1.1.2-prerelease+meta", log), 1); + assertEquals(GoVersionUtils.getMajorVersion("v1.1.2+meta", log), 1); + assertEquals(GoVersionUtils.getMajorVersion("v1.0.0-alpha", log), 1); + assertEquals(GoVersionUtils.getMajorVersion("v1.0.0-alpha.beta", log), 1); + assertEquals(GoVersionUtils.getMajorVersion("v1.0.0-alpha.1", log), 1); + assertEquals(GoVersionUtils.getMajorVersion("v1.0.0-alpha.0valid", log), 1); + assertEquals(GoVersionUtils.getMajorVersion("v1.0.0-rc.1+build.1", log), 1); + assertEquals(GoVersionUtils.getMajorVersion("v1.2.3-beta", log), 1); + assertEquals(GoVersionUtils.getMajorVersion("v10.2.3-DEV-SNAPSHOT", log), 10); + assertEquals(GoVersionUtils.getMajorVersion("v1.2.3-SNAPSHOT-123", log), 1); + assertEquals(GoVersionUtils.getMajorVersion("v1.0.0", log), 1); + assertEquals(GoVersionUtils.getMajorVersion("v2.0.0+build.1848", log), 2); + assertEquals(GoVersionUtils.getMajorVersion("v2.0.1-alpha.1227", log), 2); + assertEquals(GoVersionUtils.getMajorVersion("v1.0.0-alpha+beta", log), 1); + assertEquals(GoVersionUtils.getMajorVersion("v1.2.3----RC-SNAPSHOT.12.9.1--.12+788", log), 1); + assertEquals(GoVersionUtils.getMajorVersion("v1.2.3----R-S.12.9.1--.12+meta", log), 1); + assertEquals(GoVersionUtils.getMajorVersion("v2.2.0-beta.1", log), 2); + assertEquals(GoVersionUtils.getMajorVersion("v2.0.0-beta-1", log), 2); + } + + @Test + public void getMajorVersion_InvalidVersion_ReturnsZero() { + Log log = new NullLog(); + assertEquals(GoVersionUtils.getMajorVersion("invalid.version", log), 0); + assertEquals(GoVersionUtils.getMajorVersion("", log), 0); + assertEquals(GoVersionUtils.getMajorVersion(null, log), 0); + assertEquals(GoVersionUtils.getMajorVersion("v01.1.1", log), 0); + assertEquals(GoVersionUtils.getMajorVersion("v9.8.7-whatever+meta+meta", log), 0); + assertEquals(GoVersionUtils.getMajorVersion("v1.2.3.DEV", log), 0); + assertEquals(GoVersionUtils.getMajorVersion("v1.2.3-0123", log), 0); + assertEquals(GoVersionUtils.getMajorVersion("v1.0.0-alpha_beta", log), 0); + assertEquals(GoVersionUtils.getMajorVersion("v1.2-SNAPSHOT", log), 0); + assertEquals(GoVersionUtils.getMajorVersion("v1.2.31.2.3----RC-SNAPSHOT.12.09.1--..12+788", log), 0); + } + + @Test + public void getMajorProjectVersion_ValidProject_ReturnsMajorVersion() { + Log log = new NullLog(); + assertEquals(GoVersionUtils.getMajorProjectVersion("github.com/owner/repo/v3", log), 3); + assertEquals(GoVersionUtils.getMajorProjectVersion("github.com/owner/repo/v2", log), 2); + } + + @Test + public void getMajorProjectVersion_InvalidProject_ReturnsZeroOrOne() { + Log log = new NullLog(); + assertEquals(GoVersionUtils.getMajorProjectVersion("github.com/owner/repo", log), 0); + assertEquals(GoVersionUtils.getMajorProjectVersion("", log), 0); + assertEquals(GoVersionUtils.getMajorProjectVersion(null, log), 0); + } + + @Test + public void getCleanVersion_WithIncompatible_ReturnsCleanVersion() { + assertEquals(GoVersionUtils.getCleanVersion("1.2.3+incompatible"), "1.2.3"); + } + + @Test + public void getCleanVersion_WithoutIncompatible_ReturnsSameVersion() { + assertEquals(GoVersionUtils.getCleanVersion("1.2.3"), "1.2.3"); + } + + @Test + public void isCompatibleGoModuleNaming_ValidInputs_ReturnsTrue() { + Log log = new NullLog(); + assertTrue(GoVersionUtils.isCompatibleGoModuleNaming("github.com/owner/repo/v2", "v2.0.5", log)); + assertTrue(GoVersionUtils.isCompatibleGoModuleNaming("github.com/owner/repo", "v1.0.5", log)); + } + + @Test + public void isCompatibleGoModuleNaming_InvalidInputs_ReturnsFalse() { + Log log = new NullLog(); + assertFalse(GoVersionUtils.isCompatibleGoModuleNaming("github.com/owner/repo", "v2.0.5", log)); + assertFalse(GoVersionUtils.isCompatibleGoModuleNaming("github.com/owner/repo/v2", "v2.0.5+incompatible", log)); + } + + @Test + public void getSubModule_ValidProjectName_ReturnsSubModule() { + assertEquals(GoVersionUtils.getSubModule("github.com/owner/repo/submodule"), "submodule"); + } + + @Test + public void getSubModule_InvalidProjectName_ReturnsEmptyString() { + assertEquals(GoVersionUtils.getSubModule("github.com/owner/repo"), ""); + assertEquals(GoVersionUtils.getSubModule(""), ""); + assertEquals(GoVersionUtils.getSubModule(null), ""); + } + + @Test + public void getParent_ValidPath_ReturnsParentPath() { + assertEquals(GoVersionUtils.getParent("/path/to/file"), "/path/to"); + } + + @Test + public void getParent_InvalidPath_ReturnsEmptyString() { + assertEquals(GoVersionUtils.getParent(""), ""); + assertEquals(GoVersionUtils.getParent(null), ""); + } + + @Test + public void getMajorVersion() { + Log log = new NullLog(); + assertEquals(GoVersionUtils.getMajorVersion("", log), 0); + assertEquals(GoVersionUtils.getMajorVersion(null, log), 0); + assertEquals(GoVersionUtils.getMajorVersion("vX.1.2", log), 0); + } + + @Test + public void getMajorProjectVersion_InvalidMajorVersion_LogsErrorAndReturnsZero() { + Log log = new NullLog(); + assertEquals(GoVersionUtils.getMajorProjectVersion("github.com/owner/repo/vX", log), 0); + } + + @Test + public void getCleanVersion_NullVersion_ReturnsNull() { + assertNull(GoVersionUtils.getCleanVersion(null)); + } + + @Test + public void isCompatibleGoModuleNaming_EmptyProjectName_ReturnsFalse() { + Log log = new NullLog(); + assertFalse(GoVersionUtils.isCompatibleGoModuleNaming("", "v2.0.5", log)); + } + + @Test + public void isCompatibleGoModuleNaming_EmptyVersion_ReturnsFalse() { + Log log = new NullLog(); + assertFalse(GoVersionUtils.isCompatibleGoModuleNaming("github.com/owner/repo/v2", "", log)); + } + + @Test + public void isCompatibleGoModuleNaming_NullProjectName_ReturnsFalse() { + Log log = new NullLog(); + assertFalse(GoVersionUtils.isCompatibleGoModuleNaming(null, "v2.0.5", log)); + } + + @Test + public void isCompatibleGoModuleNaming_NullVersion_ReturnsFalse() { + Log log = new NullLog(); + assertFalse(GoVersionUtils.isCompatibleGoModuleNaming("github.com/owner/repo/v2", null, log)); + } + + @Test + public void getSubModule_EmptyProjectName_ReturnsEmptyString() { + assertEquals(GoVersionUtils.getSubModule(""), ""); + } + + @Test + public void getSubModule_NullProjectName_ReturnsEmptyString() { + assertEquals(GoVersionUtils.getSubModule(null), ""); + } + + @Test + public void getParent_EmptyPath_ReturnsEmptyString() { + assertEquals(GoVersionUtils.getParent(""), ""); + } + + @Test + public void getParent_NullPath_ReturnsEmptyString() { + assertEquals(GoVersionUtils.getParent(null), ""); + } + +} \ No newline at end of file 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<GradleDeployDetails> deployDetails = new TreeSet<>(); - private final MultiValuedMap<String, CharSequence> properties = MultiMapUtils.newListValuedHashMap(); + private final Multimap<String, CharSequence> properties = new ListMultimap<>(); @Input - public MultiValuedMap<String, CharSequence> getProperties() { + public Multimap<String, CharSequence> 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<String, String> getPropsToAdd(PublishArtifactInfo artifact, String .name(project.getName()).version(project.getVersion().toString()) .classifier(artifact.getClassifier()) .type(artifact.getType()).build(); - MultiValuedMap<String, CharSequence> artifactSpecsProperties = artifactoryTask.artifactSpecs.getProperties(spec); + Multimap<String, CharSequence> artifactSpecsProperties = artifactoryTask.artifactSpecs.getProperties(spec); addProps(propsToAdd, artifactSpecsProperties); return propsToAdd; } - private void addProps(Map<String, String> target, MultiValuedMap<String, CharSequence> props) { + private void addProps(Map<String, String> target, Multimap<String, CharSequence> props) { for (Map.Entry<String, CharSequence> entry : props.entries()) { // Make sure all GString are now Java Strings String key = entry.getKey(); diff --git a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/ArtifactoryProjectBuilder.java b/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/ArtifactoryProjectBuilder.java index ab093c715..fd23059ca 100644 --- a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/ArtifactoryProjectBuilder.java +++ b/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/ArtifactoryProjectBuilder.java @@ -51,7 +51,10 @@ private List<ArtifactRepository> getRepositories() { List<ArtifactRepository> repositories = new ArrayList<>(); ProxySelector proxySelector = new ProxySelector(resolutionHelper.getHttpProxyHost(), resolutionHelper.getHttpProxyPort(), resolutionHelper.getHttpProxyUsername(), resolutionHelper.getHttpProxyPassword(), resolutionHelper.getHttpsProxyHost(), resolutionHelper.getHttpsProxyPort(), resolutionHelper.getHttpsProxyUsername(), resolutionHelper.getHttpsProxyPassword(), resolutionHelper.getNoProxy()); - ArtifactoryPluginResolution artifactoryResolution = new ArtifactoryPluginResolution(resolutionHelper.getRepoReleaseUrl(), resolutionHelper.getRepoSnapshotUrl(), resolutionHelper.getRepoUsername(), resolutionHelper.getRepoPassword(), proxySelector, resolutionHelper.getLogger()); + boolean isSnapshotEnabled = !resolutionHelper.isSnapshotDisabled(); + ArtifactoryPluginResolution artifactoryResolution = new ArtifactoryPluginResolution(resolutionHelper.getRepoReleaseUrl(), resolutionHelper.getRepoSnapshotUrl(), resolutionHelper.getRepoUsername(), resolutionHelper.getRepoPassword(), proxySelector, resolutionHelper.getLogger()) + .setSnapshotEnabled(isSnapshotEnabled) + .setSnapshotUpdatePolicy(resolutionHelper.getSnapshotUpdatePolicy()); ArtifactRepository snapshotRepository = artifactoryResolution.createSnapshotRepository(); if (snapshotRepository != null) { repositories.add(snapshotRepository); diff --git a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryEclipseResolversHelper.java b/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryEclipseResolversHelper.java index 007fe7294..179d0863f 100644 --- a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryEclipseResolversHelper.java +++ b/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryEclipseResolversHelper.java @@ -43,8 +43,7 @@ void initResolutionRepositories(RepositorySystemSession session) { List<RemoteRepository> getResolutionRepositories(RepositorySystemSession session) { if (resolutionRepositories.isEmpty()) { initResolutionHelper(session); - org.jfrog.build.extractor.ProxySelector proxySelector = new org.jfrog.build.extractor.ProxySelector(resolutionHelper.getHttpProxyHost(), resolutionHelper.getHttpProxyPort(), resolutionHelper.getHttpProxyUsername(), resolutionHelper.getHttpProxyPassword(), resolutionHelper.getHttpsProxyHost(), resolutionHelper.getHttpsProxyPort(), resolutionHelper.getHttpsProxyUsername(), resolutionHelper.getHttpsProxyPassword(), resolutionHelper.getNoProxy()); - ArtifactoryResolution artifactoryResolution = new ArtifactoryResolution(resolutionHelper.getRepoReleaseUrl(), resolutionHelper.getRepoSnapshotUrl(), resolutionHelper.getRepoUsername(), resolutionHelper.getRepoPassword(), proxySelector, logger); + ArtifactoryResolution artifactoryResolution = getArtifactoryResolution(); snapshotRepository = artifactoryResolution.createSnapshotRepository(); if (snapshotRepository != null) { resolutionRepositories.add(snapshotRepository); @@ -57,6 +56,13 @@ List<RemoteRepository> getResolutionRepositories(RepositorySystemSession session return resolutionRepositories; } + private ArtifactoryResolution getArtifactoryResolution() { + ProxySelector proxySelector = new ProxySelector(resolutionHelper.getHttpProxyHost(), resolutionHelper.getHttpProxyPort(), resolutionHelper.getHttpProxyUsername(), resolutionHelper.getHttpProxyPassword(), resolutionHelper.getHttpsProxyHost(), resolutionHelper.getHttpsProxyPort(), resolutionHelper.getHttpsProxyUsername(), resolutionHelper.getHttpsProxyPassword(), resolutionHelper.getNoProxy()); + return new ArtifactoryResolution(resolutionHelper.getRepoReleaseUrl(), resolutionHelper.getRepoSnapshotUrl(), resolutionHelper.getRepoUsername(), resolutionHelper.getRepoPassword(), proxySelector, logger) + .setSnapshotEnabled(isSnapshotEnabled()) + .setSnapshotUpdatePolicy(resolutionHelper.getSnapshotUpdatePolicy()); + } + private void initResolutionHelper(RepositorySystemSession session) { if (resolutionHelper.isInitialized()) { return; @@ -70,8 +76,7 @@ private void initResolutionHelper(RepositorySystemSession session) { List<ArtifactRepository> getResolutionPluginRepositories(RepositorySystemSession session) { if (resolutionPluginRepositories.isEmpty()) { initResolutionHelper(session); - ProxySelector proxySelector = new ProxySelector(resolutionHelper.getHttpProxyHost(), resolutionHelper.getHttpProxyPort(), resolutionHelper.getHttpProxyUsername(), resolutionHelper.getHttpProxyPassword(), resolutionHelper.getHttpsProxyHost(), resolutionHelper.getHttpsProxyPort(), resolutionHelper.getHttpsProxyUsername(), resolutionHelper.getHttpsProxyPassword(), resolutionHelper.getNoProxy()); - ArtifactoryPluginResolution repositoryBuilder = new ArtifactoryPluginResolution(resolutionHelper.getRepoReleaseUrl(), resolutionHelper.getRepoSnapshotUrl(), resolutionHelper.getRepoUsername(), resolutionHelper.getRepoPassword(), proxySelector, logger); + ArtifactoryPluginResolution repositoryBuilder = getArtifactoryPluginResolution(); ArtifactRepository snapshotRepository = repositoryBuilder.createSnapshotRepository(); if (snapshotRepository != null) { resolutionPluginRepositories.add(snapshotRepository); @@ -84,6 +89,13 @@ List<ArtifactRepository> getResolutionPluginRepositories(RepositorySystemSession return resolutionPluginRepositories; } + private ArtifactoryPluginResolution getArtifactoryPluginResolution() { + ProxySelector proxySelector = new ProxySelector(resolutionHelper.getHttpProxyHost(), resolutionHelper.getHttpProxyPort(), resolutionHelper.getHttpProxyUsername(), resolutionHelper.getHttpProxyPassword(), resolutionHelper.getHttpsProxyHost(), resolutionHelper.getHttpsProxyPort(), resolutionHelper.getHttpsProxyUsername(), resolutionHelper.getHttpsProxyPassword(), resolutionHelper.getNoProxy()); + return new ArtifactoryPluginResolution(resolutionHelper.getRepoReleaseUrl(), resolutionHelper.getRepoSnapshotUrl(), resolutionHelper.getRepoUsername(), resolutionHelper.getRepoPassword(), proxySelector, logger) + .setSnapshotEnabled(isSnapshotEnabled()) + .setSnapshotUpdatePolicy(resolutionHelper.getSnapshotUpdatePolicy()); + } + RemoteRepository getSnapshotRepository(RepositorySystemSession session) { // Init repositories configured in the Artifactory plugin: initResolutionRepositories(session); @@ -99,4 +111,8 @@ RemoteRepository getReleaseRepository(RepositorySystemSession session) { return releaseRepository; } + + private boolean isSnapshotEnabled() { + return !resolutionHelper.isSnapshotDisabled(); + } } diff --git a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryPluginResolution.java b/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryPluginResolution.java index 612178c5e..fae1d9cc1 100644 --- a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryPluginResolution.java +++ b/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryPluginResolution.java @@ -13,14 +13,18 @@ * Those repositories will replace the default Maven repositories. */ public class ArtifactoryPluginResolution extends ArtifactoryResolutionRepositoryBase { + private boolean isSnapshotEnabled; + private String snapshotUpdatePolicy; public ArtifactoryPluginResolution(String repoReleaseUrl, String snapshotRepoUrl, String repoUsername, String repoPassword, ProxySelector proxySelector, Logger logger) { super(repoReleaseUrl, snapshotRepoUrl, repoUsername, repoPassword, proxySelector, logger); + this.isSnapshotEnabled = true; + this.snapshotUpdatePolicy = ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY; } public ArtifactRepository createSnapshotRepository() { if (super.shouldCreateSnapshotRepository()) { - return createDefaultRepository(snapshotRepoUrl, "artifactory-snapshot", false, true); + return createDefaultRepository(snapshotRepoUrl, "artifactory-snapshot", false, this.isSnapshotEnabled, this.snapshotUpdatePolicy); } return null; } @@ -28,14 +32,24 @@ public ArtifactRepository createSnapshotRepository() { public ArtifactRepository createReleaseRepository() { if (super.shouldCreateReleaseRepository()) { String repositoryId = snapshotPolicyEnabled() ? "artifactory-release-snapshot" : "artifactory-release"; - return createDefaultRepository(releaseRepoUrl, repositoryId, true, snapshotPolicyEnabled()); + return createDefaultRepository(releaseRepoUrl, repositoryId, true, snapshotPolicyEnabled(), this.snapshotUpdatePolicy); } return null; } - private ArtifactRepository createDefaultRepository(String repoUrl, String repoId, boolean releasePolicy, Boolean snapshotPolicy) { + public ArtifactoryPluginResolution setSnapshotEnabled(boolean isSnapshotEnabled) { + this.isSnapshotEnabled = isSnapshotEnabled; + return this; + } + + public ArtifactoryPluginResolution setSnapshotUpdatePolicy(String snapshotUpdatePolicy) { + this.snapshotUpdatePolicy = snapshotUpdatePolicy; + return this; + } + + private ArtifactRepository createDefaultRepository(String repoUrl, String repoId, boolean releasePolicy, Boolean snapshotPolicy, String snapshotUpdatePolicy) { ArtifactRepository repository = new MavenArtifactRepository(); - setPolicy(repository, releasePolicy, snapshotPolicy); + setPolicy(repository, releasePolicy, snapshotPolicy, snapshotUpdatePolicy); repository.setLayout(new DefaultRepositoryLayout()); repository.setUrl(repoUrl); repository.setId(repoId); @@ -44,10 +58,10 @@ private ArtifactRepository createDefaultRepository(String repoUrl, String repoId return repository; } - private void setPolicy(ArtifactRepository snapshotPluginRepository, boolean releasePolicyEnabled, boolean snapshotPolicyEnabled) { + private void setPolicy(ArtifactRepository snapshotPluginRepository, boolean releasePolicyEnabled, boolean snapshotPolicyEnabled, String snapshotUpdatePolicy) { ArtifactRepositoryPolicy releasePolicy = new ArtifactRepositoryPolicy(releasePolicyEnabled, ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN); snapshotPluginRepository.setReleaseUpdatePolicy(releasePolicy); - ArtifactRepositoryPolicy snapshotPolicy = new ArtifactRepositoryPolicy(snapshotPolicyEnabled, ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN); + ArtifactRepositoryPolicy snapshotPolicy = new ArtifactRepositoryPolicy(snapshotPolicyEnabled, snapshotUpdatePolicy, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN); snapshotPluginRepository.setSnapshotUpdatePolicy(snapshotPolicy); } diff --git a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryResolution.java b/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryResolution.java index 21c99f292..e73ae07e5 100644 --- a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryResolution.java +++ b/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryResolution.java @@ -13,14 +13,18 @@ * Those repositories will be used instead of the default maven repositories. */ public class ArtifactoryResolution extends ArtifactoryResolutionRepositoryBase { + private boolean isSnapshotEnabled; + private String snapshotUpdatePolicy; public ArtifactoryResolution(String repoReleaseUrl, String snapshotRepoUrl, String repoUsername, String repoPassword, ProxySelector proxySelector, Logger logger) { super(repoReleaseUrl, snapshotRepoUrl, repoUsername, repoPassword, proxySelector, logger); + this.isSnapshotEnabled = true; + this.snapshotUpdatePolicy = RepositoryPolicy.UPDATE_POLICY_DAILY; } public RemoteRepository createSnapshotRepository() { if (super.shouldCreateSnapshotRepository()) { - return createRepository(snapshotRepoUrl, "artifactory-snapshot", false, true); + return createRepository(snapshotRepoUrl, "artifactory-snapshot", false, this.isSnapshotEnabled, this.snapshotUpdatePolicy); } return null; } @@ -28,16 +32,26 @@ public RemoteRepository createSnapshotRepository() { public RemoteRepository createReleaseRepository() { if (shouldCreateReleaseRepository()) { String repositoryId = snapshotPolicyEnabled() ? "artifactory-release-snapshot" : "artifactory-release"; - return createRepository(releaseRepoUrl, repositoryId, true, snapshotPolicyEnabled()); + return createRepository(releaseRepoUrl, repositoryId, true, snapshotPolicyEnabled(), this.snapshotUpdatePolicy); } return null; } - private RemoteRepository createRepository(String repoUrl, String repoId, boolean releasePolicy, Boolean snapshotPolicy) { + public ArtifactoryResolution setSnapshotEnabled(boolean isSnapshotEnabled) { + this.isSnapshotEnabled = isSnapshotEnabled; + return this; + } + + public ArtifactoryResolution setSnapshotUpdatePolicy(String snapshotUpdatePolicy) { + this.snapshotUpdatePolicy = snapshotUpdatePolicy; + return this; + } + + private RemoteRepository createRepository(String repoUrl, String repoId, boolean releasePolicy, Boolean snapshotPolicy, String snapshotUpdatePolicy) { RemoteRepository.Builder builder = new RemoteRepository.Builder(repoId, "default", repoUrl); setAuthentication(builder); setProxy(builder, repoUrl); - setPolicy(builder, releasePolicy, snapshotPolicy); + setPolicy(builder, releasePolicy, snapshotPolicy, snapshotUpdatePolicy); return builder.build(); } @@ -49,10 +63,10 @@ private void setAuthentication(RemoteRepository.Builder builder) { } } - private void setPolicy(RemoteRepository.Builder builder, boolean releasePolicyEnabled, boolean snapshotPolicyEnabled) { + private void setPolicy(RemoteRepository.Builder builder, boolean releasePolicyEnabled, boolean snapshotPolicyEnabled, String snapshotUpdatePolicy) { RepositoryPolicy releasePolicy = new RepositoryPolicy(releasePolicyEnabled, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN); builder.setReleasePolicy(releasePolicy); - RepositoryPolicy snapshotPolicy = new RepositoryPolicy(snapshotPolicyEnabled, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN); + RepositoryPolicy snapshotPolicy = new RepositoryPolicy(snapshotPolicyEnabled, snapshotUpdatePolicy, RepositoryPolicy.CHECKSUM_POLICY_WARN); builder.setSnapshotPolicy(snapshotPolicy); } diff --git a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ResolutionHelper.java b/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ResolutionHelper.java index 396217569..7f56f850e 100644 --- a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ResolutionHelper.java +++ b/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ResolutionHelper.java @@ -113,6 +113,10 @@ public String getHttpsProxyPassword() { return internalConfiguration.httpsProxy.getPassword(); } + public boolean isSnapshotDisabled() { return internalConfiguration.resolver.isSnapshotDisabled(); } + + public String getSnapshotUpdatePolicy() { return internalConfiguration.resolver.getSnapshotUpdatePolicy(); } + public Logger getLogger() { return logger; } diff --git a/build-info-extractor-maven3/src/test/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryResolutionTest.java b/build-info-extractor-maven3/src/test/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryResolutionTest.java index 7018497ac..6682c6854 100644 --- a/build-info-extractor-maven3/src/test/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryResolutionTest.java +++ b/build-info-extractor-maven3/src/test/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryResolutionTest.java @@ -33,6 +33,7 @@ public class ArtifactoryResolutionTest { final int HTTP_PROXY_PORT = 8888; final int HTTPS_PROXY_PORT = 8889; final String NO_PROXY_PATTERN = "www.http-no-proxy-url.com"; + final String MULTIPLE_NO_PROXY_PATTERNS = "www.no-proxy-1.com,www.http-no-proxy-url.com"; ArtifactoryResolution artifactoryResolution; ArtifactoryResolution artifactoryResolutionOnlyRelease; RemoteRepository snapshotRepository; @@ -180,6 +181,16 @@ public void TestNullProxyHttps() { assertNull(artifactoryResolutionWithNoHttp.createSnapshotRepository().getProxy()); } + @Test(description = "In the case of 'http.nonProxyHosts' with multiple hosts that one of them is matching the repository URL, null is returned from getProxy().") + public void TestMultipleNoProxy() { + // Prepare + ProxySelector multipleNoHostsProxySelector = new ProxySelector(HTTP_PROXY_URL, HTTP_PROXY_PORT, HTTP_PROXY_USERNAME, HTTP_PROXY_PASSWORD, HTTPS_PROXY_URL, HTTPS_PROXY_PORT, HTTPS_PROXY_USERNAME, HTTPS_PROXY_PASSWORD, MULTIPLE_NO_PROXY_PATTERNS); + // Act + ArtifactoryResolution artifactoryResolutionWithNoHttp = new ArtifactoryResolution(HTTP_RELEASE_URL, "https://" + NO_PROXY_PATTERN, USERNAME, PASSWORD, multipleNoHostsProxySelector, new NullPlexusLog()); + // Assert + assertNull(artifactoryResolutionWithNoHttp.createSnapshotRepository().getProxy()); + } + @Test(description = "HTTP proxy is configured, but HTTPS isn't => a valid proxy return.") public void testOnlyHttpProxyConfigured() { // Prepare 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 be1550372..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.tar.TarArchiveEntry; +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<String, String> properties; + private final Multimap<String, String> 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<String, String> properties, Path path, String deploymentRepository, Log logger, Map<String, String> env, String module) { + public NpmPublish(ArtifactoryManagerBuilder artifactoryManagerBuilder, Multimap<String, String> properties, Path path, String deploymentRepository, Log logger, Map<String, String> 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(), @@ -118,7 +118,7 @@ private void readPackageInfoFromTarball() throws IOException { } try (TarArchiveInputStream inputStream = new TarArchiveInputStream( new GzipCompressorInputStream(new BufferedInputStream(Files.newInputStream(path.toFile().toPath()))))) { - TarArchiveEntry entry; + ArchiveEntry entry; while ((entry = inputStream.getNextEntry()) != null) { Path parent = Paths.get(entry.getName()).getParent(); if (parent != null && StringUtils.equals(parent.toString(), "package") && StringUtils.endsWith(entry.getName(), "package.json")) { 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<String, String>() {{ + {Project.A, new ListMultimap<>(), Project.A.getTargetPath(), ""}, + {Project.A, new ListMultimap<String, String>() {{ put("a", "b"); }}, Project.A.getTargetPath(), ""}, - {Project.B, MultiMapUtils.emptyMultiValuedMap(), Project.B.getTargetPath(), Project.B.getPackedFileName()}, - {Project.B, new ArrayListValuedHashMap<String, String>() {{ + {Project.B, new ListMultimap<>(), Project.B.getTargetPath(), Project.B.getPackedFileName()}, + {Project.B, new ListMultimap<String, String>() {{ put("a", "b"); put("c", "d"); }}, Project.B.getTargetPath(), Project.B.getPackedFileName()}, - {Project.C, MultiMapUtils.emptyMultiValuedMap(), Project.C.getTargetPath(), ""}, - {Project.C, new ArrayListValuedHashMap<String, String>() {{ + {Project.C, new ListMultimap<>(), Project.C.getTargetPath(), ""}, + {Project.C, new ListMultimap<String, String>() {{ 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<String, String> props, String targetPath, String packageName) { + public void npmPublishTest(Project project, Multimap<String, String> props, String targetPath, String packageName) { Path projectDir = null; try { // Run npm publish diff --git a/build-info-extractor-nuget/src/main/java/org/jfrog/build/extractor/nuget/extractor/NugetRun.java b/build-info-extractor-nuget/src/main/java/org/jfrog/build/extractor/nuget/extractor/NugetRun.java index 17b3d5513..afc822dd8 100644 --- a/build-info-extractor-nuget/src/main/java/org/jfrog/build/extractor/nuget/extractor/NugetRun.java +++ b/build-info-extractor-nuget/src/main/java/org/jfrog/build/extractor/nuget/extractor/NugetRun.java @@ -35,6 +35,7 @@ import java.util.stream.Stream; import static org.jfrog.build.api.util.FileChecksumCalculator.*; +import static org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration.DEFAULT_NUGET_ALLOW_INSECURE_CONNECTIONS; import static org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration.DEFAULT_NUGET_PROTOCOL; import static org.jfrog.build.extractor.packageManager.PackageManagerUtils.createArtifactoryClientConfiguration; @@ -47,7 +48,7 @@ public class NugetRun extends PackageManagerExtractor { private static final String CONFIG_FILE_FORMAT = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<configuration>\n" + "\t<packageSources>\n" + - "\t\t<add key=\"JFrogJenkins\" value=\"%s\" protocolVersion=\"%s\" />\n" + + "\t\t<add key=\"JFrogJenkins\" value=\"%s\" protocolVersion=\"%s\" allowInsecureConnections=\"%s\"/>\n" + "\t</packageSources>\n" + "\t<packageSourceCredentials>\n" + "\t\t<JFrogJenkins>\n" + @@ -75,6 +76,7 @@ public class NugetRun extends PackageManagerExtractor { private String apiProtocol; private String module; private String nugetCmdArgs; + private boolean allowInsecureConnections; private List<String> dependenciesSources; private List<Module> modulesList = new ArrayList<>(); @@ -91,10 +93,11 @@ public class NugetRun extends PackageManagerExtractor { * @param module - NuGet module * @param username - JFrog platform username. * @param password - JFrog platform password. + * @param allowInsecureConnections - Allow insecure package sources connection, should be used only for developing. * @param apiProtocol - A string indicates which NuGet protocol should be used (V2/V3). */ - public NugetRun(ArtifactoryManagerBuilder artifactoryManagerBuilder, String resolutionRepo, boolean useDotnetCli, String nugetCmdArgs, Log logger, Path path, Map<String, String> env, String module, String username, String password, String apiProtocol) { + public NugetRun(ArtifactoryManagerBuilder artifactoryManagerBuilder, String resolutionRepo, boolean useDotnetCli, String nugetCmdArgs, Log logger, Path path, Map<String, String> env, String module, String username, String password, String apiProtocol, Boolean allowInsecureConnections) { this.artifactoryManagerBuilder = artifactoryManagerBuilder; this.toolchainDriver = useDotnetCli ? new DotnetDriver(env, path, logger) : new NugetDriver(env, path, logger); this.workingDir = Files.isDirectory(path) ? path : path.toAbsolutePath().getParent(); @@ -106,6 +109,7 @@ public NugetRun(ArtifactoryManagerBuilder artifactoryManagerBuilder, String reso this.password = password; this.apiProtocol = StringUtils.isBlank(apiProtocol) ? DEFAULT_NUGET_PROTOCOL : apiProtocol; this.module = module; + this.allowInsecureConnections = allowInsecureConnections == null ? DEFAULT_NUGET_ALLOW_INSECURE_CONNECTIONS : allowInsecureConnections; } private static String removeQuotes(String str) { @@ -160,7 +164,8 @@ public static void main(String[] ignored) { handler.getModule(), clientConfiguration.resolver.getUsername(), clientConfiguration.resolver.getPassword(), - clientConfiguration.dotnetHandler.apiProtocol()); + clientConfiguration.dotnetHandler.apiProtocol(), + clientConfiguration.getNuGetAllowInsecureConnections()); nugetRun.executeAndSaveBuildInfo(clientConfiguration); } catch (RuntimeException e) { ExceptionUtils.printRootCauseStackTrace(e, System.out); @@ -208,7 +213,7 @@ private File prepareConfig(ArtifactoryManager artifactoryManager) throws Excepti if (!nugetCmdArgs.contains(toolchainDriver.getFlagSyntax(ToolchainDriverBase.CONFIG_FILE_FLAG)) && !nugetCmdArgs.contains(toolchainDriver.getFlagSyntax(ToolchainDriverBase.SOURCE_FLAG))) { configFile = File.createTempFile(NUGET_CONFIG_FILE_PREFIX, null); configFile.deleteOnExit(); - addSourceToConfigFile(configFile.getAbsolutePath(), artifactoryManager, resolutionRepo, username, password, apiProtocol); + addSourceToConfigFile(configFile.getAbsolutePath(), artifactoryManager, resolutionRepo, username, password, apiProtocol, allowInsecureConnections); } return configFile; } @@ -217,10 +222,10 @@ private File prepareConfig(ArtifactoryManager artifactoryManager) throws Excepti * We will write a temporary NuGet configuration using a string formater in order to support NuGet v3 protocol. * Currently the NuGet configuration utility doesn't allow setting protocolVersion. */ - private void addSourceToConfigFile(String configPath, ArtifactoryManager client, String repo, String username, String password, String apiProtocol) throws Exception { + private void addSourceToConfigFile(String configPath, ArtifactoryManager client, String repo, String username, String password, String apiProtocol, boolean allowInsecureConnections) throws Exception { String sourceUrl = toolchainDriver.buildNugetSourceUrl(client, repo, apiProtocol); String protocolVersion = apiProtocol.substring(apiProtocol.length() - 1); - String configFileText = String.format(CONFIG_FILE_FORMAT, sourceUrl, protocolVersion, username, password); + String configFileText = String.format(CONFIG_FILE_FORMAT, sourceUrl, protocolVersion, Boolean.toString(allowInsecureConnections), username, password); try (PrintWriter out = new PrintWriter(configPath)) { out.println(configFileText); } diff --git a/build-info-extractor-nuget/src/test/java/org/jfrog/build/extractor/nuget/extractor/NugetExtractorTest.java b/build-info-extractor-nuget/src/test/java/org/jfrog/build/extractor/nuget/extractor/NugetExtractorTest.java index 05df5962f..a608ff92b 100644 --- a/build-info-extractor-nuget/src/test/java/org/jfrog/build/extractor/nuget/extractor/NugetExtractorTest.java +++ b/build-info-extractor-nuget/src/test/java/org/jfrog/build/extractor/nuget/extractor/NugetExtractorTest.java @@ -31,6 +31,7 @@ public class NugetExtractorTest extends IntegrationTestsBase { private static final String NUGET_REMOTE_REPO = "build-info-tests-nuget-remote"; private static final String CUSTOM_MODULE = "custom-module-name"; + private static final boolean ALLOW_INSECURE_CONNECTIONS_TEST = true; private static final Path PROJECTS_ROOT = Paths.get(".").toAbsolutePath().normalize().resolve(Paths.get("src", "test", "resources", "org", "jfrog", "build", "extractor")); @@ -95,7 +96,7 @@ public void nugetRunTest(Project project, String args, String moduleName, String try { // Run nuget restore install projectDir = createProjectDir(project); - NugetRun nugetRun = new NugetRun(artifactoryManagerBuilder, remoteRepo, false, args, log, projectDir, env, moduleName, getUsername(), getAdminToken(), "v2"); + NugetRun nugetRun = new NugetRun(artifactoryManagerBuilder, remoteRepo, false, args, log, projectDir, env, moduleName, getUsername(), getAdminToken(), "v2",ALLOW_INSECURE_CONNECTIONS_TEST); executeAndAssertBuildInfo(nugetRun, expectedModules, expectedDependencies); } catch (Exception e) { fail(ExceptionUtils.getStackTrace(e)); @@ -117,7 +118,7 @@ public void dotnetCliRunTest(Project project, String args, String moduleName, St try { // Run nuget restore install projectDir = createProjectDir(project); - NugetRun nugetRun = new NugetRun(artifactoryManagerBuilder, remoteRepo, true, args, log, projectDir, env, moduleName, getUsername(), getAdminToken(), "v2"); + NugetRun nugetRun = new NugetRun(artifactoryManagerBuilder, remoteRepo, true, args, log, projectDir, env, moduleName, getUsername(), getAdminToken(), "v2",ALLOW_INSECURE_CONNECTIONS_TEST); executeAndAssertBuildInfo(nugetRun, expectedModules, expectedDependencies); } catch (Exception e) { fail(ExceptionUtils.getStackTrace(e)); @@ -167,7 +168,7 @@ private Object[][] projectRootProvider() { private void getProjectRootTest(String args, String expectedProjectRootFileName) { try { File rootDir = PROJECTS_ROOT.resolve("projectRootTestDir").toFile(); - NugetRun nugetRun = new NugetRun(artifactoryManagerBuilder, remoteRepo, false, args, log, rootDir.toPath(), env, null, getUsername(), getAdminToken(), "v2"); + NugetRun nugetRun = new NugetRun(artifactoryManagerBuilder, remoteRepo, false, args, log, rootDir.toPath(), env, null, getUsername(), getAdminToken(), "v2",ALLOW_INSECURE_CONNECTIONS_TEST); File projectRoot = nugetRun.getProjectRootPath(); assertTrue(projectRoot.getPath().endsWith(expectedProjectRootFileName)); } catch (Exception e) { diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/ProxySelector.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/ProxySelector.java index b19537677..db62b85dd 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/ProxySelector.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/ProxySelector.java @@ -25,13 +25,15 @@ public class ProxySelector { private Proxy httpsProxy; public ProxySelector(String httpHost, int httpPort, String httpUsername, String httpPassword, String httpsHost, int httpsPort, String httpsUsername, String httpsPassword, String noProxy) { - this.noProxy = noProxy; if (StringUtils.isNotBlank(httpHost)) { this.httpProxy = new Proxy(httpHost, httpPort, httpUsername, httpPassword, false); } if (StringUtils.isNotBlank(httpsHost)) { this.httpsProxy = new Proxy(httpsHost, httpsPort, httpsUsername, httpsPassword, true); } + // The NO_PROXY environment variable standard uses commas to separate no-proxy hosts. + // The Java system property http.nonProxyHosts uses pipes. + this.noProxy = StringUtils.replace(noProxy, ",", "|"); } public Proxy getProxy(String repositoryUrl) { diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/builder/ArtifactBuilder.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/builder/ArtifactBuilder.java index 19e6b4572..1c96e34d5 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/builder/ArtifactBuilder.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/builder/ArtifactBuilder.java @@ -20,6 +20,7 @@ public class ArtifactBuilder { private String md5; private String remotePath; private Properties properties; + private String originalDeploymentRepo; public ArtifactBuilder(String name) { this.name = name; @@ -43,6 +44,7 @@ public Artifact build() { artifact.setRemotePath(remotePath); artifact.setLocalPath(localPath); artifact.setProperties(properties); + artifact.setOriginalDeploymentRepo(originalDeploymentRepo); return artifact; } @@ -134,6 +136,17 @@ public ArtifactBuilder properties(Properties properties) { return this; } + /** + * Sets the originalDeploymentRepo of the artifact + * + * @param originalDeploymentRepo Artifact original deployment repository + * @return Builder instance + */ + public ArtifactBuilder originalDeploymentRepo(String originalDeploymentRepo) { + this.originalDeploymentRepo = originalDeploymentRepo; + return this; + } + /** * Adds the given property to the properties object * diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/ci/Artifact.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/ci/Artifact.java index 36a1c73f7..242edc2c6 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/ci/Artifact.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/ci/Artifact.java @@ -8,6 +8,7 @@ public class Artifact extends BaseBuildFileBean { private String name; + private String originalDeploymentRepo; /** * Returns the name of the artifact @@ -27,6 +28,24 @@ public void setName(String name) { this.name = name; } + /** + * Returns the original deployment repository of the artifact + * + * @return repository name + */ + public String getOriginalDeploymentRepo() { + return originalDeploymentRepo; + } + + /** + * Sets the original deployment repository of the artifact + * + * @param originalDeploymentRepo repository name + */ + public void setOriginalDeploymentRepo(String originalDeploymentRepo) { + this.originalDeploymentRepo = originalDeploymentRepo; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -59,6 +78,7 @@ public org.jfrog.build.api.Artifact ToBuildArtifact() { result.setSha1(sha1); result.setRemotePath(remotePath); result.setProperties(getProperties()); + result.setOriginalDeploymentRepo(originalDeploymentRepo); return result; } @@ -71,6 +91,7 @@ public static Artifact ToBuildInfoArtifact(org.jfrog.build.api.Artifact artifact result.setSha1(artifact.getSha1()); result.setRemotePath(artifact.getRemotePath()); result.setProperties(artifact.getProperties()); + result.setOriginalDeploymentRepo(artifact.getOriginalDeploymentRepo()); return result; } } 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<String, CharSequence> getProperties(ArtifactSpec spec) { - MultiValuedMap<String, CharSequence> props = MultiMapUtils.newListValuedHashMap(); + public Multimap<String, CharSequence> getProperties(ArtifactSpec spec) { + Multimap<String, CharSequence> props = new ListMultimap<>(); for (ArtifactSpec matcherSpec : this) { if (matcherSpec.matches(spec)) { Map<String, CharSequence> 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..fc9149aa7 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; @@ -9,6 +9,7 @@ import org.jfrog.build.extractor.ci.Issue; import org.jfrog.build.extractor.clientConfiguration.util.IssuesTrackerUtils; import org.jfrog.build.extractor.clientConfiguration.util.encryption.EncryptionKeyPair; +import org.eclipse.aether.repository.RepositoryPolicy; import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; @@ -41,6 +42,7 @@ public class ArtifactoryClientConfiguration { // Try checksum deploy of files greater than 10KB public static final transient int DEFAULT_MIN_CHECKSUM_DEPLOY_SIZE_KB = 10; public static final String DEFAULT_NUGET_PROTOCOL = "v2"; + public static final boolean DEFAULT_NUGET_ALLOW_INSECURE_CONNECTIONS = false; public final ResolverHandler resolver; public final PublisherHandler publisher; @@ -54,6 +56,8 @@ public class ArtifactoryClientConfiguration { public final DockerHandler dockerHandler; public final GoHandler goHandler; public final PrefixPropertyHandler root; + + /** * To configure the props builder itself, so all method of this classes delegated from here */ @@ -208,6 +212,10 @@ public boolean getInsecureTls() { return root.getBooleanValue(PROP_INSECURE_TLS, false); } + public boolean getNuGetAllowInsecureConnections() { + return root.getBooleanValue(PROP_NUGET_ALLOW_INSECURE_CONNECTIONS, false); + } + public void setInsecureTls(boolean enabled) { root.setBooleanValue(PROP_INSECURE_TLS, enabled); } @@ -779,6 +787,14 @@ public String getRepoKey() { return getStringValue(REPO_KEY); } + public Boolean isSnapshotDisabled() { + return getBooleanValue(SNAPSHOTS_DISABLED, false); + } + + public String getSnapshotUpdatePolicy() { + return getStringValue(SNAPSHOT_UPDATE_POLICY, RepositoryPolicy.UPDATE_POLICY_DAILY); + } + public void setRepoKey(String repoKey) { setStringValue(REPO_KEY, repoKey); } @@ -883,7 +899,7 @@ public void addMatrixParams(Map<String, String> vars) { } } - public void addMatrixParams(MultiValuedMap<String, String> vars) { + public void addMatrixParams(Multimap<String, String> vars) { for (Map.Entry<String, String> entry : vars.entries()) { addMatrixParam(entry.getKey(), entry.getValue()); } diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/ClientConfigurationFields.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/ClientConfigurationFields.java index f5020406a..20376ea72 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/ClientConfigurationFields.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/ClientConfigurationFields.java @@ -30,6 +30,8 @@ public interface ClientConfigurationFields { String DOCKER_HOST = "docker.host"; String URL = "url"; String REPO_KEY = "repoKey"; + String SNAPSHOTS_DISABLED = "snapshots.disabled"; + String SNAPSHOT_UPDATE_POLICY = "snapshots.updatePolicy"; String DOWN_SNAPSHOT_REPO_KEY = "downSnapshotRepoKey"; // Publish fields String PUBLISH_ARTIFACTS = "artifacts"; diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/ClientProperties.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/ClientProperties.java index b0324cb89..faee7accc 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/ClientProperties.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/ClientProperties.java @@ -70,4 +70,10 @@ public interface ClientProperties { * Property for whether to use relaxed ssl check and ignore issues with server certificate */ String PROP_INSECURE_TLS = "insecureTls"; + + /** + * Property to allow NuGet package sources to use insecure connections (HTTP). + * This setting is enforced by the NuGet client and is not recommended for production use. + */ + String PROP_NUGET_ALLOW_INSECURE_CONNECTIONS = "nuget.AllowInsecureConnections"; } \ No newline at end of file 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<String, String> properties, boolean encodeProperties) throws IOException { + public void setProperties(String relativePath, Multimap<String, String> 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<String, String> propertiesMap; + private final Multimap<String, String> propertiesMap; private final boolean encodeProperties; private final String relativePath; private final String propertiesString; - private SetProperties(String relativePath, String propertiesString, MultiValuedMap<String, String> propertiesMap, boolean encodeProperties, Log log) { + private SetProperties(String relativePath, String propertiesString, Multimap<String, String> 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<String, String> propertiesMap, boolean encodeProperties, Log log) { + public SetProperties(String relativePath, Multimap<String, String> propertiesMap, boolean encodeProperties, Log log) { this(relativePath, null, propertiesMap, encodeProperties, log); } @@ -80,8 +81,8 @@ protected void ensureRequirements(JFrogHttpClient client) throws IOException { } } - private MultiValuedMap<String, String> mapPropsString(String props) { - MultiValuedMap<String, String> propsMap = MultiMapUtils.newListValuedHashMap(); + private Multimap<String, String> mapPropsString(String props) { + Multimap<String, String> 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<DeployDetails>, Serializable, P /** * Properties to attach to the deployed file as matrix params. */ - MultiValuedMap<String, String> properties; + Multimap<String, String> properties; /** * Target deploy repository. */ @@ -74,7 +74,7 @@ public File getFile() { return file; } - public MultiValuedMap<String, String> getProperties() { + public Multimap<String, String> getProperties() { return properties; } @@ -164,7 +164,7 @@ public DeployDetails build() { public Builder bean(BuildFileBean bean) { Properties beanProperties = bean.getProperties(); if (beanProperties != null) { - MultiValuedMap<String, String> multimap = MultiMapUtils.newListValuedHashMap(); + Multimap<String, String> 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<String, String> propertiesToAdd) { if (deployDetails.properties == null) { - deployDetails.properties = MultiMapUtils.newListValuedHashMap(); + deployDetails.properties = new ListMultimap<>(); } deployDetails.properties.putAll(propertiesToAdd); return this; } - public Builder addProperties(MultiValuedMap<String, String> propertiesToAdd) { + public Builder addProperties(Multimap<String, String> 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<String, String> matrixParams, boolean encodeProperties) + public static String buildMatrixParamsString(Multimap<String, String> 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<String, String> getPublishedItemsPatternPairs(String publishedItemsPropertyValue) { - MultiValuedMap<String, String> patternPairMap = MultiMapUtils.newSetValuedHashMap(); + public static Multimap<String, String> getPublishedItemsPatternPairs(String publishedItemsPropertyValue) { + Multimap<String, String> patternPairMap = new SetMultimap<>(); if (StringUtils.isNotBlank(publishedItemsPropertyValue)) { List<String> 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<String, File> buildPublishingData(File checkoutDir, String pattern, String targetPath) + public static Multimap<String, File> buildPublishingData(File checkoutDir, String pattern, String targetPath) throws IOException { - final MultiValuedMap<String, File> filePathsMap = MultiMapUtils.newSetValuedHashMap(); + final Multimap<String, File> 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<String, File> buildPublishingData(File checkoutDir, * @return a Multimap containing the targets as keys and the files as values */ @Deprecated - public static MultiValuedMap<String, File> wildCardBuildPublishingData( + public static Multimap<String, File> 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<String, String> buildProperties; + private Multimap<String, String> buildProperties; private Pattern regexpPattern; private Pattern regexpExcludePattern; @@ -42,7 +42,7 @@ public class SingleSpecDeploymentProducer { private int separatorsCount; private Set<String> symlinkSet = new HashSet<>(); - SingleSpecDeploymentProducer(FilesGroup spec, File workspace, MultiValuedMap<String, String> buildProperties) { + SingleSpecDeploymentProducer(FilesGroup spec, File workspace, Multimap<String, String> 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<String, String> buildProperties; + private Multimap<String, String> buildProperties; - SpecDeploymentProducer(FileSpec spec, File workspace, MultiValuedMap<String, String> buildProperties) { + SpecDeploymentProducer(FileSpec spec, File workspace, Multimap<String, String> 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<Artifact> uploadArtifactsBySpec(String uploadSpec, File workspace, return uploadArtifactsBySpec(uploadSpec, DEFAULT_NUMBER_OF_THREADS, workspace, createMultiMap(buildProperties), artifactoryManagerBuilder); } - private static <K, V> MultiValuedMap<K, V> createMultiMap(Map<K, V> input) { - MultiValuedMap<K, V> multimap = MultiMapUtils.newListValuedHashMap(); + private static <K, V> Multimap<K, V> createMultiMap(Map<K, V> input) { + Multimap<K, V> multimap = new ListMultimap<>(); for (Map.Entry<K, V> entry : input.entrySet()) { multimap.put(entry.getKey(), entry.getValue()); } @@ -78,7 +79,7 @@ private static <K, V> MultiValuedMap<K, V> createMultiMap(Map<K, V> input) { * checksums or in case of any file system exception */ public List<Artifact> uploadArtifactsBySpec(String uploadSpec, int numberOfThreads, File workspace, - MultiValuedMap<String, String> buildProperties, + Multimap<String, String> 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<String, String> getPropertiesMap(String props) { - MultiValuedMap<String, String> propertiesMap = MultiMapUtils.newListValuedHashMap(); + public static Multimap<String, String> getPropertiesMap(String props) { + Multimap<String, String> propertiesMap = new ListMultimap<>(); fillPropertiesMap(props, propertiesMap); return propertiesMap; } - public static void fillPropertiesMap(String props, MultiValuedMap<String, String> propertiesMap) { + public static void fillPropertiesMap(String props, Multimap<String, String> 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<String, String> buildProperties) + Multimap<String, String> 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<String, File> getUploadPathsMap(List<File> files, File workspaceDir, String targetPath, - boolean isFlat, Pattern regexPattern, boolean isAbsolutePath) { - MultiValuedMap<String, File> filePathsMap = new HashSetValuedHashMap<>(); + public static Multimap<String, File> getUploadPathsMap(List<File> files, File workspaceDir, String targetPath, + boolean isFlat, Pattern regexPattern, boolean isAbsolutePath) { + Multimap<String, File> 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/ci/ArtifactTest.java b/build-info-extractor/src/test/java/org/jfrog/build/extractor/ci/ArtifactTest.java index 03ee45525..bac857283 100644 --- a/build-info-extractor/src/test/java/org/jfrog/build/extractor/ci/ArtifactTest.java +++ b/build-info-extractor/src/test/java/org/jfrog/build/extractor/ci/ArtifactTest.java @@ -30,6 +30,7 @@ public void testEmptyConstructor() { assertNull(artifact.getSha1(), "Artifact SHA1 checksum should have not been initialized."); assertNull(artifact.getSha256(), "Artifact SHA256 checksum should have not been initialized."); assertNull(artifact.getMd5(), "Artifact MD5 checksum should have not been initialized."); + assertNull(artifact.getOriginalDeploymentRepo(), "Artifact original deployment repository should have not been initialized."); } /** @@ -43,6 +44,7 @@ public void testSetters() { String md5 = "gog"; String localPath = "blip"; String remotePath = "blop"; + String originalDeploymentRepository = "repo"; Properties properties = new Properties(); Artifact artifact = new Artifact(); @@ -54,6 +56,7 @@ public void testSetters() { artifact.setLocalPath(localPath); artifact.setRemotePath(remotePath); artifact.setProperties(properties); + artifact.setOriginalDeploymentRepo(originalDeploymentRepository); Assert.assertEquals(artifact.getName(), name, "Unexpected artifact name."); Assert.assertEquals(artifact.getType(), type, "Unexpected artifact type."); @@ -63,6 +66,7 @@ public void testSetters() { Assert.assertEquals(artifact.getLocalPath(), localPath, "Unexpected artifact local path."); Assert.assertEquals(artifact.getRemotePath(), remotePath, "Unexpected artifact remote path."); Assert.assertEquals(artifact.getProperties(), properties, "Unexpected artifact properties."); + Assert.assertEquals(artifact.getOriginalDeploymentRepo(),originalDeploymentRepository, "Unexpected artifact original deployment repository."); } public void testEqualsAndHash() { @@ -75,6 +79,7 @@ public void testEqualsAndHash() { artifact1.setSha1("111"); artifact1.setSha256("11111"); artifact1.setMd5("1111"); + artifact1.setOriginalDeploymentRepo("repo"); artifact1.setProperties(properties); Artifact artifact2 = new Artifact(); @@ -83,6 +88,7 @@ public void testEqualsAndHash() { artifact2.setSha1("111"); artifact2.setSha256("11111"); artifact2.setMd5("1111"); + artifact2.setOriginalDeploymentRepo("repo"); artifact2.setProperties(properties); Artifact artifact3 = new Artifact(); @@ -91,6 +97,7 @@ public void testEqualsAndHash() { artifact3.setSha1("1113"); artifact3.setSha256("11133"); artifact3.setMd5("11113"); + artifact3.setOriginalDeploymentRepo("diff-repo"); artifact3.setProperties(properties); Assert.assertEquals(artifact1, artifact2, "Expected equals == true for equivalent artifacts"); diff --git a/build-info-extractor/src/test/java/org/jfrog/build/extractor/ci/BuildInfoMavenBuilderTest.java b/build-info-extractor/src/test/java/org/jfrog/build/extractor/ci/BuildInfoMavenBuilderTest.java index 2ffa85f80..327b44e85 100644 --- a/build-info-extractor/src/test/java/org/jfrog/build/extractor/ci/BuildInfoMavenBuilderTest.java +++ b/build-info-extractor/src/test/java/org/jfrog/build/extractor/ci/BuildInfoMavenBuilderTest.java @@ -34,6 +34,7 @@ public class BuildInfoMavenBuilderTest { public static final String SHA1 = "e4e264c711ae7ab54f26542f0dd09a43b93fa12c"; public static final String SHA2 = "yyyy23029162f3b2dc51f512cb64bce8cb6913ed6e540f23ec567d898f60yyyy"; public static final String MD5 = "d9303a42c66c2824fd6ba0f75e335294"; + public static final String DEPLOY_REPO = "repo"; /** * Validates the build values when using the defaults @@ -163,12 +164,12 @@ public void testDuplicateModules() { */ public void testDuplicateModuleArtifacts() { ModuleBuilder module1 = new ModuleBuilder().type(ModuleType.MAVEN).id("id"); - module1.addArtifact(new ArtifactBuilder("artifact1").md5(MD5).sha1(SHA1).sha256(SHA2).build()); - module1.addArtifact(new ArtifactBuilder("artifact2").md5(MD5).sha1(SHA1).sha256(SHA2).build()); + module1.addArtifact(new ArtifactBuilder("artifact1").md5(MD5).sha1(SHA1).sha256(SHA2).originalDeploymentRepo(DEPLOY_REPO).build()); + module1.addArtifact(new ArtifactBuilder("artifact2").md5(MD5).sha1(SHA1).sha256(SHA2).originalDeploymentRepo(DEPLOY_REPO).build()); ModuleBuilder module2 = new ModuleBuilder().type(ModuleType.MAVEN).id("id"); - module2.addArtifact(new ArtifactBuilder("artifact1").md5(MD5).sha1(SHA1).sha256(SHA2).build()); - module2.addArtifact(new ArtifactBuilder("artifact2").md5(MD5).sha1(SHA1).sha256(SHA2).build()); + module2.addArtifact(new ArtifactBuilder("artifact1").md5(MD5).sha1(SHA1).sha256(SHA2).originalDeploymentRepo(DEPLOY_REPO).build()); + module2.addArtifact(new ArtifactBuilder("artifact2").md5(MD5).sha1(SHA1).sha256(SHA2).originalDeploymentRepo(DEPLOY_REPO).build()); BuildInfoMavenBuilder builder = new BuildInfoMavenBuilder("test").number("4").started("test"); builder.addModule(module1.build()); 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<String, String> params = MultiMapUtils.newListValuedHashMap(); + Multimap<String, String> 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/clientConfiguration/client/AccessManagerTest.java b/build-info-extractor/src/test/java/org/jfrog/build/extractor/clientConfiguration/client/AccessManagerTest.java index be51d1cb5..6f8120596 100644 --- a/build-info-extractor/src/test/java/org/jfrog/build/extractor/clientConfiguration/client/AccessManagerTest.java +++ b/build-info-extractor/src/test/java/org/jfrog/build/extractor/clientConfiguration/client/AccessManagerTest.java @@ -45,7 +45,7 @@ public class AccessManagerTest extends IntegrationTestsBase { @BeforeClass @Override public void init() throws IOException { - super.init(); + super.init(true); String accessUrl = getPlatformUrl() + "access"; accessManager = new AccessManager(accessUrl, getAdminToken(), getLog()); } 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<String, String> pairs = getPublishedItemsPatternPairs("../../saas/**/*.xml=>target/xml"); + Multimap<String, String> pairs = getPublishedItemsPatternPairs("../../saas/**/*.xml=>target/xml"); for (final Map.Entry<String, String> entry : pairs.entries()) { - MultiValuedMap<String, File> buildPublishingData = getBuildPublishingData(entry); + Multimap<String, File> buildPublishingData = getBuildPublishingData(entry); assertEquals(buildPublishingData.size(), 2, "Expected to find 2 files"); for (Map.Entry<String, File> 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<String, String> pairs = getPublishedItemsPatternPairs( + Multimap<String, String> pairs = getPublishedItemsPatternPairs( absoluteFile.getAbsolutePath() + "=>jaja/gululu"); for (final Map.Entry<String, String> entry : pairs.entries()) { - MultiValuedMap<String, File> buildPublishingData = getBuildPublishingData(entry); + Multimap<String, File> 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<String, File> fileEntry : buildPublishingData.entries()) { @@ -59,9 +59,9 @@ public void testAbsolutePath() throws IOException { } public void testAbsolutePathSameWorkspace() throws IOException { - MultiValuedMap<String, String> pairs = getPublishedItemsPatternPairs(checkoutDir.getAbsolutePath() + "/inner/*.gradle" + "=>test/props"); + Multimap<String, String> pairs = getPublishedItemsPatternPairs(checkoutDir.getAbsolutePath() + "/inner/*.gradle" + "=>test/props"); for (final Map.Entry<String, String> entry : pairs.entries()) { - MultiValuedMap<String, File> buildPublishingData = getBuildPublishingData(entry); + Multimap<String, File> buildPublishingData = getBuildPublishingData(entry); assertEquals(buildPublishingData.size(), 1, "Expected to find 1 file"); for (Map.Entry<String, File> 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<String, String> pairs = getPublishedItemsPatternPairs(pattern); + Multimap<String, String> pairs = getPublishedItemsPatternPairs(pattern); assertEquals(pairs.keySet().size(), 2, "Expected to find 2 keys"); } public void testAllWorkspace() throws IOException { - MultiValuedMap<String, String> pairs = getPublishedItemsPatternPairs("**"); + Multimap<String, String> pairs = getPublishedItemsPatternPairs("**"); for (final Map.Entry<String, String> entry : pairs.entries()) { - MultiValuedMap<String, File> buildPublishingData = getBuildPublishingData(entry); + Multimap<String, File> 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<String, String> pairs = getPublishedItemsPatternPairs(fileAbsolutePath + "/ant/**"); + Multimap<String, String> pairs = getPublishedItemsPatternPairs(fileAbsolutePath + "/ant/**"); for (final Map.Entry<String, String> entry : pairs.entries()) { - MultiValuedMap<String, File> buildPublishingData = getBuildPublishingData(entry); + Multimap<String, File> buildPublishingData = getBuildPublishingData(entry); assertEquals(buildPublishingData.size(), 7, "Expected to find 7 files"); } } public void testAllSpecificFilesFromCheckoutDir() throws IOException { - MultiValuedMap<String, String> pairs = getPublishedItemsPatternPairs("**/*.blabla=>blabla"); + Multimap<String, String> pairs = getPublishedItemsPatternPairs("**/*.blabla=>blabla"); for (final Map.Entry<String, String> entry : pairs.entries()) { - MultiValuedMap<String, File> buildPublishingData = getBuildPublishingData(entry); + Multimap<String, File> buildPublishingData = getBuildPublishingData(entry); assertEquals(buildPublishingData.size(), 2, "Expected to find 2 files"); for (Map.Entry<String, File> 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<String, String> pairs = getPublishedItemsPatternPairs("../../**/**/*.xml"); + Multimap<String, String> pairs = getPublishedItemsPatternPairs("../../**/**/*.xml"); for (final Map.Entry<String, String> entry : pairs.entries()) { - MultiValuedMap<String, File> buildPublishingData = getBuildPublishingData(entry); + Multimap<String, File> buildPublishingData = getBuildPublishingData(entry); assertEquals(buildPublishingData.size(), 2, "Expected to find 2 files"); for (Map.Entry<String, File> fileEntry : buildPublishingData.entries()) { String targetPath = PublishedItemsHelper.calculateTargetPath(fileEntry.getKey(), fileEntry.getValue()); @@ -118,11 +118,11 @@ public void testEmptyTargetPath() throws IOException { } } - private MultiValuedMap<String, String> getPublishedItemsPatternPairs(String pattern) { + private Multimap<String, String> getPublishedItemsPatternPairs(String pattern) { return PublishedItemsHelper.getPublishedItemsPatternPairs(pattern); } - private MultiValuedMap<String, File> getBuildPublishingData(Map.Entry<String, String> entry) throws IOException { + private Multimap<String, File> getBuildPublishingData(Map.Entry<String, String> entry) throws IOException { return PublishedItemsHelper.buildPublishingData(checkoutDir, entry.getKey(), entry.getValue()); } diff --git a/build-info-extractor/src/testFixtures/java/org/jfrog/build/IntegrationTestsBase.java b/build-info-extractor/src/testFixtures/java/org/jfrog/build/IntegrationTestsBase.java index 1eaa468a5..e6b321c64 100644 --- a/build-info-extractor/src/testFixtures/java/org/jfrog/build/IntegrationTestsBase.java +++ b/build-info-extractor/src/testFixtures/java/org/jfrog/build/IntegrationTestsBase.java @@ -59,8 +59,7 @@ public static Log getLog() { return log; } - @BeforeClass - public void init() throws IOException { + public void init(boolean isAccessTest) throws IOException { Properties props = new Properties(); // This file is not in GitHub. Create your own in src/test/resources or use environment variables. InputStream inputStream = this.getClass().getResourceAsStream("/artifactory-bi.properties"); @@ -69,8 +68,13 @@ public void init() throws IOException { props.load(inputStream); inputStream.close(); } + String testPort = "8081"; + // Change the port variable only if isAccessTest is true + if (isAccessTest) { + testPort = "8082"; + } - platformUrl = readParam(props, "url", "http://127.0.0.1:8081"); + platformUrl = readParam(props, "url", "http://127.0.0.1:" + testPort); if (!platformUrl.endsWith("/")) { platformUrl += "/"; } @@ -92,6 +96,16 @@ public void init() throws IOException { } } + @BeforeClass + public void init() throws IOException { + init(false); + } + + @BeforeClass + public void accessInit() throws IOException { + init(true); + } + @AfterClass protected void terminate() throws IOException { // Delete the virtual first. diff --git a/build.gradle b/build.gradle index c54358561..935285696 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { antVersion = '1.10.12' buildInfoExtractorVersion = '4.29.4' commonsCodecVersion = '1.15' - commonsCompressVersion = '1.26.0' + commonsCompressVersion = '1.26.2' commonsIoVersion = '2.11.0' commonsLang3Version = '3.12.0' commonsLoggingVersion = '1.2' @@ -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") { @@ -335,6 +334,7 @@ project('build-info-extractor') { dependencies { implementation project(':build-info-client') implementation project(':build-info-api') + implementation "org.eclipse.aether:aether-api:$eclipseAetherVersion" testImplementation "org.easymock:easymockclassextension:$easymockclassextensionVersion" testImplementation('org.mock-server:mockserver-netty:5.15.0') { @@ -479,6 +479,10 @@ project('build-info-extractor-docker') { project('build-info-extractor-go') { description = 'JFrog Build-Info Go Extractor' + + dependencies { + implementation group: 'com.github.zafarkhaja', name: 'java-semver', version: '0.10.2' + } } project('build-info-extractor-pip') { diff --git a/gradle.properties b/gradle.properties index 3ee8aabfd..ebebe4e45 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -build-info-version=2.41.18 -build-info-extractor-gradle-version=4.33.17 +build-info-version=2.42.x-SNAPSHOT +build-info-extractor-gradle-version=4.34.x-SNAPSHOT diff --git a/release/pipelines.release.yml b/release/pipelines.release.yml index 543d0a2f9..26b31a3f3 100644 --- a/release/pipelines.release.yml +++ b/release/pipelines.release.yml @@ -7,13 +7,14 @@ pipelines: auto: language: java versions: - - "8.0.0" + - "8" environmentVariables: readOnly: NEXT_VERSION: 2.0.0 NEXT_DEVELOPMENT_VERSION: 2.0.x-SNAPSHOT NEXT_GRADLE_VERSION: 4.0.0 NEXT_GRADLE_DEVELOPMENT_VERSION: 4.0.x-SNAPSHOT + SKIP_AUDIT_CHECK: "false" steps: - name: Release @@ -54,7 +55,14 @@ pipelines: - jf gradlec --use-wrapper --uses-plugin --repo-resolve ecosys-maven-remote --repo-deploy ecosys-oss-release-local # Run audit - - jf audit --fail=false + - | + if [[ $SKIP_AUDIT_CHECK == "true" ]]; then + echo "Skipping audit check" + else + echo "Running audit check" + jf audit --fail=false + fi + # Update version - sed -i -e "/build-info-version=/ s/=.*/=$NEXT_VERSION/" -e "/build-info-extractor-gradle-version=/ s/=.*/=$NEXT_GRADLE_VERSION/" gradle.properties diff --git a/release/pipelines.snapshot.yml b/release/pipelines.snapshot.yml index 9b94f5ccb..a0dd47c0a 100644 --- a/release/pipelines.snapshot.yml +++ b/release/pipelines.snapshot.yml @@ -8,7 +8,7 @@ pipelines: auto: language: java versions: - - "8.0.0" + - "8" steps: - name: Snapshot