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);
}
}
}
}
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);
}
}
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;
}
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);
}
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;
}
Aggregations