summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2014-05-02 18:26:50 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2014-05-02 18:26:50 +0200
commit345c0d8f7738aab20d2b45fd6c5ebf911b75e2fa (patch)
tree0ee3919571bab4c92d9ed306c671b879db9b12ff
downloadactivemq-plugin-345c0d8f7738aab20d2b45fd6c5ebf911b75e2fa.tar.gz
activemq-plugin-345c0d8f7738aab20d2b45fd6c5ebf911b75e2fa.tar.bz2
activemq-plugin-345c0d8f7738aab20d2b45fd6c5ebf911b75e2fa.tar.xz
activemq-plugin-345c0d8f7738aab20d2b45fd6c5ebf911b75e2fa.zip
o Initial import of ActiveMQ plugin for Jenkins.
-rw-r--r--.gitattributes8
-rw-r--r--.gitignore17
-rw-r--r--pom.xml74
-rw-r--r--src/main/java/org/jenkinsci/plugins/activemq/ActiveMqClient.java55
-rw-r--r--src/main/java/org/jenkinsci/plugins/activemq/ActiveMqPlugin.java57
-rw-r--r--src/main/java/org/jenkinsci/plugins/activemq/ActiveMqRunListener.java42
-rw-r--r--src/main/resources/index.jelly3
-rw-r--r--src/main/resources/org/jenkinsci/plugins/activemq/ActiveMqPlugin/config.jelly10
-rw-r--r--src/main/resources/org/jenkinsci/plugins/activemq/ActiveMqPlugin/global.jelly21
-rw-r--r--src/main/resources/org/jenkinsci/plugins/activemq/ActiveMqPlugin/help-activeMqUrl.html6
-rw-r--r--src/main/resources/org/jenkinsci/plugins/activemq/ActiveMqPlugin/help-name.html6
11 files changed, 299 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..9a8f287
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,8 @@
+* text=auto
+
+*.java text
+*.scala text
+*.sql text
+
+*.png binary
+*.jpg binary
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9785a33
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,17 @@
+target
+.idea
+*.iml
+*.ipw
+*.iws
+*.ipr
+.classpath
+.project
+.settings
+
+*tmp*
+
+# Jenkins
+work
+
+# ActiveMq
+apache-activemq-*
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..28f454f
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,74 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jenkins-ci.plugins</groupId>
+ <artifactId>plugin</artifactId>
+ <version>1.560</version>
+ </parent>
+
+ <artifactId>activemq</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>${hpi.type}</packaging>
+
+ <properties>
+ <version.activemq>5.9.1</version.activemq>
+ <hpi.type>hpi</hpi.type>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-client</artifactId>
+ <version>${version.activemq}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-pool</artifactId>
+ <version>${version.activemq}</version>
+ </dependency>
+ </dependencies>
+
+ <licenses>
+ <license>
+ <name>MIT license</name>
+ </license>
+ </licenses>
+
+ <developers>
+ <developer>
+ <id>trygvis</id>
+ <name>Trygve Laugstol</name>
+ <email>trygvis@inamo.no</email>
+ </developer>
+ </developers>
+
+ <scm>
+ <connection>scm:git:ssh://github.com/jenkinsci/activemq.git</connection>
+ <developerConnection>scm:git:ssh://git@github.com/jenkinsci/activemq.git</developerConnection>
+ <url>https://github.com/jenkinsci/activemq</url>
+ </scm>
+
+ <repositories>
+ <repository>
+ <id>repo.jenkins-ci.org</id>
+ <url>http://repo.jenkins-ci.org/public/</url>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>repo.jenkins-ci.org</id>
+ <url>http://repo.jenkins-ci.org/public/</url>
+ </pluginRepository>
+ </pluginRepositories>
+
+ <profiles>
+ <profile>
+ <id>idea</id>
+ <properties>
+ <hpi.type>jar</hpi.type>
+ </properties>
+ </profile>
+ </profiles>
+
+</project>
diff --git a/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqClient.java b/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqClient.java
new file mode 100644
index 0000000..a40f3e6
--- /dev/null
+++ b/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqClient.java
@@ -0,0 +1,55 @@
+package org.jenkinsci.plugins.activemq;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import java.io.CharArrayWriter;
+import java.io.IOException;
+import java.util.Properties;
+
+import static java.lang.String.valueOf;
+import static javax.jms.Session.AUTO_ACKNOWLEDGE;
+
+public class ActiveMqClient {
+
+ ActiveMQConnectionFactory connectionFactory;
+
+ public ActiveMqClient(String brokerUrl) {
+ this.connectionFactory = new ActiveMQConnectionFactory(brokerUrl);
+ }
+
+ public void sendMessage(String jobName, int buildNumber, String result) {
+ try {
+ Connection connection = connectionFactory.createConnection();
+ connection.start();
+
+ Session session = connection.createSession(false, AUTO_ACKNOWLEDGE);
+
+ Destination destination = session.createQueue("jenkins.build-result");
+
+ MessageProducer producer = session.createProducer(destination);
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ Properties properties = new Properties();
+ properties.setProperty("jobName", jobName);
+ properties.setProperty("buildNumber", valueOf(buildNumber));
+ properties.setProperty("result", result);
+
+ CharArrayWriter buf = new CharArrayWriter();
+ properties.store(buf, null);
+ producer.send(session.createTextMessage(buf.toString()));
+
+ session.close();
+ connection.close();
+ } catch (JMSException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqPlugin.java b/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqPlugin.java
new file mode 100644
index 0000000..74f3504
--- /dev/null
+++ b/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqPlugin.java
@@ -0,0 +1,57 @@
+package org.jenkinsci.plugins.activemq;
+
+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 org.slf4j.Logger;
+
+import javax.servlet.ServletException;
+import java.io.IOException;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+public class ActiveMqPlugin extends Plugin {
+
+ private final Logger logger = getLogger(getClass());
+
+ public static final String DISPLAY_NAME = "ActiveMQ Plugin";
+
+ private boolean enable;
+
+ private String brokerUrl = "tcp://127.0.0.1:61616";
+
+ @Override
+ public void start() throws Exception {
+ load();
+ }
+
+ @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 String getBrokerUrl() {
+ System.out.println("ActiveMqPlugin.getBrokerUrl");
+ return brokerUrl;
+ }
+
+ public void setBrokerUrl(String brokerUrl) {
+ System.out.println("ActiveMqPlugin.setBrokerUrl");
+ System.out.println("brokerUrl = " + brokerUrl);
+ this.brokerUrl = brokerUrl;
+ }
+}
diff --git a/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqRunListener.java b/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqRunListener.java
new file mode 100644
index 0000000..62a2673
--- /dev/null
+++ b/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqRunListener.java
@@ -0,0 +1,42 @@
+package org.jenkinsci.plugins.activemq;
+
+import hudson.Extension;
+import hudson.model.Build;
+import hudson.model.TaskListener;
+import hudson.model.listeners.RunListener;
+
+import javax.annotation.Nonnull;
+
+@Extension
+public class ActiveMqRunListener extends RunListener<Build> {
+
+ private final ActiveMqClient activeMqClient;
+
+ public ActiveMqRunListener() {
+ super(Build.class);
+
+ System.out.println("JbpmRunListener.JbpmRunListener");
+
+ activeMqClient = new ActiveMqClient("tcp://localhost:61616");
+ }
+
+ @Override
+ public void onCompleted(Build build, @Nonnull TaskListener listener) {
+ System.out.println("JbpmRunListener.onCompleted");
+ System.out.println("build = " + build);
+
+ System.out.println("build variables");
+ for (Object o : build.getBuildVariables().entrySet()) {
+ System.out.println(o);
+ }
+
+ activeMqClient.sendMessage(build.getProject().getName(), build.getNumber(), build.getResult().toString());
+
+// Jenkins jenkins = Jenkins.getInstance();
+// List<AbstractProject> projects = jenkins.getAllItems(AbstractProject.class);
+// for (AbstractProject project : projects) {
+// System.out.println("project.getPronoun() = " + project.getPronoun());
+// System.out.println("project.getName() = " + project.getName());
+// }
+ }
+}
diff --git a/src/main/resources/index.jelly b/src/main/resources/index.jelly
new file mode 100644
index 0000000..7692983
--- /dev/null
+++ b/src/main/resources/index.jelly
@@ -0,0 +1,3 @@
+<div>
+ Send events to an ActiveMQ server.
+</div>
diff --git a/src/main/resources/org/jenkinsci/plugins/activemq/ActiveMqPlugin/config.jelly b/src/main/resources/org/jenkinsci/plugins/activemq/ActiveMqPlugin/config.jelly
new file mode 100644
index 0000000..879ae01
--- /dev/null
+++ b/src/main/resources/org/jenkinsci/plugins/activemq/ActiveMqPlugin/config.jelly
@@ -0,0 +1,10 @@
+<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
+ <f:section title="ActiveMQ Plugin">
+ <f:entry field="enable" title="Enable">
+ <f:checkbox/>
+ </f:entry>
+ <f:entry field="brokerUrl" title="ActiveMQ URL" description="For example tcp://127.0.0.1:61616">
+ <f:textbox/>
+ </f:entry>
+ </f:section>
+</j:jelly>
diff --git a/src/main/resources/org/jenkinsci/plugins/activemq/ActiveMqPlugin/global.jelly b/src/main/resources/org/jenkinsci/plugins/activemq/ActiveMqPlugin/global.jelly
new file mode 100644
index 0000000..6da81e0
--- /dev/null
+++ b/src/main/resources/org/jenkinsci/plugins/activemq/ActiveMqPlugin/global.jelly
@@ -0,0 +1,21 @@
+<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
+ <!--
+ This Jelly script is used to produce the global configuration option.
+
+ Jenkins uses a set of tag libraries to provide uniformity in forms.
+ To determine where this tag is defined, first check the namespace URI,
+ and then look under $JENKINS/views/. For example, <f:section> is defined
+ in $JENKINS/views/lib/form/section.jelly.
+
+ It's also often useful to just check other similar scripts to see what
+ tags they use. Views are always organized according to its owner class,
+ so it should be straightforward to find them.
+ -->
+<!--
+ <f:section title="ActiveMQ Plugin">
+ <f:entry title="ActiveMq URL" field="brokerUrl" description="yeah yeah">
+ <f:textbox/>
+ </f:entry>
+ </f:section>
+-->
+</j:jelly>
diff --git a/src/main/resources/org/jenkinsci/plugins/activemq/ActiveMqPlugin/help-activeMqUrl.html b/src/main/resources/org/jenkinsci/plugins/activemq/ActiveMqPlugin/help-activeMqUrl.html
new file mode 100644
index 0000000..df2e815
--- /dev/null
+++ b/src/main/resources/org/jenkinsci/plugins/activemq/ActiveMqPlugin/help-activeMqUrl.html
@@ -0,0 +1,6 @@
+<div>
+ This HTML fragment will be injected into the configuration screen
+ when the user clicks the 'help' icon. See global.jelly for how the
+ form decides which page to load.
+ You can have any <tt>HTML</tt> fragment here.
+</div>
diff --git a/src/main/resources/org/jenkinsci/plugins/activemq/ActiveMqPlugin/help-name.html b/src/main/resources/org/jenkinsci/plugins/activemq/ActiveMqPlugin/help-name.html
new file mode 100644
index 0000000..288f214
--- /dev/null
+++ b/src/main/resources/org/jenkinsci/plugins/activemq/ActiveMqPlugin/help-name.html
@@ -0,0 +1,6 @@
+<div>
+ Help file for fields are discovered through a file name convention. This file is
+ help for the "name" field. You can have <i>arbitrary</i> HTML here. You can write
+ this file as a Jelly script if you need a dynamic content (but if you do so, change
+ the extension to <tt>.jelly</tt>).
+</div>