diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2014-04-12 17:55:28 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2014-04-12 17:55:28 +0200 |
commit | bfcfcf5e3b4301bc94c27f47bfda61693edf3595 (patch) | |
tree | d6eedd800b1b34fd66ccbd86e5f215aaa40ccd3d /calamus-nexus-plugin/src/main/java | |
download | calamus-bfcfcf5e3b4301bc94c27f47bfda61693edf3595.tar.gz calamus-bfcfcf5e3b4301bc94c27f47bfda61693edf3595.tar.bz2 calamus-bfcfcf5e3b4301bc94c27f47bfda61693edf3595.tar.xz calamus-bfcfcf5e3b4301bc94c27f47bfda61693edf3595.zip |
wip
Diffstat (limited to 'calamus-nexus-plugin/src/main/java')
5 files changed, 166 insertions, 0 deletions
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(); + } + } +} |