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());"read .project file");
String path = Paths.get(projectPath, IOUtils.VADERE_PROJECT_FILENAME).toString();
String name = IOUtils.readTextFile(path);"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);"analysed .scenario files");"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() {
createDefaultConfigIfNonExisting();"Use config file %s", CONFIG_PATH));"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));"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);"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 =;
if(! defaultConfig.containsKey(key)){
vadereConfig.clearProperty(key);"Removed key %s in file %s because there is no entry in the " +
"\"defaultConfig\" in class", key, CONFIG_PATH));
iter.remove();"Removed key \"%s\" in file %s because there is no corresponding key entry " +
"in the \"defaultConfig\" in source file", 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
Supports Markdown
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