Resource resource = bundleResourceDeployment.getResource();
ResourceContainer container = inventoryManager.getResourceContainer(resource);
resource = container.getResource();
// find out the type of base location that is specified by the bundle destination
BundleDestinationBaseDirectory bundleDestBaseDir = null;
ResourceTypeBundleConfiguration rtbc = resource.getResourceType().getResourceTypeBundleConfiguration();
if (rtbc == null) {
throw new IllegalArgumentException("The resource type doesn't support bundle deployments: " + resource);
}
for (BundleDestinationBaseDirectory bdbd : rtbc.getBundleDestinationBaseDirectories()) {
if (bdbd.getName().equals(destBaseDirName)) {
bundleDestBaseDir = bdbd;
break;
}
}
if (bundleDestBaseDir == null) {
return null;
}
// based on the type of destination base location, determine the root base directory
String destBaseDirValueName = bundleDestBaseDir.getValueName(); // the name we look up in the given context
String baseLocation;
switch (bundleDestBaseDir.getValueContext()) {
case fileSystem: {
if (!new File(relativeDeployDir).isAbsolute()) {
// the deploy dir is not absolute; since we need to pin it to something, we assume the top root directory
// unless the descriptor told us to go somewhere else differently
baseLocation = destBaseDirValueName; // ultimately this came from the plugin descriptor
if (baseLocation == null || baseLocation.trim().length() == 0) {
baseLocation = File.separator; // paranoia, if the plugin descriptor didn't specify, assume the top root directory
}
} else {
baseLocation = null; // so the relativeDeployDir is processed as an absolute dir
}
break;
}
case pluginConfiguration: {
baseLocation = resource.getPluginConfiguration().getSimpleValue(destBaseDirValueName, null);
if (baseLocation == null) {
throw new IllegalArgumentException("Cannot determine the bundle base deployment location - "
+ "there is no plugin configuration setting for [" + destBaseDirValueName + "]");
}
break;
}
case resourceConfiguration: {
baseLocation = InventoryManager.getResourceConfiguration(resource).getSimpleValue(destBaseDirValueName,
null);
if (baseLocation == null) {
throw new IllegalArgumentException("Cannot determine the bundle base deployment location - "
+ "there is no resource configuration setting for [" + destBaseDirValueName + "]");
}
break;
}
case measurementTrait: {
baseLocation = measurementManager.getTraitValue(container, destBaseDirValueName);
if (baseLocation == null) {
throw new IllegalArgumentException("Cannot obtain trait [" + destBaseDirName + "] for resource ["
+ resource.getName() + "]");
}
break;
}
default: {
throw new IllegalArgumentException("Unknown bundle destination location context: " + bundleDestBaseDir);
}
}
File destDir = new File(baseLocation, relativeDeployDir);
if (!destDir.isAbsolute()) {
throw new IllegalArgumentException("The base location path specified by [" + destBaseDirValueName
+ "] in the context [" + bundleDestBaseDir.getValueContext()
+ "] along with the destination directory of [" + relativeDeployDir
+ "] did not resolve to an absolute path [" + destDir.getPath()
+ "] so there is no way to know where to put the bundle.");
}