Skip to content

Commit 48f7dcd

Browse files
authored
Fail to deserialize deployable artifacts (#537)
1 parent 8f08e09 commit 48f7dcd

File tree

11 files changed

+54
-61
lines changed

11 files changed

+54
-61
lines changed

build-info-extractor-docker/src/main/java/org/jfrog/build/extractor/docker/DockerUtils.java

+2-16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package org.jfrog.build.extractor.docker;
22

3-
import com.fasterxml.jackson.annotation.JsonInclude;
4-
import com.fasterxml.jackson.databind.DeserializationFeature;
53
import com.fasterxml.jackson.databind.JsonNode;
6-
import com.fasterxml.jackson.databind.ObjectMapper;
74
import org.apache.commons.codec.binary.Hex;
85
import org.apache.commons.lang3.StringUtils;
96
import org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager;
@@ -15,6 +12,8 @@
1512
import java.util.ArrayList;
1613
import java.util.List;
1714

15+
import static org.jfrog.build.extractor.BuildInfoExtractorUtils.createMapper;
16+
1817
public class DockerUtils {
1918
/**
2019
* Get config digest from manifest (image id).
@@ -76,19 +75,6 @@ public static String getImageDigestFromFatManifest(String manifest, String os, S
7675
return "";
7776
}
7877

79-
/**
80-
* Create an object mapper for serialization/deserialization.
81-
* This mapper ignore unknown properties and null values.
82-
*
83-
* @return a new object mapper
84-
*/
85-
public static ObjectMapper createMapper() {
86-
ObjectMapper mapper = new ObjectMapper();
87-
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
88-
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
89-
return mapper;
90-
}
91-
9278
/**
9379
* Get a list of layer digests from docker manifest.
9480
*/

build-info-extractor-docker/src/main/java/org/jfrog/build/extractor/docker/extractor/BuildDockerCreator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.util.stream.Collectors;
3131
import java.util.stream.Stream;
3232

33-
import static org.jfrog.build.extractor.docker.DockerUtils.createMapper;
33+
import static org.jfrog.build.extractor.BuildInfoExtractorUtils.createMapper;
3434
import static org.jfrog.build.extractor.packageManager.PackageManagerUtils.createArtifactoryClientConfiguration;
3535

3636
public class BuildDockerCreator extends PackageManagerExtractor {

build-info-extractor-npm/src/main/java/org/jfrog/build/extractor/npm/types/NpmPackageInfo.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.jfrog.build.extractor.npm.types;
22

3-
import com.fasterxml.jackson.databind.DeserializationFeature;
43
import com.fasterxml.jackson.databind.ObjectMapper;
54
import org.apache.commons.lang.StringUtils;
65
import org.jfrog.build.api.producerConsumer.ProducerConsumerItem;
@@ -10,6 +9,8 @@
109
import java.io.Serializable;
1110
import java.util.Objects;
1211

12+
import static org.jfrog.build.extractor.BuildInfoExtractorUtils.createMapper;
13+
1314
public class NpmPackageInfo implements Serializable, ProducerConsumerItem {
1415
private static final long serialVersionUID = 1L;
1516

@@ -67,8 +68,7 @@ void splitScopeFromName() {
6768
}
6869

6970
public void readPackageInfo(InputStream inputStream) throws IOException {
70-
ObjectMapper mapper = new ObjectMapper();
71-
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
71+
ObjectMapper mapper = createMapper();
7272

7373
NpmPackageInfo npmPackageInfo = mapper.readValue(inputStream, NpmPackageInfo.class);
7474

build-info-extractor-nuget/src/main/java/org/jfrog/build/extractor/nuget/types/NugetProjectAssets.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.jfrog.build.extractor.nuget.types;
22

3-
import com.fasterxml.jackson.databind.DeserializationFeature;
43
import com.fasterxml.jackson.databind.ObjectMapper;
54
import org.apache.commons.lang3.StringUtils;
65

@@ -9,6 +8,8 @@
98
import java.util.List;
109
import java.util.Map;
1110

11+
import static org.jfrog.build.extractor.BuildInfoExtractorUtils.createMapper;
12+
1213
public class NugetProjectAssets {
1314
private static final long serialVersionUID = 1L;
1415

@@ -155,7 +156,7 @@ public void setPackagesPath(String packagesPath) {
155156
public void readProjectAssets(File projectAssets) throws IOException {
156157
try (FileInputStream fis = new FileInputStream(projectAssets)) {
157158
String json = inputStreamToString(fis);
158-
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
159+
ObjectMapper mapper = createMapper();
159160
NugetProjectAssets assets = mapper.readValue(json, NugetProjectAssets.class);
160161
this.setVersion(assets.getVersion());
161162
this.setLibraries(assets.getLibraries());

build-info-extractor-pip/src/main/java/org/jfrog/build/extractor/pip/extractor/DependenciesCache.java

+3-9
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import com.fasterxml.jackson.core.JsonParseException;
5-
import com.fasterxml.jackson.databind.DeserializationFeature;
65
import com.fasterxml.jackson.databind.JsonMappingException;
76
import com.fasterxml.jackson.databind.ObjectMapper;
8-
import com.fasterxml.jackson.databind.SerializationFeature;
97
import org.jfrog.build.api.Dependency;
108
import org.jfrog.build.api.util.Log;
119

@@ -17,6 +15,8 @@
1715
import java.util.HashMap;
1816
import java.util.Map;
1917

18+
import static org.jfrog.build.extractor.BuildInfoExtractorUtils.createMapper;
19+
2020
/**
2121
* Created by Bar Belity on 19/07/2020.
2222
* <p>
@@ -30,13 +30,7 @@
3030
public class DependenciesCache {
3131

3232
private static final int CACHE_VERSION = 1;
33-
private static ObjectMapper objectMapper;
34-
35-
static {
36-
objectMapper = new ObjectMapper();
37-
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
38-
objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
39-
}
33+
private static final ObjectMapper objectMapper = createMapper();
4034

4135
@JsonProperty("version")
4236
private int version = CACHE_VERSION;

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

+15
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.fasterxml.jackson.core.JsonParser;
2323
import com.fasterxml.jackson.databind.DeserializationFeature;
2424
import com.fasterxml.jackson.databind.ObjectMapper;
25+
import com.fasterxml.jackson.databind.SerializationFeature;
2526
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
2627
import org.apache.commons.io.IOUtils;
2728
import org.apache.commons.lang.StringUtils;
@@ -294,6 +295,20 @@ public static String getModuleIdString(String organisation, String name, String
294295
return organisation + ':' + name + ':' + version;
295296
}
296297

298+
/**
299+
* Create an object mapper for serialization/deserialization.
300+
* This mapper ignore unknown properties and null values.
301+
*
302+
* @return a new object mapper
303+
*/
304+
public static ObjectMapper createMapper() {
305+
ObjectMapper mapper = new ObjectMapper();
306+
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
307+
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
308+
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
309+
return mapper;
310+
}
311+
297312
private static class PrefixPredicate implements Predicate<Object> {
298313

299314
private String prefix;

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package org.jfrog.build.extractor;
22

3-
import com.fasterxml.jackson.annotation.JsonInclude;
43
import com.fasterxml.jackson.core.JsonFactory;
54
import com.fasterxml.jackson.core.JsonGenerator;
65
import com.fasterxml.jackson.core.JsonParser;
7-
import com.fasterxml.jackson.databind.DeserializationFeature;
86
import com.fasterxml.jackson.databind.ObjectMapper;
97
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
108
import com.google.common.base.Charsets;
@@ -16,16 +14,16 @@
1614
import java.io.StringReader;
1715
import java.io.StringWriter;
1816

17+
import static org.jfrog.build.extractor.BuildInfoExtractorUtils.createMapper;
18+
1919
/**
2020
* Utilities for serializing/deserializing Module info as json
2121
*/
2222
public class ModuleExtractorUtils {
2323
private static JsonFactory createJsonFactory() {
2424
JsonFactory jsonFactory = new JsonFactory();
25-
ObjectMapper mapper = new ObjectMapper(jsonFactory);
25+
ObjectMapper mapper = createMapper();
2626
mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector());
27-
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
28-
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
2927
jsonFactory.setCodec(mapper);
3028
return jsonFactory;
3129
}

build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/client/JFrogService.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.jfrog.build.extractor.clientConfiguration.client;
22

3-
import com.fasterxml.jackson.annotation.JsonInclude;
4-
import com.fasterxml.jackson.databind.DeserializationFeature;
53
import com.fasterxml.jackson.databind.ObjectMapper;
64
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
75
import org.apache.commons.codec.net.URLCodec;
@@ -21,6 +19,7 @@
2119

2220
import static org.apache.commons.codec.binary.StringUtils.getBytesUtf8;
2321
import static org.apache.commons.codec.binary.StringUtils.newStringUsAscii;
22+
import static org.jfrog.build.extractor.BuildInfoExtractorUtils.createMapper;
2423

2524
/**
2625
* JFrogService represents a generic way of processing a REST endpoint process that structures how REST sends, handles errors, and parses the response.
@@ -65,10 +64,8 @@ public static String encodeUrl(String unescaped) {
6564
*/
6665
protected ObjectMapper getMapper() {
6766
if (mapper == null) {
68-
mapper = new ObjectMapper();
69-
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
67+
mapper = createMapper();
7068
mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector());
71-
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
7269
}
7370
return mapper;
7471
}

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

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.jfrog.build.extractor.clientConfiguration.deploy;
22

3-
import com.fasterxml.jackson.annotation.JsonInclude;
43
import com.fasterxml.jackson.core.type.TypeReference;
54
import com.fasterxml.jackson.databind.ObjectMapper;
65
import org.jfrog.build.client.DeployableArtifactDetail;
@@ -9,11 +8,13 @@
98
import java.io.IOException;
109
import java.util.*;
1110

11+
import static org.jfrog.build.extractor.BuildInfoExtractorUtils.createMapper;
12+
1213
/**
1314
* Utilities for deployable artifacts.
1415
* Deployable artifacts file is a list of DeployableArtifactDetail.
1516
* The DeployDetails set is prepared in the build artifacts phase. From DeployDetails set we extract the list of DeployableArtifactDetail.
16-
*
17+
* <p>
1718
* Created by yahavi on 25/04/2017.
1819
*/
1920
public class DeployableArtifactsUtils {
@@ -30,20 +31,19 @@ private static void saveDeployableArtifactsByModule(Map<String, Set<DeployDetail
3031
Map<String, List<DeployableArtifactDetail>> deployableArtifactsDetails = new HashMap<>();
3132
deployableArtifactsByModule.forEach((module, deployableArtifacts) ->
3233
deployableArtifactsDetails.put(module, DeployableArtifactsUtils.getDeployableArtifactsPaths(deployableArtifacts)));
33-
ObjectMapper mapper = new ObjectMapper();
34-
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
34+
ObjectMapper mapper = createMapper();
3535
mapper.writeValue(toFile, deployableArtifactsDetails);
3636
}
3737

3838
/**
3939
* 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+
*/
4141
@Deprecated
4242
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<>();
4444
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();
4747
mapper.writeValue(toFile, deployableArtifactsList);
4848
}
4949

@@ -60,20 +60,22 @@ private static Map<String, List<DeployableArtifactDetail>> loadDeployableArtifac
6060
if (fromFile == null || fromFile.length() == 0) {
6161
return new HashMap<>();
6262
}
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+
});
6566
}
6667

6768
/**
6869
* 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+
*/
7071
@Deprecated
7172
private static Map<String, List<DeployableArtifactDetail>> loadBackwardCompatibleDeployableArtifactsFromFile(File fromFile) throws IOException {
7273
if (fromFile == null || fromFile.length() == 0) {
7374
return new HashMap<>();
7475
}
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+
});
7779
// Convert to map
7880
Map<String, List<DeployableArtifactDetail>> deployableArtifactMap = new HashMap<>();
7981
if (!backwardCompatibleList.isEmpty()) {
@@ -83,7 +85,7 @@ private static Map<String, List<DeployableArtifactDetail>> loadBackwardCompatibl
8385
}
8486

8587
private static List<DeployableArtifactDetail> getDeployableArtifactsPaths(Set<DeployDetails> deployDetails) {
86-
List<DeployableArtifactDetail> deployableArtifacts = new ArrayList<DeployableArtifactDetail>();
88+
List<DeployableArtifactDetail> deployableArtifacts = new ArrayList<>();
8789
for (DeployDetails artifact : deployDetails) {
8890
deployableArtifacts.add(new DeployableArtifactDetail(artifact.getFile().getAbsolutePath(), artifact.getArtifactPath(), artifact.getSha1(), artifact.getSha256(), artifact.getDeploySucceeded(), artifact.getTargetRepository()));
8991
}

build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/JsonSerializer.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.jfrog.build.extractor.clientConfiguration.util;
1818

19-
import com.fasterxml.jackson.annotation.JsonInclude;
2019
import com.fasterxml.jackson.core.JsonFactory;
2120
import com.fasterxml.jackson.core.JsonGenerator;
2221
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -25,6 +24,8 @@
2524
import java.io.IOException;
2625
import java.io.StringWriter;
2726

27+
import static org.jfrog.build.extractor.BuildInfoExtractorUtils.createMapper;
28+
2829
/**
2930
* @author jbaruch
3031
* @since 15/02/12
@@ -33,10 +34,9 @@ public class JsonSerializer<T> {
3334

3435
public String toJSON(T object) throws IOException {
3536
JsonFactory jsonFactory = new JsonFactory();
36-
ObjectMapper mapper = new ObjectMapper(jsonFactory);
37+
ObjectMapper mapper = createMapper();
3738

3839
mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector());
39-
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
4040
jsonFactory.setCodec(mapper);
4141
StringWriter writer = new StringWriter();
4242
JsonGenerator jsonGenerator = jsonFactory.createGenerator(writer);

build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/JsonUtils.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.jfrog.build.extractor.clientConfiguration.util;
22

3-
import com.fasterxml.jackson.annotation.JsonInclude;
43
import com.fasterxml.jackson.core.JsonFactory;
54
import com.fasterxml.jackson.core.JsonGenerator;
65
import com.fasterxml.jackson.core.JsonParser;
@@ -11,6 +10,8 @@
1110
import java.io.InputStream;
1211
import java.io.StringWriter;
1312

13+
import static org.jfrog.build.extractor.BuildInfoExtractorUtils.createMapper;
14+
1415
public class JsonUtils {
1516
public static String toJsonString(Object object) throws IOException {
1617
JsonFactory jsonFactory = createJsonFactory();
@@ -33,9 +34,8 @@ public static JsonParser createJsonParser(String content) throws IOException {
3334

3435
public static JsonFactory createJsonFactory() {
3536
JsonFactory jsonFactory = new JsonFactory();
36-
ObjectMapper mapper = new ObjectMapper(jsonFactory);
37+
ObjectMapper mapper = createMapper();
3738
mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector());
38-
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
3939
jsonFactory.setCodec(mapper);
4040
return jsonFactory;
4141
}

0 commit comments

Comments
 (0)