From bfcfcf5e3b4301bc94c27f47bfda61693edf3595 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 12 Apr 2014 17:55:28 +0200 Subject: wip --- calamus-nexus-plugin/pom.xml | 75 ++++++++++++++++++++++ .../io/trygvis/calamus/nexus/CalamusConfig.java | 30 +++++++++ .../trygvis/calamus/nexus/CalamusNexusPlugin.java | 17 +++++ .../calamus/nexus/CalamusUiContributor.java | 17 +++++ .../io/trygvis/calamus/nexus/EventListener.java | 51 +++++++++++++++ .../java/io/trygvis/calamus/nexus/MqClient.java | 51 +++++++++++++++ .../static/js/Calamus/CalamusConfigPanel.js | 3 + .../static/js/calamus-nexus-plugin-boot.js | 3 + 8 files changed, 247 insertions(+) create mode 100644 calamus-nexus-plugin/pom.xml create mode 100644 calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/CalamusConfig.java create mode 100644 calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/CalamusNexusPlugin.java create mode 100644 calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/CalamusUiContributor.java create mode 100644 calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/EventListener.java create mode 100644 calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/MqClient.java create mode 100644 calamus-nexus-plugin/src/main/resources/static/js/Calamus/CalamusConfigPanel.js create mode 100644 calamus-nexus-plugin/src/main/resources/static/js/calamus-nexus-plugin-boot.js (limited to 'calamus-nexus-plugin') 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 @@ + + 4.0.0 + + io.trygvis.calamus + calamus + 1.0-SNAPSHOT + + calamus-nexus-plugin + ${project.groupId}:${project.artifactId} + ${nexus-plugin.type} + + 5.9.1 + 2.8.0-01 + + nexus-plugin + + + + org.apache.activemq + activemq-client + ${version.activemq} + + + org.apache.activemq + activemq-pool + ${version.activemq} + + + org.sonatype.nexus + nexus-plugin-api + ${version.nexus} + provided + + + org.sonatype.nexus.plugins + nexus-restlet1x-plugin + ${version.nexus} + + provided + + + org.sonatype.nexus.plugins + nexus-ui-extjs3-plugin + ${version.nexus} + + provided + + + org.sonatype.nexus + nexus-plugin-testsupport + ${version.nexus} + test + + + + + + org.sonatype.nexus + nexus-plugin-bundle-maven-plugin + 1.2 + true + + + + + + idea + + jar + + + + 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' +]); -- cgit v1.2.3