use of hudson.model.Descriptor in project promoted-builds-plugin by jenkinsci.
the class ManualConditionBug22005 method testPromotionProcessViaWebClient.
@Test
public void testPromotionProcessViaWebClient() 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);
createPromotionProcess(base, "PROM0");
createPromotionProcess(base, "PROM1");
createPromotionProcess(base, "PROM2");
FreeStyleBuild b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
assertNull(b1.getAction(ManualApproval.class));
HtmlPage page = j.createWebClient().getPage(b1, "promotion");
// Approve Promotion
List<HtmlForm> forms = ManualConditionTest.getFormsByName(page, "approve");
assertFalse(forms.isEmpty());
assertEquals(3, forms.size());
for (HtmlForm form : forms) {
submit(form);
}
// reload promotions page
page = j.createWebClient().getPage(b1, "promotion");
forms = ManualConditionTest.getFormsByName(page, "build");
for (HtmlForm form : forms) {
List<HtmlElement> parameters = ManualConditionTest.getFormParameters(form);
assertEquals(2, parameters.size());
}
}
use of hudson.model.Descriptor in project promoted-builds-plugin by jenkinsci.
the class ManualConditionInheritanceTest method testManualPromotionProcess.
@Test
public void testManualPromotionProcess() throws Exception {
InheritanceProjectsPair inheritanceProjectsPair = j.createInheritanceProjectDerivedWithBase();
ExtensionList<Descriptor> list = Jenkins.get().getExtensionList(Descriptor.class);
list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class));
JobPropertyImpl base = new JobPropertyImpl(inheritanceProjectsPair.getBase());
inheritanceProjectsPair.getBase().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);
InheritanceBuild b1 = j.assertBuildStatusSuccess(inheritanceProjectsPair.getDerived().scheduleBuild2(0));
// promote a build
List<ParameterValue> paramValues = condition.createDefaultValues();
// try to add duplicate values
paramValues.addAll(condition.createDefaultValues());
// We cannot assume that the process will contain builds because the process added to base project is different to the one in derived.
JobPropertyImpl jobProperty = inheritanceProjectsPair.getDerived().getProperty(JobPropertyImpl.class, /*Forcing inheritance as temporary hack for inheritance plugin 1.53
because that version of the plugin uses inheritance only for certain predefined cases:
-specific methods on the call stack
-url paths.
This has been changed as pull request https://github.com/i-m-c/jenkins-inheritance-plugin/pull/40
*/
IMode.INHERIT_FORCED);
assertNotNull("derived jobProperty is null", jobProperty);
PromotionProcess fooDerived = jobProperty.getItem("foo");
j.assertBuildStatusSuccess(condition.approve(b1, fooDerived, paramValues));
ManualApproval manualApproval = b1.getAction(ManualApproval.class);
assertNotNull(manualApproval);
PromotedBuildAction statuses = b1.getAction(PromotedBuildAction.class);
assertNotNull(statuses);
assertNotNull(statuses.getPromotions());
assertFalse(statuses.getPromotions().isEmpty());
}
use of hudson.model.Descriptor in project hudson-2.x by hudson.
the class DescribableListUtilTest method testConvertToProjectProperties3.
@Test
public void testConvertToProjectProperties3() throws IOException {
Hudson hudson = createMock(Hudson.class);
Mailer.DescriptorImpl descriptor = createMock(Mailer.DescriptorImpl.class);
String mailerName = "hudson-tasks-Mailer";
expect(descriptor.getJsonSafeClassName()).andReturn(mailerName);
expect(hudson.getDescriptorOrDie(Mailer.class)).andReturn(descriptor);
mockStatic(Hudson.class);
expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
prepareJob();
DescribableList<Publisher, Descriptor<Publisher>> list = new DescribableList<Publisher, Descriptor<Publisher>>();
list.add(new Mailer());
Map<String, ExternalProjectProperty<Publisher>> map = DescribableListUtil.convertToProjectProperties(list, job);
assertNotNull(map);
assertEquals(map.size(), 1);
assertNotNull(map.get(mailerName));
assertEquals(map.get(mailerName).getValue().getClass(), Mailer.class);
}
use of hudson.model.Descriptor in project hudson-2.x by hudson.
the class SCM method _for.
/**
* Returns the list of {@link SCMDescriptor}s that are applicable to the given project.
*/
public static List<SCMDescriptor<?>> _for(final AbstractProject project) {
if (project == null)
return all();
final Descriptor pd = Hudson.getInstance().getDescriptor((Class) project.getClass());
List<SCMDescriptor<?>> r = new ArrayList<SCMDescriptor<?>>();
for (SCMDescriptor<?> scmDescriptor : all()) {
if (!scmDescriptor.isApplicable(project))
continue;
if (pd instanceof AbstractProjectDescriptor) {
AbstractProjectDescriptor apd = (AbstractProjectDescriptor) pd;
if (!apd.isApplicable(scmDescriptor))
continue;
}
r.add(scmDescriptor);
}
return r;
}
use of hudson.model.Descriptor in project workflow-cps-plugin by jenkinsci.
the class DSL method invokeDescribable.
/**
* When {@link #invokeMethod(String, Object)} is calling a generic {@link Descriptor}
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Object invokeDescribable(String symbol, Object _args) {
List<StepDescriptor> metaSteps = StepDescriptor.metaStepsOf(symbol);
StepDescriptor metaStep = metaSteps.size() == 1 ? metaSteps.get(0) : null;
boolean singleArgumentOnly = false;
if (metaStep != null) {
Descriptor symbolDescriptor = SymbolLookup.get().findDescriptor((Class) (metaStep.getMetaStepArgumentType()), symbol);
DescribableModel<?> symbolModel = DescribableModel.of(symbolDescriptor.clazz);
singleArgumentOnly = symbolModel.hasSingleRequiredParameter() && symbolModel.getParameters().size() == 1;
}
// The only time a closure is valid is when the resulting Describable is immediately executed via a meta-step
NamedArgsAndClosure args = parseArgs(_args, metaStep != null && metaStep.takesImplicitBlockArgument(), UninstantiatedDescribable.ANONYMOUS_KEY, singleArgumentOnly);
UninstantiatedDescribable ud = new UninstantiatedDescribable(symbol, null, args.namedArgs);
if (metaStep == null) {
// might be resolved with a specific type.
return ud;
} else {
Descriptor d = SymbolLookup.get().findDescriptor((Class) (metaStep.getMetaStepArgumentType()), symbol);
try {
// execute this Describable through a meta-step
// split args between MetaStep (represented by mm) and Describable (represented by dm)
DescribableModel<?> mm = DescribableModel.of(metaStep.clazz);
DescribableModel<?> dm = DescribableModel.of(d.clazz);
DescribableParameter p = mm.getFirstRequiredParameter();
if (p == null) {
// meta-step not having a required parameter is a bug in this meta step
throw new IllegalArgumentException("Attempted to use meta-step " + metaStep.getFunctionName() + " to process " + symbol + " but this meta-step is buggy; it has no mandatory parameter");
}
// order of preference:
// 1. mandatory parameter in mm
// 2. mandatory parameter in dm
// 3. other parameters in mm
// 4. other parameters in dm
// mm is preferred over dm because that way at least the arguments that mm defines
// act consistently
Map<String, Object> margs = new TreeMap<>();
Map<String, Object> dargs = new TreeMap<>();
for (Entry<String, ?> e : ud.getArguments().entrySet()) {
String n = e.getKey();
Object v = e.getValue();
DescribableParameter mp = mm.getParameter(n);
DescribableParameter dp = dm.getParameter(n);
if (mp != null && mp.isRequired()) {
margs.put(n, v);
} else if (dp != null && dp.isRequired()) {
dargs.put(n, v);
} else if (mp != null) {
margs.put(n, v);
} else {
// dp might be null, but this error will be caught by UD.instantiate() later
dargs.put(n, v);
}
}
ud = new UninstantiatedDescribable(symbol, null, dargs);
margs.put(p.getName(), ud);
return invokeStep(metaStep, new NamedArgsAndClosure(margs, args.body));
} catch (Exception e) {
throw new IllegalArgumentException("Failed to prepare " + symbol + " step", e);
}
}
}
Aggregations