Search in sources :

Example 16 with Exported

use of org.kohsuke.stapler.export.Exported in project blueocean-plugin by jenkinsci.

the class BranchImpl method getBranch.

@Exported(name = BRANCH, inline = true)
public Branch getBranch() {
    ObjectMetadataAction om = job.getAction(ObjectMetadataAction.class);
    PrimaryInstanceMetadataAction pima = job.getAction(PrimaryInstanceMetadataAction.class);
    String url = om != null && om.getObjectUrl() != null ? om.getObjectUrl() : null;
    return new Branch(url, pima != null);
}
Also used : ObjectMetadataAction(jenkins.scm.api.metadata.ObjectMetadataAction) PrimaryInstanceMetadataAction(jenkins.scm.api.metadata.PrimaryInstanceMetadataAction) Exported(org.kohsuke.stapler.export.Exported)

Example 17 with Exported

use of org.kohsuke.stapler.export.Exported in project configuration-as-code-plugin by jenkinsci.

the class BaseConfigurator method describe.

public Set<Attribute> describe() {
    Set<Attribute> attributes = new HashSet<>();
    final Class<T> target = getTarget();
    final PropertyDescriptor[] properties = PropertyUtils.getPropertyDescriptors(target);
    LOGGER.log(Level.FINE, "Found {0} properties for {1}", new Object[] { properties.length, target });
    for (PropertyDescriptor p : properties) {
        final String name = p.getName();
        LOGGER.log(Level.FINER, "Processing {0} property", name);
        final Method setter = p.getWriteMethod();
        if (setter == null) {
            LOGGER.log(Level.FINE, "Ignored {0} property: read only", name);
            // read only
            continue;
        }
        if (setter.getAnnotation(Deprecated.class) != null) {
            LOGGER.log(Level.FINE, "Ignored {0} property: deprecated", name);
            // not actually public
            continue;
        }
        if (setter.getAnnotation(Restricted.class) != null) {
            LOGGER.log(Level.FINE, "Ignored {0} property: restricted", name);
            // not actually public     - require access-modifier 1.12
            continue;
        }
        // FIXME move this all into cleaner logic to discover property type
        Type type = setter.getGenericParameterTypes()[0];
        Attribute attribute = detectActualType(name, type);
        if (attribute == null)
            continue;
        attributes.add(attribute);
        final Method getter = p.getReadMethod();
        if (getter != null) {
            final Exported annotation = getter.getAnnotation(Exported.class);
            if (annotation != null && isNotBlank(annotation.name())) {
                attribute.preferredName(annotation.name());
            }
        }
        // See https://github.com/jenkinsci/structs-plugin/pull/18
        final Symbol s = setter.getAnnotation(Symbol.class);
        if (s != null) {
            attribute.preferredName(s.value()[0]);
        }
    }
    return attributes;
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) Restricted(org.kohsuke.accmod.Restricted) Symbol(org.jenkinsci.Symbol) Method(java.lang.reflect.Method) GenericArrayType(java.lang.reflect.GenericArrayType) WildcardType(java.lang.reflect.WildcardType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Exported(org.kohsuke.stapler.export.Exported) HashSet(java.util.HashSet)

Example 18 with Exported

use of org.kohsuke.stapler.export.Exported in project configuration-as-code-plugin by jenkinsci.

the class Attribute method locateGetter.

@CheckForNull
private static Method locateGetter(Class<?> clazz, @NonNull String fieldName) {
    final String upname = StringUtils.capitalize(fieldName);
    final List<String> accessors = Arrays.asList("get" + upname, "is" + upname);
    for (Method method : clazz.getMethods()) {
        if (method.getParameterCount() != 0)
            continue;
        if (accessors.contains(method.getName())) {
            return method;
        }
        final Exported exported = method.getAnnotation(Exported.class);
        if (exported != null && exported.name().equalsIgnoreCase(fieldName)) {
            return method;
        }
    }
    return null;
}
Also used : Method(java.lang.reflect.Method) Exported(org.kohsuke.stapler.export.Exported) CheckForNull(edu.umd.cs.findbugs.annotations.CheckForNull)

Example 19 with Exported

use of org.kohsuke.stapler.export.Exported in project workflow-job-plugin by jenkinsci.

the class FlowGraphAction method getNodes.

@Exported
public Collection<? extends FlowNode> getNodes() {
    FlowExecution exec = run.getExecution();
    if (exec == null) {
        return Collections.emptySet();
    }
    List<FlowNode> nodes = new ArrayList<>();
    FlowGraphWalker walker = new FlowGraphWalker(exec);
    for (FlowNode n : walker) {
        nodes.add(n);
    }
    Collections.reverse(nodes);
    return nodes;
}
Also used : FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) ArrayList(java.util.ArrayList) FlowGraphWalker(org.jenkinsci.plugins.workflow.graph.FlowGraphWalker) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Exported(org.kohsuke.stapler.export.Exported)

Example 20 with Exported

use of org.kohsuke.stapler.export.Exported in project jenkins by jenkinsci.

the class Fingerprint method _getUsages.

// this is for remote API
@Exported(name = "usage")
@NonNull
public List<RangeItem> _getUsages() {
    List<RangeItem> r = new ArrayList<>();
    final Jenkins instance = Jenkins.get();
    for (Map.Entry<String, RangeSet> e : usages.entrySet()) {
        final String itemName = e.getKey();
        if (instance.hasPermission(Jenkins.ADMINISTER) || canDiscoverItem(itemName)) {
            r.add(new RangeItem(itemName, e.getValue()));
        }
    }
    return r;
}
Also used : Jenkins(jenkins.model.Jenkins) ArrayList(java.util.ArrayList) Map(java.util.Map) TreeMap(java.util.TreeMap) NonNull(edu.umd.cs.findbugs.annotations.NonNull) Exported(org.kohsuke.stapler.export.Exported)

Aggregations

Exported (org.kohsuke.stapler.export.Exported)21 HashSet (java.util.HashSet)5 ArrayList (java.util.ArrayList)4 Jenkins (jenkins.model.Jenkins)3 NonNull (edu.umd.cs.findbugs.annotations.NonNull)2 Executable (hudson.model.Queue.Executable)2 Cloud (hudson.slaves.Cloud)2 Method (java.lang.reflect.Method)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 GregorianCalendar (java.util.GregorianCalendar)2 ObjectMetadataAction (jenkins.scm.api.metadata.ObjectMetadataAction)2 CheckForNull (edu.umd.cs.findbugs.annotations.CheckForNull)1 ExtensionPoint (hudson.ExtensionPoint)1 PluginWrapper (hudson.PluginWrapper)1 User (hudson.model.User)1 Entry (hudson.scm.ChangeLogSet.Entry)1 UserProperty (hudson.tasks.Mailer.UserProperty)1 AdaptedIterator (hudson.util.AdaptedIterator)1 CopyOnWriteList (hudson.util.CopyOnWriteList)1