diff options
Diffstat (limited to 'calamus-nexus-plugin')
-rw-r--r-- | calamus-nexus-plugin/pom.xml | 45 | ||||
-rw-r--r-- | calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/CalamusEventListener.java (renamed from calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/EventListener.java) | 19 | ||||
-rw-r--r-- | calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/CalamusNexusPlugin.java | 14 | ||||
-rw-r--r-- | calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/CalamusUiContributor.java | 2 | ||||
-rw-r--r-- | calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/MqClient.java | 35 | ||||
-rw-r--r-- | calamus-nexus-plugin/src/main/resources/static/js/Calamus/CalamusConfigPanel.js | 3 | ||||
-rw-r--r-- | calamus-nexus-plugin/src/main/resources/static/js/calamus-nexus-plugin-boot.js | 3 |
7 files changed, 63 insertions, 58 deletions
diff --git a/calamus-nexus-plugin/pom.xml b/calamus-nexus-plugin/pom.xml index 5060827..464daa6 100644 --- a/calamus-nexus-plugin/pom.xml +++ b/calamus-nexus-plugin/pom.xml @@ -1,21 +1,26 @@ -<project> +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> - <groupId>io.trygvis.calamus</groupId> - <artifactId>calamus</artifactId> + <groupId>org.sonatype.nexus.examples</groupId> + <artifactId>nexus-examples</artifactId> <version>1.0-SNAPSHOT</version> </parent> + + <groupId>io.trygvis.calamus</groupId> <artifactId>calamus-nexus-plugin</artifactId> + <version>1.0-SNAPSHOT</version> + <name>${project.groupId}:${project.artifactId}</name> - <packaging>${nexus-plugin.type}</packaging> + <packaging>nexus-plugin</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> @@ -27,24 +32,18 @@ <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> + <artifactId>nexus-ui-extjs3-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> + <groupId>org.sonatype.nexus</groupId> + <artifactId>nexus-plugin-api</artifactId> <version>${version.nexus}</version> - <!--<type>jar</type>--> <scope>provided</scope> </dependency> <dependency> @@ -64,12 +63,4 @@ </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/EventListener.java b/calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/CalamusEventListener.java index 4770974..ddfd171 100644 --- a/calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/EventListener.java +++ b/calamus-nexus-plugin/src/main/java/io/trygvis/calamus/nexus/CalamusEventListener.java @@ -14,8 +14,8 @@ import javax.inject.Singleton; import static org.slf4j.LoggerFactory.getLogger; @Singleton -@Named -public class EventListener implements EventSubscriber { +@Named("CalamusEventListener") +public class CalamusEventListener implements EventSubscriber { private final Logger log = getLogger(getClass()); @@ -23,8 +23,8 @@ public class EventListener implements EventSubscriber { private final GavCalculator gavCalculator; @Inject - public EventListener(CalamusConfig config, @Named("maven2") GavCalculator gavCalculator) { - log.info("CalamusNexusPlugin.CalamusNexusPlugin"); + public CalamusEventListener(CalamusConfig config, @Named("maven2") GavCalculator gavCalculator) { + log.info("CalamusEventListener.CalamusEventListener"); log.info("gavCalculator = " + gavCalculator); this.mqClient = new MqClient(config.getBrokerUrl()); @@ -33,19 +33,20 @@ public class EventListener implements EventSubscriber { @Subscribe public void onRepositoryItemEventStoreCreate(RepositoryItemEventStoreCreate event) { + log.info("EventListener.onRepositoryItemEventStoreCreate"); + Gav gav = gavCalculator.pathToGav(event.getItem().getPath()); - if (gav == null) { + if (gav == null || gav.isHash() || gav.isSignature()) { return; } String groupId = gav.getGroupId(); String artifactId = gav.getArtifactId(); String version = gav.getVersion(); - String type = gav.getExtension(); + String extension = 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); + log.info("New artifact: groupId={}, artifactId={}, version={}, classifier={}, extension={}", groupId, artifactId, version, classifier, extension); + mqClient.sendMessage(event.getRepository().getId(), groupId, artifactId, version, classifier, extension); } } 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 index e60fed7..96d2c1d 100644 --- 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 @@ -1,17 +1,25 @@ package io.trygvis.calamus.nexus; -import org.eclipse.sisu.EagerSingleton; +//import org.eclipse.sisu.EagerSingleton; + +import org.slf4j.Logger; import org.sonatype.nexus.plugin.PluginIdentity; import javax.inject.Inject; import javax.inject.Named; -@EagerSingleton -@Named("calamus") +import static org.slf4j.LoggerFactory.getLogger; + +@Named +//@EagerSingleton public class CalamusNexusPlugin extends PluginIdentity { + private final Logger log = getLogger(getClass()); + @Inject public CalamusNexusPlugin() throws Exception { super("io.trygvis.calamus", "calamus-nexus-plugin"); + + System.out.println("CalamusNexusPlugin.CalamusNexusPlugin"); } } 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 index ed2f745..18e1c68 100644 --- 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 @@ -1,10 +1,12 @@ 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 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 index 51b2b3a..2564ed9 100644 --- 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 @@ -1,26 +1,33 @@ package io.trygvis.calamus.nexus; import org.apache.activemq.ActiveMQConnectionFactory; +import org.slf4j.Logger; 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 java.io.CharArrayWriter; +import java.io.IOException; +import java.util.Properties; import static javax.jms.Session.AUTO_ACKNOWLEDGE; +import static org.apache.commons.lang.StringUtils.trimToEmpty; +import static org.slf4j.LoggerFactory.getLogger; public class MqClient { - ActiveMQConnectionFactory connectionFactory; + private final Logger log = getLogger(getClass()); + + private final 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) { + public void sendMessage(String repository, String groupId, String artifactId, String version, String classifier, String extension) { try { Connection connection = connectionFactory.createConnection(); connection.start(); @@ -32,20 +39,22 @@ public class MqClient { 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); + Properties p = new Properties(); + p.setProperty("repository", repository); + p.setProperty("groupId", groupId); + p.setProperty("artifactId", artifactId); + p.setProperty("version", version); + p.setProperty("classifier", trimToEmpty(classifier)); + p.setProperty("extension", extension); - producer.send(message); + CharArrayWriter buf = new CharArrayWriter(); + p.store(buf, null); + producer.send(session.createTextMessage(buf.toString())); session.close(); connection.close(); - } catch (JMSException e) { - e.printStackTrace(); + } catch (JMSException | IOException e) { + log.warn("Unable to send message to broker", e); } } } 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 deleted file mode 100644 index 81a7887..0000000 --- a/calamus-nexus-plugin/src/main/resources/static/js/Calamus/CalamusConfigPanel.js +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index 0c454be..0000000 --- a/calamus-nexus-plugin/src/main/resources/static/js/calamus-nexus-plugin-boot.js +++ /dev/null @@ -1,3 +0,0 @@ -define('calamus-nexus-plugin', [ - 'Calamus/CalamusConfigPanel' -]); |