未验证 提交 e091ea21 编写于 作者: O Oleg Nenashev 提交者: GitHub

Merge pull request #3305 from mikecirioli/JENKINS-49588

[JENKINS-49588] add readResolve method for 'usages' in Fingerprint.java
......@@ -866,7 +866,7 @@ public class Fingerprint implements ModelObject, Saveable {
/**
* Range of builds that use this file keyed by a job full name.
*/
private final Hashtable<String,RangeSet> usages = new Hashtable<String,RangeSet>();
private Hashtable<String,RangeSet> usages = new Hashtable<String,RangeSet>();
PersistedList<FingerprintFacet> facets = new PersistedList<FingerprintFacet>(this);
......@@ -1029,6 +1029,14 @@ public class Fingerprint implements ModelObject, Saveable {
save();
}
// JENKINS-49588
protected Object readResolve() {
if (usages == null) {
usages = new Hashtable<String,RangeSet>();
}
return this;
}
void addWithoutSaving(@Nonnull String jobFullName, int n) {
synchronized(usages) { // TODO why not synchronized (this) like some, though not all, other accesses?
RangeSet r = usages.get(jobFullName);
......
......@@ -222,6 +222,13 @@ public class FingerprintTest {
Fingerprint.load(new File(FingerprintTest.class.getResource("fingerprint.xml").toURI())).toString());
}
@Test public void loadFingerprintWithoutUsages() throws Exception {
Fingerprint fp = Fingerprint.load(new File(FingerprintTest.class.getResource("fingerprintWithoutUsages.xml").toURI()));
assertNotNull(fp);
assertEquals("test:jenkinsfile-example-1.0-SNAPSHOT.jar", fp.getFileName());
assertNotNull(fp.getUsages());
}
@Test public void roundTrip() throws Exception {
Fingerprint f = new Fingerprint(new Fingerprint.BuildPtr("foo", 13), "stuff&more.jar", SOME_MD5);
f.addWithoutSaving("some", 1);
......
<?xml version='1.0' encoding='UTF-8'?>
<fingerprint>
<timestamp>2018-02-21 16:33:12.291 UTC</timestamp>
<original>
<name>maven1/test:jenkinsfile-example</name>
<number>4</number>
</original>
<md5sum>f003726dfd1d07868e3c1ab5aab0682d</md5sum>
<fileName>test:jenkinsfile-example-1.0-SNAPSHOT.jar</fileName>
<facets/>
</fingerprint>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册