Search in sources :

Example 1 with ResourceRoot

use of org.jboss.as.server.deployment.module.ResourceRoot in project wildfly by wildfly.

the class JSFManagedBeanProcessor method getConfigurationFiles.

public Set<VirtualFile> getConfigurationFiles(DeploymentUnit deploymentUnit) {
    final Set<VirtualFile> ret = new HashSet<VirtualFile>();
    final List<ResourceRoot> resourceRoots = DeploymentUtils.allResourceRoots(deploymentUnit);
    for (final ResourceRoot resourceRoot : resourceRoots) {
        final VirtualFile webInfFacesConfig = resourceRoot.getRoot().getChild(WEB_INF_FACES_CONFIG);
        if (webInfFacesConfig.exists()) {
            ret.add(webInfFacesConfig);
        }
        //look for files that end in .faces-config.xml
        final VirtualFile metaInf = resourceRoot.getRoot().getChild("META-INF");
        if (metaInf.exists() && metaInf.isDirectory()) {
            for (final VirtualFile file : metaInf.getChildren()) {
                if (file.getName().equals("faces-config.xml") || file.getName().endsWith(".faces-config.xml")) {
                    ret.add(file);
                }
            }
        }
    }
    String configFiles = null;
    //now look for files in the javax.faces.CONFIG_FILES context param
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData != null) {
        final WebMetaData webMetaData = warMetaData.getWebMetaData();
        if (webMetaData != null) {
            final List<ParamValueMetaData> contextParams = webMetaData.getContextParams();
            if (contextParams != null) {
                for (final ParamValueMetaData param : contextParams) {
                    if (param.getParamName().equals(CONFIG_FILES)) {
                        configFiles = param.getParamValue();
                        break;
                    }
                }
            }
        }
    }
    if (configFiles != null) {
        final String[] files = configFiles.split(",");
        final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
        if (deploymentRoot != null) {
            for (final String file : files) {
                final VirtualFile configFile = deploymentRoot.getRoot().getChild(file);
                if (configFile.exists()) {
                    ret.add(configFile);
                }
            }
        }
    }
    return ret;
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ParamValueMetaData(org.jboss.metadata.javaee.spec.ParamValueMetaData) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) WarMetaData(org.jboss.as.web.common.WarMetaData) WebMetaData(org.jboss.metadata.web.spec.WebMetaData) HashSet(java.util.HashSet)

Example 2 with ResourceRoot

use of org.jboss.as.server.deployment.module.ResourceRoot in project keycloak by keycloak.

the class ScriptProviderDeploymentProcessor method deploy.

