Skip to content

Commit

Permalink
whitespace fixes to graphhopper.sh and avoid reading old properties f…
Browse files Browse the repository at this point in the history
…ile, fixes #1371
  • Loading branch information
karussell committed May 16, 2018
1 parent e5d56cf commit 59c00d8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 86 deletions.
4 changes: 4 additions & 0 deletions core/files/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.11
web resources for dropwizard web framework (no servlets anymore)
prefix -Dgraphhopper. for command line arguments necessary, see docs/web/quickstart.md or docs/core/quickstart-from-source.md#running--debbuging-with-intellij for details
delegated reading properties to dropwizard, i.e. the new format yml is not read again in GraphHopper.init
0.9
remove war bundling support #297
rename of DefaultModule to GraphHopperModule and GHServletModule to GraphHopperServletModule
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/graphhopper/GraphHopper.java
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ public FlagEncoderFactory getFlagEncoderFactory() {
* CmdArgs.readFromConfig("config.properties", "graphhopper.config")
*/
public GraphHopper init(CmdArgs args) {
args = CmdArgs.readFromConfigAndMerge(args, "config", "graphhopper.config");
args.merge(CmdArgs.readFromSystemProperties());
if (args.has("osmreader.osm"))
throw new IllegalArgumentException("Instead osmreader.osm use datareader.file, for other changes see core/files/changelog.txt");

Expand Down
78 changes: 1 addition & 77 deletions core/src/main/java/com/graphhopper/util/CmdArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,37 +46,6 @@ public CmdArgs(Map<String, String> map) {
super(map);
}

/**
* @param fileStr the file name of config.properties
* @param systemProperty the property name of the configuration. E.g. -Dgraphhopper.config
*/
public static CmdArgs readFromConfig(String fileStr, String systemProperty) throws IOException {
if (systemProperty.startsWith("-D"))
systemProperty = systemProperty.substring(2);

String configLocation = System.getProperty(systemProperty);
if (Helper.isEmpty(configLocation))
configLocation = fileStr;

Map<String, String> map = new LinkedHashMap<>();
loadProperties(map, new InputStreamReader(new FileInputStream(
new File(configLocation).getAbsoluteFile()), UTF_CS));
CmdArgs args = new CmdArgs();
args.merge(map);

// overwrite with system settings
Properties props = System.getProperties();
for (Entry<Object, Object> e : props.entrySet()) {
String k = ((String) e.getKey());
String v = ((String) e.getValue());
if (k.startsWith("graphhopper.")) {
k = k.substring("graphhopper.".length());
args.put(k, v);
}
}
return args;
}

/**
* This method creates a CmdArgs object from the specified string array (a list of key=value pairs).
*/
Expand Down Expand Up @@ -107,52 +76,7 @@ public static CmdArgs read(String[] args) {
return new CmdArgs(map);
}

/**
* Command line configuration overwrites the ones in the config file.
*
* @return a new CmdArgs object if necessary.
*/
public static CmdArgs readFromConfigAndMerge(CmdArgs args, String configKey, String configSysAttr) {
String configVal = args.get(configKey, "");
if (!Helper.isEmpty(configVal)) {
try {
CmdArgs tmp = CmdArgs.readFromConfig(configVal, configSysAttr);
tmp.merge(args);
return tmp;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
return args;
}

public static CmdArgs readFromConfigAndMerge(CmdArgs args) {
final CmdArgs argsFromSystemProperties = argsFromSystemProperties();
args.merge(argsFromSystemProperties);

String propertiesFile = args.get("config", "");
if (!Helper.isEmpty(propertiesFile)) {
final CmdArgs argsFromPropertiesFile = argsFromPropertiesFile(propertiesFile);
argsFromPropertiesFile.merge(args);
return argsFromPropertiesFile;
}
return args;
}

private static CmdArgs argsFromPropertiesFile(String configLocation) {
CmdArgs cmdArgs = new CmdArgs();
Map<String, String> map = new LinkedHashMap<>();
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(
new File(configLocation).getAbsoluteFile()), Helper.UTF_CS)) {
Helper.loadProperties(map, reader);
} catch (IOException e) {
throw new RuntimeException(e);
}
cmdArgs.merge(map);
return cmdArgs;
}

private static CmdArgs argsFromSystemProperties() {
public static CmdArgs readFromSystemProperties() {
CmdArgs cmdArgs = new CmdArgs();
for (Entry<Object, Object> e : System.getProperties().entrySet()) {
String k = ((String) e.getKey());
Expand Down
18 changes: 12 additions & 6 deletions graphhopper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ while [ ! -z $1 ]; do
-D*)
GH_WEB_OPTS="$GH_WEB_OPTS $1"; shift 1;;
# forward parameter via replacing first two characters of the key with -Dgraphhopper.
*=*)
echo "Old parameter assignment not allowed $1"; exit 2;;
--*)
GH_WEB_OPTS="$GH_WEB_OPTS -Dgraphhopper.${1:2}=$2"; shift 2;;
-*) echo "Option unknown: $1"
Expand All @@ -84,6 +86,11 @@ if [ "$ACTION" = "" ]; then
printBashUsage
fi

if [[ "$CONFIG" == *properties ]]; then
echo "$CONFIG not allowed as configuration. Use yml"
exit
fi

# default init, https://stackoverflow.com/a/28085062/194609
: "${CONFIG:=config.yml}"
if [ ! -f "config.yml" ]; then
Expand Down Expand Up @@ -238,7 +245,6 @@ echo "## now $ACTION. JAVA_OPTS=$JAVA_OPTS"

if [[ "$ACTION" = "web" ]]; then
export MAVEN_OPTS="$MAVEN_OPTS $JAVA_OPTS"

if [[ "$RUN_BACKGROUND" == "true" ]]; then
exec "$JAVA" $JAVA_OPTS -Dgraphhopper.datareader.file="$OSM_FILE" -Dgraphhopper.graph.location="$GRAPH" \
$GH_WEB_OPTS -jar "$JAR" server $CONFIG <&- &
Expand All @@ -255,16 +261,16 @@ if [[ "$ACTION" = "web" ]]; then
fi

elif [ "$ACTION" = "import" ]; then
"$JAVA" $JAVA_OPTS -Dgraphhopper.datareader.file="$OSM_FILE" -Dgraphhopper.graph.location="$GRAPH" \
"$JAVA" $JAVA_OPTS -Dgraphhopper.datareader.file="$OSM_FILE" -Dgraphhopper.graph.location="$GRAPH" \
$GH_IMPORT_OPTS -jar "$JAR" import $CONFIG

elif [ "$ACTION" = "torture" ]; then
execMvn --projects tools -am -DskipTests clean package
JAR=tools/target/graphhopper-tools-$VERSION-jar-with-dependencies.jar
"$JAVA" $JAVA_OPTS -cp "$JAR" com.graphhopper.tools.QueryTorture $@
execMvn --projects tools -am -DskipTests clean package
JAR=tools/target/graphhopper-tools-$VERSION-jar-with-dependencies.jar
"$JAVA" $JAVA_OPTS -cp "$JAR" com.graphhopper.tools.QueryTorture $@

elif [ "$ACTION" = "measurement" ]; then
ARGS="$GH_WEB_OPTS graph.location=$GRAPH datareader.file=$OSM_FILE prepare.ch.weightings=fastest prepare.lm.weightings=fastest graph.flag_encoders=car \
ARGS="$GH_WEB_OPTS graph.location=$GRAPH datareader.file=$OSM_FILE prepare.ch.weightings=fastest prepare.lm.weightings=fastest graph.flag_encoders=car \
prepare.min_network_size=10000 prepare.min_oneway_network_size=10000"

function startMeasurement {
Expand Down
4 changes: 2 additions & 2 deletions web/src/main/java/com/graphhopper/http/GraphHopperBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ public void initialize(Bootstrap<?> bootstrap) {
}

@Override
public void run(GraphHopperBundleConfiguration configuration, Environment environment) throws Exception {
configuration.getGraphHopperConfiguration().merge(CmdArgs.readFromConfigAndMerge(configuration.getGraphHopperConfiguration()));
public void run(GraphHopperBundleConfiguration configuration, Environment environment) {
configuration.getGraphHopperConfiguration().merge(CmdArgs.readFromSystemProperties());

if (configuration.getGraphHopperConfiguration().has("gtfs.file")) {
// switch to different API implementation when using Pt
Expand Down

0 comments on commit 59c00d8

Please sign in to comment.