Search in sources :

Example 1 with Descriptor

use of hudson.model.Descriptor in project workflow-cps-plugin by jenkinsci.

the class StepDescriptorCache method getDescriptor.

@CheckForNull
public StepDescriptor getDescriptor(String descriptorId) {
    if (descriptorId == null) {
        return null;
    }
    StepDescriptor v = store.get(descriptorId);
    if (v != null) {
        return v;
    } else {
        Jenkins j = Jenkins.getActiveInstance();
        Descriptor d = j.getDescriptor(descriptorId);
        if (d instanceof StepDescriptor) {
            store.put(descriptorId, (StepDescriptor) d);
            return (StepDescriptor) d;
        }
        return null;
    }
}
Also used : Jenkins(jenkins.model.Jenkins) StepDescriptor(org.jenkinsci.plugins.workflow.steps.StepDescriptor) Descriptor(hudson.model.Descriptor) StepDescriptor(org.jenkinsci.plugins.workflow.steps.StepDescriptor) CheckForNull(javax.annotation.CheckForNull)

Example 2 with Descriptor

use of hudson.model.Descriptor in project configuration-as-code-plugin by jenkinsci.

the class DataBoundConfigurator method getExtensionPoint.

public Class getExtensionPoint() {
    final Descriptor descriptor = getDescriptor();
    if (descriptor != null) {
        // detect common pattern DescriptorImpl extends Descriptor<ExtensionPoint>
        final Type superclass = descriptor.getClass().getGenericSuperclass();
        if (superclass instanceof ParameterizedType) {
            final ParameterizedType genericSuperclass = (ParameterizedType) superclass;
            Type type = genericSuperclass.getActualTypeArguments()[0];
            if (type instanceof ParameterizedType) {
                type = ((ParameterizedType) type).getRawType();
            }
            if (type instanceof Class) {
                return (Class) type;
            }
        }
    }
    return super.getExtensionPoint();
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Descriptor(hudson.model.Descriptor) ClassDescriptor(org.kohsuke.stapler.ClassDescriptor)

Example 3 with Descriptor

use of hudson.model.Descriptor in project promoted-builds-plugin by jenkinsci.

the class ManualConditionTest method addPromotionProcess.

private PromotionProcess addPromotionProcess(AbstractProject<?, ?> owner, String name) throws Exception {
    ExtensionList<Descriptor> list = j.jenkins.getExtensionList(Descriptor.class);
    list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class));
    JobPropertyImpl base = new JobPropertyImpl(owner);
    owner.addProperty(base);
    return base.addProcess(name);
}
Also used : Descriptor(hudson.model.Descriptor) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl)

Example 4 with Descriptor

use of hudson.model.Descriptor in project promoted-builds-plugin by jenkinsci.

the class ManualConditionTest method testManualPromotionProcess.

@Test
public void testManualPromotionProcess() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject();
    ExtensionList<Descriptor> list = j.jenkins.getExtensionList(Descriptor.class);
    list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class));
    JobPropertyImpl base = new JobPropertyImpl(p);
    p.addProperty(base);
    PromotionProcess foo = base.addProcess("foo");
    ManualCondition condition = new ManualCondition();
    condition.getParameterDefinitions().add(new StringParameterDefinition("bogus_string_param_1", "bogus_value_1", "Bog parameter"));
    condition.getParameterDefinitions().add(new StringParameterDefinition("bogus_string_param_2", "bogus_value_2", "Bog parameter"));
    foo.conditions.add(condition);
    FreeStyleBuild b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
    // promote a build
    List<ParameterValue> paramValues = condition.createDefaultValues();
    // try to add duplicate values
    paramValues.addAll(condition.createDefaultValues());
    j.assertBuildStatusSuccess(condition.approve(b1, foo, paramValues));
    ManualApproval manualApproval = b1.getAction(ManualApproval.class);
    assertNotNull(manualApproval);
    PromotedBuildAction statuses = b1.getAction(PromotedBuildAction.class);
    assertNotNull(statuses);
    assertNotNull(statuses.getPromotions());
    assertFalse(statuses.getPromotions().isEmpty());
}
Also used : ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) StringParameterDefinition(hudson.model.StringParameterDefinition) StringParameterValue(hudson.model.StringParameterValue) ParameterValue(hudson.model.ParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) Descriptor(hudson.model.Descriptor) Test(org.junit.Test)

