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 0acee9cd authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

Merge branch 'vadereManager' into 'master'

Vadere manager

See merge request !79
parents 5518b3b8 4807a7a0
Pipeline #135478 passed with stages
in 138 minutes and 39 seconds
......@@ -44,6 +44,7 @@ VadereModelCalibration/**/output
VadereModelTests/**/legacy
VadereUtils/output/**
VadereModelTests/*_private
**/current_commit_hash.txt
# Operating system files
.DS_Store
......@@ -53,3 +54,7 @@ VadereModelTests/*_private
**/output/
**/legacy/
**/*_private/
# Vadere Cache
**/__cache__
**/vadere-server-output
\ No newline at end of file
package org.vadere.annotation.traci.client;
import com.google.auto.service.AutoService;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Processor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.MirroredTypeException;
import javax.tools.JavaFileObject;
@SupportedAnnotationTypes("org.vadere.annotation.traci.client.TraCIApi")
@SupportedSourceVersion(SourceVersion.RELEASE_11)
@AutoService(Processor.class)
public class ClientAnnotationProcessor extends AbstractProcessor {
private StringBuilder apiMembers;
private StringBuilder apiInit;
private StringBuilder apiMapping;
private StringBuilder apiAbstract;
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
apiMembers = new StringBuilder();
apiInit = new StringBuilder();
apiMapping = new StringBuilder();
apiAbstract = new StringBuilder();
// see SupportedAnnotationTypes (here only TraCIApi)
for (TypeElement annotation : annotations) {
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;
for (Element annotatedElement : annotatedElements) {
try {
writeApiClass(annotatedElement);
} catch (IOException e) {
e.printStackTrace();
}
}
}
try {
TypeElement element = processingEnv.getElementUtils().
getTypeElement("org.vadere.manager.client.AbstractTestClient");
if (element == null)
writeAbstractTestClient();
} catch (IOException e) {
e.printStackTrace();
}
return true;
}
protected void writeAbstractTestClient() throws IOException {
JavaFileObject jFile = processingEnv.getFiler().createSourceFile("AbstractTestClient");
try (PrintWriter writer = new PrintWriter(jFile.openWriter())){
writer.append("package org.vadere.manager.client; ").println();
writer.println();
writer.append("import org.vadere.manager.TraCISocket;").println();
writer.append("import org.vadere.manager.client.ConsoleReader;").println();
writer.append("import java.io.IOException;").println();
writer.println();
writer.append("public abstract class AbstractTestClient {").println();
writer.append(apiMembers.toString()).println();
writer.append("\tpublic AbstractTestClient() { }").println();
writer.println();
writer.append("\tpublic void init(TraCISocket socket, ConsoleReader consoleReader){").println();
writer.append(apiInit.toString());
writer.println();
writer.append(apiMapping.toString());
writer.append("\t}").println();
writer.println();
writer.append(apiAbstract.toString());
writer.println();
writer.append("}").println();
}
}
protected void writeApiClass(Element apiClass) throws IOException {
TraCiApiWrapper traCIApi = new TraCiApiWrapper(apiClass);
JavaFileObject jFile = processingEnv.getFiler().createSourceFile(traCIApi.name);
apiMembers.append(String.format("\tprotected %s.%s %s;\n", traCIApi.packageName, traCIApi.name, traCIApi.name.toLowerCase()));
apiInit.append(String.format("\t\t%s = new %s.%s(socket);\n", traCIApi.name.toLowerCase(), traCIApi.packageName, traCIApi.name));
try (PrintWriter writer = new PrintWriter(jFile.openWriter())){
writer.append("package ").append(traCIApi.packageName).append(";").println();
writer.println();
for (String anImport : traCIApi.imports) {
writer.append("import ").append(anImport).append(";").println();
}
writer.append("import ").append(traCIApi.cmdEnum).append(";").println();
writer.append("import ").append(traCIApi.varEnum).append(";").println();
writer.println();
// start API class
writer.append("public class ").append(traCIApi.name).append(" extends ")
.append(traCIApi.extendedClassName).append(" {").println();
// constructor
writer.append("\tpublic ").append(traCIApi.name).append("(TraCISocket socket) {").println();
writer.append("\t\tsuper(socket, \"").append(traCIApi.name).append("\");").println();
writer.append("\t}").println();
writer.println();
for (Element element : apiClass.getEnclosedElements()) {
List<? extends AnnotationMirror> anMirrors = element.getAnnotationMirrors();
if (anMirrors != null){
for (AnnotationMirror anMirror : anMirrors) {
String anName = anMirror.getAnnotationType().asElement().getSimpleName().toString();
String singeAn = traCIApi.singleAnnotation
.substring(traCIApi.singleAnnotation.lastIndexOf(".") + 1).trim();
if (anName.equals(singeAn)){
ApiHandler apiHandler = new ApiHandler(traCIApi, element, anMirror);
apiMapping.append(String.format("\t\tconsoleReader.addCommand(\"%s.%s\", \"\", this::%s_%s);\n", traCIApi.name.toLowerCase(), apiHandler.name, traCIApi.name.toLowerCase(), apiHandler.name));
apiAbstract.append(String.format("\t\tabstract public void %s_%s (String args[]) throws IOException;\n",traCIApi.name.toLowerCase(), apiHandler.name));
switch (apiHandler.apiType){
case "GET":
writeGET(writer, apiHandler);
break;
case "SET":
writeSET(writer, apiHandler);
break;
}
}
}
}
}
writer.append("}").println(); // end API class
}
}
protected void writeGET(PrintWriter writer, ApiHandler apiHandler){
if (apiHandler.ignoreElementId){
writer.append("\tpublic TraCIGetResponse ").append(apiHandler.name).append("() throws IOException {").println();
writer.append("\t\tTraCIPacket p = TraCIGetCommand.build(").append(apiHandler.cmd).append(", ").append(apiHandler.varId).append(", \"-1\");").println();
}
else {
writer.append("\tpublic TraCIGetResponse ").append(apiHandler.name).append("(String elementID) throws IOException {").println();
writer.append("\t\tTraCIPacket p = TraCIGetCommand.build(").append(apiHandler.cmd).append(", ").append(apiHandler.varId).append(", elementID);").println();
}
writer.append("\n\t\tsocket.sendExact(p);\n").println();
writer.append("\t\treturn (TraCIGetResponse) socket.receiveResponse();").println();
writer.append("\t}").println();
writer.println();
}
protected void writeSET(PrintWriter writer, ApiHandler apiHandler){
writer.append("\tpublic TraCIResponse ").append(apiHandler.name).append("(String elementId, ").append(apiHandler.dataTypeStr).append(" data) throws IOException {").println();
writer.append("\t\tTraCIPacket p = TraCISetCommand.build(")
.append(apiHandler.cmd).append(", elementId, ").append(apiHandler.varId).append(", ").append(apiHandler.varType).append(", data);").println();
writer.append("\n\t\tsocket.sendExact(p);\n").println();
writer.append("\t\treturn socket.receiveResponse();").println();
writer.append("\t}").println();
writer.println();
}
class TraCiApiWrapper {
String name;
String singleAnnotation;
String multipleAnnotation;
String cmdEnum;
String varEnum;
String packageName;
String[] imports;
String extendedClassName;
TraCiApiWrapper(Element apiClass){
TraCIApi traCIApi = apiClass.getAnnotation(TraCIApi.class);
name = traCIApi.name();
packageName = traCIApi.packageName();
imports = traCIApi.imports();
extendedClassName = traCIApi.extendedClassName();
try {
singleAnnotation = traCIApi.singleAnnotation().getCanonicalName();
} catch (MirroredTypeException e){
singleAnnotation = e.getTypeMirror().toString();
}
try {
multipleAnnotation = traCIApi.multipleAnnotation().getCanonicalName();
} catch (MirroredTypeException e){
multipleAnnotation = e.getTypeMirror().toString();
}
try {
cmdEnum = traCIApi.cmdEnum().getCanonicalName();
} catch (MirroredTypeException e){
cmdEnum = e.getTypeMirror().toString();
}
try {
varEnum = traCIApi.varEnum().getCanonicalName();
} catch (MirroredTypeException e){
varEnum = e.getTypeMirror().toString();
}
}
}
class ApiHandler {
String cmd;
String varId;
String varType;
String name;
String dataTypeStr;
boolean ignoreElementId;
String apiType; //SET, GET, SUB
public ApiHandler(TraCiApiWrapper traCIApi, Element method, AnnotationMirror annotationMirror){
ignoreElementId = false; //default
dataTypeStr = "";
String cmdPrefix = traCIApi.cmdEnum;
cmdPrefix = cmdPrefix.substring(cmdPrefix.lastIndexOf('.') + 1).trim();
String varPrefix = traCIApi.varEnum;
varPrefix = varPrefix.substring(varPrefix.lastIndexOf('.') + 1).trim();
Map<? extends ExecutableElement, ? extends AnnotationValue> valueMap = annotationMirror.getElementValues();
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : valueMap.entrySet()) {
String key = entry.getKey().getSimpleName().toString();
Object value = entry.getValue().getValue();
switch (key){
case "cmd":
this.cmd = cmdPrefix+ "." + value.toString();
this.apiType = value.toString().substring(0, 3);
break;
case "var":
this.varId = varPrefix + "." + value.toString() + ".id";
this.varType = varPrefix + "." + value.toString() + ".type";
break;
case "name":
this.name = (String) value;
break;
case "ignoreElementId":
this.ignoreElementId = (boolean) value;
break;
case "dataTypeStr":
this.dataTypeStr = value.toString();
}
}
}
@Override
public String toString() {
return "ApiHandler{" +
"cmd='" + cmd + '\'' +
", varId='" + varId + '\'' +
", varType='" + varType + '\'' +
", name='" + name + '\'' +
", ignoreElementId=" + ignoreElementId +
", apiType='" + apiType + '\'' +
'}';
}
}
}
package org.vadere.annotation.traci.client;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface TraCIApi {
String packageName() default "org.vadere.manager.client.traci";
String[] imports() default {
"org.vadere.manager.client.traci.TraCIClientApi",
"org.vadere.manager.TraCISocket",
"org.vadere.manager.traci.commands.TraCIGetCommand",
"org.vadere.manager.traci.commands.TraCISetCommand",
"org.vadere.manager.traci.respons.TraCIGetResponse",
"org.vadere.manager.traci.writer.TraCIPacket",
"org.vadere.manager.traci.respons.TraCIResponse",
"java.io.IOException",
"java.util.ArrayList"
};
String extendedClassName() default "TraCIClientApi";
String name();
Class singleAnnotation();
Class multipleAnnotation();
Class cmdEnum();
Class varEnum();
}
......@@ -81,7 +81,7 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen
Theme syntaxTheme = Theme.load(in);
syntaxTheme.apply(textAreaLocal);
} catch (IOException e) {
logger.error("could not load theme" + e.getMessage());
logger.error("could not loadFromFilesystem theme" + e.getMessage());
}
txtrTextfiletextarea = textAreaLocal;
......
......@@ -47,7 +47,7 @@ public abstract class ActionAbstractAddScenario extends AbstractAction {
return;
addScenario(vadere);
} catch (IOException e) {
logger.error(String.format("topographyError during output load: '%s'", e.getLocalizedMessage()));
logger.error(String.format("topographyError during output loadFromFilesystem: '%s'", e.getLocalizedMessage()));
}
} else {
IOUtils.errorBox(Messages.getString("renameErrorDialog.text"),
......
......@@ -4,15 +4,19 @@ package org.vadere.gui.projectview.control;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.projectview.model.ProjectViewModel;
import org.vadere.gui.projectview.view.ProjectView;
import org.vadere.gui.projectview.view.VDialogManager;
import org.vadere.simulator.projects.VadereProject;
import org.vadere.util.logging.Logger;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import javax.swing.*;
import static org.vadere.gui.projectview.control.ActionAbstractSaveProject.saveProjectUnlessUserCancels;
public class ActionCreateProject extends AbstractAction {
private static final long serialVersionUID = 1L;
......@@ -40,10 +44,16 @@ public class ActionCreateProject extends AbstractAction {
if (newProjectName == null || newProjectName.trim().length() == 0) {
logger.info("invalid project name");
} else {
VadereProject project = new VadereProject(newProjectName, new ArrayList<>());
model.setCurrentProjectPath(null);
final String projectDirectory= VDialogManager.saveProjectDialog();
if(projectDirectory == null)
return; // do not create project without saving it first.
VadereProject project = new VadereProject(newProjectName, new ArrayList<>(), Paths.get(projectDirectory));
model.setProject(project);
model.refreshOutputTable();
saveProjectUnlessUserCancels(model);
ProjectView.getMainWindow().setProjectSpecificActionsEnabled(true);
logger.info("create project: " + newProjectName);
}
......
......@@ -70,17 +70,17 @@ public class ActionLoadProject extends AbstractAction {
else {
migrationOptions = MigrationOptions.reapplyFromVersion((Version)option);
}
// 3. load project
// 3. loadFromFilesystem project
loadProjectByPath(model, projectFilePath, migrationOptions);
} else {
// 3. load project
// 3. loadFromFilesystem project
loadProjectByPath(model, projectFilePath);
}
} else {
logger.info(String.format("user canceled load project."));
logger.info(String.format("user canceled loadFromFilesystem project."));
}
} catch (IOException e1) {
e1.printStackTrace();
......@@ -109,13 +109,12 @@ public class ActionLoadProject extends AbstractAction {
public static void loadProjectByPath(ProjectViewModel projectViewModel, String projectFilePath, MigrationOptions options) {
try {
VadereProject project = IOVadere.readProjectJson(projectFilePath, options);
projectViewModel.setCurrentProjectPath(projectFilePath);
projectViewModel.setProject(project);
projectViewModel.refreshOutputTable();
logger.info("refreshed output table - 2");
// select and load first scenario from list
// select and loadFromFilesystem first scenario from list
projectViewModel.setSelectedRowIndexInScenarioTable(0);
logger.info("selected the first scenario");
......@@ -170,7 +169,7 @@ public class ActionLoadProject extends AbstractAction {
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage(), "JoltMigrationAssistant assistant",
JOptionPane.ERROR_MESSAGE);
logger.error("could not load project: " + e.getMessage());
logger.error("could not loadFromFilesystem project: " + e.getMessage());
e.printStackTrace();
}
}
......
package org.vadere.gui.projectview.control;
import javax.swing.*;
import org.vadere.gui.projectview.model.ProjectViewModel;
import org.vadere.gui.projectview.view.VTable;
import java.awt.event.ActionEvent;
import javax.swing.*;
public class ActionRunSelectedScenarios extends AbstractAction {
private final ProjectViewModel model;
......
package org.vadere.gui.projectview.model;
import org.jetbrains.annotations.NotNull;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.projectview.control.IOutputFileRefreshListener;
import org.vadere.gui.projectview.control.IProjectChangeListener;
......@@ -16,6 +17,12 @@ import org.vadere.util.logging.Logger;
import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
......@@ -29,7 +36,7 @@ public class ProjectViewModel implements IScenarioChecker {
private final OutputFileTableModel outputTableModel;
private final VadereScenarioTableModel scenarioTableModel;
private String currentProjectPath;
// private String currentProjectPath;
private ExecutorService refreshOutputExecutor;
......@@ -190,19 +197,19 @@ public class ProjectViewModel implements IScenarioChecker {
* been saved to disk yet.
*/
public String getCurrentProjectPath() {
return currentProjectPath;
return isProjectAvailable() ? project.getProjectDirectory().toAbsolutePath().toString() : null;
}
/**
* Set path of the directory where the project is saved. It may be null if the model have not
* been saved to disk yet.
*/
public void setCurrentProjectPath(final String currentProjectPath) {
if (currentProjectPath == null) {
this.currentProjectPath = null;
} else {
this.currentProjectPath = ProjectWriter.getProjectDir(currentProjectPath);
}
public void setCurrentProjectPath(@NotNull final String currentProjectPath) {
if (isProjectAvailable())
project.setProjectDirectory(Paths.get(currentProjectPath));
else
throw new IllegalStateException();
}
public OutputBundle getSelectedOutputBundle() throws IOException {
......
{
"name" : "Neues_Szenario",
"description" : "",
"release" : "1.1",
"release" : "1.2",
"processWriters" : {
"files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile",
......@@ -169,6 +169,8 @@
"potentialFieldResolution" : 0.1,
"obstacleGridPenalty" : 0.1,
"targetAttractionStrength" : 1.0,
"cacheType" : "NO_CACHE",
"cacheDir" : "",
"timeCostAttributes" : {
"standardDeviation" : 0.7,
"type" : "UNIT",
......
package org.vadere.gui.vadere;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.LinkedList;
import java.util.stream.Collectors;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import org.junit.BeforeClass;
import org.junit.Test;
import org.vadere.simulator.models.osm.OptimalStepsModel;
......@@ -29,6 +18,18 @@ import org.vadere.state.attributes.models.AttributesPotentialOSM;
import org.vadere.state.scenario.Topography;
import org.xml.sax.SAXException;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.util.LinkedList;
import java.util.stream.Collectors;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import static org.junit.Assert.assertEquals;
public class TestProjectWriterAndReader {
private static VadereProject testProject;
......@@ -49,7 +50,7 @@ public class TestProjectWriterAndReader {
tests.add(new Scenario(new ScenarioStore(testName + "1", "", OptimalStepsModel.class.getName(), attributes, new AttributesSimulation(), new Topography())));
tests.add(new Scenario(new ScenarioStore(testName + "2", "", OptimalStepsModel.class.getName(), attributes, new AttributesSimulation(), new Topography())));