static void deploy(DeploymentUnit deploymentUnit, KeycloakDeploymentInfo info) {
    ResourceRoot resourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    if (resourceRoot == null) {
        return;
    }
    VirtualFile jarFile = resourceRoot.getRoot();
    if (jarFile == null || !jarFile.exists() || !jarFile.getName().endsWith(".jar")) {
        return;
    }
    ScriptProviderDescriptor descriptor = readScriptProviderDescriptor(jarFile);
    if (descriptor == null) {
        return;
    }
    for (Map.Entry<String, List<ScriptProviderMetadata>> entry : descriptor.getProviders().entrySet()) {
        for (ScriptProviderMetadata metadata : entry.getValue()) {
            String fileName = metadata.getFileName();
            if (fileName == null) {
                throw new RuntimeException("You must provide the script file name");
            }
            try (InputStream in = jarFile.getChild(fileName).openStream()) {
                metadata.setCode(StreamUtil.readString(in, StandardCharsets.UTF_8));
            } catch (IOException cause) {
                throw new RuntimeException("Failed to read script file [" + fileName + "]", cause);
            }
            metadata.setId(new StringBuilder("script").append("-").append(fileName).toString());
            String name = metadata.getName();
            if (name == null) {
                name = fileName;
            }
            metadata.setName(name);
            PROVIDERS.get(entry.getKey()).accept(info, metadata);
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) ScriptProviderMetadata(org.keycloak.representations.provider.ScriptProviderMetadata) InputStream(java.io.InputStream) ScriptProviderDescriptor(org.keycloak.representations.provider.ScriptProviderDescriptor) List(java.util.List) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with ResourceRoot

use of org.jboss.as.server.deployment.module.ResourceRoot in project teiid by teiid.

the class VDBDependencyDeployer method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!TeiidAttachments.isVDBDeployment(deploymentUnit)) {
        return;
    }
    final VDBMetaData deployment = deploymentUnit.getAttachment(TeiidAttachments.VDB_METADATA);
    ArrayList<ModuleDependency> localDependencies = new ArrayList<ModuleDependency>();
    ArrayList<ModuleDependency> userDependencies = new ArrayList<ModuleDependency>();
    // $NON-NLS-1$
    String moduleNames = deployment.getPropertyValue("lib");
    if (moduleNames != null) {
        StringTokenizer modules = new StringTokenizer(moduleNames);
        while (modules.hasMoreTokens()) {
            String moduleName = modules.nextToken().trim();
            ModuleIdentifier lib = ModuleIdentifier.create(moduleName);
            ModuleLoader moduleLoader = Module.getCallerModuleLoader();
            try {
                moduleLoader.loadModule(lib);
                localDependencies.add(new ModuleDependency(moduleLoader, ModuleIdentifier.create(moduleName), false, false, false, false));
            } catch (ModuleLoadException e) {
                // this is to handle JAR based deployments which take on name like "deployment.<jar-name>"
                moduleLoader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER);
                try {
                    moduleLoader.loadModule(lib);
                    userDependencies.add(new ModuleDependency(moduleLoader, ModuleIdentifier.create(moduleName), false, false, false, true));
                } catch (ModuleLoadException e1) {
                    throw new DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50088, moduleName, deployment.getName(), deployment.getVersion(), e1));
                }
            }
        }
    }
    if (!TeiidAttachments.isVDBXMLDeployment(deploymentUnit)) {
        try {
            final ResourceRoot deploymentResourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
            final VirtualFile deploymentRoot = deploymentResourceRoot.getRoot();
            if (deploymentRoot == null) {
                return;
            }
            final VirtualFile libDir = deploymentRoot.getChild(LIB);
            if (libDir.exists()) {
                final List<VirtualFile> archives = libDir.getChildren(DEFAULT_JAR_LIB_FILTER);
                for (final VirtualFile archive : archives) {
                    try {
                        final Closeable closable = VFS.mountZip(archive, archive, TempFileProviderService.provider());
                        final ResourceRoot jarArchiveRoot = new ResourceRoot(archive.getName(), archive, new MountHandle(closable));
                        ModuleRootMarker.mark(jarArchiveRoot);
                        deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, jarArchiveRoot);
                    } catch (IOException e) {
                        throw new DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50018, archive), e);
                    }
                }
            }
        } catch (IOException e) {
            throw new DeploymentUnitProcessingException(e);
        }
    }
    // add translators as dependent modules to this VDB.
    try {
        final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
        // $NON-NLS-1$
        final ModuleLoader moduleLoader = Module.getCallerModule().getModule(ModuleIdentifier.create("org.jboss.teiid")).getModuleLoader();
        // $NON-NLS-1$
        moduleSpecification.addLocalDependency(new ModuleDependency(moduleLoader, ModuleIdentifier.create("org.jboss.teiid.api"), false, false, false, false));
        // $NON-NLS-1$
        moduleSpecification.addLocalDependency(new ModuleDependency(moduleLoader, ModuleIdentifier.create("org.jboss.teiid.common-core"), false, false, false, false));
        // $NON-NLS-1$
        moduleSpecification.addLocalDependency(new ModuleDependency(moduleLoader, ModuleIdentifier.create("javax.api"), false, false, false, false));
        if (!localDependencies.isEmpty()) {
            moduleSpecification.addLocalDependencies(localDependencies);
        }
        if (!userDependencies.isEmpty()) {
            moduleSpecification.addUserDependencies(userDependencies);
        }
    } catch (ModuleLoadException e) {
        throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50018.name(), e);
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) VirtualFile(org.jboss.vfs.VirtualFile) ModuleLoader(org.jboss.modules.ModuleLoader) ModuleDependency(org.jboss.as.server.deployment.module.ModuleDependency) MountHandle(org.jboss.as.server.deployment.module.MountHandle) Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) StringTokenizer(java.util.StringTokenizer) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ModuleSpecification(org.jboss.as.server.deployment.module.ModuleSpecification) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 4 with ResourceRoot