Example 5 with Descriptor

use of hudson.model.Descriptor in project promoted-builds-plugin by jenkinsci.

the class ManualConditionBug22005 method testPromotionProcess.

@Test
public void testPromotionProcess() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject();
    ExtensionList<Descriptor> list = j.jenkins.getExtensionList(Descriptor.class);
    list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class));
    JobPropertyImpl base = new JobPropertyImpl(p);
    p.addProperty(base);
    PromotionProcess prom0 = createPromotionProcess(base, "PROM0");
    ManualCondition prom0Condition = prom0.conditions.get(ManualCondition.class);
    PromotionProcess prom1 = createPromotionProcess(base, "PROM1");
    ManualCondition prom1Condition = prom1.conditions.get(ManualCondition.class);
    PromotionProcess prom2 = createPromotionProcess(base, "PROM2");
    ManualCondition prom2Condition = prom2.conditions.get(ManualCondition.class);
    FreeStyleBuild b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
    Promotion p0b1 = j.assertBuildStatusSuccess(prom0Condition.approve(b1, prom0));
    assertEquals(2, p0b1.getParameterValues().size());
    assertEquals(2, p0b1.getParameterDefinitionsWithValue().size());
    Promotion p1b1 = j.assertBuildStatusSuccess(prom1Condition.approve(b1, prom1));
    assertEquals(2, p1b1.getParameterValues().size());
    assertEquals(2, p1b1.getParameterDefinitionsWithValue().size());
    Promotion p2b1 = j.assertBuildStatusSuccess(prom2Condition.approve(b1, prom2));
    assertEquals(2, p2b1.getParameterValues().size());
    assertEquals(2, p2b1.getParameterDefinitionsWithValue().size());
    List<ManualApproval> approvals = b1.getActions(ManualApproval.class);
    assertEquals(3, approvals.size());
    PromotedBuildAction promBuildAction = b1.getAction(PromotedBuildAction.class);
    List<Status> statuses = promBuildAction.getPromotions();
    assertEquals(3, statuses.size());
    for (Status status : statuses) {
        Promotion lastBuild = status.getLast();
        List<ParameterDefinition> lastBuildParameters = lastBuild.getParameterDefinitionsWithValue();
        assertEquals(2, lastBuildParameters.size());
    }
}
Also used : Status(hudson.plugins.promoted_builds.Status) ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) FreeStyleBuild(hudson.model.FreeStyleBuild) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Promotion(hudson.plugins.promoted_builds.Promotion) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) Descriptor(hudson.model.Descriptor) ParameterDefinition(hudson.model.ParameterDefinition) StringParameterDefinition(hudson.model.StringParameterDefinition) Test(org.junit.Test)

Aggregations

Descriptor (hudson.model.Descriptor)22 Test (org.junit.Test)9 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)8 ArrayList (java.util.ArrayList)8 ManualApproval (hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval)7 StringParameterDefinition (hudson.model.StringParameterDefinition)6 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)6 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)6 FreeStyleBuild (hudson.model.FreeStyleBuild)5 FreeStyleProject (hudson.model.FreeStyleProject)5 Promotion (hudson.plugins.promoted_builds.Promotion)4 StepDescriptor (org.jenkinsci.plugins.workflow.steps.StepDescriptor)4 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)3 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)3 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)3 AbstractProjectDescriptor (hudson.model.AbstractProject.AbstractProjectDescriptor)3 ParameterDefinition (hudson.model.ParameterDefinition)3 ParameterValue (hudson.model.ParameterValue)3 Jenkins (jenkins.model.Jenkins)3 Describable (hudson.model.Describable)2