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

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

View File

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

View File

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