-
Notifications
You must be signed in to change notification settings - Fork 748
Expand file tree
/
Copy pathRootElementConfigurator.java
More file actions
66 lines (56 loc) · 2.46 KB
/
RootElementConfigurator.java
File metadata and controls
66 lines (56 loc) · 2.46 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
package io.jenkins.plugins.casc;
import hudson.model.Descriptor;
import hudson.model.ManagementLink;
import io.jenkins.plugins.casc.impl.configurators.DescriptorConfigurator;
import io.jenkins.plugins.casc.impl.configurators.GlobalConfigurationCategoryConfigurator;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.GlobalConfigurationCategory;
import jenkins.model.Jenkins;
/**
* Define a {@link Configurator} which handles a root configuration element, identified by name.
* Note: we assume any configurator here will use a unique name for root element.
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
*/
public interface RootElementConfigurator<T> extends Configurator<T> {
Logger LOGGER = Logger.getLogger(RootElementConfigurator.class.getName());
static List<RootElementConfigurator> all() {
final Jenkins jenkins = Jenkins.get();
List<RootElementConfigurator> configurators =
new ArrayList<>(jenkins.getExtensionList(RootElementConfigurator.class));
for (GlobalConfigurationCategory category : GlobalConfigurationCategory.all()) {
configurators.add(new GlobalConfigurationCategoryConfigurator(category));
}
for (ManagementLink link : ManagementLink.all()) {
try {
final String name = link.getUrlName();
if (name != null && !name.isEmpty()) {
final Descriptor descriptor = Jenkins.get().getDescriptor(name);
if (descriptor != null) {
configurators.add(new DescriptorConfigurator(descriptor));
}
}
} catch (Exception | LinkageError e) {
LOGGER.log(
Level.WARNING,
"Failed to load configuration for ManagementLink: "
+ link.getClass().getName() + ". Skipping.",
e);
}
}
configurators.sort(Configurator.extensionOrdinalSort());
return configurators;
}
/* This function is used for configurator-pointer in the documentation.jelly file only. */
default boolean isRootElement() {
return true;
}
/**
* Retrieve the target component managed by this RootElementConfigurator
* @return
* @param context
*/
T getTargetComponent(ConfigurationContext context);
}