store descriptions from extension points and extensions in module and plugin descriptors

This commit is contained in:
Sebastian Sdorra
2014-07-06 16:44:10 +02:00
parent 6d7beeec99
commit 1fba76c969
8 changed files with 156 additions and 23 deletions

View File

@@ -58,10 +58,12 @@ public final class ClassElement
* *
* *
* @param clazz * @param clazz
* @param description
*/ */
public ClassElement(Class<?> clazz) public ClassElement(Class<?> clazz, String description)
{ {
this.clazz = clazz; this.clazz = clazz;
this.description = description;
} }
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
@@ -89,7 +91,8 @@ public final class ClassElement
final ClassElement other = (ClassElement) obj; final ClassElement other = (ClassElement) obj;
return Objects.equal(clazz, other.clazz); return Objects.equal(clazz, other.clazz)
&& Objects.equal(description, other.description);
} }
/** /**
@@ -101,7 +104,7 @@ public final class ClassElement
@Override @Override
public int hashCode() public int hashCode()
{ {
return Objects.hashCode(clazz); return Objects.hashCode(clazz, description);
} }
/** /**
@@ -116,6 +119,7 @@ public final class ClassElement
//J- //J-
return Objects.toStringHelper(this) return Objects.toStringHelper(this)
.add("clazz", clazz) .add("clazz", clazz)
.add("description", description)
.toString(); .toString();
//J+ //J+
} }
@@ -133,9 +137,23 @@ public final class ClassElement
return clazz; return clazz;
} }
/**
* Method description
*
*
* @return
*/
public String getDescription()
{
return description;
}
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** Field description */ /** Field description */
@XmlElement(name = "class") @XmlElement(name = "class")
private Class<?> clazz; private Class<?> clazz;
/** Field description */
private String description;
} }

View File

@@ -63,11 +63,14 @@ public final class ExtensionPointElement
* *
* *
* @param clazz * @param clazz
* @param description
* @param multiple * @param multiple
*/ */
public ExtensionPointElement(Class<?> clazz, boolean multiple) public ExtensionPointElement(Class<?> clazz, String description,
boolean multiple)
{ {
this.clazz = clazz; this.clazz = clazz;
this.description = description;
this.multiple = multiple; this.multiple = multiple;
} }
@@ -97,6 +100,7 @@ public final class ExtensionPointElement
final ExtensionPointElement other = (ExtensionPointElement) obj; final ExtensionPointElement other = (ExtensionPointElement) obj;
return Objects.equal(clazz, other.clazz) return Objects.equal(clazz, other.clazz)
&& Objects.equal(description, other.description)
&& Objects.equal(multiple, other.multiple); && Objects.equal(multiple, other.multiple);
} }
@@ -109,7 +113,7 @@ public final class ExtensionPointElement
@Override @Override
public int hashCode() public int hashCode()
{ {
return Objects.hashCode(clazz, multiple); return Objects.hashCode(clazz, description, multiple);
} }
/** /**
@@ -124,6 +128,7 @@ public final class ExtensionPointElement
//J- //J-
return Objects.toStringHelper(this) return Objects.toStringHelper(this)
.add("class", clazz) .add("class", clazz)
.add("description", description)
.add("multiple", multiple) .add("multiple", multiple)
.toString(); .toString();
//J+ //J+
@@ -142,6 +147,17 @@ public final class ExtensionPointElement
return clazz; return clazz;
} }
/**
* Method description
*
*
* @return
*/
public String getDescription()
{
return description;
}
/** /**
* Method description * Method description
* *
@@ -159,6 +175,9 @@ public final class ExtensionPointElement
@XmlElement(name = "class") @XmlElement(name = "class")
private Class<?> clazz; private Class<?> clazz;
/** Field description */
private String description;
/** Field description */ /** Field description */
@XmlElement(name = "multi") @XmlElement(name = "multi")
private boolean multiple = true; private boolean multiple = true;

View File

@@ -34,11 +34,11 @@ package sonia.scm.plugin;
//~--- non-JDK imports -------------------------------------------------------- //~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Objects; import com.google.common.base.Objects;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
//~--- JDK imports ------------------------------------------------------------ //~--- JDK imports ------------------------------------------------------------
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
@@ -64,11 +64,14 @@ public final class SubscriberElement
* *
* @param subscriberClass * @param subscriberClass
* @param eventClass * @param eventClass
* @param description
*/ */
public SubscriberElement(Class<?> subscriberClass, Class<?> eventClass) public SubscriberElement(Class<?> subscriberClass, Class<?> eventClass,
String description)
{ {
this.subscriberClass = subscriberClass; this.subscriberClass = subscriberClass;
this.eventClass = eventClass; this.eventClass = eventClass;
this.description = description;
} }
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
@@ -97,7 +100,8 @@ public final class SubscriberElement
final SubscriberElement other = (SubscriberElement) obj; final SubscriberElement other = (SubscriberElement) obj;
return Objects.equal(eventClass, other.eventClass) return Objects.equal(eventClass, other.eventClass)
&& Objects.equal(subscriberClass, other.subscriberClass); && Objects.equal(subscriberClass, other.subscriberClass)
&& Objects.equal(description, other.description);
} }
/** /**
@@ -109,7 +113,7 @@ public final class SubscriberElement
@Override @Override
public int hashCode() public int hashCode()
{ {
return Objects.hashCode(eventClass, subscriberClass); return Objects.hashCode(eventClass, subscriberClass, description);
} }
/** /**
@@ -125,12 +129,24 @@ public final class SubscriberElement
return Objects.toStringHelper(this) return Objects.toStringHelper(this)
.add("eventClass", eventClass) .add("eventClass", eventClass)
.add("subscriberClass", subscriberClass) .add("subscriberClass", subscriberClass)
.add("description", description)
.toString(); .toString();
//J+ //J+
} }
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public String getDescription()
{
return description;
}
/** /**
* Method description * Method description
* *
@@ -155,6 +171,9 @@ public final class SubscriberElement
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** Field description */
private String description;
/** Field description */ /** Field description */
@XmlElement(name = "event") @XmlElement(name = "event")
private Class<?> eventClass; private Class<?> eventClass;

