}
File executablePath = getExecutableAbsolutePath(process);
log.debug("Apache executable path: " + executablePath);
ApacheBinaryInfo binaryInfo;
try {
binaryInfo = ApacheBinaryInfo.getInfo(executablePath.getPath(), discoveryContext.getSystemInformation());
} catch (Exception e) {
throw new DiscoveryFailureException("'" + executablePath + "' is not a valid Apache executable (" + e
+ ").");
}
if (!isSupportedVersion(binaryInfo.getVersion())) {
throw new DiscoveryFailureException("Apache " + binaryInfo.getVersion() + " is not supported.");
}
String serverRoot = getServerRoot(binaryInfo, process.getProcessInfo());
if (serverRoot == null) {
throw new DiscoveryFailureException("Unable to determine server root.");
}
File serverConfigFile = getServerConfigFile(binaryInfo, process.getProcessInfo(), serverRoot);
if (serverConfigFile == null) {
throw new DiscoveryFailureException("Unable to determine server config file.");
}
Configuration pluginConfig = discoveryContext.getDefaultPluginConfiguration();
PropertySimple executablePathProp =
new PropertySimple(ApacheServerComponent.PLUGIN_CONFIG_PROP_EXECUTABLE_PATH, executablePath);
pluginConfig.put(executablePathProp);
PropertySimple serverRootProp =
new PropertySimple(ApacheServerComponent.PLUGIN_CONFIG_PROP_SERVER_ROOT, serverRoot);
pluginConfig.put(serverRootProp);
PropertySimple configFile =
new PropertySimple(ApacheServerComponent.PLUGIN_CONFIG_PROP_HTTPD_CONF, serverConfigFile);
pluginConfig.put(configFile);
PropertySimple inclusionGlobs =
new PropertySimple(PluginDescriptorBasedAugeasConfiguration.INCLUDE_GLOBS_PROP, serverConfigFile);
pluginConfig.put(inclusionGlobs);
pluginConfig.put(new PropertyList(ApacheServerComponent.PLUGIN_CONFIG_CUSTOM_MODULE_NAMES));
ApacheDirectiveTree serverConfig =
parseRuntimeConfiguration(serverConfigFile.getAbsolutePath(), process.getProcessInfo(), binaryInfo);
String serverUrl = null;
String vhostsGlobInclude = null;
//now check if the httpd.conf doesn't redefine the ServerRoot
List<ApacheDirective> serverRoots = serverConfig.search("/ServerRoot");
if (!serverRoots.isEmpty()) {
serverRoot = AugeasNodeValueUtil.unescape(serverRoots.get(0).getValuesAsString());
serverRootProp.setValue(serverRoot);
}
serverUrl = getUrl(serverConfig, binaryInfo.getVersion());
vhostsGlobInclude = scanForGlobInclude(serverConfig);
if (serverUrl != null) {
Property urlProp = new PropertySimple(ApacheServerComponent.PLUGIN_CONFIG_PROP_URL, serverUrl);
pluginConfig.put(urlProp);