summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2014-05-10 20:30:50 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2014-05-10 20:30:50 +0200
commite8b94392b58cdd40a28367ed8e5e540640a1d3b9 (patch)
tree2b373c04a302ca5adee69236696051d6a5923155
parent5384f28dfd66bdb1839935802aa6769ee55849d2 (diff)
downloadactivemq-plugin-e8b94392b58cdd40a28367ed8e5e540640a1d3b9.tar.gz
activemq-plugin-e8b94392b58cdd40a28367ed8e5e540640a1d3b9.tar.bz2
activemq-plugin-e8b94392b58cdd40a28367ed8e5e540640a1d3b9.tar.xz
activemq-plugin-e8b94392b58cdd40a28367ed8e5e540640a1d3b9.zip
o Better error messages.
-rw-r--r--src/main/java/org/jenkinsci/plugins/activemq/ActiveMqBuildTrigger.java38
-rw-r--r--src/main/java/org/jenkinsci/plugins/activemq/ActiveMqPlugin.java4
2 files changed, 33 insertions, 9 deletions
diff --git a/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqBuildTrigger.java b/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqBuildTrigger.java
index 9f9c6a6..0beb6eb 100644
--- a/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqBuildTrigger.java
+++ b/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqBuildTrigger.java
@@ -6,17 +6,20 @@ import hudson.model.BuildableItem;
import hudson.model.Item;
import hudson.triggers.Trigger;
import hudson.triggers.TriggerDescriptor;
+import hudson.util.FormValidation;
import org.kohsuke.stapler.DataBoundConstructor;
-import org.mvel2.MVEL;
+import org.kohsuke.stapler.QueryParameter;
import org.slf4j.Logger;
import java.io.Serializable;
import java.util.Map;
+import java.util.TreeMap;
import static java.util.Collections.singletonMap;
import static org.apache.commons.lang.StringUtils.trimToNull;
import static org.jenkinsci.plugins.activemq.ActiveMqClient.BuildRequest;
import static org.mvel2.MVEL.compileExpression;
+import static org.mvel2.MVEL.executeExpression;
import static org.slf4j.LoggerFactory.getLogger;
public class ActiveMqBuildTrigger extends Trigger<AbstractProject> {
@@ -30,13 +33,14 @@ public class ActiveMqBuildTrigger extends Trigger<AbstractProject> {
@DataBoundConstructor
public ActiveMqBuildTrigger(String mvel) {
log.info("ActiveMqBuildTrigger.ActiveMqBuildTrigger");
+ this.mvel = mvel;
}
@Override
public void start(AbstractProject project, boolean newInstance) {
super.start(project, newInstance);
log.info("ActiveMqBuildTrigger.start");
- setMvel_(mvel);
+ compileMvel();
}
public String getMvel() {
@@ -44,6 +48,10 @@ public class ActiveMqBuildTrigger extends Trigger<AbstractProject> {
return mvel;
}
+ public void setMvel(String mvel) {
+ this.mvel = mvel;
+ }
+
private void setMvel_(String mvel) {
mvel = trimToNull(mvel);
if (mvel == null) {
@@ -53,16 +61,20 @@ public class ActiveMqBuildTrigger extends Trigger<AbstractProject> {
return;
}
+ compileMvel();
+ }
+
+ private void compileMvel() {
try {
compiledMvel = compileExpression(mvel);
- this.mvel = mvel;
- log.info("ActiveMqBuildTrigger.setMvel_: mvel={}", mvel);
+ log.info("ActiveMqBuildTrigger.compileMvel: mvel={}", mvel);
} catch (Exception e) {
log.warn("Unable to compile MVEL", e);
}
}
// public FormValidation doCheckMvel(@QueryParameter String mvel) {
+// log.info("ActiveMqBuildTrigger.doCheckMvel");
// mvel = trimToNull(mvel);
// if (mvel == null) {
// return FormValidation.ok();
@@ -85,10 +97,22 @@ public class ActiveMqBuildTrigger extends Trigger<AbstractProject> {
return false;
}
- Map<String, Map<String, String>> context = singletonMap("parameters", req.parameters);
- Boolean b = MVEL.executeExpression(compiledMvel, context, Boolean.class);
+ Map<String, String> parameters = new TreeMap<String, String>(req.parameters);
+ Map<String, Map<String, String>> context = singletonMap("parameters", parameters);
+ try {
+ Boolean b = executeExpression(compiledMvel, context, Boolean.class);
- return b != null && b;
+ return b != null && b;
+ } catch (Exception e) {
+ log.warn("Could not evaluate expression");
+ log.warn("Expression = {}", mvel);
+ log.warn("Context:");
+ for (Map.Entry<String, Map<String, String>> entry : context.entrySet()) {
+ log.warn("{} = {}", entry.getKey(), entry.getValue());
+ }
+ log.warn("Exception", e);
+ return false;
+ }
}
@Extension
diff --git a/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqPlugin.java b/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqPlugin.java
index cc73898..b82443a 100644
--- a/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqPlugin.java
+++ b/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqPlugin.java
@@ -37,9 +37,9 @@ public class ActiveMqPlugin extends Plugin implements ActiveMqClient.BuildReques
}
public void onCompleted(Build build, @Nonnull TaskListener listener) {
- log.info("ActiveMqPlugin.onCompleted");
- log.info("build variables");
+ log.info("ActiveMqPlugin.onCompleted: listener={}", listener);
@SuppressWarnings("unchecked") Map<String, String> buildVariables = build.getBuildVariables();
+ log.info("Build variables");
for (Map.Entry<String, String> e : buildVariables.entrySet()) {
log.info(e.getKey() + " = " + e.getValue());
}