From 5c762750101f12abd51621355a871e42fd9c7a33 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 4 May 2014 23:34:16 +0200 Subject: o Getting the web configuration to work. --- .../jenkinsci/plugins/activemq/ActiveMqPlugin.java | 91 +++++++++++++--------- 1 file changed, 56 insertions(+), 35 deletions(-) (limited to 'src/main/java/org/jenkinsci/plugins/activemq/ActiveMqPlugin.java') diff --git a/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqPlugin.java b/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqPlugin.java index 74f3504..6ec65c0 100644 --- a/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqPlugin.java +++ b/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqPlugin.java @@ -1,57 +1,78 @@ package org.jenkinsci.plugins.activemq; +import hudson.Extension; import hudson.Plugin; -import hudson.model.Descriptor; -import hudson.util.FormValidation; -import net.sf.json.JSONObject; -import org.kohsuke.stapler.QueryParameter; -import org.kohsuke.stapler.StaplerRequest; +import hudson.model.Build; +import hudson.model.TaskListener; +import jenkins.model.GlobalConfiguration; import org.slf4j.Logger; -import javax.servlet.ServletException; -import java.io.IOException; +import javax.annotation.Nonnull; +import java.util.Map; import static org.slf4j.LoggerFactory.getLogger; -public class ActiveMqPlugin extends Plugin { +@Extension +public class ActiveMqPlugin extends Plugin /*implements ReconfigurableDescribable*/ { - private final Logger logger = getLogger(getClass()); +// public static final String DISPLAY_NAME = "ActiveMQ Plugin Display Name"; - public static final String DISPLAY_NAME = "ActiveMQ Plugin"; + private static final Logger log = getLogger(ActiveMqPlugin.class); - private boolean enable; - - private String brokerUrl = "tcp://127.0.0.1:61616"; + private transient ActiveMqClient client; @Override public void start() throws Exception { - load(); + reconfigure(); } - @Override - public void configure(StaplerRequest req, JSONObject formData) throws IOException, ServletException, Descriptor.FormException { - brokerUrl = formData.getString("brokerUrl"); - enable = formData.getBoolean("enable"); - - System.out.println("brokerUrl = " + brokerUrl); - - save(); - } - - public FormValidation doCheckBrokerUrl(@QueryParameter String activeMqUrl) { - System.out.println("ActiveMqPlugin.doCheckActiveMqUrl"); - - return FormValidation.error("wat"); + public void postInitialize() throws Exception { + log.info("ActiveMqPlugin.postInitialize"); + reconfigure(); } - public String getBrokerUrl() { - System.out.println("ActiveMqPlugin.getBrokerUrl"); - return brokerUrl; + public void onCompleted(Build build, @Nonnull TaskListener listener) { + log.info("ActiveMqPlugin.onCompleted"); + log.info("build variables"); + @SuppressWarnings("unchecked") Map buildVariables = build.getBuildVariables(); + for (Map.Entry e : buildVariables.entrySet()) { + log.info(e.getKey() + " = " + e.getValue()); + } + + log.info("client = " + client); + if (client == null) { + log.debug("client is null"); + return; + } + + client.sendMessage(build.getProject().getName(), build.getNumber(), build.getResult().toString()); } - public void setBrokerUrl(String brokerUrl) { - System.out.println("ActiveMqPlugin.setBrokerUrl"); - System.out.println("brokerUrl = " + brokerUrl); - this.brokerUrl = brokerUrl; + public void reconfigure() { + log.info("ActiveMqPlugin.reconfigure"); + ActiveMqGlobalConfig config = GlobalConfiguration.all().get(ActiveMqGlobalConfig.class); + log.info("config = " + config); + if (config == null) { + return; + } + String brokerUrl = config.getBrokerUrl(); + boolean enable = config.isEnable(); + + if (enable) { + if (client != null && !client.brokerUrl.equals(brokerUrl)) { + log.info("Disposing current JMS client."); + client.close(); + client = null; + } + + log.info("Creating client of broker {}", brokerUrl); + client = new ActiveMqClient(brokerUrl); + } else { + if (client != null) { + log.info("Disposing current JMS client."); + client.close(); + client = null; + } + } } } -- cgit v1.2.3