use of java.io.Closeable in project wildfly by wildfly.
the class EarStructureProcessor method createResourceRoot.
/**
* Creates a {@link ResourceRoot} for the passed {@link VirtualFile file} and adds it to the list of {@link ResourceRoot}s
* in the {@link DeploymentUnit deploymentUnit}
*
* @param deploymentUnit The deployment unit
* @param file The file for which the resource root will be created
* @param markAsSubDeployment If this is true, then the {@link ResourceRoot} that is created will be marked as a subdeployment
* through a call to {@link SubDeploymentMarker#mark(org.jboss.as.server.deployment.module.ResourceRoot)}
* @param explodeDuringMount If this is true then the {@link VirtualFile file} will be exploded during mount,
* while creating the {@link ResourceRoot}
* @return Returns the created {@link ResourceRoot}
* @throws IOException
*/
private ResourceRoot createResourceRoot(final DeploymentUnit deploymentUnit, final VirtualFile file, final boolean markAsSubDeployment, final boolean explodeDuringMount) throws IOException {
final boolean war = file.getName().toLowerCase(Locale.ENGLISH).endsWith(WAR_EXTENSION);
final Closeable closable = file.isFile() ? mount(file, explodeDuringMount) : exportExplodedWar(war, file, deploymentUnit);
final MountHandle mountHandle = new MountHandle(closable);
final ResourceRoot resourceRoot = new ResourceRoot(file, mountHandle);
deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, resourceRoot);
if (markAsSubDeployment) {
SubDeploymentMarker.mark(resourceRoot);
}
if (war) {
resourceRoot.putAttachment(Attachments.INDEX_RESOURCE_ROOT, false);
SubExplodedDeploymentMarker.mark(resourceRoot);
}
return resourceRoot;
}
use of java.io.Closeable in project wildfly by wildfly.
the class RaOperationUtil method installRaServicesAndDeployFromModule.
public static void installRaServicesAndDeployFromModule(OperationContext context, String name, ModifiableResourceAdapter resourceAdapter, String fullModuleName, final List<ServiceController<?>> newControllers) throws OperationFailedException {
ServiceName raServiceName = installRaServices(context, name, resourceAdapter, newControllers);
final boolean resolveProperties = true;
final ServiceTarget serviceTarget = context.getServiceTarget();
final String moduleName;
//load module
String slot = "main";
if (fullModuleName.contains(":")) {
slot = fullModuleName.substring(fullModuleName.indexOf(":") + 1);
moduleName = fullModuleName.substring(0, fullModuleName.indexOf(":"));
} else {
moduleName = fullModuleName;
}
Module module;
try {
ModuleIdentifier moduleId = ModuleIdentifier.create(moduleName, slot);
module = Module.getCallerModuleLoader().loadModule(moduleId);
} catch (ModuleLoadException e) {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleRA(moduleName), e);
}
URL path = module.getExportedResource("META-INF/ra.xml");
Closeable closable = null;
try {
VirtualFile child;
if (path.getPath().contains("!")) {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.compressedRarNotSupportedInModuleRA(moduleName));
} else {
child = VFS.getChild(path.getPath().split("META-INF")[0]);
closable = VFS.mountReal(new File(path.getPath().split("META-INF")[0]), child);
}
//final Closeable closable = VFS.mountZip((InputStream) new JarInputStream(new FileInputStream(path.getPath().split("!")[0].split(":")[1])), path.getPath().split("!")[0].split(":")[1], child, TempFileProviderService.provider());
final MountHandle mountHandle = new MountHandle(closable);
final ResourceRoot resourceRoot = new ResourceRoot(child, mountHandle);
final VirtualFile deploymentRoot = resourceRoot.getRoot();
if (deploymentRoot == null || !deploymentRoot.exists())
return;
ConnectorXmlDescriptor connectorXmlDescriptor = RaDeploymentParsingProcessor.process(resolveProperties, deploymentRoot, null, name);
IronJacamarXmlDescriptor ironJacamarXmlDescriptor = IronJacamarDeploymentParsingProcessor.process(deploymentRoot, resolveProperties);
RaNativeProcessor.process(deploymentRoot);
Map<ResourceRoot, Index> annotationIndexes = new HashMap<ResourceRoot, Index>();
ResourceRootIndexer.indexResourceRoot(resourceRoot);
Index index = resourceRoot.getAttachment(Attachments.ANNOTATION_INDEX);
if (index != null) {
annotationIndexes.put(resourceRoot, index);
}
if (ironJacamarXmlDescriptor != null) {
ConnectorLogger.SUBSYSTEM_RA_LOGGER.forceIJToNull();
ironJacamarXmlDescriptor = null;
}
final ServiceName deployerServiceName = ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(connectorXmlDescriptor.getDeploymentName());
final ServiceController<?> deployerService = context.getServiceRegistry(true).getService(deployerServiceName);
if (deployerService == null) {
ServiceBuilder builder = ParsedRaDeploymentProcessor.process(connectorXmlDescriptor, ironJacamarXmlDescriptor, module.getClassLoader(), serviceTarget, annotationIndexes, RAR_MODULE.append(name), null, null);
newControllers.add(builder.addDependency(raServiceName).setInitialMode(ServiceController.Mode.ACTIVE).install());
}
String rarName = resourceAdapter.getArchive();
if (fullModuleName.equals(rarName)) {
ServiceName serviceName = ConnectorServices.INACTIVE_RESOURCE_ADAPTER_SERVICE.append(name);
InactiveResourceAdapterDeploymentService service = new InactiveResourceAdapterDeploymentService(connectorXmlDescriptor, module, name, name, RAR_MODULE.append(name), null, serviceTarget, null);
newControllers.add(serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE).install());
}
} catch (Exception e) {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleRA(moduleName), e);
} finally {
if (closable != null) {
try {
closable.close();
} catch (IOException e) {
}
}
}
}
use of java.io.Closeable in project wildfly by wildfly.
the class JaxrsSpringProcessor method getResteasySpringVirtualFile.
/**
* Lookup Seam integration resource loader.
*
* @return the Seam integration resource loader
* @throws DeploymentUnitProcessingException
* for any error
*/
protected synchronized VirtualFile getResteasySpringVirtualFile() throws DeploymentUnitProcessingException {
if (resourceRoot != null) {
return resourceRoot;
}
try {
Module module = Module.getBootModuleLoader().loadModule(MODULE);
URL fileUrl = module.getClassLoader().getResource(JAR_LOCATION);
if (fileUrl == null) {
throw JaxrsLogger.JAXRS_LOGGER.noSpringIntegrationJar();
}
File dir = new File(fileUrl.toURI());
File file = null;
for (String jar : dir.list()) {
if (jar.endsWith(".jar")) {
file = new File(dir, jar);
break;
}
}
if (file == null) {
throw JaxrsLogger.JAXRS_LOGGER.noSpringIntegrationJar();
}
VirtualFile vf = VFS.getChild(file.toURI());
final Closeable mountHandle = VFS.mountZip(file, vf, TempFileProviderService.provider());
Service<Closeable> mountHandleService = new Service<Closeable>() {
public void start(StartContext startContext) throws StartException {
}
public void stop(StopContext stopContext) {
VFSUtils.safeClose(mountHandle);
}
public Closeable getValue() throws IllegalStateException, IllegalArgumentException {
return mountHandle;
}
};
ServiceBuilder<Closeable> builder = serviceTarget.addService(ServiceName.JBOSS.append(SERVICE_NAME), mountHandleService);
builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
resourceRoot = vf;
return resourceRoot;
} catch (Exception e) {
throw new DeploymentUnitProcessingException(e);
}
}
use of java.io.Closeable in project wildfly by wildfly.
the class WarStructureDeploymentProcessor method createResourceRoots.
/**
* Create the resource roots for a .war deployment
*
*
* @param deploymentRoot the deployment root
* @return the resource roots
* @throws java.io.IOException for any error
*/
private List<ResourceRoot> createResourceRoots(final VirtualFile deploymentRoot, final DeploymentUnit deploymentUnit) throws IOException, DeploymentUnitProcessingException {
final List<ResourceRoot> entries = new ArrayList<ResourceRoot>();
// WEB-INF classes
final VirtualFile webinfClasses = deploymentRoot.getChild(WEB_INF_CLASSES);
if (webinfClasses.exists()) {
final ResourceRoot webInfClassesRoot = new ResourceRoot(webinfClasses.getName(), webinfClasses, null);
ModuleRootMarker.mark(webInfClassesRoot);
entries.add(webInfClassesRoot);
}
// WEB-INF lib
Map<String, MountedDeploymentOverlay> overlays = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_OVERLAY_LOCATIONS);
final VirtualFile webinfLib = deploymentRoot.getChild(WEB_INF_LIB);
if (webinfLib.exists()) {
final List<VirtualFile> archives = webinfLib.getChildren(DEFAULT_WEB_INF_LIB_FILTER);
for (final VirtualFile archive : archives) {
try {
String relativeName = archive.getPathNameRelativeTo(deploymentRoot);
MountedDeploymentOverlay overlay = overlays.get(relativeName);
Closeable closable = null;
if (overlay != null) {
overlay.remountAsZip(false);
} else if (archive.isFile()) {
closable = VFS.mountZip(archive, archive, TempFileProviderService.provider());
} else {
closable = null;
}
final ResourceRoot webInfArchiveRoot = new ResourceRoot(archive.getName(), archive, new MountHandle(closable));
ModuleRootMarker.mark(webInfArchiveRoot);
entries.add(webInfArchiveRoot);
} catch (IOException e) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToProcessWebInfLib(archive), e);
}
}
}
return entries;
}
use of java.io.Closeable in project wildfly by wildfly.
the class ApplicationClientStructureProcessor method deploy.
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
String deploymentUnitName = deploymentUnit.getName().toLowerCase(Locale.ENGLISH);
if (deploymentUnitName.endsWith(".ear")) {
final Map<VirtualFile, ResourceRoot> existing = new HashMap<VirtualFile, ResourceRoot>();
for (final ResourceRoot additional : deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS)) {
existing.put(additional.getRoot(), additional);
}
final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
final VirtualFile appClientRoot = root.getRoot().getChild(deployment);
if (appClientRoot.exists()) {
if (existing.containsKey(appClientRoot)) {
final ResourceRoot existingRoot = existing.get(appClientRoot);
SubDeploymentMarker.mark(existingRoot);
ModuleRootMarker.mark(existingRoot);
} else {
final Closeable closable = appClientRoot.isFile() ? mount(appClientRoot, false) : null;
final MountHandle mountHandle = new MountHandle(closable);
final ResourceRoot childResource = new ResourceRoot(appClientRoot, mountHandle);
ModuleRootMarker.mark(childResource);
SubDeploymentMarker.mark(childResource);
deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, childResource);
}
} else {
throw AppClientLogger.ROOT_LOGGER.cannotFindAppClient(deployment);
}
} else if (deploymentUnit.getParent() != null && deploymentUnitName.endsWith(".jar")) {
final ResourceRoot parentRoot = deploymentUnit.getParent().getAttachment(Attachments.DEPLOYMENT_ROOT);
final VirtualFile appClientRoot = parentRoot.getRoot().getChild(deployment);
final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
if (appClientRoot.equals(root.getRoot())) {
DeploymentTypeMarker.setType(DeploymentType.APPLICATION_CLIENT, deploymentUnit);
}
}
}
Aggregations