use of org.jboss.vfs.VirtualFile 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.vfs.VirtualFile in project wildfly by wildfly.
the class JSFManagedBeanProcessor method processXmlManagedBeans.
/**
* Parse the faces config files looking for managed bean classes. The parser is quite
* simplistic as the only information we need is the managed-bean-class element
*/
private void processXmlManagedBeans(final DeploymentUnit deploymentUnit, final Set<String> managedBeanClasses) {
for (final VirtualFile facesConfig : getConfigurationFiles(deploymentUnit)) {
InputStream is = null;
try {
is = facesConfig.openStream();
final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setXMLResolver(NoopXMLResolver.create());
XMLStreamReader parser = inputFactory.createXMLStreamReader(is);
StringBuilder className = null;
int indent = 0;
boolean managedBean = false;
boolean managedBeanClass = false;
while (true) {
int event = parser.next();
if (event == XMLStreamConstants.END_DOCUMENT) {
parser.close();
break;
}
if (event == XMLStreamConstants.START_ELEMENT) {
indent++;
if (indent == 2) {
if (parser.getLocalName().equals(MANAGED_BEAN)) {
managedBean = true;
}
} else if (indent == 3 && managedBean) {
if (parser.getLocalName().equals(MANAGED_BEAN_CLASS)) {
managedBeanClass = true;
className = new StringBuilder();
}
}
} else if (event == XMLStreamConstants.END_ELEMENT) {
indent--;
managedBeanClass = false;
if (indent == 1) {
managedBean = false;
}
if (className != null) {
managedBeanClasses.add(className.toString().trim());
className = null;
}
} else if (managedBeanClass && event == XMLStreamConstants.CHARACTERS) {
className.append(parser.getText());
}
}
} catch (Exception e) {
JSFLogger.ROOT_LOGGER.managedBeansConfigParseFailed(facesConfig);
} finally {
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
// Ignore
}
}
}
}
use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.
the class ServiceDeploymentParsingProcessor method deploy.
/**
* Process a deployment for jboss-service.xml files. Will parse the xml file and attach a configuration discovered
* during processing.
*
* @param phaseContext the deployment unit context
* @throws DeploymentUnitProcessingException
*/
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final VirtualFile deploymentRoot = phaseContext.getDeploymentUnit().getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
if (deploymentRoot == null || !deploymentRoot.exists())
return;
VirtualFile serviceXmlFile = null;
if (deploymentRoot.isDirectory()) {
serviceXmlFile = deploymentRoot.getChild(SERVICE_DESCRIPTOR_PATH);
} else if (deploymentRoot.getName().toLowerCase(Locale.ENGLISH).endsWith(SERVICE_DESCRIPTOR_SUFFIX)) {
serviceXmlFile = deploymentRoot;
}
if (serviceXmlFile == null || !serviceXmlFile.exists())
return;
final XMLMapper xmlMapper = XMLMapper.Factory.create();
final JBossServiceXmlDescriptorParser jBossServiceXmlDescriptorParser = new JBossServiceXmlDescriptorParser(JBossDescriptorPropertyReplacement.propertyReplacer(phaseContext.getDeploymentUnit()));
xmlMapper.registerRootElement(new QName("urn:jboss:service:7.0", "server"), jBossServiceXmlDescriptorParser);
xmlMapper.registerRootElement(new QName(null, "server"), jBossServiceXmlDescriptorParser);
InputStream xmlStream = null;
try {
xmlStream = serviceXmlFile.openStream();
final XMLStreamReader reader = inputFactory.createXMLStreamReader(xmlStream);
final ParseResult<JBossServiceXmlDescriptor> result = new ParseResult<JBossServiceXmlDescriptor>();
xmlMapper.parseDocument(result, reader);
final JBossServiceXmlDescriptor xmlDescriptor = result.getResult();
if (xmlDescriptor != null)
phaseContext.getDeploymentUnit().putAttachment(JBossServiceXmlDescriptor.ATTACHMENT_KEY, xmlDescriptor);
else
throw SarLogger.ROOT_LOGGER.failedXmlParsing(serviceXmlFile);
} catch (Exception e) {
throw SarLogger.ROOT_LOGGER.failedXmlParsing(e, serviceXmlFile);
} finally {
VFSUtils.safeClose(xmlStream);
}
}
use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.
the class BeanDeploymentTestCase method initializeDeployment.
private VirtualFile initializeDeployment(final String path) throws Exception {
final VirtualFile virtualFile = VFS.getChild(getResource(BeanDeploymentTestCase.class, path));
copyResource(BeanDeploymentTestCase.class, "/org/jboss/as/mc/LegacyBean.class", path, "org/jboss/as/mc");
return virtualFile;
}
use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.
the class ServletContainerInitializerDeploymentProcessor method deploy.
/**
* Process SCIs.
*/
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
final ServiceModuleLoader loader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER);
if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
// Skip non web deployments
return;
}
WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
assert warMetaData != null;
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
if (module == null) {
throw UndertowLogger.ROOT_LOGGER.failedToResolveModule(deploymentUnit);
}
final ClassLoader classLoader = module.getClassLoader();
ScisMetaData scisMetaData = deploymentUnit.getAttachment(ScisMetaData.ATTACHMENT_KEY);
if (scisMetaData == null) {
scisMetaData = new ScisMetaData();
deploymentUnit.putAttachment(ScisMetaData.ATTACHMENT_KEY, scisMetaData);
}
Set<ServletContainerInitializer> scis = scisMetaData.getScis();
Set<Class<? extends ServletContainerInitializer>> sciClasses = new HashSet<>();
if (scis == null) {
scis = new HashSet<ServletContainerInitializer>();
scisMetaData.setScis(scis);
}
Map<ServletContainerInitializer, Set<Class<?>>> handlesTypes = scisMetaData.getHandlesTypes();
if (handlesTypes == null) {
handlesTypes = new HashMap<ServletContainerInitializer, Set<Class<?>>>();
scisMetaData.setHandlesTypes(handlesTypes);
}
// Find the SCIs from shared modules
for (ModuleDependency dependency : moduleSpecification.getAllDependencies()) {
try {
Module depModule = loader.loadModule(dependency.getIdentifier());
ServiceLoader<ServletContainerInitializer> serviceLoader = depModule.loadService(ServletContainerInitializer.class);
for (ServletContainerInitializer service : serviceLoader) {
if (sciClasses.add(service.getClass())) {
scis.add(service);
}
}
} catch (ModuleLoadException e) {
if (dependency.isOptional() == false) {
throw UndertowLogger.ROOT_LOGGER.errorLoadingSCIFromModule(dependency.getIdentifier(), e);
}
}
}
// Find local ServletContainerInitializer services
List<String> order = warMetaData.getOrder();
Map<String, VirtualFile> localScis = warMetaData.getScis();
if (order != null && localScis != null) {
for (String jar : order) {
VirtualFile sci = localScis.get(jar);
if (sci != null) {
scis.addAll(loadSci(classLoader, sci, jar, true, sciClasses));
}
}
}
// Process HandlesTypes for ServletContainerInitializer
Map<Class<?>, Set<ServletContainerInitializer>> typesMap = new HashMap<Class<?>, Set<ServletContainerInitializer>>();
for (ServletContainerInitializer service : scis) {
if (service.getClass().isAnnotationPresent(HandlesTypes.class)) {
HandlesTypes handlesTypesAnnotation = service.getClass().getAnnotation(HandlesTypes.class);
Class<?>[] typesArray = handlesTypesAnnotation.value();
if (typesArray != null) {
for (Class<?> type : typesArray) {
Set<ServletContainerInitializer> servicesSet = typesMap.get(type);
if (servicesSet == null) {
servicesSet = new HashSet<ServletContainerInitializer>();
typesMap.put(type, servicesSet);
}
servicesSet.add(service);
handlesTypes.put(service, new HashSet<Class<?>>());
}
}
}
}
Class<?>[] typesArray = typesMap.keySet().toArray(new Class<?>[0]);
final CompositeIndex index = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
if (index == null) {
throw UndertowLogger.ROOT_LOGGER.unableToResolveAnnotationIndex(deploymentUnit);
}
//WFLY-4205, look in the parent as well as the war
CompositeIndex parentIndex = deploymentUnit.getParent() == null ? null : deploymentUnit.getParent().getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
// Find classes which extend, implement, or are annotated by HandlesTypes
for (Class<?> type : typesArray) {
DotName className = DotName.createSimple(type.getName());
Set<ClassInfo> classInfos = new HashSet<>();
classInfos.addAll(processHandlesType(className, type, index));
if (parentIndex != null) {
classInfos.addAll(processHandlesType(className, type, parentIndex));
}
Set<Class<?>> classes = loadClassInfoSet(classInfos, classLoader);
Set<ServletContainerInitializer> sciSet = typesMap.get(type);
for (ServletContainerInitializer sci : sciSet) {
handlesTypes.get(sci).addAll(classes);
}
}
}
Aggregations