use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.
the class UrlScanner method handleBeansXml.
public boolean handleBeansXml(final URL url, final List<String> discoveredClasses) {
String urlPath = url.toExternalForm();
// determin resource type (eg: jar, file, bundle)
String urlType = "file";
int colonIndex = urlPath.indexOf(":");
if (colonIndex != -1) {
urlType = urlPath.substring(0, colonIndex);
}
// Extra built-in support for simple file-based resources
if ("file".equals(urlType) || "jar".equals(urlType)) {
// switch to using getPath() instead of toExternalForm()
urlPath = url.getPath();
if (urlPath.indexOf('!') > 0) {
urlPath = urlPath.substring(0, urlPath.indexOf('!'));
} else {
// hack for /META-INF/beans.xml
File dirOrArchive = new File(urlPath);
dirOrArchive = dirOrArchive.getParentFile();
urlPath = dirOrArchive.getParent();
}
try {
urlPath = URLDecoder.decode(urlPath, "UTF-8");
} catch (UnsupportedEncodingException ex) {
throw new RuntimeException(ex);
}
handle(urlPath, discoveredClasses);
return true;
} else if ("vfs".equals(urlType)) {
try {
VirtualFile vfsRoot = VFS.getChild(url).getParent().getParent();
handle(vfsRoot, discoveredClasses);
return true;
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
} else {
WeldLogger.DEPLOYMENT_LOGGER.doNotUnderstandProtocol(url);
return false;
}
}
use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.
the class BeansXmlProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
Map<ResourceRoot, ExplicitBeanArchiveMetadata> beanArchiveMetadata = new HashMap<ResourceRoot, ExplicitBeanArchiveMetadata>();
ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
if (deploymentRoot == null) {
return;
}
PropertyReplacingBeansXmlParser parser = new PropertyReplacingBeansXmlParser(deploymentUnit);
ResourceRoot classesRoot = null;
List<ResourceRoot> structure = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
for (ResourceRoot resourceRoot : structure) {
if (ModuleRootMarker.isModuleRoot(resourceRoot) && !SubDeploymentMarker.isSubDeployment(resourceRoot)) {
if (resourceRoot.getRootName().equals("classes")) {
// hack for dealing with war modules
classesRoot = resourceRoot;
deploymentUnit.putAttachment(WeldAttachments.CLASSES_RESOURCE_ROOT, resourceRoot);
} else {
VirtualFile beansXml = resourceRoot.getRoot().getChild(META_INF_BEANS_XML);
if (beansXml.exists() && beansXml.isFile()) {
WeldLogger.DEPLOYMENT_LOGGER.debugf("Found beans.xml: %s", beansXml.toString());
beanArchiveMetadata.put(resourceRoot, new ExplicitBeanArchiveMetadata(beansXml, resourceRoot, parseBeansXml(beansXml, parser, deploymentUnit), false));
}
}
}
}
if (DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
final VirtualFile rootBeansXml = deploymentRoot.getRoot().getChild(WEB_INF_BEANS_XML);
final boolean rootBeansXmlPresent = rootBeansXml.exists() && rootBeansXml.isFile();
VirtualFile beansXml = null;
if (classesRoot != null) {
beansXml = classesRoot.getRoot().getChild(META_INF_BEANS_XML);
}
final boolean beansXmlPresent = beansXml != null && beansXml.exists() && beansXml.isFile();
if (rootBeansXmlPresent) {
if (beansXmlPresent) {
// warn that it is not portable to use both locations at the same time
WeldLogger.DEPLOYMENT_LOGGER.duplicateBeansXml();
beanArchiveMetadata.put(deploymentRoot, new ExplicitBeanArchiveMetadata(rootBeansXml, beansXml, classesRoot, parseBeansXml(rootBeansXml, parser, deploymentUnit), true));
} else {
WeldLogger.DEPLOYMENT_LOGGER.debugf("Found beans.xml: %s", rootBeansXml);
beanArchiveMetadata.put(deploymentRoot, new ExplicitBeanArchiveMetadata(rootBeansXml, classesRoot, parseBeansXml(rootBeansXml, parser, deploymentUnit), true));
}
} else if (beansXmlPresent) {
WeldLogger.DEPLOYMENT_LOGGER.debugf("Found beans.xml: %s", beansXml);
beanArchiveMetadata.put(deploymentRoot, new ExplicitBeanArchiveMetadata(beansXml, classesRoot, parseBeansXml(beansXml, parser, deploymentUnit), true));
}
} else if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
final VirtualFile rootBeansXml = deploymentRoot.getRoot().getChild(META_INF_BEANS_XML);
if (rootBeansXml.exists() && rootBeansXml.isFile()) {
WeldLogger.DEPLOYMENT_LOGGER.debugf("Found beans.xml: %s", rootBeansXml.toString());
beanArchiveMetadata.put(deploymentRoot, new ExplicitBeanArchiveMetadata(rootBeansXml, deploymentRoot, parseBeansXml(rootBeansXml, parser, deploymentUnit), true));
}
}
if (!beanArchiveMetadata.isEmpty()) {
ExplicitBeanArchiveMetadataContainer deploymentMetadata = new ExplicitBeanArchiveMetadataContainer(beanArchiveMetadata);
deploymentUnit.putAttachment(ExplicitBeanArchiveMetadataContainer.ATTACHMENT_KEY, deploymentMetadata);
for (Iterator<Entry<ResourceRoot, ExplicitBeanArchiveMetadata>> iterator = beanArchiveMetadata.entrySet().iterator(); iterator.hasNext(); ) {
if (BeanDiscoveryMode.NONE != iterator.next().getValue().getBeansXml().getBeanDiscoveryMode()) {
// mark the deployment as requiring CDI integration as long as it contains at least one bean archive with bean-discovery-mode other than "none"
WeldDeploymentMarker.mark(deploymentUnit);
break;
}
}
}
}
use of org.jboss.vfs.VirtualFile 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);
}
}
}
use of org.jboss.vfs.VirtualFile 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;
}
}
use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.
the class RaNativeProcessor method deploy.
/**
* Process a deployment for standard ra deployment files. Will parse the xml
* file and attach a configuration discovered during processing.
* @param phaseContext the deployment unit context
* @throws DeploymentUnitProcessingException
*/
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final VirtualFile deploymentRoot = phaseContext.getDeploymentUnit().getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
process(deploymentRoot);
}
Aggregations