summaryrefslogtreecommitdiff
path: root/calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/EventListener.java
diff options
context:
space:
mode:
Diffstat (limited to 'calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/EventListener.java')
-rw-r--r--calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/EventListener.java51
1 files changed, 51 insertions, 0 deletions
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);
+ }
+}