Search in sources :

Example 36 with ResourceRoot

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

the class PersistenceUnitServiceHandler method handleEarDeployment.

private static void handleEarDeployment(DeploymentPhaseContext phaseContext, boolean startEarly, Platform platform) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (isEarDeployment(deploymentUnit) && JPADeploymentMarker.isJPADeployment(deploymentUnit)) {
        // handle META-INF/persistence.xml
        final List<ResourceRoot> deploymentRoots = DeploymentUtils.allResourceRoots(deploymentUnit);
        for (final ResourceRoot root : deploymentRoots) {
            if (!SubDeploymentMarker.isSubDeployment(root)) {
                PersistenceUnitMetadataHolder holder;
                ArrayList<PersistenceUnitMetadataHolder> puList = new ArrayList<PersistenceUnitMetadataHolder>(1);
                if (root != null && (holder = root.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS)) != null && holder.getPersistenceUnits().size() > 0) {
                    // assemble and install the PU service
                    puList.add(holder);
                }
                ROOT_LOGGER.tracef("install persistence unit definitions for ear %s", root.getRootName());
                addPuService(phaseContext, puList, startEarly, platform);
            }
        }
    }
}
Also used : ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) ArrayList(java.util.ArrayList) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 37 with ResourceRoot

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

the class PersistenceUnitServiceHandler method setAnnotationIndexes.

/**
     * Setup the annotation index map
     *
     * @param puHolder
     * @param deploymentUnit
     */
private static void setAnnotationIndexes(final PersistenceUnitMetadataHolder puHolder, DeploymentUnit deploymentUnit) {
    final Map<URL, Index> annotationIndexes = new HashMap<>();
    do {
        for (ResourceRoot root : DeploymentUtils.allResourceRoots(deploymentUnit)) {
            final Index index = root.getAttachment(Attachments.ANNOTATION_INDEX);
            if (index != null) {
                try {
                    ROOT_LOGGER.tracef("adding '%s' to annotation index map", root.getRoot().toURL());
                    annotationIndexes.put(root.getRoot().toURL(), index);
                } catch (MalformedURLException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        // get annotation indexes for top level also
        deploymentUnit = deploymentUnit.getParent();
    } while (deploymentUnit != null);
    for (PersistenceUnitMetadata pu : puHolder.getPersistenceUnits()) {
        // hold onto the annotation index for Persistence Provider use during deployment
        pu.setAnnotationIndex(annotationIndexes);
    }
}
Also used : ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) MalformedURLException(java.net.MalformedURLException) HashMap(java.util.HashMap) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata) Index(org.jboss.jandex.Index) URL(java.net.URL)

Example 38 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 39 with ResourceRoot

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

the class PersistenceUnitSearch method getPersistenceUnit.

private static PersistenceUnitMetadata getPersistenceUnit(DeploymentUnit current, final String absolutePath, String puName) {
    final String path;
    if (absolutePath.startsWith("../")) {
        path = absolutePath.substring(3);
    } else {
        path = absolutePath;
    }
    final VirtualFile parent = current.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot().getParent();
    final VirtualFile resolvedPath = parent.getChild(path);
    List<ResourceRoot> resourceRoots = DeploymentUtils.allResourceRoots(DeploymentUtils.getTopDeploymentUnit(current));
    for (ResourceRoot resourceRoot : resourceRoots) {
        if (resourceRoot.getRoot().equals(resolvedPath)) {
            PersistenceUnitMetadataHolder holder = resourceRoot.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS);
            if (holder != null) {
                for (PersistenceUnitMetadata pu : holder.getPersistenceUnits()) {
                    if (traceEnabled) {
                        ROOT_LOGGER.tracef("getPersistenceUnit check '%s' against pu '%s'", puName, pu.getPersistenceUnitName());
                    }
                    if (pu.getPersistenceUnitName().equals(puName)) {
                        if (traceEnabled) {
                            ROOT_LOGGER.tracef("getPersistenceUnit matched '%s' against pu '%s'", puName, pu.getPersistenceUnitName());
                        }
                        return pu;
                    }
                }
            }
        }
    }
    throw JpaLogger.ROOT_LOGGER.persistenceUnitNotFound(absolutePath, puName, current);
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata)

Example 40 with ResourceRoot

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

the class PersistenceUnitSearch method findWithinLibraryJar.

private static PersistenceUnitMetadata findWithinLibraryJar(DeploymentUnit unit, ResourceRoot moduleResourceRoot, String persistenceUnitName) {
    final ResourceRoot deploymentRoot = moduleResourceRoot;
    PersistenceUnitMetadataHolder holder = deploymentRoot.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS);
    if (holder == null || holder.getPersistenceUnits() == null) {
        if (traceEnabled) {
            ROOT_LOGGER.tracef("findWithinLibraryJar checking for '%s' found no persistence units", persistenceUnitName);
        }
        return null;
    }
    ambiguousPUError(unit, persistenceUnitName, holder);
    persistenceUnitName = defaultPersistenceUnitName(persistenceUnitName, holder);
    for (PersistenceUnitMetadata persistenceUnit : holder.getPersistenceUnits()) {
        if (traceEnabled) {
            ROOT_LOGGER.tracef("findWithinLibraryJar check '%s' against pu '%s'", persistenceUnitName, persistenceUnit.getPersistenceUnitName());
        }
        if (persistenceUnitName == null || persistenceUnitName.length() == 0 || persistenceUnit.getPersistenceUnitName().equals(persistenceUnitName)) {
            if (traceEnabled) {
                ROOT_LOGGER.tracef("findWithinLibraryJar matched '%s' against pu '%s'", persistenceUnitName, persistenceUnit.getPersistenceUnitName());
            }
            return persistenceUnit;
        }
    }
    return null;
}
Also used : ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata)

Aggregations

ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)71 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)49 VirtualFile (org.jboss.vfs.VirtualFile)37 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)16 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)12 HashMap (java.util.HashMap)10 PersistenceUnitMetadataHolder (org.jboss.as.jpa.config.PersistenceUnitMetadataHolder)10 WarMetaData (org.jboss.as.web.common.WarMetaData)10 MountHandle (org.jboss.as.server.deployment.module.MountHandle)9 Index (org.jboss.jandex.Index)8 Closeable (java.io.Closeable)7 URL (java.net.URL)7 HashSet (java.util.HashSet)7 Module (org.jboss.modules.Module)7 InputStream (java.io.InputStream)6 EarMetaData (org.jboss.metadata.ear.spec.EarMetaData)6 ServiceName (org.jboss.msc.service.ServiceName)6 XMLStreamException (javax.xml.stream.XMLStreamException)5 EEApplicationDescription (org.jboss.as.ee.component.EEApplicationDescription)5