* @see ContentFacet#deployPackages(Set, ContentServices)
*/
public DeployPackagesResponse deployPackages(Set<ResourcePackageDetails> packages, ContentServices contentServices) {
Submit client = getBytemanClient();
DeployPackagesResponse response = new DeployPackagesResponse();
DeployIndividualPackageResponse individualResponse;
for (ResourcePackageDetails detail : packages) {
PackageDetailsKey packageKey = detail.getKey();
String packageType = detail.getPackageTypeName();
individualResponse = new DeployIndividualPackageResponse(packageKey);
response.addPackageResponse(individualResponse);
try {
Boolean isBootJar = null; // null if not a classpath jar (this is for the future; today, it will always get set)
// if necessary, create the data directory where the file should be deployed
if (PKG_TYPE_NAME_BOOT_JAR.equals(packageType)) {
this.bootJarsDataDir.mkdirs();
isBootJar = Boolean.TRUE;
} else if (PKG_TYPE_NAME_SYSTEM_JAR.equals(packageType)) {
this.systemJarsDataDir.mkdirs();
isBootJar = Boolean.FALSE;
} else {
throw new UnsupportedOperationException("Cannot deploy package of type [" + packageType + "]");
}
// download the package to our data directory
File newFile = getPackageFile(detail);
FileOutputStream fos = new FileOutputStream(newFile);
try {
ContentContext contentContext = this.resourceContext.getContentContext();
contentServices.downloadPackageBits(contentContext, packageKey, fos, true);
} finally {
fos.close();
}
// tell the byteman agent to add it to the proper classloader
if (isBootJar != null) {
if (isBootJar.booleanValue()) {
client.addJarsToBootClassloader(Arrays.asList(newFile.getAbsolutePath()));
} else {
client.addJarsToSystemClassloader(Arrays.asList(newFile.getAbsolutePath()));
}
}
// everything is OK
individualResponse.setResult(ContentResponseResult.SUCCESS);
} catch (Exception e) {
individualResponse.setErrorMessage(ThrowableUtil.getStackAsString(e));
individualResponse.setResult(ContentResponseResult.FAILURE);
}
}
return response;
}