diff --git a/publisher-discovery/src/main/java/org/iplantc/de/publish/discovery/PublisherDiscoveryService.java b/publisher-discovery/src/main/java/org/iplantc/de/publish/discovery/PublisherDiscoveryService.java index 23919a0..bf8bfab 100644 --- a/publisher-discovery/src/main/java/org/iplantc/de/publish/discovery/PublisherDiscoveryService.java +++ b/publisher-discovery/src/main/java/org/iplantc/de/publish/discovery/PublisherDiscoveryService.java @@ -64,15 +64,31 @@ public void setPublisherDiscoveryConfiguration( public List listPublisherDescriptions() { log.info("listPublisherDescriptions()"); Set> classes = listPublisherClasses(); + List descriptions = new ArrayList(); + PublisherPluginDescription description; + PublicationDriver driver; for (Class clazz : classes) { log.info("processing class:{}", clazz); for (Annotation annotation : clazz.getDeclaredAnnotations()) { - log.info("...annotation:{}", annotation.toString()); + if (annotation instanceof PublicationDriver) { + driver = clazz.getAnnotation(PublicationDriver.class); + log.info("...annotation:{}", annotation.toString()); + log.info("driver name:{}", driver.name()); + description = new PublisherPluginDescription(); + description.setAsynch(driver.isAsynch()); + description.setAuthor(driver.author()); + description.setDescription(driver.description()); + description.setPublisherClass(clazz); + description.setPublisherName(driver.name()); + description.setVersion(driver.version()); + descriptions.add(description); + } + } } - return null; + return descriptions; } @@ -159,8 +175,10 @@ private void loadPublisherClasses(String libDir) { } } - DefaultContextLoader context = new DefaultContextLoader(jcl); - context.loadContext(); + if (JclContext.get() == null) { + DefaultContextLoader context = new DefaultContextLoader(jcl); + context.loadContext(); + } } diff --git a/publisher-discovery/src/test/java/org/iplantc/de/publish/discovery/PublisherDiscoveryServiceTest.java b/publisher-discovery/src/test/java/org/iplantc/de/publish/discovery/PublisherDiscoveryServiceTest.java index be0529c..8f4cb50 100644 --- a/publisher-discovery/src/test/java/org/iplantc/de/publish/discovery/PublisherDiscoveryServiceTest.java +++ b/publisher-discovery/src/test/java/org/iplantc/de/publish/discovery/PublisherDiscoveryServiceTest.java @@ -1,5 +1,6 @@ package org.iplantc.de.publish.discovery; +import java.io.File; import java.util.List; import java.util.Properties; @@ -43,11 +44,14 @@ public void testInitWithConfig() throws PublicationException { } @Test - public void testListPublicationDescriptions() throws PublicationException { + public void testListPublicationDescriptions() throws Exception { + File testDriver = PublisherTestingProperties + .getClasspathResourceAsFile("/sample-jars/dummy-publish-1.0.0-SNAPSHOT.jar"); PublisherDiscoveryConfiguration publisherDiscoveryConfiguration = new PublisherDiscoveryConfiguration(); - publisherDiscoveryConfiguration - .setJarFilePluginDir(testingProperties - .getProperty(PublisherTestingProperties.TEST_PUBLISHER_DIR_PROPERTY)); + publisherDiscoveryConfiguration.setJarFilePluginDir(testDriver + .getParent()); + // testingProperties + // .getProperty(PublisherTestingProperties.TEST_PUBLISHER_DIR_PROPERTY)); PublisherDiscoveryService publisherDiscoveryService = new PublisherDiscoveryService(); publisherDiscoveryService .setPublisherDiscoveryConfiguration(publisherDiscoveryConfiguration); @@ -55,7 +59,22 @@ public void testListPublicationDescriptions() throws PublicationException { List descriptions = publisherDiscoveryService .listPublisherDescriptions(); Assert.assertNotNull("null descriptions found:{}", descriptions); + String dummyName = "Dummy Logging"; + boolean found = false; - } + for (PublisherPluginDescription description : descriptions) { + if (!description.getPublisherName().equals(dummyName)) { + continue; + } + Assert.assertFalse(description.getAuthor().isEmpty()); + Assert.assertFalse(description.getDescription().isEmpty()); + Assert.assertFalse(description.getPublisherName().isEmpty()); + Assert.assertFalse(description.getVersion().isEmpty()); + found = true; + } + + Assert.assertTrue("didnt find test driver", found); + + } } diff --git a/publisher-discovery/src/test/java/org/iplantc/de/publish/discovery/PublisherTestingProperties.java b/publisher-discovery/src/test/java/org/iplantc/de/publish/discovery/PublisherTestingProperties.java index 85662d7..050d152 100644 --- a/publisher-discovery/src/test/java/org/iplantc/de/publish/discovery/PublisherTestingProperties.java +++ b/publisher-discovery/src/test/java/org/iplantc/de/publish/discovery/PublisherTestingProperties.java @@ -3,10 +3,15 @@ */ package org.iplantc.de.publish.discovery; +import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.URISyntaxException; +import java.net.URL; import java.util.Properties; +import org.irods.jargon.core.exception.JargonException; +import org.irods.jargon.core.utils.LocalFileUtils; import org.irods.jargon.testutils.TestingUtilsException; /** @@ -52,4 +57,29 @@ public Properties getTestProperties() throws TestingUtilsException { return properties; } + public static File getClasspathResourceAsFile(final String resourcePath) + throws JargonException { + + if (resourcePath == null || resourcePath.isEmpty()) { + throw new IllegalArgumentException("null or empty resourcePath"); + } + // Load the directory as a resource + URL resourceUrl = LocalFileUtils.class.getResource(resourcePath); + + if (resourceUrl == null) { + throw new JargonException("null resource, cannot find file"); + } + + // Turn the resource into a File object + try { + File resourceFile = new File(resourceUrl.toURI()); + if (!resourceFile.exists()) { + throw new JargonException("resource file does not exist"); + } + return resourceFile; + } catch (URISyntaxException e) { + throw new JargonException("unable to create uri from file path"); + } + } + }