Skip to content

Commit d7a88a9

Browse files
authored
Bugfix - Build-info ignores duplicate artifacts checksum (#579)
1 parent 7ad443a commit d7a88a9

File tree

5 files changed

+64
-12
lines changed

5 files changed

+64
-12
lines changed

Diff for: build-info-api/src/main/java/org/jfrog/build/api/Artifact.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.jfrog.build.api;
1818

1919
import com.thoughtworks.xstream.annotations.XStreamAlias;
20+
import org.apache.commons.lang.StringUtils;
2021

2122
/**
2223
* Contains the build deployed artifact information
@@ -59,10 +60,7 @@ public boolean equals(Object o) {
5960
}
6061

6162
Artifact artifact = (Artifact) o;
62-
if (name != null ? !name.equals(artifact.name) : artifact.name != null) {
63-
return false;
64-
}
65-
return true;
63+
return StringUtils.equals(name, artifact.name) && StringUtils.equals(remotePath, artifact.remotePath);
6664
}
6765

6866
@Override

Diff for: build-info-api/src/main/java/org/jfrog/build/api/BaseBuildFileBean.java

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public int hashCode() {
111111
result = 31 * result + (sha1 != null ? sha1.hashCode() : 0);
112112
result = 31 * result + (sha256 != null ? sha256.hashCode() : 0);
113113
result = 31 * result + (md5 != null ? md5.hashCode() : 0);
114+
result = 31 * result + (remotePath != null ? remotePath.hashCode() : 0);
114115
return result;
115116
}
116117
}

Diff for: build-info-api/src/main/java/org/jfrog/build/api/Dependency.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.thoughtworks.xstream.annotations.XStreamAlias;
2020
import org.apache.commons.lang.ArrayUtils;
21+
import org.apache.commons.lang.StringUtils;
2122

2223
import java.util.Arrays;
2324
import java.util.Objects;
@@ -121,7 +122,10 @@ public boolean equals(Object o) {
121122
}
122123
Dependency that = (Dependency) o;
123124

124-
if (!Objects.equals(id, that.id)) {
125+
if (!StringUtils.equals(id, that.id)) {
126+
return false;
127+
}
128+
if (!StringUtils.equals(remotePath, that.remotePath)) {
125129
return false;
126130
}
127131
if (!Objects.equals(scopes, that.scopes)) {
@@ -132,6 +136,6 @@ public boolean equals(Object o) {
132136

133137
@Override
134138
public int hashCode() {
135-
return Objects.hash(id, scopes, Arrays.deepHashCode(requestedBy));
139+
return Objects.hash(id, scopes, Arrays.deepHashCode(requestedBy), remotePath);
136140
}
137141
}

Diff for: build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/DependenciesDownloaderHelper.java

+18-5
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,22 @@
2121
import org.jfrog.filespecs.FileSpec;
2222
import org.jfrog.filespecs.entities.FilesGroup;
2323

24-
import java.io.*;
24+
import java.io.File;
25+
import java.io.FileInputStream;
26+
import java.io.FileNotFoundException;
27+
import java.io.FileOutputStream;
28+
import java.io.IOException;
29+
import java.io.InputStream;
30+
import java.io.PrintWriter;
31+
import java.io.SequenceInputStream;
32+
import java.io.StringWriter;
2533
import java.security.NoSuchAlgorithmException;
26-
import java.util.*;
34+
import java.util.ArrayList;
35+
import java.util.HashMap;
36+
import java.util.HashSet;
37+
import java.util.List;
38+
import java.util.Map;
39+
import java.util.Set;
2740
import java.util.regex.Pattern;
2841

2942
import static org.jfrog.build.extractor.clientConfiguration.client.artifactory.services.Upload.MD5_HEADER_NAME;
@@ -62,7 +75,7 @@ public DependenciesDownloaderHelper(ArtifactoryManager artifactoryManager, Strin
6275

6376
/**
6477
* Download dependencies by the provided spec using the provided in the constructor client.
65-
* returns list of downloaded artifacts
78+
* returns a distinct list of downloaded artifacts
6679
*
6780
* @param downloadSpec the download spec
6881
* @return list of downloaded artifacts
@@ -72,7 +85,7 @@ public List<Dependency> downloadDependencies(FileSpec downloadSpec) throws IOExc
7285
ArtifactorySearcher searcher = new ArtifactorySearcher(downloader.getArtifactoryManager(), log);
7386
Set<DownloadableArtifact> downloadableArtifacts;
7487
List<AqlSearchResult.SearchEntry> searchResults;
75-
List<Dependency> resolvedDependencies = new ArrayList<>();
88+
HashSet<Dependency> resolvedDependencies = new HashSet<>();
7689

7790
for (FilesGroup file : downloadSpec.getFiles()) {
7891
log.debug("Downloading dependencies using spec: \n" + file.toString());
@@ -84,7 +97,7 @@ public List<Dependency> downloadDependencies(FileSpec downloadSpec) throws IOExc
8497
}
8598
resolvedDependencies.addAll(downloadDependencies(downloadableArtifacts));
8699
}
87-
return resolvedDependencies;
100+
return new ArrayList<>(resolvedDependencies);
88101
}
89102

90103
private void replaceTargetPlaceholders(String searchPattern, Set<DownloadableArtifact> downloadableArtifacts, String target) {

Diff for: build-info-extractor/src/test/java/org/jfrog/build/extractor/clientConfiguration/util/DownloadTest.java

+37-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.jfrog.build.api.dependency.pattern.PatternType;
88
import org.jfrog.build.api.util.FileChecksumCalculator;
99
import org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails;
10+
import org.jfrog.filespecs.FileSpec;
11+
import org.jfrog.filespecs.entities.FilesGroup;
1012
import org.testng.Assert;
1113
import org.testng.annotations.AfterClass;
1214
import org.testng.annotations.BeforeClass;
@@ -18,9 +20,13 @@
1820
import java.io.RandomAccessFile;
1921
import java.security.NoSuchAlgorithmException;
2022
import java.util.HashMap;
23+
import java.util.List;
2124
import java.util.Map;
2225

23-
import static org.jfrog.build.extractor.clientConfiguration.util.DependenciesDownloaderHelper.*;
26+
import static org.jfrog.build.extractor.clientConfiguration.util.DependenciesDownloaderHelper.ArtifactMetaData;
27+
import static org.jfrog.build.extractor.clientConfiguration.util.DependenciesDownloaderHelper.MD5_ALGORITHM_NAME;
28+
import static org.jfrog.build.extractor.clientConfiguration.util.DependenciesDownloaderHelper.MIN_SIZE_FOR_CONCURRENT_DOWNLOAD;
29+
import static org.jfrog.build.extractor.clientConfiguration.util.DependenciesDownloaderHelper.SHA1_ALGORITHM_NAME;
2430

2531
/**
2632
* Integration tests for the DependenciesDownloader classes.
@@ -112,6 +118,36 @@ public void testDownloadArtifactWithoutContentLength(Map<String, String> uploade
112118
Assert.assertEquals((new File(targetDirPath + fileName)).length(), fileSize);
113119
}
114120

121+
public void testDownloadArtifactFromDifferentPath() throws IOException {
122+
String targetDirPath = tempWorkspace.getPath() + File.separatorChar + "testDownloaddupArtifactFromDifferentPath" + File.separatorChar;
123+
FileSpec fileSpec = new FileSpec();
124+
// Upload one file to different locations in Artifactory.
125+
try {
126+
File file = createRandomFile(tempWorkspace.getPath() + File.pathSeparatorChar + "file", 1);
127+
for (int i = 0; i < 3; i++) {
128+
String filePath = TEST_REPO_PATH + "/" + i + "/file";
129+
DeployDetails deployDetails = new DeployDetails.Builder()
130+
.file(file)
131+
.artifactPath(filePath)
132+
.targetRepository(localRepo1)
133+
.explode(false)
134+
.packageType(DeployDetails.PackageType.GENERIC)
135+
.build();
136+
FilesGroup fg = new FilesGroup();
137+
fg.setPattern(localRepo1 + "/" + filePath);
138+
fg.setTarget(targetDirPath);
139+
fileSpec.addFilesGroup(fg);
140+
// Upload artifact
141+
artifactoryManager.upload(deployDetails);
142+
}
143+
DependenciesDownloaderHelper helper = new DependenciesDownloaderHelper(artifactoryManager, tempWorkspace.getPath(), log);
144+
List<Dependency> dependencies = helper.downloadDependencies(fileSpec);
145+
Assert.assertEquals(dependencies.size(), 3);
146+
} finally {
147+
FileUtils.deleteDirectory(tempWorkspace);
148+
}
149+
}
150+
115151
/**
116152
* Create and upload files to Artifactory.
117153
* The test files are created according to the data provided in testFilesMap

0 commit comments

Comments
 (0)