summaryrefslogtreecommitdiff
path: root/calamus-nexus-plugin
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2014-04-12 17:55:28 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2014-04-12 17:55:28 +0200
commitbfcfcf5e3b4301bc94c27f47bfda61693edf3595 (patch)
treed6eedd800b1b34fd66ccbd86e5f215aaa40ccd3d /calamus-nexus-plugin
downloadcalamus-bfcfcf5e3b4301bc94c27f47bfda61693edf3595.tar.gz
calamus-bfcfcf5e3b4301bc94c27f47bfda61693edf3595.tar.bz2
calamus-bfcfcf5e3b4301bc94c27f47bfda61693edf3595.tar.xz
calamus-bfcfcf5e3b4301bc94c27f47bfda61693edf3595.zip
wip
Diffstat (limited to 'calamus-nexus-plugin')
-rw-r--r--calamus-nexus-plugin/pom.xml75
-rw-r--r--calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/CalamusConfig.java30
-rw-r--r--calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/CalamusNexusPlugin.java17
-rw-r--r--calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/CalamusUiContributor.java17
-rw-r--r--calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/EventListener.java51
-rw-r--r--calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/MqClient.java51
-rw-r--r--calamus-nexus-plugin/src/main/resources/static/js/Calamus/CalamusConfigPanel.js3
-rw-r--r--calamus-nexus-plugin/src/main/resources/static/js/calamus-nexus-plugin-boot.js3
8 files changed, 247 insertions, 0 deletions
diff --git a/calamus-nexus-plugin/pom.xml b/calamus-nexus-plugin/pom.xml
new file mode 100644
index 0000000..5060827
--- /dev/null
+++ b/calamus-nexus-plugin/pom.xml
@@ -0,0 +1,75 @@
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>io.trygvis.calamus</groupId>
+ <artifactId>calamus</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>calamus-nexus-plugin</artifactId>
+ <name>${project.groupId}:${project.artifactId}</name>
+ <packaging>${nexus-plugin.type}</packaging>
+ <properties>
+ <version.activemq>5.9.1</version.activemq>
+ <version.nexus>2.8.0-01</version.nexus>
+ <!--
+ Support for loading Nexus projects in Intellij IDEA; as it doesn't handle the 'nexus-plugin' packaging WRT to dependency calculations.
+ -->
+ <nexus-plugin.type>nexus-plugin</nexus-plugin.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>
+ <dependency>
+ <groupId>org.sonatype.nexus</groupId>
+ <artifactId>nexus-plugin-api</artifactId>
+ <version>${version.nexus}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.nexus.plugins</groupId>
+ <artifactId>nexus-restlet1x-plugin</artifactId>
+ <version>${version.nexus}</version>
+ <!--<type>${nexus-plugin.type}</type>-->
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.nexus.plugins</groupId>
+ <artifactId>nexus-ui-extjs3-plugin</artifactId>
+ <version>${version.nexus}</version>
+ <!--<type>jar</type>-->
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.nexus</groupId>
+ <artifactId>nexus-plugin-testsupport</artifactId>
+ <version>${version.nexus}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.sonatype.nexus</groupId>
+ <artifactId>nexus-plugin-bundle-maven-plugin</artifactId>
+ <version>1.2</version>
+ <extensions>true</extensions>
+ </plugin>
+ </plugins>
+ </build>
+ <profiles>
+ <profile>
+ <id>idea</id>
+ <properties>
+ <nexus-plugin.type>jar</nexus-plugin.type>
+ </properties>
+ </profile>
+ </profiles>
+</project>
diff --git a/calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/CalamusConfig.java b/calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/CalamusConfig.java
new file mode 100644
index 0000000..a3c09a1
--- /dev/null
+++ b/calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/CalamusConfig.java
@@ -0,0 +1,30 @@
+package io.trygvis.calamus.nexus;
+
+import org.slf4j.Logger;
+import org.sonatype.nexus.configuration.application.ApplicationConfiguration;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import java.io.File;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+@Singleton
+public class CalamusConfig {
+
+ private final Logger log = getLogger(getClass());
+
+ private final ApplicationConfiguration applicationConfiguration;
+
+ @Inject
+ public CalamusConfig(ApplicationConfiguration applicationConfiguration) {
+ this.applicationConfiguration = applicationConfiguration;
+ log.info("applicationConfiguration = " + applicationConfiguration);
+ File configurationDirectory = applicationConfiguration.getConfigurationDirectory();
+ log.info("configurationDirectory = " + configurationDirectory);
+ }
+
+ public String getBrokerUrl() {
+ return "tcp://localhost:61616";
+ }
+}
diff --git a/calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/CalamusNexusPlugin.java b/calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/CalamusNexusPlugin.java
new file mode 100644
index 0000000..e60fed7
--- /dev/null
+++ b/calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/CalamusNexusPlugin.java
@@ -0,0 +1,17 @@
+package io.trygvis.calamus.nexus;
+
+import org.eclipse.sisu.EagerSingleton;
+import org.sonatype.nexus.plugin.PluginIdentity;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+@EagerSingleton
+@Named("calamus")
+public class CalamusNexusPlugin extends PluginIdentity {
+
+ @Inject
+ public CalamusNexusPlugin() throws Exception {
+ super("io.trygvis.calamus", "calamus-nexus-plugin");
+ }
+}
diff --git a/calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/CalamusUiContributor.java b/calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/CalamusUiContributor.java
new file mode 100644
index 0000000..ed2f745
--- /dev/null
+++ b/calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/CalamusUiContributor.java
@@ -0,0 +1,17 @@
+package io.trygvis.calamus.nexus;
+
+import org.sonatype.nexus.plugins.ui.contribution.UiContributorSupport;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+//@Named
+//@Singleton
+public class CalamusUiContributor /*extends UiContributorSupport*/ {
+
+// @Inject
+// public CalamusUiContributor(CalamusNexusPlugin plugin) {
+// super(plugin);
+// }
+}
diff --git a/calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/EventListener.java b/calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/EventListener.java
new file mode 100644
index 0000000..4770974
--- /dev/null
+++ b/calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/EventListener.java
@@ -0,0 +1,51 @@
+package io.trygvis.calamus.nexus;
+
+import com.google.common.eventbus.Subscribe;
+import org.slf4j.Logger;
+import org.sonatype.nexus.events.EventSubscriber;
+import org.sonatype.nexus.proxy.events.RepositoryItemEventStoreCreate;
+import org.sonatype.nexus.proxy.maven.gav.Gav;
+import org.sonatype.nexus.proxy.maven.gav.GavCalculator;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+@Singleton
+@Named
+public class EventListener implements EventSubscriber {
+
+ private final Logger log = getLogger(getClass());
+
+ private final MqClient mqClient;
+ private final GavCalculator gavCalculator;
+
+ @Inject
+ public EventListener(CalamusConfig config, @Named("maven2") GavCalculator gavCalculator) {
+ log.info("CalamusNexusPlugin.CalamusNexusPlugin");
+ log.info("gavCalculator = " + gavCalculator);
+
+ this.mqClient = new MqClient(config.getBrokerUrl());
+ this.gavCalculator = gavCalculator;
+ }
+
+ @Subscribe
+ public void onRepositoryItemEventStoreCreate(RepositoryItemEventStoreCreate event) {
+ Gav gav = gavCalculator.pathToGav(event.getItem().getPath());
+
+ if (gav == null) {
+ return;
+ }
+
+ String groupId = gav.getGroupId();
+ String artifactId = gav.getArtifactId();
+ String version = gav.getVersion();
+ String type = gav.getExtension();
+ String classifier = gav.getClassifier();
+ mqClient.sendMessage(event.getRepository().getId(), groupId, artifactId, version, type, classifier);
+
+ log.info("New artifact: groupId={}, artifactId={}, version={}, type={}, classifier={}", groupId, artifactId, version, type, classifier);
+ }
+}
diff --git a/calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/MqClient.java b/calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/MqClient.java
new file mode 100644
index 0000000..51b2b3a
--- /dev/null
+++ b/calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/MqClient.java
@@ -0,0 +1,51 @@
+package io.trygvis.calamus.nexus;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+
+import static javax.jms.Session.AUTO_ACKNOWLEDGE;
+
+public class MqClient {
+
+ ActiveMQConnectionFactory connectionFactory;
+
+ public MqClient(String brokerUrl) {
+ this.connectionFactory = new ActiveMQConnectionFactory(brokerUrl);
+ }
+
+ public void sendMessage(String repository, String groupId, String artifactId, String version, String type, String classifier) {
+ try {
+ Connection connection = connectionFactory.createConnection();
+ connection.start();
+
+ Session session = connection.createSession(false, AUTO_ACKNOWLEDGE);
+
+ Destination destination = session.createQueue("nexus.new-artifact");
+
+ MessageProducer producer = session.createProducer(destination);
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ MapMessage message = session.createMapMessage();
+ message.setString("repository", repository);
+ message.setString("groupId", groupId);
+ message.setString("artifactId", artifactId);
+ message.setString("version", version);
+ message.setString("type", type);
+ message.setString("classifier", classifier);
+
+ producer.send(message);
+
+ session.close();
+ connection.close();
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/calamus-nexus-plugin/src/main/resources/static/js/Calamus/CalamusConfigPanel.js b/calamus-nexus-plugin/src/main/resources/static/js/Calamus/CalamusConfigPanel.js
new file mode 100644
index 0000000..81a7887
--- /dev/null
+++ b/calamus-nexus-plugin/src/main/resources/static/js/Calamus/CalamusConfigPanel.js
@@ -0,0 +1,3 @@
+define('Sonatype/repoServer/LdapConfigPanel', function () {
+
+});
diff --git a/calamus-nexus-plugin/src/main/resources/static/js/calamus-nexus-plugin-boot.js b/calamus-nexus-plugin/src/main/resources/static/js/calamus-nexus-plugin-boot.js
new file mode 100644
index 0000000..0c454be
--- /dev/null
+++ b/calamus-nexus-plugin/src/main/resources/static/js/calamus-nexus-plugin-boot.js
@@ -0,0 +1,3 @@
+define('calamus-nexus-plugin', [
+ 'Calamus/CalamusConfigPanel'
+]);