Currently job artifacts in CI/CD pipelines on LRZ GitLab never expire. Starting from Wed 26.1.2022 the default expiration time will be 30 days (GitLab default). Currently existing artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

Commit bb7e35d0 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

resolve merge conflict.

parents 7ecc4813 6900e8e5
Pipeline #59629 failed with stage
in 41 seconds
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>vadere</artifactId>
<groupId>org.vadere</groupId>
<version>0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>annotation</artifactId>
<name>Vadere Annotation</name>
<dependencies>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>${auto-service.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>tests</testSourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>testResources</directory>
</testResource>
<testResource>
<directory>tests</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler.version}</version>
<configuration>
<source>${maven-compiler.source.version}</source>
<target>${maven-compiler.target.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<!-- Use JaCoCo's Java agents to record coverage data by using on-the-fly class file instrumentation. -->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<output>file</output>
<destFile>${project.build.directory}/coverage-data/jacoco-unit-tests.coverage</destFile>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!-- Use JaCoCo agent output to create coverage reports in CSV, HTML and XML format. -->
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/coverage-data/jacoco-unit-tests.coverage</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/coverage-reports</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- Maven Surefire is used to execute unit tests. -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<argLine>${surefireArgLine}</argLine>
<failIfNoTests>false</failIfNoTests>
<excludes>
<exclude></exclude>
</excludes>
<skipTests>${skip.unit.tests}</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package org.vadere.annotation.factories;
import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.annotation.factories.outputfiles.OutputFileClass;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
/**
* Base FactoryProcessor to generate Factories
*
* Factories are crated with two annotations: {@link FactoryType} and a specific Annotation Interface
* declaring a new Factory. {@link FactoryType} is used to annotate the specific annotation used
* for factories (i.e. {@link OutputFileClass}, {@link DataProcessorClass},
* {@link org.vadere.annotation.factories.models.ModelClass} and
* {@link org.vadere.annotation.factories.attributes.ModelAttributeClass})
*
* The {@link AbstractFactoryProcessor} defines process loop used to
* generate java source files. It also provides abstract methods as hooks to allow
* child classes to add additional elements into the generated java source file.
* All hooks have access to the PrintWriter used to create the java source file as well
* the Set of TypElements annotated with the specific annotation used in this {@link javax.annotation.processing.Processor}
*
* <ul>
* <li>{@link #addImports(Set, PrintWriter)}: </br>
* This hook allows the implementing class to add additional import statements
* which where not mentioned in the {@link FactoryType} annotation interface.
* </li>
* <li>{@link #addMembers(Set, PrintWriter)}: </br>
* This hook allows the implementing class to add additional members to the new
* java source file.
* </li>
* <li>{@link #addLastConstructor(Set, PrintWriter)}: </br>
* This hook allows the implementing class to add additional statement to the
* Constructor of the new Factory. Only the Default constructor is implemented!
* </li>
* <li>{@link #addLastConstructor(Set, PrintWriter)}: </br>
* This hook allows the implementing class to add additional function to the
* new java source file.
* </li>
* </ul>
*
*
* {@link #addImports(Set, PrintWriter)}
*/
public abstract class AbstractFactoryProcessor extends AbstractProcessor {
private static final String QUOTE = "\"";
protected String factoryClassName; //Name of the new Factory
protected String extendedClassName; //Name of the Factory which needs to be extended.
protected String genericFactoryTypes; //Generics if extendedClass needs it.
protected String factoryPackage; //Where to place the new Factory.
protected String[] factoryImports; //Imports needed by the new Factory.
/**
* This method is called from the java compiler directly*
*/
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (TypeElement annotation : annotations) {
//only no abstract classes...
Set<? extends Element> annotatedElements =
roundEnv.getElementsAnnotatedWith(annotation)
.stream()
.filter(e -> e.getKind().isClass()
&& !e.getKind().equals(ElementKind.ENUM)
&& !e.getModifiers().contains(Modifier.ABSTRACT)
)
.collect(Collectors.toSet());
if (annotatedElements.isEmpty())
continue;
setup(annotation);
try {
writeFactory(annotatedElements);
} catch (IOException e) {
e.printStackTrace();
}
}
return true;
}
protected abstract void addImports(Set<? extends Element> elements, PrintWriter writer);
protected abstract void addMembers(Set<? extends Element> elements, PrintWriter writer);
protected abstract void addLastConstructor(Set<? extends Element> elements, PrintWriter writer);
protected abstract void addLast(Set<? extends Element> elements, PrintWriter writer);
protected String name(Element e) {
return e.getSimpleName().toString();
}
/**
* This method is called for each SupportedAnnotationTypes from the {@link #process(Set, RoundEnvironment)}
* method. The current implementation only allows ONE SupportedAnnotationTypes because this
* method build the whole java source file.
*
* @param elements Elements annotated with one of the SupportedAnnotationTypes
*/
protected abstract void writeFactory(Set<? extends Element> elements) throws IOException;
/**
* Create class statement based on information provided by the {@link FactoryType} annotation
*
* @param elements Elements annotated with one of the SupportedAnnotationTypes
* @param writer PrintWriter used to create the source file.
*/
protected void buildClass(Set<? extends Element> elements, PrintWriter writer) {
writer.append("public class ").append(factoryClassName);
if (!extendedClassName.isEmpty()) {
writer.append(" extends ").append(extendedClassName);
if (!genericFactoryTypes.isEmpty()) {
writer.append("<").append(genericFactoryTypes).append("> ");
}
}
writer.println("{");
}
/**
* Create a getter for each Element in elements set. The underling TypeElement
* is a Class and must have a constructor without parameters.
*
* @param elements Elements annotated with one of the SupportedAnnotationTypes
* @param writer PrintWriter used to create the source file.
*/
protected void buildGetters(Set<? extends Element> elements, PrintWriter writer) {
for (Element element : elements) {
TypeElement p = (TypeElement) element;
writer.append(" public ").append(p.getSimpleName())
.append(" get").append(p.getSimpleName()).append("()").println("{");
writer.append(" return new ").append(p.getSimpleName()).println("();");
writer.append(" }").println();
writer.println();
}
}
/**
* Creates a static method to provide a thread safe singletone implementation.
*/
protected void createSingletone(final String instanceType, PrintWriter writer){
writer.append(" private static ").append(instanceType).append(" instance;").println();
writer.println();
writer.println(" //performance threadsafe Singletone. Sync block will only be used once");
writer.append(" public static ").append(instanceType).append(" instance(){").println();
writer.println(" if(instance == null){");
writer.append(" synchronized (").append(instanceType).append(".class){").println();
writer.println(" if(instance == null){");
writer.append(" instance = new ").append(instanceType).append("();").println();
writer.println(" }");
writer.println(" }");
writer.println(" }");
writer.println(" return instance;");
writer.println(" }");
writer.println();
}
protected String quote(final String data){
return QUOTE + data + QUOTE;
}
private void setup(TypeElement annotation) {
FactoryType factoryType = annotation.getAnnotation(FactoryType.class);
assert factoryType != null;
this.factoryClassName = factoryType.factoryClassName();
this.extendedClassName = factoryType.extendedClassName();
this.genericFactoryTypes = factoryType.genericFactoryTypes();
this.factoryPackage = factoryType.factoryPackage();
this.factoryImports = factoryType.factoryImports();
}
}
package org.vadere.annotation.factories;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Set;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.tools.JavaFileObject;
/**
* Implements the default layout of the java source file.
*/
public abstract class BaseFactoryProcessor extends AbstractFactoryProcessor {
@Override
protected void writeFactory(Set<? extends Element> elements) throws IOException {
JavaFileObject jFile = processingEnv.getFiler().createSourceFile(factoryClassName);
try (PrintWriter out = new PrintWriter(jFile.openWriter())) {
out.append("package ").append(factoryPackage).append(";").println();
out.println();
// Add Imports start
for (String factoryImport : factoryImports) {
out.append("import ").append(factoryImport).println(";");
}
out.println();
for (Element e : elements) {
TypeElement p = (TypeElement) e;
out.append("import ").append(p.getQualifiedName()).println(";");
}
out.println();
//add additional import defined by subclass
addImports(elements, out);
//Add Import ends
out.println();
out.println();
buildClass(elements, out);
out.println();
addMembers(elements, out);
out.println();
createSingletone(factoryClassName, out);
out.println();
// private constructor.
out.append(" private ").append(factoryClassName).append("(){").println();
out.println();
addLastConstructor(elements, out);
out.println(" }");
out.println();
out.println();
out.println(" // Getters");
buildGetters(elements, out);
addLast(elements, out);
out.println();
out.println("}");
}
}
}
package org.vadere.annotation.factories;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
/**
* This annotation interface is used to annotate specific factory annotations. The members in this
* annotation provides information about the new factory java source file.
*/
@Target(ElementType.ANNOTATION_TYPE)
public @interface FactoryType {
/**
* @return Nam of the new Factory class. This is mandatory.
*/
String factoryClassName();
/**
* @return Name of the super class if one exists.
*/
String extendedClassName() default "";
/**
* @return Generic information for super class if one exists.
*/
String genericFactoryTypes() default "";
/**
* @return List of imports needed for the new Factory class.
*/
String[] factoryImports() default {};
/**
* @return Package name of the new Factory class. This is mandatory.
*/
String factoryPackage();
}
package org.vadere.annotation.factories.attributes;
import com.google.auto.service.AutoService;
import org.vadere.annotation.factories.BaseFactoryProcessor;
import java.io.PrintWriter;
import java.util.Set;
import javax.annotation.processing.Processor;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
@SupportedAnnotationTypes("org.vadere.annotation.factories.attributes.ModelAttributeClass")
@SupportedSourceVersion(SourceVersion.RELEASE_8)
@AutoService(Processor.class)
public class BaseAttributeFactoryProcessor extends BaseFactoryProcessor {
@Override
protected void addImports(Set<? extends Element> elements, PrintWriter writer) {
}
@Override
protected void addMembers(Set<? extends Element> elements, PrintWriter writer) {
}
@Override
protected void addLastConstructor(Set<? extends Element> elements, PrintWriter writer) {
for (Element e : elements) {
TypeElement te = (TypeElement) e;
String className = te.getSimpleName().toString();
writer.append(" addMember(");
writer.append(className).append(".class, ");
writer.append("this::").append("get").append(name(e)).println(");");
}
}
@Override
protected void addLast(Set<? extends Element> elements, PrintWriter writer) {
}
}
package org.vadere.annotation.factories.attributes;
import org.vadere.annotation.factories.FactoryType;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
/**
* This annotation interface defines the ModelAttributeFactory. The main logic of the factory
* resides in the AttributeBaseFactory (util-Module). The generated java source file only
* provides the tedious getter and Map creations.
*/
@Target(ElementType.TYPE)
@FactoryType(
factoryClassName = "ModelAttributeFactory",
extendedClassName = "AttributeBaseFactory",
genericFactoryTypes = "Attributes",
factoryImports = {
"org.vadere.state.attributes.Attributes",
"org.vadere.util.factory.attributes.AttributeBaseFactory"
},
factoryPackage = "org.vadere.state.attributes"
)
public @interface ModelAttributeClass {
}
package org.vadere.annotation.factories.dataprocessors;
import org.vadere.annotation.factories.FactoryType;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
/**
* This annotation interface defines the DataProcessorFactory. The main logic of the factory
* resides in the ProcessorBaseFactory (util-Module). The generated java source file only
* provides the tedious getter and Map creations.
*/
@Target(ElementType.TYPE)
@FactoryType(
factoryClassName = "DataProcessorFactory",
extendedClassName = "ProcessorBaseFactory",
genericFactoryTypes = "DataProcessor<?, ?>",
factoryImports = {
"org.vadere.simulator.projects.dataprocessing.processor.DataProcessor",
"org.vadere.util.factory.processors.ProcessorBaseFactory"
},
factoryPackage = "org.vadere.simulator.projects.dataprocessing.processor"
)
public @interface DataProcessorClass {
String label() default "";
String description() default "";
}
package org.vadere.annotation.factories.dataprocessors;
import com.google.auto.service.AutoService;
import org.vadere.annotation.factories.BaseFactoryProcessor;
import java.io.PrintWriter;
import java.util.Set;
import javax.annotation.processing.Processor;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
@SupportedAnnotationTypes("org.vadere.annotation.factories.dataprocessors.DataProcessorClass")
@SupportedSourceVersion(SourceVersion.RELEASE_8)
@AutoService(Processor.class)
public class DataProcessorFactoryProcessor extends BaseFactoryProcessor {
@Override
protected void addImports(Set<? extends Element> elements, PrintWriter writer) {
writer.println("import org.vadere.simulator.projects.dataprocessing.store.DataProcessorStore;");
}
@Override
protected void addMembers(Set<? extends Element> elements, PrintWriter writer) {
}
@Override
protected void addLastConstructor(Set<? extends Element> elements, PrintWriter writer) {
for (Element e : elements) {
writer.append(" addMember(");
writer.append(e.getSimpleName().toString()).append(".class, ");
writer.append("this::").append("get").append(name(e)).append(", ");
writer.append(quote(label(e))).append(", ");
writer.append(quote(descr(e))).println("); ");
}
}
@Override
protected void addLast(Set<? extends Element> elements, PrintWriter writer) {
writer.println(" public DataProcessor<?, ?> createDataProcessor(DataProcessorStore dataProcessorStore) throws ClassNotFoundException {");
writer.println(" DataProcessor<?, ?> processor = getInstanceOf(dataProcessorStore.getType());");
writer.println(" processor.setId(dataProcessorStore.getId());");
writer.println(" processor.setAttributes(dataProcessorStore.getAttributes());");
writer.println(" return processor;");
writer.println(" }");
writer.println();
writer.println();
writer.println(" public DataProcessor<?, ?> createDataProcessor(String type) throws ClassNotFoundException {");
writer.println(" DataProcessorStore dataProcessorStore = new DataProcessorStore();");
writer.println(" dataProcessorStore.setType(type);");
writer.println(" DataProcessor<?, ?> processor = getInstanceOf(dataProcessorStore.getType());");
writer.println(" processor.setId(dataProcessorStore.getId());");
writer.println(" processor.setAttributes(dataProcessorStore.getAttributes());");
writer.println(" return processor;");
writer.println(" }");
writer.println();