Skip to content
This repository has been archived by the owner on Jul 3, 2018. It is now read-only.

Commit

Permalink
#2 now can list annotations of discovered classes
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-conway committed Jun 1, 2016
1 parent 2c36e53 commit 73b7d3a
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package org.iplantc.de.publish.mechanism.api.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
* Annotation that marks up a publish mechanism for discovery
Expand All @@ -12,6 +14,7 @@
*
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
public @interface PublicationDriver {
/**
* Author of the publisher plugin
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/**
*
*/
package org.iplantc.de.publish.sandbox;

/**
* Describes publishers discovered in the sandbox
*
* @author Mike Conway - DICE
*
*/
public class PublisherDescription {

private Class<?> publisherClass;
private String publisherName;
private String description;
private boolean asynch;
private String author;
private String version;

/**
*
*/
public PublisherDescription() {
}

/**
* @return the publisherClass
*/
public Class<?> getPublisherClass() {
return publisherClass;
}

/**
* @param publisherClass
* the publisherClass to set
*/
public void setPublisherClass(Class<?> publisherClass) {
this.publisherClass = publisherClass;
}

/**
* @return the publisherName
*/
public String getPublisherName() {
return publisherName;
}

/**
* @param publisherName
* the publisherName to set
*/
public void setPublisherName(String publisherName) {
this.publisherName = publisherName;
}

/**
* @return the description
*/
public String getDescription() {
return description;
}

/**
* @param description
* the description to set
*/
public void setDescription(String description) {
this.description = description;
}

/**
* @return the asynch
*/
public boolean isAsynch() {
return asynch;
}

/**
* @param asynch
* the asynch to set
*/
public void setAsynch(boolean asynch) {
this.asynch = asynch;
}

/**
* @return the author
*/
public String getAuthor() {
return author;
}

/**
* @param author
* the author to set
*/
public void setAuthor(String author) {
this.author = author;
}

/**
* @return the version
*/
public String getVersion() {
return version;
}

/**
* @param version
* the version to set
*/
public void setVersion(String version) {
this.version = version;
}

/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("PublisherDescription [");
if (publisherClass != null) {
builder.append("publisherClass=").append(publisherClass)
.append(", ");
}
if (publisherName != null) {
builder.append("publisherName=").append(publisherName).append(", ");
}
if (description != null) {
builder.append("description=").append(description).append(", ");
}
builder.append("asynch=").append(asynch).append(", ");
if (author != null) {
builder.append("author=").append(author).append(", ");
}
if (version != null) {
builder.append("version=").append(version);
}
builder.append("]");
return builder.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.iplantc.de.publish.sandbox;

import java.io.File;
import java.lang.annotation.Annotation;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
Expand Down Expand Up @@ -47,7 +48,28 @@ public PublisherEmulator() {

}

public Set<Class<?>> listPublishers() {
public List<PublisherDescription> listPublisherDescriptions() {
log.info("listPublisherDescriptions()");
Set<Class<?>> classes = listPublisherClasses();

for (Class clazz : classes) {
log.info("processing class:{}", clazz);
for (Annotation annotation : clazz.getDeclaredAnnotations()) {
log.info("...annotation:{}", annotation.toString());
}
}

return null;

}

/**
* Method returns the classes for all registered publishers. Good for
* debugging and testing purposes
*
* @return <code>Set</code> of all of the annotated publisher classes
*/
public Set<Class<?>> listPublisherClasses() {

/*
* see: https://github.com/ronmamo/reflections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package org.iplantc.de.publish.sandbox;

import java.util.List;
import java.util.Properties;
import java.util.Set;

Expand Down Expand Up @@ -58,9 +59,24 @@ public void testListPublishers() throws PublicationException {
PublisherEmulator emulator = new PublisherEmulator();
emulator.setSandboxConfiguration(sandboxConfiguration);
emulator.init();
Set<Class<?>> mechanisms = emulator.listPublishers();
Set<Class<?>> mechanisms = emulator.listPublisherClasses();
Assert.assertFalse("no mechanisms returned", mechanisms.isEmpty());

}

@Test
public void testListPublicationDescriptions() throws PublicationException {
SandboxConfiguration sandboxConfiguration = new SandboxConfiguration();
sandboxConfiguration
.setJarFilePluginDir(testingProperties
.getProperty(PublisherTestingProperties.TEST_PUBLISHER_DIR_PROPERTY));
PublisherEmulator emulator = new PublisherEmulator();
emulator.setSandboxConfiguration(sandboxConfiguration);
emulator.init();
List<PublisherDescription> descriptions = emulator
.listPublisherDescriptions();
Assert.assertNotNull("null descriptions found:{}", descriptions);

}

}

0 comments on commit 73b7d3a

Please sign in to comment.