1
1
package org .jfrog .build .extractor .clientConfiguration .deploy ;
2
2
3
- import com .fasterxml .jackson .annotation .JsonInclude ;
4
3
import com .fasterxml .jackson .core .type .TypeReference ;
5
4
import com .fasterxml .jackson .databind .ObjectMapper ;
6
5
import org .jfrog .build .client .DeployableArtifactDetail ;
9
8
import java .io .IOException ;
10
9
import java .util .*;
11
10
11
+ import static org .jfrog .build .extractor .BuildInfoExtractorUtils .createMapper ;
12
+
12
13
/**
13
14
* Utilities for deployable artifacts.
14
15
* Deployable artifacts file is a list of DeployableArtifactDetail.
15
16
* The DeployDetails set is prepared in the build artifacts phase. From DeployDetails set we extract the list of DeployableArtifactDetail.
16
- *
17
+ * <p>
17
18
* Created by yahavi on 25/04/2017.
18
19
*/
19
20
public class DeployableArtifactsUtils {
@@ -30,20 +31,19 @@ private static void saveDeployableArtifactsByModule(Map<String, Set<DeployDetail
30
31
Map <String , List <DeployableArtifactDetail >> deployableArtifactsDetails = new HashMap <>();
31
32
deployableArtifactsByModule .forEach ((module , deployableArtifacts ) ->
32
33
deployableArtifactsDetails .put (module , DeployableArtifactsUtils .getDeployableArtifactsPaths (deployableArtifacts )));
33
- ObjectMapper mapper = new ObjectMapper ();
34
- mapper .setSerializationInclusion (JsonInclude .Include .NON_NULL );
34
+ ObjectMapper mapper = createMapper ();
35
35
mapper .writeValue (toFile , deployableArtifactsDetails );
36
36
}
37
37
38
38
/**
39
39
* For backward compatibility, save the deployable artifacts as list (for pipelines using Gradle Artifactory Plugin with version 4.15.1 and above, along with Jenkins Artifactory Plugin bellow 3.6.1)
40
- * * /
40
+ */
41
41
@ Deprecated
42
42
private static void saveBackwardCompatibleDeployableArtifacts (Map <String , Set <DeployDetails >> deployableArtifactsByModule , File toFile ) throws IOException {
43
- List <DeployableArtifactDetail > deployableArtifactsList = new ArrayList <DeployableArtifactDetail >();
43
+ List <DeployableArtifactDetail > deployableArtifactsList = new ArrayList <>();
44
44
deployableArtifactsByModule .forEach ((module , deployableArtifacts ) ->
45
- deployableArtifactsList .addAll (DeployableArtifactsUtils .getDeployableArtifactsPaths (deployableArtifacts )));
46
- ObjectMapper mapper = new ObjectMapper ();
45
+ deployableArtifactsList .addAll (DeployableArtifactsUtils .getDeployableArtifactsPaths (deployableArtifacts )));
46
+ ObjectMapper mapper = createMapper ();
47
47
mapper .writeValue (toFile , deployableArtifactsList );
48
48
}
49
49
@@ -60,20 +60,22 @@ private static Map<String, List<DeployableArtifactDetail>> loadDeployableArtifac
60
60
if (fromFile == null || fromFile .length () == 0 ) {
61
61
return new HashMap <>();
62
62
}
63
- ObjectMapper mapper = new ObjectMapper ();
64
- return mapper .readValue (fromFile , new TypeReference <Map <String , List <DeployableArtifactDetail >>>(){});
63
+ ObjectMapper mapper = createMapper ();
64
+ return mapper .readValue (fromFile , new TypeReference <Map <String , List <DeployableArtifactDetail >>>() {
65
+ });
65
66
}
66
67
67
68
/**
68
69
* For backwards compatibility, load the deployable artifacts as list (for pipelines using Gradle Artifactory Plugin with version bellow 4.15.0, along with Jenkins Artifactory Plugin 3.6.1 and above)
69
- * * /
70
+ */
70
71
@ Deprecated
71
72
private static Map <String , List <DeployableArtifactDetail >> loadBackwardCompatibleDeployableArtifactsFromFile (File fromFile ) throws IOException {
72
73
if (fromFile == null || fromFile .length () == 0 ) {
73
74
return new HashMap <>();
74
75
}
75
- ObjectMapper mapper = new ObjectMapper ();
76
- List <DeployableArtifactDetail > backwardCompatibleList = mapper .readValue (fromFile , new TypeReference <List <DeployableArtifactDetail >>(){});
76
+ ObjectMapper mapper = createMapper ();
77
+ List <DeployableArtifactDetail > backwardCompatibleList = mapper .readValue (fromFile , new TypeReference <List <DeployableArtifactDetail >>() {
78
+ });
77
79
// Convert to map
78
80
Map <String , List <DeployableArtifactDetail >> deployableArtifactMap = new HashMap <>();
79
81
if (!backwardCompatibleList .isEmpty ()) {
@@ -83,7 +85,7 @@ private static Map<String, List<DeployableArtifactDetail>> loadBackwardCompatibl
83
85
}
84
86
85
87
private static List <DeployableArtifactDetail > getDeployableArtifactsPaths (Set <DeployDetails > deployDetails ) {
86
- List <DeployableArtifactDetail > deployableArtifacts = new ArrayList <DeployableArtifactDetail >();
88
+ List <DeployableArtifactDetail > deployableArtifacts = new ArrayList <>();
87
89
for (DeployDetails artifact : deployDetails ) {
88
90
deployableArtifacts .add (new DeployableArtifactDetail (artifact .getFile ().getAbsolutePath (), artifact .getArtifactPath (), artifact .getSha1 (), artifact .getSha256 (), artifact .getDeploySucceeded (), artifact .getTargetRepository ()));
89
91
}
0 commit comments