private ResourceHandle installSharedResourceInternal(Context context, Resource resource) throws Exception {
LOGGER.info("Installing shared resource: {}", resource);
ResourceIdentity identity = resource.getIdentity();
String symbolicName = identity.getSymbolicName();
Version version = identity.getVersion();
File modulesDir = injectedServerEnvironment.getValue().getModulesDir();
File moduleDir = new File(modulesDir, symbolicName.replace(".", File.separator) + File.separator + version);
if (moduleDir.exists())
throw new IllegalStateException("Module dir already exists: " + moduleDir);
ResourceContent content = resource.adapt(ResourceContent.class);
IllegalStateAssertion.assertNotNull(content, "Cannot obtain content from: " + resource);
// copy resource content
moduleDir.mkdirs();
File resFile = new File(moduleDir, symbolicName + "-" + version + ".jar");
IOUtils.copyStream(content.getContent(), new FileOutputStream(resFile));
ModuleIdentifier modid = ModuleIdentifier.create(symbolicName, version.toString());
// generate module.xml
File xmlFile = new File(moduleDir, "module.xml");
Map<Requirement, Resource> mapping = context.getResourceMapping();
String moduleXML = generateModuleXML(resFile, resource, modid, mapping);