View File

@@ -77,9 +77,9 @@ public class ScmModuleTest
assertThat( assertThat(
module.getExtensionPoints(), module.getExtensionPoints(),
containsInAnyOrder( containsInAnyOrder(
new ExtensionPointElement(String.class, true), new ExtensionPointElement(String.class, "ext01", true),
new ExtensionPointElement(Long.class, true), new ExtensionPointElement(Long.class, "ext02", true),
new ExtensionPointElement(Integer.class, false) new ExtensionPointElement(Integer.class, "ext03", false)
) )
); );
assertThat( assertThat(
@@ -92,8 +92,8 @@ public class ScmModuleTest
assertThat( assertThat(
module.getSubscribers(), module.getSubscribers(),
containsInAnyOrder( containsInAnyOrder(
new SubscriberElement(Long.class, Integer.class), new SubscriberElement(Long.class, Integer.class, "sub01"),
new SubscriberElement(Double.class, Float.class) new SubscriberElement(Double.class, Float.class, "sub02")
) )
); );
assertThat( assertThat(

View File

@@ -5,11 +5,13 @@
<subscriber> <subscriber>
<class>java.lang.Long</class> <class>java.lang.Long</class>
<event>java.lang.Integer</event> <event>java.lang.Integer</event>
<description>sub01</description>
</subscriber> </subscriber>
<subscriber> <subscriber>
<class>java.lang.Double</class> <class>java.lang.Double</class>
<event>java.lang.Float</event> <event>java.lang.Float</event>
<description>sub02</description>
</subscriber> </subscriber>
<!-- events --> <!-- events -->
@@ -26,15 +28,18 @@
<extension-point> <extension-point>
<class>java.lang.String</class> <class>java.lang.String</class>
<description>ext01</description>
</extension-point> </extension-point>
<extension-point> <extension-point>
<class>java.lang.Integer</class> <class>java.lang.Integer</class>
<description>ext03</description>
<multi>false</multi> <multi>false</multi>
</extension-point> </extension-point>
<extension-point> <extension-point>
<class>java.lang.Long</class> <class>java.lang.Long</class>
<description>ext02</description>
<multi>true</multi> <multi>true</multi>
</extension-point> </extension-point>

View File

@@ -33,6 +33,8 @@ package sonia.scm.annotation;
//~--- non-JDK imports -------------------------------------------------------- //~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Strings;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
@@ -51,6 +53,9 @@ public class ClassSetElement implements DescriptorElement
/** Field description */ /** Field description */
private static final String EL_CLASS = "class"; private static final String EL_CLASS = "class";
/** Field description */
private static final String EL_DESCRIPTION = "description";
//~--- constructors --------------------------------------------------------- //~--- constructors ---------------------------------------------------------
/** /**
@@ -87,9 +92,18 @@ public class ClassSetElement implements DescriptorElement
classEl.setTextContent(c.className); classEl.setTextContent(c.className);
if (!Strings.isNullOrEmpty(c.description))
{
Element descriptionEl = doc.createElement(EL_DESCRIPTION);
descriptionEl.setTextContent(c.description);
element.appendChild(descriptionEl);
}
for (Entry<String, String> e : c.attributes.entrySet()) for (Entry<String, String> e : c.attributes.entrySet())
{ {
Element attr = doc.createElement(e.getKey()); Element attr = doc.createElement(e.getKey());
attr.setTextContent(e.getValue()); attr.setTextContent(e.getValue());
element.appendChild(attr); element.appendChild(attr);
} }
@@ -98,7 +112,6 @@ public class ClassSetElement implements DescriptorElement
root.appendChild(element); root.appendChild(element);
} }
} }
//~--- inner classes -------------------------------------------------------- //~--- inner classes --------------------------------------------------------
@@ -118,11 +131,14 @@ public class ClassSetElement implements DescriptorElement
* *
* *
* @param className * @param className
* @param description
* @param attributes * @param attributes
*/ */
public ClassWithAttributes(String className, Map<String, String> attributes) public ClassWithAttributes(String className, String description,
Map<String, String> attributes)
{ {
this.className = className; this.className = className;
this.description = description;
this.attributes = attributes; this.attributes = attributes;
} }
@@ -133,6 +149,9 @@ public class ClassSetElement implements DescriptorElement
/** Field description */ /** Field description */
private final String className; private final String className;
/** Field description */
private final String description;
} }

View File

@@ -117,9 +117,15 @@ public final class ScmAnnotationProcessor extends AbstractProcessor
/** Field description */ /** Field description */
private static final String DESCRIPTOR_PLUGIN = "META-INF/scm/plugin.xml"; private static final String DESCRIPTOR_PLUGIN = "META-INF/scm/plugin.xml";
/** Field description */
private static final String EL_MODULE = "module";
/** Field description */ /** Field description */
private static final String EMPTY = ""; private static final String EMPTY = "";
/** Field description */
private static final String PROPERTY_VALUE = "yes";
/** Field description */ /** Field description */
private static final Set<String> SUBSCRIBE_ANNOTATIONS = private static final Set<String> SUBSCRIBE_ANNOTATIONS =
ImmutableSet.of(Subscribe.class.getName()); ImmutableSet.of(Subscribe.class.getName());
@@ -289,7 +295,7 @@ public final class ScmAnnotationProcessor extends AbstractProcessor
else else
{ {
doc = builder.newDocument(); doc = builder.newDocument();
doc.appendChild(doc.createElement("module")); doc.appendChild(doc.createElement(EL_MODULE));
} }
} }
catch (ParserConfigurationException | SAXException | IOException catch (ParserConfigurationException | SAXException | IOException
@@ -344,9 +350,22 @@ public final class ScmAnnotationProcessor extends AbstractProcessor
if (e.getKind().isClass() || e.getKind().isInterface()) if (e.getKind().isClass() || e.getKind().isInterface())
{ {
TypeElement type = (TypeElement) e; TypeElement type = (TypeElement) e;
String desc = processingEnv.getElementUtils().getDocComment(type);
classes.add(new ClassWithAttributes(type.getQualifiedName().toString(), if (desc != null)
getAttributesFromAnnotation(e, annotation))); {
desc = desc.trim();
}
//J-
classes.add(
new ClassWithAttributes(
type.getQualifiedName().toString(),
desc,
getAttributesFromAnnotation(e, annotation)
)
);
//J+
} }
} }
@@ -376,9 +395,23 @@ public final class ScmAnnotationProcessor extends AbstractProcessor
{ {
VariableElement param = params.get(0); VariableElement param = params.get(0);
Element clazz = el.getEnclosingElement();
String desc = processingEnv.getElementUtils().getDocComment(clazz);
if (desc != null)
{
desc = desc.trim();
}
//J-
descriptorElements.add( descriptorElements.add(
new SubscriberElement( new SubscriberElement(
el.getEnclosingElement().toString(), param.asType().toString())); clazz.toString(),
param.asType().toString(),
desc
)
);
//J+
} }
} }
} }
@@ -438,7 +471,7 @@ public final class ScmAnnotationProcessor extends AbstractProcessor
Transformer transformer = Transformer transformer =
TransformerFactory.newInstance().newTransformer(); TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.INDENT, PROPERTY_VALUE);
transformer.transform(new DOMSource(doc), new StreamResult(writer)); transformer.transform(new DOMSource(doc), new StreamResult(writer));
} }
catch (IOException | IllegalArgumentException | TransformerException ex) catch (IOException | IllegalArgumentException | TransformerException ex)

