forked from jenkinsci/unique-id-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FolderIdStore.java
99 lines (83 loc) · 2.81 KB
/
FolderIdStore.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
99
package org.jenkinsci.plugins.uniqueid.impl;
import hudson.Extension;
import hudson.model.Action;
import hudson.model.Actionable;
import hudson.util.DescribableList;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.logging.Logger;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import com.cloudbees.hudson.plugins.folder.FolderProperty;
import com.cloudbees.hudson.plugins.folder.FolderPropertyDescriptor;
import com.cloudbees.hudson.plugins.folder.Folder;
/**
* Stores ids for folders as a {@link FolderIdProperty}
* @deprecated {@see PersistenceRootIdStore}
*/
@Extension(optional = true)
@Deprecated
@Restricted(NoExternalUse.class)
public class FolderIdStore extends LegacyIdStore<Folder> {
public FolderIdStore() {
super(Folder.class);
}
@Override
public void remove(Folder folder) throws IOException {
DescribableList<FolderProperty<?>,FolderPropertyDescriptor> properties = folder.getProperties();
for (Iterator<FolderProperty<?>> itr = properties.iterator(); itr.hasNext(); ) {
FolderProperty<?> prop = itr.next();
if (prop instanceof FolderIdProperty) {
itr.remove();
}
}
folder.save();
}
@Override
public String get(Folder folder) {
String id = Id.getId((Actionable) folder);
if (id != null) {
return id;
} else {
FolderIdProperty idProperty = folder.getProperties().get(FolderIdProperty.class);
if (idProperty != null) {
return idProperty.getId();
}
}
return null;
}
/**
* A unique ID for folders.
*/
public static class FolderIdProperty extends FolderProperty {
private Id id = new Id();
@Override
public Collection<? extends Action> getFolderActions() {
return Collections.singleton(id);
}
@Extension(optional = true)
public static class DescriptorImpl extends FolderPropertyDescriptor {
@Override
public String getDisplayName() {
return "Unique ID";
}
@Override
public boolean isApplicable(Class<? extends Folder> containerType) {
return false;
}
}
/**
* Since {@link Folder#getAction(Class)} does return actions from a property,
* (like {@link hudson.model.Job#getAction(Class)} does)
* this method is added for convenience.
*
* @return the id for this folder
*/
public String getId() {
return id.getId();
}
}
private final static Logger LOGGER = Logger.getLogger(FolderIdStore.class.getName());
}