Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
vadere
vadere
Commits
39a5d8e3
Commit
39a5d8e3
authored
Jul 29, 2019
by
Daniel Lehmberg
Browse files
code improvements (comments, better logging)
parent
02d6bd83
Pipeline
#139561
passed with stages
in 120 minutes and 2 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
VadereSimulator/src/org/vadere/simulator/projects/io/IOVadere.java
View file @
39a5d8e3
...
...
@@ -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
(
"
a
nalysed .scenario files"
);
logger
.
info
(
"
A
nalysed .scenario files
.
"
);
for
(
File
file
:
IOUtils
.
getFilesInScenarioDirectory
(
p
))
{
try
{
Scenario
scenario
=
JsonConverter
.
deserializeScenarioRunManager
(
IOUtils
.
readTextFile
(
file
.
getAbsolutePath
()));
if
(!
scenarioNames
.
add
(
scenario
.
getName
()))
{
logger
.
error
(
"
t
here are two scenarios with the same name!"
);
logger
.
error
(
"
T
here are two scenarios with the same name!"
);
throw
new
IOException
(
"Found two scenarios with the same name."
);
}
scenarios
.
add
(
scenario
);
...
...
VadereUtils/src/org/vadere/util/config/VadereConfig.java
View file @
39a5d8e3
...
...
@@ -59,7 +59,7 @@ public class VadereConfig {
private
VadereConfig
()
{
createDefaultConfigIfNonExisting
();
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
();
//
f
irst 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
//
F
irst 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
)){
vadereConfig
.
clearProperty
(
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
));
iter
.
remove
(
);
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.
vadereConfig
.
getKeys
();
//TODO [improvement]: sort the entries in the configuration file alphabetically.
}
// Static setters
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment