forked from synopsys-arc-oss/ownership-plugin
/
FolderOwnershipProperty.java
98 lines (86 loc) · 3.58 KB
/
FolderOwnershipProperty.java
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* The MIT License
*
* Copyright (c) 2015 Oleg Nenashev.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.jenkinsci.plugins.ownership.model.folders;
import com.cloudbees.hudson.plugins.folder.AbstractFolder;
import com.cloudbees.hudson.plugins.folder.AbstractFolderProperty;
import com.cloudbees.hudson.plugins.folder.AbstractFolderPropertyDescriptor;
import com.cloudbees.hudson.plugins.folder.Folder;
import com.cloudbees.hudson.plugins.folder.FolderProperty;
import com.synopsys.arc.jenkins.plugins.ownership.IOwnershipHelper;
import com.synopsys.arc.jenkins.plugins.ownership.IOwnershipItem;
import com.synopsys.arc.jenkins.plugins.ownership.OwnershipDescription;
import hudson.Extension;
import hudson.model.Descriptor;
import java.io.IOException;
import javax.annotation.CheckForNull;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;
/**
* Ownership property for {@link Folder}s.
* @author Oleg Nenashev
* @since TODO
*/
public class FolderOwnershipProperty
extends AbstractFolderProperty<AbstractFolder<?>>
implements IOwnershipItem<AbstractFolder<?>>{
@CheckForNull
OwnershipDescription ownership;
public FolderOwnershipProperty(@CheckForNull OwnershipDescription ownership) {
this.ownership = ownership;
}
@Override
public IOwnershipHelper<AbstractFolder<?>> helper() {
return FolderOwnershipHelper.getInstance();
}
@Override
public AbstractFolder<?> getDescribedItem() {
return owner;
}
@Override
public OwnershipDescription getOwnership() {
return ownership != null ? ownership : OwnershipDescription.DISABLED_DESCR;
}
/**
* Sets the new ownership description.
* @param description Description to be set. Use {@code null} to drop settings.
* @throws IOException Property cannot be saved.
*/
public void setOwnershipDescription(@CheckForNull OwnershipDescription description) throws IOException {
ownership = description;
owner.save();
}
@Override
public AbstractFolderProperty<?> reconfigure(StaplerRequest req, JSONObject form) throws Descriptor.FormException {
// Retain the current configuration in order to prevent changes by form submissions
return new FolderOwnershipProperty(ownership);
}
@Extension(optional = true)
public static class DescriptorImpl extends AbstractFolderPropertyDescriptor {
@Override
public String getDisplayName() {
// It prevents the property from displaying
return null;
}
}
}