Skip to content

Commit cea8bb4

Browse files
committedApr 17, 2015
Merge pull request #12 from glenritchie/master
JENKINS-27722 - fix for previous merge that could stop plugin working on some jobs
2 parents 54a13e3 + fad26ee commit cea8bb4

File tree

5 files changed

+194
-20
lines changed

5 files changed

+194
-20
lines changed
 

‎src/main/java/hudson/plugins/release/ReleaseWrapper.java

+1-13
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,7 @@ public Run<?,?> resolve(Job<?,?> job) {
169169
*/
170170
public ReleaseWrapper() {
171171
}
172-
173-
public List<Descriptor> getBuildSteps(AbstractProject<?,?> project)
174-
{
175-
List<Descriptor<Publisher>> publishers = Functions.getPublisherDescriptors(project);
176-
List<Descriptor<Builder>> builders = Functions.getBuilderDescriptors(project);
177-
178-
List<Descriptor> descriptors = new LinkedList<Descriptor>();
179-
descriptors.addAll(publishers);
180-
descriptors.addAll(builders);
181-
182-
return descriptors;
183-
}
184-
172+
185173
public String getReleaseVersionTemplate() {
186174
return releaseVersionTemplate;
187175
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
*
3+
*/
4+
package hudson.plugins.release;
5+
6+
import hudson.Functions;
7+
import hudson.model.AbstractProject;
8+
import hudson.model.Descriptor;
9+
import hudson.tasks.Builder;
10+
import hudson.tasks.Publisher;
11+
import java.util.LinkedList;
12+
import java.util.List;
13+
14+
/**
15+
* Helper class
16+
*/
17+
public class ReleaseWrapperHelper
18+
{
19+
/** Retrieve a list of all build steps including publishers and builders
20+
*
21+
* @param project The project
22+
* @return A list of descriptor's for both publishers and builders
23+
*/
24+
static public List<Descriptor> getBuildSteps(AbstractProject<?,?> project)
25+
{
26+
List<Descriptor<Publisher>> publishers = Functions.getPublisherDescriptors(project);
27+
List<Descriptor<Builder>> builders = Functions.getBuilderDescriptors(project);
28+
29+
List<Descriptor> descriptors = new LinkedList<Descriptor>();
30+
descriptors.addAll(publishers);
31+
descriptors.addAll(builders);
32+
33+
return descriptors;
34+
}
35+
}

‎src/main/resources/hudson/plugins/release/ReleaseWrapper/config.jelly

+12-7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
2828
xmlns:p="/lib/hudson/project">
2929

30+
<!-- Due to bug JENKINS-26579 we can't just call j:new, we have to use this workaround to get an instance of the helper class
31+
that we can then use to call the static method getBuildSteps()
32+
-->
33+
<j:set var="h2" value="${app.pluginManager.uberClassLoader.loadClass('hudson.plugins.release.ReleaseWrapperHelper').newInstance()}"/>
34+
3035
<f:entry title="${%Release Version Template}" help="/plugin/release/help-releaseVersionTemplate.html">
3136
<f:textbox field="releaseVersionTemplate" />
3237
</f:entry>
@@ -58,7 +63,7 @@
5863
<!-- Pre build steps -->
5964
<label class="attach-previous">${%Before release build}</label>
6065
<f:hetero-list name="preBuildSteps" hasHeader="true"
61-
descriptors="${instance.getBuildSteps(it)}"
66+
descriptors="${h2.getBuildSteps(it)}"
6267
items="${instance.preBuildSteps}"
6368
addCaption="${%Add release step}"/>
6469
</div>
@@ -72,7 +77,7 @@
7277
<!-- Post successful build steps -->
7378
<label class="attach-previous">${%After successful release build}</label>
7479
<f:hetero-list name="postSuccessfulBuildSteps" hasHeader="true"
75-
descriptors="${instance.getBuildSteps(it)}"
80+
descriptors="${h2.getBuildSteps(it)}"
7681
items="${instance.postSuccessfulBuildSteps}"
7782
addCaption="${%Add release step}"/>
7883
</div>
@@ -86,7 +91,7 @@
8691
<!-- Post failed build steps -->
8792
<label class="attach-previous">${%After failed release build}</label>
8893
<f:hetero-list name="postFailedBuildSteps" hasHeader="true"
89-
descriptors="${instance.getBuildSteps(it)}"
94+
descriptors="${h2.getBuildSteps(it)}"
9095
items="${instance.postFailedBuildSteps}"
9196
addCaption="${%Add release step}"/>
9297
</div>
@@ -100,7 +105,7 @@
100105
<!-- Post build steps -->
101106
<label class="attach-previous">${%After failed or successful release build}</label>
102107
<f:hetero-list name="postBuildSteps" hasHeader="true"
103-
descriptors="${instance.getBuildSteps(it)}"
108+
descriptors="${h2.getBuildSteps(it)}"
104109
items="${instance.postBuildSteps}"
105110
addCaption="${%Add release step}"/>
106111
</div>
@@ -115,7 +120,7 @@
115120
<!-- Pre matrix build steps -->
116121
<label class="attach-previous">${%Before release build and all matrix configurations}</label>
117122
<f:hetero-list name="preMatrixBuildSteps" hasHeader="true"
118-
descriptors="${instance.getBuildSteps(it)}"
123+
descriptors="${h2.getBuildSteps(it)}"
119124
items="${instance.preMatrixBuildSteps}"
120125
addCaption="${%Add release step}"/>
121126
</div>
@@ -141,7 +146,7 @@
141146
<!-- Post failed build steps -->
142147
<label class="attach-previous">${%After failed release build and all matrix configurations}</label>
143148
<f:hetero-list name="postFailedMatrixBuildSteps" hasHeader="true"
144-
descriptors="${instance.getBuildSteps(it)}"
149+
descriptors="${h2.getBuildSteps(it)}"
145150
items="${instance.postFailedMatrixBuildSteps}"
146151
addCaption="${%Add release step}"/>
147152
</div>
@@ -155,7 +160,7 @@
155160
<!-- Post build steps -->
156161
<label class="attach-previous">${%After failed or successful release build and all matrix configurations}</label>
157162
<f:hetero-list name="postBuildSteps" hasHeader="true"
158-
descriptors="${instance.getBuildSteps(it)}"
163+
descriptors="${h2.getBuildSteps(it)}"
159164
items="${instance.postBuildSteps}"
160165
addCaption="${%Add release step}"/>
161166
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package hudson.plugins.release;
2+
3+
import hudson.PluginWrapper;
4+
import hudson.model.Descriptor;
5+
6+
import org.junit.Rule;
7+
import org.junit.Test;
8+
import org.jvnet.hudson.test.JenkinsRule;
9+
10+
import static org.junit.Assert.assertNotNull;
11+
import static org.junit.Assert.assertTrue;
12+
13+
/**
14+
* Test the general integration of the plugin with Jenkins/Hudson and ensure the plugin is registered properly and is active
15+
*/
16+
public class TestReleasePlugin
17+
{
18+
@Rule
19+
public JenkinsRule j = new JenkinsRule();
20+
21+
@Test
22+
public void testPluginActive() throws Exception
23+
{
24+
// Check if the plugin is loaded and active
25+
PluginWrapper plugin = j.getPluginManager().getPlugin("release");
26+
assertTrue("Plugin not active", plugin.isActive());
27+
}
28+
29+
@Test
30+
public void testDescriptorRegistered() throws Exception
31+
{
32+
Descriptor<?> descriptor = Descriptor.find(ReleaseWrapper.DescriptorImpl.class.getName());
33+
assertNotNull("Must have ReleaseWrapper descriptor", descriptor);
34+
}
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package hudson.plugins.release;
2+
3+
import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
4+
import com.gargoylesoftware.htmlunit.html.HtmlForm;
5+
import com.gargoylesoftware.htmlunit.html.HtmlPage;
6+
7+
import org.jvnet.hudson.test.JenkinsRule;
8+
9+
import hudson.model.*;
10+
import hudson.plugins.release.ReleaseWrapper;
11+
import hudson.plugins.release.ReleaseWrapper.ReleaseAction;
12+
import hudson.tasks.BuildWrapper;
13+
import hudson.util.DescribableList;
14+
15+
import java.util.Collection;
16+
import java.util.List;
17+
18+
import static org.hamcrest.CoreMatchers.not;
19+
import static org.hamcrest.Matchers.is;
20+
import static org.hamcrest.Matchers.notNullValue;
21+
22+
import static org.junit.Assert.assertNotNull;
23+
import static org.junit.Assert.assertThat;
24+
import static org.junit.Assert.assertTrue;
25+
26+
import org.junit.After;
27+
import org.junit.Before;
28+
import org.junit.Test;
29+
import org.junit.Rule;
30+
31+
/**
32+
* Test the general integration of the plugin with Jenkins/Hudson and ensure it gets added properly and correctly add it's links/buttons etc to the
33+
* required pages.
34+
*/
35+
public class TestReleasePluginJob
36+
{
37+
@Rule
38+
public JenkinsRule j = new JenkinsRule();
39+
40+
FreeStyleProject job;
41+
42+
@Before
43+
public void createJob() throws Exception
44+
{
45+
job = j.createFreeStyleProject("test");
46+
}
47+
48+
@After
49+
public void deleteJob() throws Exception
50+
{
51+
job.delete();
52+
}
53+
54+
@Test
55+
public void testPermission() throws Exception
56+
{
57+
// Check if the user has permission to release
58+
assertTrue("No permission", ReleaseWrapper.hasReleasePermission(job));
59+
}
60+
61+
@Test
62+
public void testInBuilders() throws Exception
63+
{
64+
// Check the job has the ReleaseWrapper listed in it's builders, AND that it it listed in the project actions
65+
enableReleaseBuilder();
66+
DescribableList<BuildWrapper, Descriptor<BuildWrapper>> buildWrappersList = job.getBuildWrappersList();
67+
Descriptor<BuildWrapper> descriptor = Descriptor.find(ReleaseWrapper.DescriptorImpl.class.getName());
68+
BuildWrapper buildWrapper = buildWrappersList.get(descriptor);
69+
assertNotNull(buildWrapper);
70+
Collection<? extends Action> actions = buildWrapper.getProjectActions(job);
71+
assertNotNull("Actions can't be null", actions);
72+
assertThat("Must have actions", actions.size(), not(0));
73+
}
74+
75+
@Test
76+
public void testInActions() throws Exception
77+
{
78+
// Check that the job has an action listed when release is enabled
79+
enableReleaseBuilder();
80+
assertNotNull("Must have action", job.getAction(ReleaseAction.class));
81+
}
82+
83+
@Test
84+
public void testEnableReleaseUsingWebPage() throws Exception
85+
{
86+
enableReleaseBuilder();
87+
88+
/** Check if the Release links exist */
89+
HtmlPage page = j.createWebClient().goTo("job/test/");
90+
// Internationalisation not needed because the URL doesn't change between languages
91+
// see getUrlName() in ReleaseAction
92+
List<Object> nodes = page.selectNodes("//a[contains(@href, '/test/release')]");
93+
assertThat("Require 2 href links", nodes.size(), is(2));
94+
}
95+
96+
/** Enable the release builder by adding it to the job */
97+
private void enableReleaseBuilder() throws Exception
98+
{
99+
/** Enable the release plugin for the job */
100+
HtmlForm configForm = j.createWebClient().getPage(job, "configure").getFormByName("config");
101+
assertThat(configForm, notNullValue());
102+
103+
// not sure if internationalisation required for this?
104+
HtmlCheckBoxInput releaseCheckButton = configForm.getInputByName("hudson-plugins-release-ReleaseWrapper");
105+
assertThat("No Release Check Button found", releaseCheckButton, notNullValue());
106+
releaseCheckButton.setChecked(true);
107+
j.submit(configForm);
108+
}
109+
110+
}

0 commit comments

Comments
 (0)