Skip to content

Commit d07836f

Browse files
authored
Rollback artifactTarget and add targetRepo to json output (#532)
1 parent aee0184 commit d07836f

File tree

6 files changed

+30
-21
lines changed

6 files changed

+30
-21
lines changed

build-info-client/src/main/java/org/jfrog/build/client/DeployableArtifactDetail.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,18 @@ public class DeployableArtifactDetail implements Serializable {
2626
* In case of deploy - is the deployment succeeded.
2727
*/
2828
private Boolean deploySucceeded;
29+
/**
30+
* Target deployment repository.
31+
*/
32+
private String targetRepository;
2933

30-
public DeployableArtifactDetail(String artifactSource, String artifactDest, String sha1, String sha256, Boolean deploySucceeded) {
34+
public DeployableArtifactDetail(String artifactSource, String artifactDest, String sha1, String sha256, Boolean deploySucceeded, String targetRepository) {
3135
this.sourcePath = artifactSource;
3236
this.artifactDest = artifactDest;
3337
this.sha1 = sha1;
3438
this.sha256 = sha256;
3539
this.deploySucceeded = deploySucceeded;
40+
this.targetRepository = targetRepository;
3641
}
3742

3843
public DeployableArtifactDetail() {
@@ -54,6 +59,10 @@ public String getSha256() {
5459
return sha256;
5560
}
5661

62+
public String getTargetRepository() {
63+
return targetRepository;
64+
}
65+
5766
public Boolean isDeploySucceeded() {
5867
return deploySucceeded;
5968
}

build-info-extractor-gradle/src/main/groovy/org/jfrog/gradle/plugin/artifactory/task/DeployTask.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ private void handleBuildInfoDeployment(ArtifactoryClientConfiguration accRoot, B
141141
}
142142
if (isGenerateDeployableArtifactsToFile(accRoot)) {
143143
try {
144-
exportDeployableArtifacts(allDeployDetails, new File(accRoot.info.getDeployableArtifactsFilePath()), accRoot.info.isBackwardCompatibleDeployableArtifacts(), contextUrl);
144+
exportDeployableArtifacts(allDeployDetails, new File(accRoot.info.getDeployableArtifactsFilePath()), accRoot.info.isBackwardCompatibleDeployableArtifacts());
145145
} catch (Exception e) {
146146
log.error("Failed writing deployable artifacts to file: ", e);
147147
throw new RuntimeException("Failed writing deployable artifacts to file", e);
@@ -235,9 +235,9 @@ private void exportBuildInfo(Build build, File toFile) throws IOException {
235235
BuildInfoExtractorUtils.saveBuildInfoToFile(build, toFile);
236236
}
237237

238-
private void exportDeployableArtifacts(Map<String, Set<DeployDetails>> allDeployDetails, File toFile, boolean exportBackwardCompatibleDeployableArtifacts, String rtUrl) throws IOException {
238+
private void exportDeployableArtifacts(Map<String, Set<DeployDetails>> allDeployDetails, File toFile, boolean exportBackwardCompatibleDeployableArtifacts) throws IOException {
239239
log.debug("Exporting deployable artifacts to '{}'", toFile.getAbsolutePath());
240-
DeployableArtifactsUtils.saveDeployableArtifactsToFile(allDeployDetails, toFile, exportBackwardCompatibleDeployableArtifacts, rtUrl);
240+
DeployableArtifactsUtils.saveDeployableArtifactsToFile(allDeployDetails, toFile, exportBackwardCompatibleDeployableArtifacts);
241241
}
242242

243243
private File getExportFile(ArtifactoryClientConfiguration clientConf) {

build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/BuildDeploymentHelper.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ public void deploy( Build build,
8282

8383
if (!StringUtils.isEmpty(clientConf.info.getDeployableArtifactsFilePath())) {
8484
try {
85-
String rtUrl = clientConf.info.getProps().get("artifactory.publish.contextUrl");
86-
DeployableArtifactsUtils.saveDeployableArtifactsToFile(deployableArtifactsByModule, new File(clientConf.info.getDeployableArtifactsFilePath()), false, rtUrl);
85+
DeployableArtifactsUtils.saveDeployableArtifactsToFile(deployableArtifactsByModule, new File(clientConf.info.getDeployableArtifactsFilePath()), false);
8786
} catch (Exception e) {
8887
logger.error("Failed writing deployable artifacts to file: ", e);
8988
throw new RuntimeException("Failed writing deployable artifacts to file", e);

build-info-extractor/src/main/java/org/jfrog/build/extractor/ModuleParallelDeployHelper.java

+4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ private void deploy(ArtifactoryManager artifactoryManager, Set<DeployDetails> de
4444
deployableArtifacts.forEach(artifact -> {
4545
try {
4646
ArtifactoryUploadResponse response = artifactoryManager.upload(artifact, logPrefix);
47+
// Save information returned from Artifactory after the deployment.
4748
artifact.setDeploySucceeded(true);
4849
artifact.setSha256(response.getChecksums().getSha256());
50+
// When a maven SNAPSHOT artifact is deployed, Artifactory adds a timestamp to the artifact name, after the artifact is deployed.
51+
// ArtifactPath needs to be updated accordingly.
52+
artifact.setArtifactPath(response.getPath());
4953
} catch (IOException e) {
5054
artifact.setDeploySucceeded(false);
5155
artifact.setSha256("");

build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/deploy/DeployDetails.java

+4
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ public void setSha256(String sha256) {
107107
this.sha256=sha256;
108108
}
109109

110+
public void setArtifactPath(String artifactPath) {
111+
this.artifactPath=artifactPath;
112+
}
113+
110114
public Boolean getDeploySucceeded() {
111115
return deploySucceeded;
112116
}

build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/deploy/DeployableArtifactsUtils.java

+8-15
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import com.fasterxml.jackson.annotation.JsonInclude;
44
import com.fasterxml.jackson.core.type.TypeReference;
55
import com.fasterxml.jackson.databind.ObjectMapper;
6-
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
7-
import org.apache.commons.lang.StringUtils;
86
import org.jfrog.build.client.DeployableArtifactDetail;
97

108
import java.io.File;
@@ -20,18 +18,18 @@
2018
*/
2119
public class DeployableArtifactsUtils {
2220

23-
public static void saveDeployableArtifactsToFile(Map<String, Set<DeployDetails>> deployableArtifactsByModule, File toFile, boolean saveBackwardCompatible, String rtUrl) throws IOException {
21+
public static void saveDeployableArtifactsToFile(Map<String, Set<DeployDetails>> deployableArtifactsByModule, File toFile, boolean saveBackwardCompatible) throws IOException {
2422
if (saveBackwardCompatible) {
2523
saveBackwardCompatibleDeployableArtifacts(deployableArtifactsByModule, toFile);
2624
return;
2725
}
28-
saveDeployableArtifactsByModule(deployableArtifactsByModule, toFile, rtUrl);
26+
saveDeployableArtifactsByModule(deployableArtifactsByModule, toFile);
2927
}
3028

31-
private static void saveDeployableArtifactsByModule(Map<String, Set<DeployDetails>> deployableArtifactsByModule, File toFile, String rtUrl) throws IOException {
29+
private static void saveDeployableArtifactsByModule(Map<String, Set<DeployDetails>> deployableArtifactsByModule, File toFile) throws IOException {
3230
Map<String, List<DeployableArtifactDetail>> deployableArtifactsDetails = new HashMap<>();
3331
deployableArtifactsByModule.forEach((module, deployableArtifacts) ->
34-
deployableArtifactsDetails.put(module, DeployableArtifactsUtils.getDeployableArtifactsPaths(deployableArtifacts, rtUrl)));
32+
deployableArtifactsDetails.put(module, DeployableArtifactsUtils.getDeployableArtifactsPaths(deployableArtifacts)));
3533
ObjectMapper mapper = new ObjectMapper();
3634
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
3735
mapper.writeValue(toFile, deployableArtifactsDetails);
@@ -44,7 +42,7 @@ private static void saveDeployableArtifactsByModule(Map<String, Set<DeployDetail
4442
private static void saveBackwardCompatibleDeployableArtifacts(Map<String, Set<DeployDetails>> deployableArtifactsByModule, File toFile) throws IOException {
4543
List<DeployableArtifactDetail> deployableArtifactsList = new ArrayList<DeployableArtifactDetail>();
4644
deployableArtifactsByModule.forEach((module, deployableArtifacts) ->
47-
deployableArtifactsList.addAll(DeployableArtifactsUtils.getDeployableArtifactsPaths(deployableArtifacts, "")));
45+
deployableArtifactsList.addAll(DeployableArtifactsUtils.getDeployableArtifactsPaths(deployableArtifacts)));
4846
ObjectMapper mapper = new ObjectMapper();
4947
mapper.writeValue(toFile, deployableArtifactsList);
5048
}
@@ -84,15 +82,10 @@ private static Map<String, List<DeployableArtifactDetail>> loadBackwardCompatibl
8482
return deployableArtifactMap;
8583
}
8684

87-
private static List<DeployableArtifactDetail> getDeployableArtifactsPaths(Set<DeployDetails> deployDetails, String rtUrl) {
88-
List<DeployableArtifactDetail> deployableArtifacts = new ArrayList<>();
85+
private static List<DeployableArtifactDetail> getDeployableArtifactsPaths(Set<DeployDetails> deployDetails) {
86+
List<DeployableArtifactDetail> deployableArtifacts = new ArrayList<DeployableArtifactDetail>();
8987
for (DeployDetails artifact : deployDetails) {
90-
String artifactDest = artifact.getArtifactPath();
91-
// In case we want artifact absolute path in Artifactory - add rtUrl and repository to destination.
92-
if (StringUtils.isBlank(rtUrl)){
93-
artifactDest = rtUrl + artifact.getTargetRepository() + "/" + artifactDest;
94-
}
95-
deployableArtifacts.add(new DeployableArtifactDetail(artifact.getFile().getAbsolutePath(), artifactDest, artifact.getSha1(), artifact.getSha256(), artifact.getDeploySucceeded()));
88+
deployableArtifacts.add(new DeployableArtifactDetail(artifact.getFile().getAbsolutePath(), artifact.getArtifactPath(), artifact.getSha1(), artifact.getSha256(), artifact.getDeploySucceeded(), artifact.getTargetRepository()));
9689
}
9790
return deployableArtifacts;
9891
}

0 commit comments

Comments
 (0)