Configuration pluginConfig = resourceContext.getPluginConfiguration();
String creationType = pluginConfig.getSimpleValue(PLUGIN_CONFIG_PROP_VHOST_CREATION_POLICY,
PLUGIN_CONFIG_VHOST_PER_FILE_PROP_VALUE);
AugeasNode vhost = null;
String vhostFile = comp.getConfiguration().getModules().get(0).getConfigFiles().get(0);
if (PLUGIN_CONFIG_VHOST_IN_SINGLE_FILE_PROP_VALUE.equals(creationType)) {
vhost = tree.createNode(tree.getRootNode(), "<VirtualHost", null, seq);
} else if (PLUGIN_CONFIG_VHOST_PER_FILE_PROP_VALUE.equals(creationType)) {
String mask = pluginConfig.getSimpleValue(PLUGIN_CONFIG_PROP_VHOST_FILES_MASK, null);
if (mask == null) {
report.setErrorMessage("No virtual host file mask configured.");
} else {
vhostFile = getNewVhostFileName(addr, mask);
File vhostFileFile = new File(vhostFile);
//we're creating a new file here, so we must ensure that Augeas does have this file
//on its load path, otherwise it will refuse to create it.
AugeasConfigurationApache config = (AugeasConfigurationApache) comp.getConfiguration();
AugeasModuleConfig moduleConfig = config.getModuleByName(config.getAugeasModuleName());
boolean willPersist = false;
for (String glob : moduleConfig.getIncludedGlobs()) {
if (Glob.matches(getServerRoot(), glob, vhostFileFile)) {
willPersist = true;
break;
}
}
if (!willPersist) {
//the file wouldn't be loaded by augeas
moduleConfig.addIncludedGlob(vhostFile);
//this also means that there was no include
//that would load the file, so we have to
//add the include directive to the main conf.
List<AugeasNode> includes = tree.matchRelative(tree.getRootNode(), "Include");
AugeasNode include = tree.createNode(tree.getRootNode(), "Include", null,
includes.size() + 1);
tree.createNode(include, "param", vhostFile, 0);
tree.save();
}