use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.
the class ServletResourceManager method getResource.
@Override
public Resource getResource(final String path) throws IOException {
Resource res = deploymentResourceManager.getResource(path);
if (res != null) {
return new ServletResource(this, res);
}
String p = path;
if (p.startsWith("/")) {
p = p.substring(1);
}
if (overlays != null) {
for (VirtualFile overlay : overlays) {
VirtualFile child = overlay.getChild(p);
if (child.exists()) {
return new ServletResource(this, new VirtualFileResource(overlay.getPhysicalFile(), child, path));
}
}
}
for (int i = 0; i < externalOverlays.length; ++i) {
ResourceManager manager = externalOverlays[i];
res = manager.getResource(path);
if (res != null) {
return res;
}
}
return null;
}
use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.
the class ServletResourceManager method list.
/**
* Lists all children of a particular path, taking overlays into account
*
* @param path The path
* @return The list of children
*/
public List<Resource> list(String path) {
try {
final List<Resource> ret = new ArrayList<>();
Resource res = deploymentResourceManager.getResource(path);
if (res != null) {
for (Resource child : res.list()) {
ret.add(new ServletResource(this, child));
}
}
String p = path;
if (p.startsWith("/")) {
p = p.substring(1);
}
if (overlays != null) {
for (VirtualFile overlay : overlays) {
VirtualFile child = overlay.getChild(p);
if (child.exists()) {
VirtualFileResource vfsResource = new VirtualFileResource(overlay.getPhysicalFile(), child, path);
for (Resource c : vfsResource.list()) {
ret.add(new ServletResource(this, c));
}
}
}
}
return ret;
} catch (IOException e) {
//this method really should have thrown IOException
throw new RuntimeException(e);
}
}
use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.
the class TldParsingDeploymentProcessor method processTlds.
private void processTlds(VirtualFile root, List<VirtualFile> files, Map<String, TldMetaData> tlds, final List<TldMetaData> uniqueTlds) throws DeploymentUnitProcessingException {
for (VirtualFile file : files) {
if (file.isFile() && file.getName().toLowerCase(Locale.ENGLISH).endsWith(TLD)) {
String pathNameRelativeToRoot;
try {
pathNameRelativeToRoot = file.getPathNameRelativeTo(root);
} catch (IllegalArgumentException e) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.tldFileNotContainedInRoot(file.getPathName(), root.getPathName()), e);
}
final TldMetaData value = parseTLD(file);
String key = "/" + pathNameRelativeToRoot;
uniqueTlds.add(value);
if (!tlds.containsKey(key)) {
tlds.put(key, value);
}
} else if (file.isDirectory()) {
processTlds(root, file.getChildren(), tlds, uniqueTlds);
}
}
}
use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.
the class TldParsingDeploymentProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
// Skip non web deployments
return;
}
final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
if (warMetaData == null || warMetaData.getMergedJBossWebMetaData() == null) {
return;
}
TldsMetaData tldsMetaData = deploymentUnit.getAttachment(TldsMetaData.ATTACHMENT_KEY);
if (tldsMetaData == null) {
tldsMetaData = new TldsMetaData();
deploymentUnit.putAttachment(TldsMetaData.ATTACHMENT_KEY, tldsMetaData);
}
Map<String, TldMetaData> tlds = new HashMap<String, TldMetaData>();
tldsMetaData.setTlds(tlds);
final List<TldMetaData> uniqueTlds = new ArrayList<>();
final VirtualFile deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
final List<VirtualFile> testRoots = new ArrayList<VirtualFile>();
testRoots.add(deploymentRoot);
testRoots.add(deploymentRoot.getChild(WEB_INF));
testRoots.add(deploymentRoot.getChild(META_INF));
for (ResourceRoot root : deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS)) {
testRoots.add(root.getRoot());
testRoots.add(root.getRoot().getChild(META_INF));
}
JspConfigMetaData merged = warMetaData.getMergedJBossWebMetaData().getJspConfig();
if (merged != null && merged.getTaglibs() != null) {
for (final TaglibMetaData tld : merged.getTaglibs()) {
boolean found = false;
for (final VirtualFile root : testRoots) {
VirtualFile child = root.getChild(tld.getTaglibLocation());
if (child.exists()) {
String pathNameRelativeToRoot;
try {
pathNameRelativeToRoot = child.getPathNameRelativeTo(deploymentRoot);
} catch (IllegalArgumentException e) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.tldFileNotContainedInRoot(child.getPathName(), deploymentRoot.getPathName()), e);
}
final TldMetaData value = parseTLD(child);
value.setUri(tld.getTaglibUri());
uniqueTlds.add(value);
String key = "/" + pathNameRelativeToRoot;
if (!tlds.containsKey(key)) {
tlds.put(key, value);
}
if (!tlds.containsKey(tld.getTaglibUri())) {
tlds.put(tld.getTaglibUri(), value);
}
found = true;
break;
}
}
if (!found) {
UndertowLogger.ROOT_LOGGER.tldNotFound(tld.getTaglibLocation());
}
}
}
// TLDs are located in WEB-INF or any subdir (except the top level "classes" and "lib")
// and in JARs from WEB-INF/lib, in META-INF or any subdir
List<ResourceRoot> resourceRoots = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
for (ResourceRoot resourceRoot : resourceRoots) {
if (resourceRoot.getRoot().getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
VirtualFile webFragment = resourceRoot.getRoot().getChild(META_INF);
if (webFragment.exists() && webFragment.isDirectory()) {
processTlds(deploymentRoot, webFragment.getChildren(), tlds, uniqueTlds);
}
}
}
VirtualFile webInf = deploymentRoot.getChild(WEB_INF);
if (webInf.exists() && webInf.isDirectory()) {
for (VirtualFile file : webInf.getChildren()) {
if (file.isFile() && file.getName().toLowerCase(Locale.ENGLISH).endsWith(TLD)) {
String pathNameRelativeToRoot;
try {
pathNameRelativeToRoot = file.getPathNameRelativeTo(deploymentRoot);
} catch (IllegalArgumentException e) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.tldFileNotContainedInRoot(file.getPathName(), deploymentRoot.getPathName()), e);
}
final TldMetaData value = parseTLD(file);
uniqueTlds.add(value);
String key = "/" + pathNameRelativeToRoot;
if (!tlds.containsKey(key)) {
tlds.put(key, value);
}
} else if (file.isDirectory() && !CLASSES.equals(file.getName()) && !LIB.equals(file.getName())) {
processTlds(deploymentRoot, file.getChildren(), tlds, uniqueTlds);
}
}
}
JBossWebMetaData mergedMd = warMetaData.getMergedJBossWebMetaData();
if (mergedMd.getListeners() == null) {
mergedMd.setListeners(new ArrayList<ListenerMetaData>());
}
final ArrayList<TldMetaData> allTlds = new ArrayList<>(uniqueTlds);
allTlds.addAll(tldsMetaData.getSharedTlds(deploymentUnit));
for (final TldMetaData tld : allTlds) {
if (tld.getListeners() != null) {
for (ListenerMetaData l : tld.getListeners()) {
mergedMd.getListeners().add(l);
}
}
}
}
use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.
the class JBossWebParsingDeploymentProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
// Skip non web deployments
return;
}
final VirtualFile deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
final VirtualFile jbossWebXml = deploymentRoot.getChild(JBOSS_WEB_XML);
WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
assert warMetaData != null;
if (jbossWebXml.exists()) {
InputStream is = null;
try {
is = jbossWebXml.openStream();
final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setXMLResolver(NoopXMLResolver.create());
XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is);
final JBossWebMetaData jBossWebMetaData = JBossWebMetaDataParser.parse(xmlReader, JBossDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
warMetaData.setJBossWebMetaData(jBossWebMetaData);
// deployment unit
if (jBossWebMetaData.getValves() != null) {
for (ValveMetaData valve : jBossWebMetaData.getValves()) {
UndertowLogger.ROOT_LOGGER.unsupportedValveFeature(valve.getValveClass());
}
}
if (jBossWebMetaData.getDistinctName() != null) {
deploymentUnit.putAttachment(org.jboss.as.ee.structure.Attachments.DISTINCT_NAME, jBossWebMetaData.getDistinctName());
}
} catch (XMLStreamException e) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(jbossWebXml.toString(), e.getLocation().getLineNumber(), e.getLocation().getColumnNumber()), e);
} catch (IOException e) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(jbossWebXml.toString()), e);
} finally {
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
// Ignore
}
}
} else {
//jboss web embedded inside jboss-all.xml
final JBossWebMetaData jbMeta = deploymentUnit.getAttachment(WebJBossAllParser.ATTACHMENT_KEY);
if (jbMeta != null) {
warMetaData.setJBossWebMetaData(jbMeta);
}
}
}
Aggregations