Skip to content

Commit

Permalink
Fix JENKINS-12912
Browse files Browse the repository at this point in the history
  • Loading branch information
gboissinot committed Mar 5, 2012
1 parent a152c67 commit c39c888
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -32,7 +32,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<xtrigger.lib.version>0.8</xtrigger.lib.version>
<xtrigger.lib.version>0.9-SNAPSHOT</xtrigger.lib.version>
<jersey.client.version>1.9.1</jersey.client.version>
<json.path.version>0.5.5</json.path.version>
<jackson.mapper.as1.version>1.8.3</jackson.mapper.as1.version>
Expand Down
31 changes: 25 additions & 6 deletions src/main/java/org/jenkinsci/plugins/urltrigger/URLTrigger.java
Expand Up @@ -51,17 +51,28 @@ public class URLTrigger extends AbstractTrigger {

private List<URLTriggerEntry> entries = new ArrayList<URLTriggerEntry>();

private boolean labelRestriction;

@DataBoundConstructor
public URLTrigger(String cronTabSpec, List<URLTriggerEntry> entries) throws ANTLRException {
super(cronTabSpec);
public URLTrigger(String cronTabSpec,
List<URLTriggerEntry> entries,
boolean labelRestriction,
String triggerLabel) throws ANTLRException {
super(cronTabSpec, triggerLabel);
this.entries = entries;
this.labelRestriction = labelRestriction;
}

@SuppressWarnings("unused")
public List<URLTriggerEntry> getEntries() {
return entries;
}

@SuppressWarnings("unused")
public boolean isLabelRestriction() {
return labelRestriction;
}

@Override
public Collection<? extends Action> getProjectActions() {

Expand Down Expand Up @@ -231,13 +242,13 @@ protected void start(Node node, BuildableItem buildableItem, boolean newInstance
}

@Override
public URLScriptTriggerDescriptor getDescriptor() {
return (URLScriptTriggerDescriptor) Hudson.getInstance().getDescriptorOrDie(getClass());
public URLTriggerDescriptor getDescriptor() {
return (URLTriggerDescriptor) Hudson.getInstance().getDescriptorOrDie(getClass());
}

@Extension
@SuppressWarnings("unused")
public static class URLScriptTriggerDescriptor extends XTriggerDescriptor {
public static class URLTriggerDescriptor extends XTriggerDescriptor {

private transient final SequentialExecutionQueue queue = new SequentialExecutionQueue(Executors.newSingleThreadExecutor());

Expand All @@ -254,6 +265,14 @@ public boolean isApplicable(Item item) {
public URLTrigger newInstance(StaplerRequest req, JSONObject formData) throws FormException {

String cronTabSpec = formData.getString("cronTabSpec");
boolean labelRestriction = false;
String triggerLabel = null;
Object labelRestrictionObject = formData.get("labelRestriction");
if (labelRestrictionObject != null) {
labelRestriction = true;
triggerLabel = ((JSONObject) labelRestrictionObject).getString("triggerLabel");
}

Object entryObject = formData.get("urlElements");

List<URLTriggerEntry> entries = new ArrayList<URLTriggerEntry>();
Expand All @@ -270,7 +289,7 @@ public URLTrigger newInstance(StaplerRequest req, JSONObject formData) throws Fo

URLTrigger urlTrigger;
try {
urlTrigger = new URLTrigger(cronTabSpec, entries);
urlTrigger = new URLTrigger(cronTabSpec, entries, labelRestriction, triggerLabel);
} catch (ANTLRException e) {
throw new RuntimeException(e.getMessage());
}
Expand Down
Expand Up @@ -93,7 +93,27 @@

</table>
</f:repeatable>
</f:entry>


<f:entry title="${%Polling Node}">
<f:entry>
<table style="width:100%">
<f:optionalBlock
name="labelRestriction"
field="labelRestriction"
checked="${instance.labelRestriction}"
title="${%Restrict where the polling can be run}">

<f:block>
<f:entry title="Label Expression">
<f:textbox name="triggerLabel"
value="${instance.triggerLabel}"/>
</f:entry>
</f:block>
</f:optionalBlock>
</table>
</f:entry>
</f:entry>

<f:entry title="${%Schedule}" help="/descriptor/hudson.triggers.TimerTrigger/help/spec">
Expand Down
Expand Up @@ -35,7 +35,7 @@ public void init() {

public void testStartEmptyEntries() throws Exception {
List<URLTriggerEntry> entries = new ArrayList<URLTriggerEntry>();
URLTrigger urlTrigger = new URLTrigger(validCron, entries);
URLTrigger urlTrigger = new URLTrigger(validCron, entries, false, null);
urlTrigger.start(project, false);
Assert.assertTrue(true);
}
Expand Down

0 comments on commit c39c888

Please sign in to comment.