View File

@@ -33,6 +33,8 @@ package sonia.scm.annotation;
//~--- non-JDK imports -------------------------------------------------------- //~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Strings;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
@@ -46,6 +48,9 @@ public class SubscriberElement implements DescriptorElement
/** Field description */ /** Field description */
private static final String EL_CLASS = "class"; private static final String EL_CLASS = "class";
/** Field description */
private static final String EL_DESCRIPTION = "description";
/** Field description */ /** Field description */
private static final String EL_EVENT = "event"; private static final String EL_EVENT = "event";
@@ -60,11 +65,14 @@ public class SubscriberElement implements DescriptorElement
* *
* @param subscriberType * @param subscriberType
* @param eventType * @param eventType
* @param description
*/ */
public SubscriberElement(String subscriberType, String eventType) public SubscriberElement(String subscriberType, String eventType,
String description)
{ {
this.subscriberType = subscriberType; this.subscriberType = subscriberType;
this.eventType = eventType; this.eventType = eventType;
this.description = description;
} }
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
@@ -89,11 +97,23 @@ public class SubscriberElement implements DescriptorElement
eventEl.setTextContent(eventType); eventEl.setTextContent(eventType);
subscriberEl.appendChild(eventEl); subscriberEl.appendChild(eventEl);
if (!Strings.isNullOrEmpty(description))
{
Element descriptionEl = doc.createElement(EL_DESCRIPTION);
descriptionEl.setTextContent(description);
subscriberEl.appendChild(descriptionEl);
}
root.appendChild(subscriberEl); root.appendChild(subscriberEl);
} }
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** Field description */
private final String description;
/** Field description */ /** Field description */
private final String eventType; private final String eventType;