2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 39a5d8e3 authored by Daniel Lehmberg's avatar Daniel Lehmberg
Browse files

code improvements (comments, better logging)

parent 02d6bd83
Pipeline #139561 passed with stages
in 120 minutes and 2 seconds
......@@ -52,8 +52,9 @@ public class IOVadere {
public static VadereProject readProject(final String projectPath, final MigrationOptions options) throws IOException {
String name = IOUtils.readTextFile(Paths.get(projectPath, IOUtils.VADERE_PROJECT_FILENAME).toString());
logger.info("read .project file");
String path = Paths.get(projectPath, IOUtils.VADERE_PROJECT_FILENAME).toString();
String name = IOUtils.readTextFile(path);
logger.info(String.format("Read .project file from path %s", path));
List<Scenario> scenarios = new ArrayList<>();
Set<String> scenarioNames = new HashSet<>();
......@@ -63,13 +64,13 @@ public class IOVadere {
MigrationAssistant migrationAssistant = MigrationAssistant.getNewInstance(options);
migrationStats = migrationAssistant.analyzeProject(projectPath);
logger.info("analysed .scenario files");
logger.info("Analysed .scenario files.");
for (File file : IOUtils.getFilesInScenarioDirectory(p)) {
try {
Scenario scenario =
if (!scenarioNames.add(scenario.getName())) {
logger.error("there are two scenarios with the same name!");
logger.error("There are two scenarios with the same name!");
throw new IOException("Found two scenarios with the same name.");
......@@ -59,7 +59,7 @@ public class VadereConfig {
private VadereConfig() {
LOGGER.info(String.format("Use config file %s", CONFIG_PATH));
LOGGER.info(String.format("Use config file from path %s", CONFIG_PATH));
// If Vadere was started like "vadere-console.jar --config-file here.txt", search in current working directory.
String basePath = (CONFIG_PATH.getParent() == null) ? System.getProperty("user.dir") : CONFIG_PATH.getParent().toString() ;
......@@ -113,30 +113,42 @@ public class VadereConfig {
private void compareAndChangeDefaultKeysInExistingFile(){
// Function that removes and adds Key-Value pairs locally when keys are inserted or removed in Vadere.conf.
// For both actions a info is written on the console.
// The keys of the default config have to match the keys from the existing file!
Map<String, String> defaultConfig = getDefaultConfig();
// first case: if key is missing in existing file then add it but added in to the defaultConfig
// -- usually happens when a new key was introduced
// First case: if key is missing in existing file then add it but added in to the defaultConfig
// -- usually happens when a new configuration key was introduced
for(String key : defaultConfig.keySet()){
if(! vadereConfig.containsKey(key)){
vadereConfig.setProperty(key, defaultConfig.get(key));
LOGGER.info(String.format("Added key %s to file %s with default value because the key was not present "
+ "in the file before.", key, CONFIG_PATH));
String defaultValue = defaultConfig.get(key);
vadereConfig.addProperty(key, defaultValue);
LOGGER.info(String.format("Added key \"%s = %s\" to file %s because the configuration key-value pair " +
"was not present in the file.", key, defaultValue, CONFIG_PATH));
// Second case: if key was removed from defaultConfig, then it is also removed from the current file
// -- usually happens when a key was removed
// -- usually happens when a configuration key was removed
for(Iterator<String> iter = vadereConfig.getKeys(); iter.hasNext();){
String key = iter.next();
if(! defaultConfig.containsKey(key)){
LOGGER.info(String.format("Removed key %s in file %s because there is no entry in the " +
"\"defaultConfig\" in class VadereConfig.java", key, CONFIG_PATH));
LOGGER.info(String.format("Removed key \"%s\" in file %s because there is no corresponding key entry " +
"in the \"defaultConfig\" in source file VadereConfig.java", key, CONFIG_PATH));
//The following "getKeys" call is only here to enforce the autosaving of the configuration file (otherwise
// removed / inserted keys may not immediately appear in the config file after this function call.
//TODO [improvement]: sort the entries in the configuration file alphabetically.
// Static setters
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment