Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Actual functionality.

  • Loading branch information...
commit f9ef2f670cb7283438f9d8fa1e177addc55826de 1 parent 6734007
@dth authored
View
14 README.TXT
@@ -1,13 +1 @@
-You have successfully created a plugin using the Bamboo plugin archetype!
-
-Here are the SDK commands you'll use immediately:
-
-* atlas-run -- installs this plugin into Bamboo and starts it on http://localhost:6990/bamboo
-* atlas-debug -- same as atlas-run, but allows a debugger to attach at port 5005
-* atlas-cli -- after atlas-run or atlas-debug, opens a Maven command line window:
- - 'pi' reinstalls the plugin into the running Bamboo instance
-* atlas-help -- prints description for all commands in the SDK
-
-Full documentation is always available at:
-
-https://developer.atlassian.com/display/DOCS/Developing+with+the+Atlassian+Plugin+SDK
+This plugin provides a task to publish artifact metadata (taken from the POM) to Zookeeper
View
19 pom.xml
@@ -35,9 +35,22 @@
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
- <version>3.3.1</version>
+ <version>3.3.3</version>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.jms</groupId>
+ <artifactId>jms</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.sun.jmx</groupId>
+ <artifactId>jmxri</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.sun.jdmk</groupId>
+ <artifactId>jmxtools</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
-
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -58,7 +71,7 @@
<productDataVersion>${bamboo.data.version}</productDataVersion>
</configuration>
</plugin>
-
+
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
View
66 src/main/java/net/ceg/bamboo/ZooKeeperPublisherTask.java
@@ -1,31 +1,71 @@
package net.ceg.bamboo;
-import com.atlassian.bamboo.build.CustomPostBuildCompletedAction;
import com.atlassian.bamboo.build.logger.BuildLogger;
-import com.atlassian.bamboo.plan.artifact.ArtifactContext;
-import com.atlassian.bamboo.plan.artifact.ArtifactDefinitionContext;
-import com.atlassian.bamboo.task.TaskContext;
-import com.atlassian.bamboo.task.TaskException;
-import com.atlassian.bamboo.task.TaskResult;
-import com.atlassian.bamboo.task.TaskResultBuilder;
-import com.atlassian.bamboo.task.TaskType;
-import com.atlassian.bamboo.v2.build.BuildContext;
+import com.atlassian.bamboo.plan.artifact.ArtifactSubscriptionContext;
+import com.atlassian.bamboo.task.*;
+import org.apache.zookeeper.ZooKeeper;
import org.jetbrains.annotations.NotNull;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
-public class ZooKeeperPublisherTask implements TaskType
-{
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+public class ZooKeeperPublisherTask implements TaskType {
@NotNull
@Override
public TaskResult execute(@NotNull TaskContext taskContext) throws TaskException {
final BuildLogger logger = taskContext.getBuildLogger();
+ logger.addBuildLogEntry("Executing ZooKeeperPublisherTask");
+
+ final String connection = taskContext.getConfigurationMap().get("connection");
+
+ try {
+ ZooKeeper zk = new ZooKeeper(connection, 3000, null);
+ logger.addBuildLogEntry("Zookeeper Connected to " + connection);
+ } catch (IOException ioe) {
+ logger.addBuildLogEntry(ioe.getMessage());
+// oh no!
+ }
+
final String zkPath = taskContext.getConfigurationMap().get("path");
final String zkData = taskContext.getConfigurationMap().get("data");
- for(ArtifactDefinitionContext adc: taskContext.getBuildContext().getArtifactContext().getDefinitionContexts()) {
- logger.addBuildLogEntry("Publishing artifact " + adc.getName() + " to " + zkPath + " with data " + zkData);
+ for (ArtifactSubscriptionContext asc : taskContext.getBuildContext().getArtifactContext().getSubscriptionContexts()) {
+ try {
+ String artifact = null;
+ String version = null;
+
+ XPath xpath = XPathFactory.newInstance().newXPath();
+ NodeList nodes = ((Node) xpath.evaluate("/", new InputSource(new FileInputStream(new File(asc.getEffectiveDestinationPath()))), XPathConstants.NODE)).getFirstChild().getChildNodes();
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Node n = nodes.item(i);
+ if (n.getNodeName().equalsIgnoreCase("artifactId")) {
+ artifact = n.getFirstChild().getTextContent();
+ }
+ if (n.getNodeName().equalsIgnoreCase("version")) {
+ version = n.getFirstChild().getTextContent();
+ }
+ }
+ logger.addBuildLogEntry("Artifact name: " + artifact);
+ logger.addBuildLogEntry("Artifact version: " + version);
+ logger.addBuildLogEntry("Publishing subscription artifact " + asc.getEffectiveDestinationPath() + " to " + zkPath + " with data " + zkData);
+ } catch (IOException pe) {
+ logger.addErrorLogEntry("Error reading " + asc.getEffectiveDestinationPath());
+ } catch (XPathExpressionException e) {
+ logger.addErrorLogEntry("Error xpathing " + asc.getEffectiveDestinationPath());
+ e.printStackTrace();
+ }
}
+
return TaskResultBuilder.create(taskContext).success().build();
}
}
View
39 src/main/java/net/ceg/bamboo/ZooKeeperPublisherTaskConfigurator.java
@@ -11,6 +11,8 @@
import org.jetbrains.annotations.Nullable;
import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
public class ZooKeeperPublisherTaskConfigurator extends AbstractTaskConfigurator
{
@@ -21,7 +23,11 @@
public Map<String, String> generateTaskConfigMap(@NotNull final ActionParametersMap params, @Nullable final TaskDefinition previousTaskDefinition)
{
final Map<String, String> config = super.generateTaskConfigMap(params, previousTaskDefinition);
+ config.put("connection", params.getString("connection"));
+ config.put("artifact", params.getString("artifact"));
+ config.put("artifactRegex", params.getString("artifactRegex"));
config.put("path", params.getString("path"));
+ config.put("data", params.getString("data"));
return config;
}
@@ -29,7 +35,9 @@
public void populateContextForCreate(@NotNull final Map<String, Object> context)
{
super.populateContextForCreate(context);
-
+ context.put("connection", "");
+ context.put("artifact", true);
+ context.put("artifactRegex", "*.rpm");
context.put("path", "/foo/bar/release-");
context.put("data", "app={} version={} environment={} cluster={} datacentre={}");
}
@@ -39,6 +47,9 @@ public void populateContextForEdit(@NotNull final Map<String, Object> context, @
{
super.populateContextForEdit(context, taskDefinition);
+ context.put("connection", taskDefinition.getConfiguration().get("connection"));
+ context.put("artifact", taskDefinition.getConfiguration().get("artifact"));
+ context.put("artifactRegex", taskDefinition.getConfiguration().get("artifactRegex"));
context.put("path", taskDefinition.getConfiguration().get("path"));
context.put("data", taskDefinition.getConfiguration().get("data"));
}
@@ -47,6 +58,9 @@ public void populateContextForEdit(@NotNull final Map<String, Object> context, @
public void populateContextForView(@NotNull final Map<String, Object> context, @NotNull final TaskDefinition taskDefinition)
{
super.populateContextForView(context, taskDefinition);
+ context.put("connection", taskDefinition.getConfiguration().get("connection"));
+ context.put("artifact", taskDefinition.getConfiguration().get("artifact"));
+ context.put("artifactRegex", taskDefinition.getConfiguration().get("artifactRegex"));
context.put("path", taskDefinition.getConfiguration().get("path"));
context.put("data", taskDefinition.getConfiguration().get("data"));
}
@@ -56,6 +70,21 @@ public void validate(@NotNull final ActionParametersMap params, @NotNull final E
{
super.validate(params, errorCollection);
+ final String connectionValue = params.getString("connection");
+ if (StringUtils.isEmpty(connectionValue))
+ {
+ errorCollection.addError("connection", textProvider.getText("net.ceg.bamboo.config.connection.error"));
+ }
+
+ final Boolean artifactValue = params.getBoolean("artifact");
+ final String artifactRegex = params.getString("artifactRegex");
+ if (artifactValue)
+ {
+ if(StringUtils.isEmpty(artifactRegex) || !isValidRegex(artifactRegex)) {
+ errorCollection.addError("artifactRegex", textProvider.getText("net.ceg.bamboo.config.artifactRegex.error"));
+ }
+ }
+
final String pathValue = params.getString("path");
if (StringUtils.isEmpty(pathValue))
{
@@ -68,6 +97,14 @@ public void validate(@NotNull final ActionParametersMap params, @NotNull final E
}
}
+ private boolean isValidRegex(String regex) {
+ try {
+ Pattern.compile(regex);
+ return true;
+ } catch (PatternSyntaxException pse) { }
+ return false;
+ }
+
public void setTextProvider(final TextProvider textProvider)
{
this.textProvider = textProvider;
View
3  src/main/resources/atlassian-plugin.xml
@@ -6,7 +6,8 @@
</plugin-info>
- <taskType key="net.ceg.bamboo.ZooKeeperPublisherTask" name="ZooKeeper Publishing Task">
+ <taskType key="net.ceg.bamboo.ZooKeeperPublisherTask" name="ZooKeeper Publishing Task"
+ class="net.ceg.bamboo.ZooKeeperPublisherTask">
<category name="deployment"/>
View
12 src/main/resources/english.properties
@@ -1,6 +1,18 @@
+net.ceg.bamboo.config.connection = Zookeeper Connection String
+net.ceg.bamboo.config.connection.description = Connection string for Zookeeper (eg: zk1:2181,zk2:2181,zk3:2181)
+net.ceg.bamboo.config.connection.error = You did not configure a connection string!
+
+net.ceg.bamboo.config.artifact = Use artifacts?
+net.ceg.bamboo.config.artifact.description = Should I use data from produced artifacts to send to Zookeeper?
+
+net.ceg.bamboo.config.artifactRegex = Artifact Regex
+net.ceg.bamboo.config.artifactRegex.description = Regex to filter artifacts
+net.ceg.bamboo.config.artifactRegex.error = Invalid Regex supplied!
+
net.ceg.bamboo.config.path = Zookeeper Path
net.ceg.bamboo.config.path.description = What should Bamboo print to the log?
net.ceg.bamboo.config.path.error = You did not configure Bamboo with anything to say.
+
net.ceg.bamboo.config.data = Zookeeper Data
net.ceg.bamboo.config.data.description = What should Bamboo print to the log?
net.ceg.bamboo.config.data.error = You did not configure Bamboo with anything to say.
View
3  src/main/resources/zookeeperEdit.ftl
@@ -1,2 +1,5 @@
+[@ww.textfield labelKey="net.ceg.bamboo.connection.path" name="connection" required='true'/]
+[@ww.checkbox labelKey="net.ceg.bamboo.artifact.path" name="artifact" required='true'/]
+[@ww.textfield labelKey="net.ceg.bamboo.artifactRegex.path" name="artifactRegex" required='false'/]
[@ww.textfield labelKey="net.ceg.bamboo.config.path" name="path" required='true'/]
[@ww.textfield labelKey="net.ceg.bamboo.config.data" name="data" required='true'/]
View
2  src/main/resources/zookeeperView.ftl
@@ -1,2 +1,4 @@
+[@ww.label labelKey="net.ceg.bamboo.artifact.path" name="artifact" /]
+[@ww.label labelKey="net.ceg.bamboo.artifactRegex.path" name="artifactRegex" /]
[@ww.label labelKey="net.ceg.bamboo.config.path" name="path"/]
[@ww.label labelKey="net.ceg.bamboo.config.data" name="data"/]
View
39 src/test/java/XpathTest.java
@@ -0,0 +1,39 @@
+import org.junit.Test;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathFactory;
+import java.io.File;
+import java.io.FileInputStream;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author <a href="mailto:dale.harrison@morningstar.com">Dale Harrison</a>
+ */
+public class XpathTest {
+
+ @Test
+ public void validXpath() throws Exception {
+
+ XPath xpath = XPathFactory.newInstance().newXPath();
+ String artifactId = "";
+ String version = "";
+
+ NodeList nodes = ((Node) xpath.evaluate("/", new InputSource(new FileInputStream(new File("pom.xml"))), XPathConstants.NODE)).getFirstChild().getChildNodes();
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Node n = nodes.item(i);
+ if (n.getNodeName().equalsIgnoreCase("artifactId")) {
+ artifactId = n.getFirstChild().getTextContent();
+ }
+ if (n.getNodeName().equalsIgnoreCase("version")) {
+ version = n.getFirstChild().getTextContent();
+ }
+ }
+ assertEquals("zookeeper-publisher", artifactId);
+ assertEquals("1.0-SNAPSHOT", version);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.