4
4
import com .fasterxml .jackson .core .type .TypeReference ;
5
5
import com .fasterxml .jackson .databind .ObjectMapper ;
6
6
import com .fasterxml .jackson .databind .exc .MismatchedInputException ;
7
+ import org .apache .commons .lang .StringUtils ;
7
8
import org .jfrog .build .client .DeployableArtifactDetail ;
8
9
9
10
import java .io .File ;
19
20
*/
20
21
public class DeployableArtifactsUtils {
21
22
22
- public static void saveDeployableArtifactsToFile (Map <String , Set <DeployDetails >> deployableArtifactsByModule , File toFile , boolean saveBackwardCompatible ) throws IOException {
23
+ public static void saveDeployableArtifactsToFile (Map <String , Set <DeployDetails >> deployableArtifactsByModule , File toFile , boolean saveBackwardCompatible , String rtUrl ) throws IOException {
23
24
if (saveBackwardCompatible ) {
24
25
saveBackwardCompatibleDeployableArtifacts (deployableArtifactsByModule , toFile );
25
26
return ;
26
27
}
27
- saveDeployableArtifactsByModule (deployableArtifactsByModule , toFile );
28
+ saveDeployableArtifactsByModule (deployableArtifactsByModule , toFile , rtUrl );
28
29
}
29
30
30
- private static void saveDeployableArtifactsByModule (Map <String , Set <DeployDetails >> deployableArtifactsByModule , File toFile ) throws IOException {
31
+ private static void saveDeployableArtifactsByModule (Map <String , Set <DeployDetails >> deployableArtifactsByModule , File toFile , String rtUrl ) throws IOException {
31
32
Map <String , List <DeployableArtifactDetail >> deployableArtifactsDetails = new HashMap <>();
32
33
deployableArtifactsByModule .forEach ((module , deployableArtifacts ) ->
33
- deployableArtifactsDetails .put (module , DeployableArtifactsUtils .getDeployableArtifactsPaths (deployableArtifacts )));
34
+ deployableArtifactsDetails .put (module , DeployableArtifactsUtils .getDeployableArtifactsPaths (deployableArtifacts , rtUrl )));
34
35
ObjectMapper mapper = new ObjectMapper ();
35
36
mapper .setSerializationInclusion (JsonInclude .Include .NON_NULL );
36
37
mapper .writeValue (toFile , deployableArtifactsDetails );
@@ -43,7 +44,7 @@ private static void saveDeployableArtifactsByModule(Map<String, Set<DeployDetail
43
44
private static void saveBackwardCompatibleDeployableArtifacts (Map <String , Set <DeployDetails >> deployableArtifactsByModule , File toFile ) throws IOException {
44
45
List <DeployableArtifactDetail > deployableArtifactsList = new ArrayList <DeployableArtifactDetail >();
45
46
deployableArtifactsByModule .forEach ((module , deployableArtifacts ) ->
46
- deployableArtifactsList .addAll (DeployableArtifactsUtils .getDeployableArtifactsPaths (deployableArtifacts )));
47
+ deployableArtifactsList .addAll (DeployableArtifactsUtils .getDeployableArtifactsPaths (deployableArtifacts , "" )));
47
48
ObjectMapper mapper = new ObjectMapper ();
48
49
mapper .writeValue (toFile , deployableArtifactsList );
49
50
}
@@ -83,10 +84,15 @@ private static Map<String, List<DeployableArtifactDetail>> loadBackwardCompatibl
83
84
return deployableArtifactMap ;
84
85
}
85
86
86
- private static List <DeployableArtifactDetail > getDeployableArtifactsPaths (Set <DeployDetails > deployDetails ) {
87
- List <DeployableArtifactDetail > deployableArtifacts = new ArrayList <DeployableArtifactDetail >();
87
+ private static List <DeployableArtifactDetail > getDeployableArtifactsPaths (Set <DeployDetails > deployDetails , String rtUrl ) {
88
+ List <DeployableArtifactDetail > deployableArtifacts = new ArrayList <>();
88
89
for (DeployDetails artifact : deployDetails ) {
89
- deployableArtifacts .add (new DeployableArtifactDetail (artifact .getFile ().getAbsolutePath (), artifact .getArtifactPath (), artifact .getSha1 (), artifact .getSha256 (), artifact .getDeploySucceeded ()));
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 ()));
90
96
}
91
97
return deployableArtifacts ;
92
98
}
0 commit comments