return detail;
}
@Override
public ResourceUpgradeReport upgrade(ResourceUpgradeContext inventoriedResource) {
ResourceUpgradeReport report = new ResourceUpgradeReport();
boolean upgraded = false;
String currentResourceKey = inventoriedResource.getResourceKey();
Configuration pluginConfiguration = inventoriedResource.getPluginConfiguration();
ServerPluginConfiguration serverPluginConfiguration = new ServerPluginConfiguration(pluginConfiguration);
boolean hasLocalResourcePrefix = currentResourceKey.startsWith(LOCAL_RESOURCE_KEY_PREFIX);
boolean hasRemoteResourcePrefix = currentResourceKey.startsWith(REMOTE_RESOURCE_KEY_PREFIX);
if (!hasLocalResourcePrefix && !hasRemoteResourcePrefix) {
// Resource key in wrong format
upgraded = true;
if (new File(currentResourceKey).isDirectory()) {
// Old key format for a local resource (key is base dir)
report.setNewResourceKey(createKeyForLocalResource(serverPluginConfiguration));
} else if (currentResourceKey.contains(":")) {
// Old key format for a remote (manually added) resource (key is base dir)
report.setNewResourceKey(createKeyForRemoteResource(currentResourceKey));
} else {
upgraded = false;
LOG.warn("Unknown format, cannot upgrade resource key [" + currentResourceKey + "]");
}
} else if (hasLocalResourcePrefix) {
String configFilePath = currentResourceKey.substring(LOCAL_RESOURCE_KEY_PREFIX.length());
File configFile = new File(configFilePath);
try {
String configFileCanonicalPath = configFile.getCanonicalPath();
if (!configFileCanonicalPath.equals(configFilePath)) {
upgraded = true;
report.setNewResourceKey(LOCAL_RESOURCE_KEY_PREFIX + configFileCanonicalPath);
}
} catch (IOException e) {
LOG.warn("Unexpected IOException while converting host config file path to its canonical form", e);
}
}
if (pluginConfiguration.getSimpleValue("expectedRuntimeProductName") == null) {
upgraded = true;
pluginConfiguration.setSimpleValue("expectedRuntimeProductName",
serverPluginConfiguration.getProductType().PRODUCT_NAME);
report.setNewPluginConfiguration(pluginConfiguration);
}
String supportsPatching = pluginConfiguration.getSimpleValue("supportsPatching");
if (supportsPatching == null || supportsPatching.startsWith("__UNINITIALIZED_")) {
upgraded = true;
JBossProductType productType = JBossProductType.valueOf(pluginConfiguration.getSimpleValue("productType"));
pluginConfiguration
.setSimpleValue("supportsPatching", Boolean.toString(supportsPatching(productType, inventoriedResource.getVersion())));
report.setNewPluginConfiguration(pluginConfiguration);
}
if (upgraded) {
return report;
}