sort Attributes and RootElementConfigurator according to Extension ordinal (#1394)
This commit is contained in:
parent
d6759fbfb0
commit
0f26dd810b
|
|
@ -298,7 +298,8 @@ public abstract class BaseConfigurator<T> implements Configurator<T> {
|
|||
*/
|
||||
protected void configure(Mapping config, T instance, boolean dryrun, ConfigurationContext context) throws ConfiguratorException {
|
||||
final Set<Attribute<T,?>> attributes = describe();
|
||||
for (Attribute<T,?> attribute : attributes) {
|
||||
List<Attribute<T, ?>> sortedAttributes = attributes.stream().sorted(Configurator.extensionOrdinalSort()).collect(Collectors.toList());
|
||||
for (Attribute<T,?> attribute : sortedAttributes) {
|
||||
|
||||
final String name = attribute.getName();
|
||||
CNode sub = removeIgnoreCase(config, name);
|
||||
|
|
@ -403,7 +404,6 @@ public abstract class BaseConfigurator<T> implements Configurator<T> {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static final class TypePair {
|
||||
|
||||
final Type type;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ package io.jenkins.plugins.casc;
|
|||
|
||||
import edu.umd.cs.findbugs.annotations.CheckForNull;
|
||||
import edu.umd.cs.findbugs.annotations.NonNull;
|
||||
import hudson.Extension;
|
||||
import hudson.ExtensionPoint;
|
||||
import io.jenkins.plugins.casc.model.CNode;
|
||||
import io.jenkins.plugins.casc.model.Mapping;
|
||||
|
|
@ -209,4 +210,28 @@ public interface Configurator<T> {
|
|||
return mapping;
|
||||
}
|
||||
|
||||
static double extractExtensionOrdinal(Object obj) {
|
||||
if (obj instanceof Attribute<?, ?>) {
|
||||
return extractExtensionOrdinal((Attribute<?, ?>) obj);
|
||||
} else {
|
||||
return extractExtensionOrdinal(obj.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
static double extractExtensionOrdinal(Attribute<?, ?> attribute) {
|
||||
return extractExtensionOrdinal(attribute.type);
|
||||
}
|
||||
|
||||
static double extractExtensionOrdinal(Class clazz) {
|
||||
Extension extension = (Extension) clazz.getAnnotation(Extension.class);
|
||||
if (extension == null) {
|
||||
return 0.0;
|
||||
}
|
||||
return extension.ordinal();
|
||||
}
|
||||
|
||||
static Comparator<Object> extensionOrdinalSort() {
|
||||
return Comparator.comparingDouble(Configurator::extractExtensionOrdinal).reversed();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ public interface RootElementConfigurator<T> extends Configurator<T> {
|
|||
configurators.add(new DescriptorConfigurator(descriptor));
|
||||
}
|
||||
|
||||
configurators.sort(Configurator.extensionOrdinalSort());
|
||||
|
||||
return configurators;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ import static io.jenkins.plugins.casc.Attribute.noop;
|
|||
/**
|
||||
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
|
||||
*/
|
||||
@Extension
|
||||
@Extension(ordinal = 1)
|
||||
@Restricted(NoExternalUse.class)
|
||||
public class JenkinsConfigurator extends BaseConfigurator<Jenkins> implements RootElementConfigurator<Jenkins> {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue