use of hudson.model.Descriptor in project promoted-builds-plugin by jenkinsci.
the class ManualConditionInheritanceTest method testManualPromotionProcessViaWebClient.
@Test
public void testManualPromotionProcessViaWebClient() 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.getDerived().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));
assertNull(b1.getAction(ManualApproval.class));
HtmlPage page = j.createWebClient().getPage(b1, "promotion");
// Approve Promotion
List<HtmlForm> forms = getFormsByName(page, "approve");
assertFalse(forms.isEmpty());
assertEquals(1, forms.size());
HtmlForm form = forms.get(0);
List<HtmlElement> parameters = getFormParameters(form);
assertEquals(parameters.size(), condition.getParameterDefinitions().size());
for (HtmlElement param : parameters) {
HtmlElement v = param.getElementsByAttribute("input", "name", "value").get(0);
v.setAttribute("value", v.getAttribute("value") + "1");
}
j.submit(forms.get(0));
j.waitUntilNoActivity();
// We cannot assume that the process will contain builds because the process added to base project is different to the one in derived.
final 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);
final PromotionProcess fooDerived = jobProperty.getItem("foo");
ManualApproval approval = b1.getAction(ManualApproval.class);
assertNotNull(approval);
SortedMap<Integer, Promotion> builds = fooDerived.getBuildsAsMap();
assertNotNull(builds);
assertEquals(1, builds.size());
// Re-Execute approved promotion
page = j.createWebClient().getPage(b1, "promotion");
forms = getFormsByName(page, "build");
assertFalse(forms.isEmpty());
assertEquals(1, forms.size());
form = forms.get(0);
parameters = getFormParameters(form);
assertEquals(parameters.size(), condition.getParameterDefinitions().size());
for (HtmlElement param : parameters) {
HtmlElement v = param.getElementsByAttribute("input", "name", "value").get(0);
v.setAttribute("value", v.getAttribute("value") + "2");
}
j.submit(form);
j.waitUntilNoActivity();
final JobPropertyImpl jobProperty2 = 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", jobProperty2);
final PromotionProcess fooDerived2 = jobProperty2.getItem("foo");
builds = fooDerived2.getBuildsAsMap();
assertEquals(2, builds.size());
List<ManualApproval> actions = b1.getActions(ManualApproval.class);
assertEquals(1, actions.size());
PromotedBuildAction buildActions = b1.getAction(PromotedBuildAction.class);
int buildIndex = 1;
String valueSufix = "1";
List<Promotion> promotions = new ArrayList<Promotion>();
promotions.addAll(builds.values());
Collections.reverse(promotions);
for (Promotion build : promotions) {
List<ParameterDefinition> values = build.getParameterDefinitionsWithValue();
assertEquals(values.size(), condition.getParameterDefinitions().size());
for (ParameterDefinition v : values) {
assertTrue(v instanceof StringParameterDefinition);
String pvalue = ((StringParameterDefinition) v).getDefaultValue();
assertTrue(pvalue.endsWith(valueSufix));
}
buildIndex++;
valueSufix += buildIndex;
}
}
use of hudson.model.Descriptor in project hudson-2.x by hudson.
the class CascadingUtilTest method testBuildExternalProperties.
@Test
@PrepareForTest({ Hudson.class, StaplerRequest.class })
public void testBuildExternalProperties() throws Exception {
Job job = new FreeStyleProjectMock("job");
StaplerRequest req = createMock(StaplerRequest.class);
String javadocArchiverKey = "hudson-tasks-JavadocArchiver";
JSONObject archiver = new JSONObject();
archiver.put("javadoc_dir", "dir");
archiver.put("keep_all", true);
JSONObject json = new JSONObject();
json.put(javadocArchiverKey, archiver);
Hudson hudson = createMock(Hudson.class);
Descriptor<Publisher> javadocDescriptor = new JavadocArchiver.DescriptorImpl();
expect(hudson.getDescriptorOrDie(JavadocArchiver.class)).andReturn(javadocDescriptor);
JavadocArchiver javadocArchiver = new JavadocArchiver("dir", true);
expect(req.bindJSON(JavadocArchiver.class, archiver)).andReturn(javadocArchiver).anyTimes();
List<Descriptor<Publisher>> descriptors = new ArrayList<Descriptor<Publisher>>();
descriptors.add(javadocDescriptor);
mockStatic(Hudson.class);
expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
replay(Hudson.class, hudson, req);
assertNull(CascadingUtil.getExternalProjectProperty(job, javadocArchiverKey).getValue());
CascadingUtil.buildExternalProperties(req, archiver, descriptors, job);
assertNull(CascadingUtil.getExternalProjectProperty(job, javadocArchiverKey).getValue());
CascadingUtil.buildExternalProperties(req, json, descriptors, job);
assertNotNull(CascadingUtil.getExternalProjectProperty(job, javadocArchiverKey).getValue());
verifyAll();
}
use of hudson.model.Descriptor in project hudson-2.x by hudson.
the class DescriptorExtensionList method load.
/**
* Loading the descriptors in this case means filtering the descriptor from the master {@link ExtensionList}.
*/
@Override
protected List<ExtensionComponent<D>> load() {
List<ExtensionComponent<D>> r = new ArrayList<ExtensionComponent<D>>();
for (ExtensionComponent<Descriptor> c : hudson.getExtensionList(Descriptor.class).getComponents()) {
Descriptor d = c.getInstance();
Type subTyping = Types.getBaseClass(d.getClass(), Descriptor.class);
if (!(subTyping instanceof ParameterizedType)) {
LOGGER.severe(d.getClass() + " doesn't extend Descriptor with a type parameter");
// skip this one
continue;
}
if (Types.erasure(Types.getTypeArgument(subTyping, 0)) == (Class) describableType)
r.add((ExtensionComponent) c);
}
return r;
}
use of hudson.model.Descriptor in project hudson-2.x by hudson.
the class BuildStepDescriptor method filter.
/**
* Filters a descriptor for {@link BuildStep}s by using {@link BuildStepDescriptor#isApplicable(Class)}.
*/
public static <T extends BuildStep & Describable<T>> List<Descriptor<T>> filter(List<Descriptor<T>> base, Class<? extends AbstractProject> type) {
// descriptor of the project
Descriptor pd = Hudson.getInstance().getDescriptor((Class) type);
List<Descriptor<T>> r = new ArrayList<Descriptor<T>>(base.size());
for (Descriptor<T> d : base) {
if (pd instanceof AbstractProjectDescriptor && !((AbstractProjectDescriptor) pd).isApplicable(d))
continue;
if (d instanceof BuildStepDescriptor) {
BuildStepDescriptor<T> bd = (BuildStepDescriptor<T>) d;
if (!bd.isApplicable(type))
continue;
r.add(bd);
} else {
// old plugins built before 1.150 may not implement BuildStepDescriptor
r.add(d);
}
}
return r;
}
use of hudson.model.Descriptor in project hudson-2.x by hudson.
the class BuildWrappers method getFor.
/**
* List up all {@link BuildWrapperDescriptor}s that are applicable for the given project.
*
* @return
* The signature doesn't use {@link BuildWrapperDescriptor} to maintain compatibility
* with {@link BuildWrapper} implementations before 1.150.
*/
public static List<Descriptor<BuildWrapper>> getFor(AbstractProject<?, ?> project) {
List<Descriptor<BuildWrapper>> result = new ArrayList<Descriptor<BuildWrapper>>();
Descriptor pd = Hudson.getInstance().getDescriptor((Class) project.getClass());
for (Descriptor<BuildWrapper> w : BuildWrapper.all()) {
if (pd instanceof AbstractProjectDescriptor && !((AbstractProjectDescriptor) pd).isApplicable(w))
continue;
if (w instanceof BuildWrapperDescriptor) {
BuildWrapperDescriptor bwd = (BuildWrapperDescriptor) w;
if (bwd.isApplicable(project))
result.add(bwd);
} else {
// old BuildWrapper that doesn't implement BuildWrapperDescriptor
result.add(w);
}
}
return result;
}
Aggregations