use of org.jboss.as.server.deployment.module.ResourceRoot in project teiid by teiid.

the class DynamicVDBRootMountDeployer method undeploy.

public void undeploy(DeploymentUnit context) {
    final ResourceRoot resourceRoot = context.removeAttachment(Attachments.DEPLOYMENT_ROOT);
    if (resourceRoot != null) {
        final Closeable mountHandle = resourceRoot.getMountHandle();
        VFSUtils.safeClose(mountHandle);
    }
}
Also used : ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) Closeable(java.io.Closeable)

Example 5 with ResourceRoot

use of org.jboss.as.server.deployment.module.ResourceRoot in project wildfly by wildfly.

the class ApplicationClientParsingDeploymentProcessor method parseAppClient.

private ApplicationClientMetaData parseAppClient(DeploymentUnit deploymentUnit, final PropertyReplacer propertyReplacer) throws DeploymentUnitProcessingException {
    final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    final VirtualFile alternateDescriptor = deploymentRoot.getAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_CLIENT_DEPLOYMENT_DESCRIPTOR);
    // Locate the descriptor
    final VirtualFile descriptor;
    if (alternateDescriptor != null) {
        descriptor = alternateDescriptor;
    } else {
        descriptor = deploymentRoot.getRoot().getChild(APP_XML);
    }
    if (descriptor.exists()) {
        InputStream is = null;
        try {
            is = descriptor.openStream();
            ApplicationClientMetaData data = new ApplicationClientMetaDataParser().parse(getXMLStreamReader(is), propertyReplacer);
            return data;
        } catch (XMLStreamException e) {
            throw AppClientLogger.ROOT_LOGGER.failedToParseXml(e, descriptor, e.getLocation().getLineNumber(), e.getLocation().getColumnNumber());
        } catch (IOException e) {
            throw new DeploymentUnitProcessingException("Failed to parse " + descriptor, e);
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
            } catch (IOException e) {
            // Ignore
            }
        }
    } else {
        return null;
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) ApplicationClientMetaData(org.jboss.metadata.appclient.spec.ApplicationClientMetaData) IOException(java.io.IOException) ApplicationClientMetaDataParser(org.jboss.metadata.appclient.parser.spec.ApplicationClientMetaDataParser)

Aggregations

ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)86 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)56 VirtualFile (org.jboss.vfs.VirtualFile)47 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)19 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)13 HashMap (java.util.HashMap)12 MountHandle (org.jboss.as.server.deployment.module.MountHandle)12 WarMetaData (org.jboss.as.web.common.WarMetaData)12 HashSet (java.util.HashSet)11 Closeable (java.io.Closeable)10 PersistenceUnitMetadataHolder (org.jboss.as.jpa.config.PersistenceUnitMetadataHolder)10 Index (org.jboss.jandex.Index)8 EarMetaData (org.jboss.metadata.ear.spec.EarMetaData)8 Module (org.jboss.modules.Module)8 URL (java.net.URL)7 ModuleSpecification (org.jboss.as.server.deployment.module.ModuleSpecification)7 ServiceName (org.jboss.msc.service.ServiceName)7 InputStream (java.io.InputStream)6 JBossWebMetaData (org.jboss.metadata.web.jboss.JBossWebMetaData)6