Closeables.closeQuietly(fis);
}
}
protected List<String> updateProvisioning(Map<String, File> artifacts, Provisioner provisionService) throws Exception {
ResourceInstaller resourceInstaller = provisionService.getResourceInstaller();
Map<ResourceIdentity, Resource> installedResources = getInstalledResources(provisionService);
Map<Requirement, Resource> requirements = new HashMap<Requirement, Resource>();
Set<Map.Entry<String, File>> entries = artifacts.entrySet();
List<Resource> resourcesToInstall = new ArrayList<Resource>();
List<String> resourceUrisInstalled = new ArrayList<String>();
updateStatus(Container.PROVISION_INSTALLING, null, null);
for (Map.Entry<String, File> entry : entries) {
String name = entry.getKey();
File file = entry.getValue();
String coords = name;
int idx = coords.lastIndexOf(':');
if (idx > 0) {
coords = name.substring(idx + 1);
}
// lets switch to gravia's mvn coordinates
coords = coords.replace('/', ':');
MavenCoordinates mvnCoords = parse(coords);
URL url = file.toURI().toURL();
if (url == null) {
LOGGER.warn("Could not find URL for file " + file);
continue;
}
// TODO lets just detect wars for now for servlet engines - how do we decide on WildFly?
boolean isShared = !isWar(name, file);
Resource resource = findMavenResource(mvnCoords, url, isShared);
if (resource == null) {
LOGGER.warn("Could not find resource for " + mvnCoords + " and " + url);
} else {
ResourceIdentity identity = resource.getIdentity();
Resource oldResource = installedResources.remove(identity);
if (oldResource == null && !resourcehandleMap.containsKey(identity)) {
if (isShared) {
// TODO lest not deploy shared stuff for now since bundles throw an exception when trying to stop them
// which breaks the tests ;)
LOGGER.debug("TODO not installing " + (isShared ? "shared" : "non-shared") + " resource: " + identity);
} else {
LOGGER.info("Installing " + (isShared ? "shared" : "non-shared") + " resource: " + identity);
resourcesToInstall.add(resource);
resourceUrisInstalled.add(name);
}
}
}
}
for (Resource installedResource : installedResources.values()) {
ResourceIdentity identity = installedResource.getIdentity();
ResourceHandle resourceHandle = resourcehandleMap.get(identity);
if (resourceHandle == null) {
// TODO should not really happen when we can ask about the installed Resources
LOGGER.warn("TODO: Cannot uninstall " + installedResource + " as we have no handle!");
} else {
LOGGER.info("Uninstalling " + installedResource);
resourceHandle.uninstall();
resourcehandleMap.remove(identity);
LOGGER.info("Uninstalled " + installedResource);
}
}
if (resourcesToInstall.size() > 0) {
LOGGER.info("Installing " + resourcesToInstall.size() + " resource(s)");
Set<ResourceHandle> resourceHandles = new LinkedHashSet<>();
ResourceInstaller.Context context = new DefaultInstallerContext(resourcesToInstall, requirements);
for (Resource resource : resourcesToInstall) {
resourceHandles.add(resourceInstaller.installResource(context, resource));
}
LOGGER.info("Got " + resourceHandles.size() + " resource handle(s)");
for (ResourceHandle resourceHandle : resourceHandles) {