parent
2f998221ba
commit
f28eeaea85
|
|
@ -5,10 +5,11 @@
|
|||
## sample configuration
|
||||
|
||||
```yaml
|
||||
git:
|
||||
installations:
|
||||
- name: git
|
||||
home: /usr/local/bin/git
|
||||
tool:
|
||||
git:
|
||||
installations:
|
||||
- name: git
|
||||
home: /usr/local/bin/git
|
||||
```
|
||||
|
||||
## implementation note
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import hudson.Extension;
|
|||
import hudson.ExtensionList;
|
||||
import hudson.ExtensionPoint;
|
||||
import hudson.model.Describable;
|
||||
import hudson.model.Descriptor;
|
||||
import hudson.model.TopLevelItem;
|
||||
import hudson.remoting.Which;
|
||||
import jenkins.model.Jenkins;
|
||||
|
|
@ -49,7 +50,8 @@ public abstract class Configurator<T> implements ExtensionPoint {
|
|||
|
||||
Class clazz = asClass(type);
|
||||
|
||||
final ExtensionList<Configurator> l = Jenkins.getInstance().getExtensionList(Configurator.class);
|
||||
final Jenkins jenkins = Jenkins.getInstance();
|
||||
final ExtensionList<Configurator> l = jenkins.getExtensionList(Configurator.class);
|
||||
for (Configurator c : l) {
|
||||
if (clazz == c.getTarget()) {
|
||||
// this type has a dedicated Configurator implementation
|
||||
|
|
@ -69,6 +71,10 @@ public abstract class Configurator<T> implements ExtensionPoint {
|
|||
return lookup(actualType);
|
||||
}
|
||||
|
||||
if (Descriptor.class.isAssignableFrom(clazz)) {
|
||||
return new DescriptorRootElementConfigurator((Descriptor) jenkins.getExtensionList(clazz).get(0));
|
||||
}
|
||||
|
||||
if (getDataBoundConstructor(clazz) != null) {
|
||||
return new DataBoundConfigurator(clazz);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
package org.jenkinsci.plugins.casc;
|
||||
|
||||
import hudson.ExtensionList;
|
||||
import hudson.model.Descriptor;
|
||||
import jenkins.model.GlobalConfigurationCategory;
|
||||
import jenkins.model.Jenkins;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jenkinsci.Symbol;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
|
||||
*/
|
||||
public class GlobalConfigurationCategoryConfigurator extends BaseConfigurator implements RootElementConfigurator {
|
||||
|
||||
private final GlobalConfigurationCategory category;
|
||||
|
||||
public GlobalConfigurationCategoryConfigurator(GlobalConfigurationCategory category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
final Class c = category.getClass();
|
||||
final Symbol symbol = (Symbol) c.getAnnotation(Symbol.class);
|
||||
if (symbol != null) return symbol.value()[0];
|
||||
|
||||
String name = c.getSimpleName();
|
||||
name = StringUtils.remove(name, "Global");
|
||||
name = StringUtils.remove(name, "Configuration");
|
||||
name = StringUtils.remove(name, "Category");
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getTarget() {
|
||||
return category.getClass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object configure(Object config) throws Exception {
|
||||
configure((Map) config, category);
|
||||
return category;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Attribute> describe() {
|
||||
|
||||
Set<Attribute> attributes = new HashSet<>();
|
||||
final ExtensionList<Descriptor> descriptors = Jenkins.getInstance().getExtensionList(Descriptor.class);
|
||||
for (Descriptor descriptor : descriptors) {
|
||||
if (descriptor.getCategory() == category && descriptor.getGlobalConfigPage() != null) {
|
||||
|
||||
final DescriptorRootElementConfigurator configurator = new DescriptorRootElementConfigurator(descriptor);
|
||||
attributes.add(new Attribute(configurator.getName(), configurator.getTarget()) {
|
||||
@Override
|
||||
public void setValue(Object target, Object value) throws Exception {
|
||||
// No actual attribute to set, DescriptorRootElementConfigurator manages singleton Descriptor components
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return attributes;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package org.jenkinsci.plugins.casc;
|
|||
|
||||
import hudson.ExtensionList;
|
||||
import hudson.model.Descriptor;
|
||||
import jenkins.model.GlobalConfigurationCategory;
|
||||
import jenkins.model.Jenkins;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -20,10 +21,14 @@ public interface RootElementConfigurator {
|
|||
final Jenkins jenkins = Jenkins.getInstance();
|
||||
configurators.addAll(jenkins.getExtensionList(RootElementConfigurator.class));
|
||||
|
||||
// Check for Descriptors with a global.jelly view
|
||||
for (GlobalConfigurationCategory category : GlobalConfigurationCategory.all()) {
|
||||
configurators.add(new GlobalConfigurationCategoryConfigurator(category));
|
||||
}
|
||||
|
||||
// Check for unclassified Descriptors
|
||||
final ExtensionList<Descriptor> descriptors = jenkins.getExtensionList(Descriptor.class);
|
||||
for (Descriptor descriptor : descriptors) {
|
||||
if (descriptor.getGlobalConfigPage() != null) {
|
||||
if (descriptor.getGlobalConfigPage() != null && descriptor.getCategory() instanceof GlobalConfigurationCategory.Unclassified) {
|
||||
configurators.add(new DescriptorRootElementConfigurator(descriptor));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
git:
|
||||
installations:
|
||||
- name: git
|
||||
home: /bin/git
|
||||
- name: another_git
|
||||
home: /usr/local/bin/git
|
||||
tool:
|
||||
git:
|
||||
installations:
|
||||
- name: git
|
||||
home: /bin/git
|
||||
- name: another_git
|
||||
home: /usr/local/bin/git
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue