Committed-by: Eduard Heimbuch<eduard.heimbuch@cloudogu.com>
Pushed-by: Rene Pfeuffer<rene.pfeuffer@cloudogu.com>
Co-authored-by: René Pfeuffer<rene.pfeuffer@cloudogu.com>
Pushed-by: Eduard Heimbuch<eduard.heimbuch@cloudogu.com>
Committed-by: René Pfeuffer<rene.pfeuffer@cloudogu.com>
This commit is contained in:
Eduard Heimbuch
2023-11-29 18:14:03 +01:00
committed by René Pfeuffer
parent d760f46d9d
commit cf4d9cf20f
1217 changed files with 7258 additions and 5987 deletions

View File

@@ -0,0 +1,59 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.annotation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.util.Map;
public class ConfigElement implements DescriptorElement {
private final Map<String, String> attributes;
private final String type;
public ConfigElement(Map<String, String> attributes, String type) {
this.attributes = attributes;
this.type = type;
}
@Override
public void append(Document doc, Element root) {
Element configEl = doc.createElement("config-value");
for (Map.Entry<String, String> entry : attributes.entrySet()) {
Element attributeEl = doc.createElement(entry.getKey());
attributeEl.setTextContent(entry.getValue());
configEl.appendChild(attributeEl);
}
Element typeEl = doc.createElement("type");
typeEl.setTextContent(type);
configEl.appendChild(typeEl);
root.appendChild(configEl);
}
}

View File

@@ -29,6 +29,8 @@ import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.ext.Provider;
import org.kohsuke.MetaInfServices;
import org.mapstruct.Mapper;
import org.w3c.dom.DOMException;
@@ -36,6 +38,7 @@ import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import picocli.CommandLine;
import sonia.scm.annotation.ClassSetElement.ClassWithAttributes;
import sonia.scm.config.ConfigValue;
import sonia.scm.plugin.PluginAnnotation;
import sonia.scm.plugin.Requires;
@@ -56,8 +59,6 @@ import javax.lang.model.element.VariableElement;
import javax.tools.Diagnostic.Kind;
import javax.tools.FileObject;
import javax.tools.StandardLocation;
import javax.ws.rs.Path;
import javax.ws.rs.ext.Provider;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -75,18 +76,18 @@ import java.lang.annotation.Annotation;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import static javax.lang.model.util.ElementFilter.methodsIn;
/**
* @author Sebastian Sdorra
*/
@SupportedAnnotationTypes("*")
@MetaInfServices(Processor.class)
@SuppressWarnings({"Since16"})
@SupportedSourceVersion(SourceVersion.RELEASE_11)
@SupportedSourceVersion(SourceVersion.RELEASE_17)
public final class ScmAnnotationProcessor extends AbstractProcessor {
private static final String DESCRIPTOR_MODULE = "META-INF/scm/module.xml";
@@ -96,6 +97,8 @@ public final class ScmAnnotationProcessor extends AbstractProcessor {
private static final String PROPERTY_VALUE = "yes";
private static final Set<String> SUBSCRIBE_ANNOTATIONS =
ImmutableSet.of(Subscribe.class.getName());
private static final Set<String> CONFIG_ANNOTATIONS = ImmutableSet.of(ConfigValue.class.getName());
private static final Set<ClassAnnotation> CLASS_ANNOTATIONS =
ImmutableSet.of(new ClassAnnotation("rest-resource", Path.class),
new ClassAnnotation("rest-provider", Provider.class),
@@ -108,6 +111,7 @@ public final class ScmAnnotationProcessor extends AbstractProcessor {
if (!roundEnv.processingOver()) {
Set<DescriptorElement> descriptorElements = Sets.newHashSet();
Set<TypeElement> subscriberAnnotations = Sets.newHashSet();
Set<TypeElement> configAnnotations = Sets.newHashSet();
for (TypeElement e : annotations) {
PluginAnnotation pa = e.getAnnotation(PluginAnnotation.class);
@@ -119,6 +123,10 @@ public final class ScmAnnotationProcessor extends AbstractProcessor {
if (SUBSCRIBE_ANNOTATIONS.contains(e.getQualifiedName().toString())) {
subscriberAnnotations.add(e);
}
if (CONFIG_ANNOTATIONS.contains(e.getQualifiedName().toString())) {
configAnnotations.add(e);
}
}
for (ClassAnnotation ca : CLASS_ANNOTATIONS) {
@@ -134,6 +142,9 @@ public final class ScmAnnotationProcessor extends AbstractProcessor {
for (TypeElement annotation : subscriberAnnotations) {
scanForSubscriberAnnotations(descriptorElements, roundEnv, annotation);
}
for (TypeElement annotation : configAnnotations) {
scanForConfigAnnotations(descriptorElements, roundEnv, annotation);
}
write(descriptorElements);
}
@@ -141,6 +152,19 @@ public final class ScmAnnotationProcessor extends AbstractProcessor {
return false;
}
private void scanForConfigAnnotations(Set<DescriptorElement> descriptorElements, RoundEnvironment roundEnv, TypeElement annotation) {
Set<? extends Element> elementsAnnotatedWith = roundEnv.getElementsAnnotatedWith(annotation);
for (Element element : elementsAnnotatedWith) {
Map<String, String> attributesFromAnnotation = getAttributesFromAnnotation(element, annotation);
String type = element.asType().toString();
descriptorElements.add(new ConfigElement(attributesFromAnnotation, type));
}
}
private TypeElement findAnnotation(Set<? extends TypeElement> annotations,
Class<? extends Annotation> annotationClass) {
TypeElement annotation = null;
@@ -353,8 +377,8 @@ public final class ScmAnnotationProcessor extends AbstractProcessor {
String qn = annotationMirror.getAnnotationType().asElement().toString();
if (qn.equals(annotation.toString())) {
for (Entry<? extends ExecutableElement,
? extends AnnotationValue> entry : annotationMirror.getElementValues().entrySet()) {
for (Map.Entry<? extends ExecutableElement,
? extends AnnotationValue> entry : annotationMirror.getElementValues().entrySet()) {
attributes.put(entry.getKey().getSimpleName().toString(),
getValue(entry.getValue()));
}