-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathGlobalConfigurationItem.java
More file actions
84 lines (69 loc) · 2.23 KB
/
Copy pathGlobalConfigurationItem.java
File metadata and controls
84 lines (69 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package io.jenkins.plugins.util;
import edu.hm.hafner.util.VisibleForTesting;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest2;
import jenkins.model.GlobalConfiguration;
/**
* Testable base class for items of the {@link GlobalConfiguration} page.
*
* @author Ullrich Hafner
*/
@SuppressFBWarnings("IS2_INCONSISTENT_SYNC")
public class GlobalConfigurationItem extends GlobalConfiguration {
private transient Runnable actualSave;
private transient Runnable actualLoad;
/**
* Creates a new {@link GlobalConfigurationItem}.
*/
protected GlobalConfigurationItem() {
super();
actualLoad = super::load;
actualSave = super::save;
}
/**
* Creates a new {@link GlobalConfigurationItem}.
*
* @param facade
* the facade to use
*/
@VisibleForTesting
protected GlobalConfigurationItem(final GlobalConfigurationFacade facade) {
super();
actualLoad = facade::load;
actualSave = facade::save;
}
/**
* Called after deserialization to restore transient fields.
*
* @return this
*/
protected Object readResolve() {
actualLoad = super::load;
actualSave = super::save;
return this;
}
@Override
public boolean configure(final StaplerRequest2 req, final JSONObject json) throws FormException {
clearRepeatableProperties();
return super.configure(req, json);
}
/**
* Clears all model elements of a repeatable property. Due to a bug in Stapler data binding of repeatable properties
* the model elements are only changed if they consist of one or more values. If all values have been removed and
* the associated form is empty, then the setter is not invoked anymore.
*/
protected void clearRepeatableProperties() {
// empty default implementation
}
@Override
@SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel")
public final synchronized void load() {
actualLoad.run();
}
@Override
@SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel")
public final synchronized void save() {
actualSave.run();
}
}