Skip to content

Commit

Permalink
Fix JENKINS-14620
Browse files Browse the repository at this point in the history
  • Loading branch information
gboissinot committed Oct 21, 2012
1 parent e83bf26 commit a7888ee
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 28 deletions.
31 changes: 11 additions & 20 deletions src/main/java/org/jenkinsci/plugins/urltrigger/URLTrigger.java
Expand Up @@ -177,8 +177,8 @@ private Client getClientObject(URLTriggerEntry entry, XTriggerLog log) {
take down all of the jenkins schedule events.
*/
int timeout = entry.getTimeout();
client.setConnectTimeout(timeout*1000); //in milliseconds
client.setReadTimeout(timeout*1000); //in milliseconds
client.setConnectTimeout(timeout * 1000); //in milliseconds
client.setReadTimeout(timeout * 1000); //in milliseconds

return client;
}
Expand Down Expand Up @@ -382,31 +382,22 @@ private URLTriggerEntry fillAndGetEntry(StaplerRequest req, JSONObject entryObje
} else {
urlTriggerEntry.setInspectingContent(true);
JSONObject inspectingContentJSONObject = entryObject.getJSONObject("inspectingContent");
JSON contentTypesJsonElt;
try {
contentTypesJsonElt = inspectingContentJSONObject.getJSONArray("contentTypes");
} catch (JSONException jsone) {
contentTypesJsonElt = inspectingContentJSONObject.getJSONObject("contentTypes");
}
if (contentTypesJsonElt != null && !isEmptyJSONElement(contentTypesJsonElt)) {
if (inspectingContentJSONObject.size() == 0) {
urlTriggerEntry.setInspectingContent(false);
} else {
JSON contentTypesJsonElt;
try {
contentTypesJsonElt = inspectingContentJSONObject.getJSONArray("contentTypes");
} catch (JSONException jsone) {
contentTypesJsonElt = inspectingContentJSONObject.getJSONObject("contentTypes");
}
List<URLTriggerContentType> types = req.bindJSONToList(URLTriggerContentType.class, contentTypesJsonElt);
urlTriggerEntry.setContentTypes(types.toArray(new URLTriggerContentType[types.size()]));
} else {
urlTriggerEntry.setInspectingContent(false);
}

}

return urlTriggerEntry;
}

private boolean isEmptyJSONElement(JSON element) {
if (element instanceof JSONObject) {
return ((JSONObject) element).getString("kind").isEmpty();
}
return false;
}

@Override
public String getDisplayName() {
return Messages.urltrigger_displayName();
Expand Down
Expand Up @@ -57,6 +57,12 @@ private Map<String, Object> readJsonPath(String content) throws XTriggerExceptio
@Override
protected boolean isTriggeringBuildForContent(String content, XTriggerLog log) throws XTriggerException {

if (jsonPaths == null || jsonPaths.size() == 0) {
log.error("You must configure at least one JSON Path. Exit with no changes.");
return false;
}


if (results == null) {
log.info("Capturing URL context. Waiting next schedule to check a change.");
return false;
Expand Down
@@ -1,5 +1,6 @@
package org.jenkinsci.plugins.urltrigger.content;

import hudson.Util;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.Serializable;
Expand All @@ -13,7 +14,10 @@ public class TEXTContentEntry implements Serializable {

@DataBoundConstructor
public TEXTContentEntry(String regEx) {
this.regEx = regEx;
this.regEx = Util.fixEmptyAndTrim(regEx);
if (this.regEx == null) {
this.regEx = ".*";
}
}

public String getRegEx() {
Expand Down
Expand Up @@ -44,6 +44,11 @@ protected void initForContentType(String content, XTriggerLog log) throws XTrigg
@Override
protected boolean isTriggeringBuildForContent(String content, XTriggerLog log) throws XTriggerException {

if (regExElements == null || regExElements.size() == 0) {
log.error("You must configure at least one REGEX. Exit with no changes.");
return false;
}

if (capturedValues == null) {
log.info("Capturing URL context. Waiting next schedule to check a change.");
return false;
Expand Down Expand Up @@ -102,10 +107,12 @@ private Map<String, List<String>> getMatchedValue(String content) throws XTrigge
while ((line = bufferedReader.readLine()) != null) {
for (TEXTContentEntry regexEntry : regExElements) {
String regEx = regexEntry.getRegEx();
Pattern pattern = Pattern.compile(regEx);
Matcher matcher = pattern.matcher(line);
if (matcher.matches()) {
addMatchedValue(capturedValues, regEx, matcher.group());
if (regEx != null) {
Pattern pattern = Pattern.compile(regEx);
Matcher matcher = pattern.matcher(line);
if (matcher.matches()) {
addMatchedValue(capturedValues, regEx, matcher.group());
}
}
}
}
Expand Down
Expand Up @@ -87,6 +87,12 @@ private Map<String, Object> readXMLPath(Document document) throws XTriggerExcept
@Override
protected boolean isTriggeringBuildForContent(String content, XTriggerLog log) throws XTriggerException {

if (xPaths == null || xPaths.size() == 0) {
log.error("You must configure at least one XPath. Exit with no changes.");
return false;
}


if (results == null) {
log.info("Capturing URL context. Waiting next schedule to check a change.");
return false;
Expand Down
Expand Up @@ -4,7 +4,7 @@
help="/descriptor/org.jenkinsci.plugins.urltrigger.content.TEXTContentType/help/type">
<f:repeatable var="element" items="${instance.regExElements}" add="${%Add a regEx}">
<table width="100%">
<f:entry field="regEx" title="${%Regular Expression}">
<f:entry field="regEx" title="${%REGEX}">
<f:textbox name="txt.regEx" value="${element.regEx}"/>
</f:entry>
</table>
Expand Down
@@ -1,6 +1,7 @@
<div>
<p>
Give a regular expression to query a piece of data in the text content.
The data value will be used for checking if the system should trigger a build.
Give a regular expression to query a piece of data in the text content.<br/>
The data value will be used for checking if the system should trigger a build.<br/>
Without supplying a value, '.*' is used.
</p>
</div>

0 comments on commit a7888ee

Please sign in to comment.