}
}
public static void addDefaultVariables(Map<String, String> variables, String prefix) {
InetAddress localhost = determineLocalhost();
PortScout portScout = new PortScout();
try {
checkOrAddDefault(variables, "localhost", localhost.getHostName());
checkOrAddDefault(variables, "localhost.ip", localhost.getHostAddress());
checkOrAddDefault(variables, "unresolvable.host", "unreachable.host.com");
checkOrAddDefault(variables, "port1", getRandomFreePort(portScout));
checkOrAddDefault(variables, "port2", getRandomFreePort(portScout));
checkOrAddDefault(variables, "port3", getRandomFreePort(portScout));
checkOrAddDefault(variables, "port4", getRandomFreePort(portScout));
if (prefix != null && !prefix.trim().isEmpty()) {
prefix += ".";
} else {
prefix = "";
}
checkOrAddDefault(variables, prefix + "snmp.port", getRandomFreePort(portScout));
checkOrAddDefault(variables, prefix + "listen1", "${port1}");
checkOrAddDefault(variables, prefix + "listen2", "${port2}");
checkOrAddDefault(variables, prefix + "listen3", "${port3}");
checkOrAddDefault(variables, prefix + "listen4", "${port4}");
checkOrAddDefault(variables, prefix + "vhost1.servername", "${localhost}:${port1}");
checkOrAddDefault(variables, prefix + "vhost1.urls", "${" + prefix + "vhost1.servername}");
checkOrAddDefault(variables, prefix + "vhost1.servername.directive", "ServerName ${" + prefix
+ "vhost1.servername}");
checkOrAddDefault(variables, prefix + "vhost2.servername", "${localhost}:${port2}");
checkOrAddDefault(variables, prefix + "vhost2.urls", "${" + prefix + "vhost2.servername}");
checkOrAddDefault(variables, prefix + "vhost2.servername.directive", "ServerName ${" + prefix
+ "vhost2.servername}");
checkOrAddDefault(variables, prefix + "vhost3.servername", "${localhost}:${port3}");
checkOrAddDefault(variables, prefix + "vhost3.urls", "${" + prefix + "vhost3.servername}");
checkOrAddDefault(variables, prefix + "vhost3.servername.directive", "ServerName ${" + prefix
+ "vhost3.servername}");
checkOrAddDefault(variables, prefix + "vhost4.servername", "${localhost}:${port4}");
checkOrAddDefault(variables, prefix + "vhost4.urls", "${" + prefix + "vhost4.servername}");
checkOrAddDefault(variables, prefix + "vhost4.servername.directive", "ServerName ${" + prefix
+ "vhost4.servername}");
} finally {
try {
portScout.close();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}