mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-26 09:19:12 +01:00
create module.xml, if plugin.xml is not available
This commit is contained in:
@@ -43,6 +43,11 @@ import org.w3c.dom.Element;
|
||||
public class ClassSetElement implements DescriptorElement
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final String EL_CLASS = "class";
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
@@ -72,7 +77,7 @@ public class ClassSetElement implements DescriptorElement
|
||||
|
||||
for (String c : classes)
|
||||
{
|
||||
Element classEl = doc.createElement("class");
|
||||
Element classEl = doc.createElement(EL_CLASS);
|
||||
|
||||
classEl.setTextContent(c);
|
||||
element.appendChild(classEl);
|
||||
|
||||
@@ -49,6 +49,7 @@ import sonia.scm.plugin.PluginAnnotation;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -80,6 +81,7 @@ import javax.tools.StandardLocation;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Transformer;
|
||||
@@ -98,6 +100,15 @@ import javax.xml.transform.stream.StreamResult;
|
||||
public final class ScmAnnotationProcessor extends AbstractProcessor
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final String DESCRIPTOR_MODULE = "META-INF/scm/module.xml";
|
||||
|
||||
/** Field description */
|
||||
private static final String DESCRIPTOR_PLUGIN = "META-INF/scm/plugin.xml";
|
||||
|
||||
/** Field description */
|
||||
private static final String EMPTY = "";
|
||||
|
||||
/** Field description */
|
||||
private static final Set<String> SUBSCRIBE_ANNOTATIONS =
|
||||
ImmutableSet.of(Subscribe.class.getName());
|
||||
@@ -182,33 +193,61 @@ public final class ScmAnnotationProcessor extends AbstractProcessor
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param filer
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private File findDescriptor(Filer filer) throws IOException
|
||||
{
|
||||
FileObject f = filer.getResource(StandardLocation.CLASS_OUTPUT, EMPTY,
|
||||
DESCRIPTOR_PLUGIN);
|
||||
File file = new File(f.toUri());
|
||||
|
||||
if (!file.exists())
|
||||
{
|
||||
f = filer.getResource(StandardLocation.CLASS_OUTPUT, EMPTY,
|
||||
DESCRIPTOR_MODULE);
|
||||
file = new File(f.toUri());
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param f
|
||||
*
|
||||
* @param file
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Document parseDocument(FileObject f)
|
||||
private Document parseDocument(File file)
|
||||
{
|
||||
Document doc = null;
|
||||
InputStream input = null;
|
||||
|
||||
try
|
||||
{
|
||||
File file = new File(f.toUri());
|
||||
DocumentBuilder builder =
|
||||
DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
|
||||
if (file.exists())
|
||||
{
|
||||
input = f.openInputStream();
|
||||
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
|
||||
input);
|
||||
input = new FileInputStream(file);
|
||||
doc = builder.parse(input);
|
||||
}
|
||||
else
|
||||
{
|
||||
processingEnv.getMessager().printMessage(Kind.WARNING,
|
||||
"could not find plugin descriptor");
|
||||
doc = builder.newDocument();
|
||||
doc.appendChild(doc.createElement("module"));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -243,18 +282,10 @@ public final class ScmAnnotationProcessor extends AbstractProcessor
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param classes
|
||||
* @param descriptorElements
|
||||
* @param elementName
|
||||
* @param elements
|
||||
*
|
||||
* @param descriptorElements
|
||||
* @param roundEnv
|
||||
* @param annotationClass
|
||||
* @param pa
|
||||
* @param typeElement
|
||||
* @param <T>
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private void scanForClassAnnotations(
|
||||
@@ -265,7 +296,7 @@ public final class ScmAnnotationProcessor extends AbstractProcessor
|
||||
|
||||
for (Element e : elements)
|
||||
{
|
||||
if (e.getKind().isClass())
|
||||
if (e.getKind().isClass() || e.getKind().isInterface())
|
||||
{
|
||||
TypeElement type = (TypeElement) e;
|
||||
|
||||
@@ -311,9 +342,6 @@ public final class ScmAnnotationProcessor extends AbstractProcessor
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param roundEnv
|
||||
* @param classes
|
||||
*
|
||||
* @param descriptorElements
|
||||
*/
|
||||
private void write(Set<DescriptorElement> descriptorElements)
|
||||
@@ -322,10 +350,9 @@ public final class ScmAnnotationProcessor extends AbstractProcessor
|
||||
|
||||
try
|
||||
{
|
||||
FileObject f = filer.getResource(StandardLocation.CLASS_OUTPUT, "",
|
||||
"META-INF/scm/plugin.xml");
|
||||
File file = findDescriptor(filer);
|
||||
|
||||
Document doc = parseDocument(f);
|
||||
Document doc = parseDocument(file);
|
||||
|
||||
if (doc != null)
|
||||
{
|
||||
@@ -336,7 +363,7 @@ public final class ScmAnnotationProcessor extends AbstractProcessor
|
||||
el.append(doc, root);
|
||||
}
|
||||
|
||||
writeDocument(doc, f);
|
||||
writeDocument(doc, file);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -351,14 +378,16 @@ public final class ScmAnnotationProcessor extends AbstractProcessor
|
||||
*
|
||||
* @param doc
|
||||
* @param f
|
||||
* @param file
|
||||
*/
|
||||
private void writeDocument(Document doc, FileObject f)
|
||||
private void writeDocument(Document doc, File file)
|
||||
{
|
||||
Writer writer = null;
|
||||
|
||||
try
|
||||
{
|
||||
writer = new FileWriter(new File(f.toUri()));
|
||||
file.getParentFile().mkdirs();
|
||||
writer = new FileWriter(file);
|
||||
|
||||
Transformer transformer =
|
||||
TransformerFactory.newInstance().newTransformer();
|
||||
|
||||
@@ -43,6 +43,17 @@ import org.w3c.dom.Element;
|
||||
public class SubscriberElement implements DescriptorElement
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final String EL_CLASS = "class";
|
||||
|
||||
/** Field description */
|
||||
private static final String EL_EVENT = "event";
|
||||
|
||||
/** Field description */
|
||||
private static final String EL_SUBSCRIBER = "subscriber";
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
@@ -68,13 +79,13 @@ public class SubscriberElement implements DescriptorElement
|
||||
@Override
|
||||
public void append(Document doc, Element root)
|
||||
{
|
||||
Element subscriberEl = doc.createElement("subscriber");
|
||||
Element classEl = doc.createElement("class");
|
||||
Element subscriberEl = doc.createElement(EL_SUBSCRIBER);
|
||||
Element classEl = doc.createElement(EL_CLASS);
|
||||
|
||||
classEl.setTextContent(subscriberType);
|
||||
subscriberEl.appendChild(classEl);
|
||||
|
||||
Element eventEl = doc.createElement("event");
|
||||
Element eventEl = doc.createElement(EL_EVENT);
|
||||
|
||||
eventEl.setTextContent(eventType);
|
||||
subscriberEl.appendChild(eventEl);
|
||||
|
||||
Reference in New Issue
Block a user