Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jenkinsci/configuration-as-code-plugin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: itaborda/configuration-as-code-plugin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Oct 3, 2018

  1. Add support to With-NO @symbol annotation Descriptors

    Isaac Taborda da Silva committed Oct 3, 2018
    Copy the full SHA
    a537406 View commit details
31 changes: 31 additions & 0 deletions plugin/src/main/java/io/jenkins/plugins/casc/Configurator.java
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@

package io.jenkins.plugins.casc;

import hudson.ExtensionList;
import hudson.ExtensionPoint;
import io.jenkins.plugins.casc.model.CNode;
import org.apache.commons.lang.StringUtils;
@@ -32,8 +33,12 @@
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import jenkins.model.Jenkins;

/**
* Define a {@link Configurator} which handles a configuration element, identified by name.
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
@@ -53,6 +58,32 @@ static String normalize(@Nonnull String name) {
return name;
}

/**
* Finds a Configurator for base type and a short name
* @param clazz Base class
* @param shortname Short name of the implementation
* @return Configurator
*/
@CheckForNull
static Configurator<?> lookupForBaseType(Class<?> clazz, @Nonnull String shortname) {

final Logger LOGGER = Logger.getLogger(Configurator.class.getName());

final Jenkins jenkins = Jenkins.getInstance();
final ExtensionList<Configurator> l = jenkins.getExtensionList(Configurator.class);
for (Configurator c : l) {

LOGGER.log(Level.FINE, "Checking if configurator '"+c.getName()+" > "+c.getTarget().getName()+"' match with '"+shortname+" > "+clazz.getName()+"'");

if (shortname.equalsIgnoreCase(c.getName())) { // short name match, ensure that the type is compliant
if (clazz.isAssignableFrom(c.getTarget())) { // Implements child class
return c;
}
}
}
return null;
}

/**
* Get a configurator name.
* @return short name for this component when used in a configuration.yaml file
Original file line number Diff line number Diff line change
@@ -137,6 +137,17 @@ private Class<T> findDescribableBySymbol(CNode node, String shortname, List<Desc
}
}
}

// Not all Describable classes have symbols, give a chance to custom configurators in standalone plugins
// TODO: probably this logic should have a priority over Symbol so that extensions can override it
final Configurator<?> c = Configurator.lookupForBaseType(target, shortname);
if (c != null) {
Class<?> clazz = c.getTarget();
if (Describable.class.isAssignableFrom(clazz)) {
return (Class<T>) clazz;
}
}

final String errSupport = !_hasSupportPluginInstalled() ? "\nPossible solution: Try to install 'configuration-as-code-support' plugin" : "";
final String msg = "No "+target.getName()+ " implementation found for "+shortname;
throw new IllegalArgumentException(String.format("%s%s", msg, errSupport));