use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.
the class WildFlyJobXmlResolver method create.
private static WildFlyJobXmlResolver create(final ClassLoader classLoader, final List<ResourceRoot> resources) throws DeploymentUnitProcessingException {
final Map<String, VirtualFile> foundJobXmlFiles = new LinkedHashMap<>();
for (ResourceRoot r : resources) {
final VirtualFile root = r.getRoot();
try {
addJobXmlFiles(foundJobXmlFiles, root.getChild(DEFAULT_PATH));
} catch (IOException e) {
throw BatchLogger.LOGGER.errorProcessingBatchJobsDir(e);
}
}
final WildFlyJobXmlResolver jobXmlResolver = new WildFlyJobXmlResolver(foundJobXmlFiles);
// Initialize this instance
jobXmlResolver.init(classLoader);
return jobXmlResolver;
}
use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.
the class WildFlyJobXmlResolver method init.
/**
* Initializes the state of an instance
*/
private void init(final ClassLoader classLoader) {
// Load the user defined resolvers
for (JobXmlResolver resolver : ServiceLoader.load(JobXmlResolver.class, classLoader)) {
jobXmlResolvers.add(resolver);
for (String jobXml : resolver.getJobXmlNames(classLoader)) {
addJob(jobXml, resolver.resolveJobName(jobXml, classLoader));
}
}
// Load the default names
for (Map.Entry<String, VirtualFile> entry : jobXmlFiles.entrySet()) {
try {
// Parsing the entire job XML seems excessive to just get the job name. There are two reasons for this:
// 1) If an error occurs during parsing there's no real need to consider this a valid job
// 2) Using the implementation parser seems less error prone for future-proofing
final Job job = JobParser.parseJob(entry.getValue().openStream(), classLoader, new XMLResolver() {
// this is essentially what JBeret does, but it's ugly. JBeret might need an API to handle this
@Override
public Object resolveEntity(final String publicID, final String systemID, final String baseURI, final String namespace) throws XMLStreamException {
try {
return (jobXmlFiles.containsKey(systemID) ? jobXmlFiles.get(systemID).openStream() : null);
} catch (IOException e) {
throw new XMLStreamException(e);
}
}
});
addJob(entry.getKey(), job.getId());
} catch (XMLStreamException | IOException e) {
// Report the possible error as we don't want to fail the deployment. The job may never be run.
BatchLogger.LOGGER.invalidJobXmlFile(entry.getKey());
}
}
}
use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.
the class EjbJarParsingDeploymentUnitProcessor method parseEjbJarXml.
private static EjbJarMetaData parseEjbJarXml(final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
final VirtualFile alternateDescriptor = deploymentRoot.getAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_EJB_DEPLOYMENT_DESCRIPTOR);
//this is a bit tri
// Locate the descriptor
final VirtualFile descriptor;
if (alternateDescriptor != null) {
descriptor = alternateDescriptor;
} else {
descriptor = getDescriptor(deploymentRoot.getRoot(), EJB_JAR_XML);
}
if (descriptor == null) {
// no descriptor found, nothing to do!
return null;
}
// get the XMLStreamReader and parse the descriptor
MetaDataElementParser.DTDInfo dtdInfo = new MetaDataElementParser.DTDInfo();
InputStream stream = open(descriptor);
try {
XMLStreamReader reader = getXMLStreamReader(stream, descriptor, dtdInfo);
EjbJarMetaData ejbJarMetaData = EjbJarMetaDataParser.parse(reader, dtdInfo, SpecDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
return ejbJarMetaData;
} catch (XMLStreamException xmlse) {
throw EjbLogger.ROOT_LOGGER.failedToParse(xmlse, "ejb-jar.xml: " + descriptor.getPathName());
} finally {
try {
stream.close();
} catch (IOException ioe) {
EjbLogger.DEPLOYMENT_LOGGER.failToCloseFile(ioe);
}
}
}
use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.
the class EjbJarParsingDeploymentUnitProcessor method parseJBossEjb3Xml.
private static EjbJarMetaData parseJBossEjb3Xml(final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
final VirtualFile deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
// Locate the descriptor
final VirtualFile descriptor = getDescriptor(deploymentRoot, JBOSS_EJB3_XML);
if (descriptor == null) {
//but there may have been an ejb-jar element in jboss-all.xml
return deploymentUnit.getAttachment(EjbJarJBossAllParser.ATTACHMENT_KEY);
}
// get the XMLStreamReader and parse the descriptor
MetaDataElementParser.DTDInfo dtdInfo = new MetaDataElementParser.DTDInfo();
InputStream stream = open(descriptor);
try {
XMLStreamReader reader = getXMLStreamReader(stream, descriptor, dtdInfo);
final JBossEjb3MetaDataParser parser = new JBossEjb3MetaDataParser(createJbossEjbJarParsers());
final EjbJarMetaData ejbJarMetaData = parser.parse(reader, dtdInfo, JBossDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
return ejbJarMetaData;
} catch (XMLStreamException xmlse) {
throw EjbLogger.ROOT_LOGGER.failedToParse(xmlse, JBOSS_EJB3_XML + ": " + descriptor.getPathName());
} finally {
try {
stream.close();
} catch (IOException ioe) {
EjbLogger.DEPLOYMENT_LOGGER.failToCloseFile(ioe);
}
}
}
use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.
the class SarStructureProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final ResourceRoot resourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
if (resourceRoot == null) {
return;
}
final VirtualFile deploymentRoot = resourceRoot.getRoot();
if (deploymentRoot == null || !deploymentRoot.exists()) {
return;
}
final String deploymentRootName = deploymentRoot.getName().toLowerCase(Locale.ENGLISH);
if (!deploymentRootName.endsWith(SAR_EXTENSION)) {
return;
}
ModuleRootMarker.mark(resourceRoot, true);
Map<String, MountedDeploymentOverlay> overlays = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_OVERLAY_LOCATIONS);
try {
final List<VirtualFile> childArchives = deploymentRoot.getChildren(CHILD_ARCHIVE_FILTER);
for (final VirtualFile child : childArchives) {
String relativeName = child.getPathNameRelativeTo(deploymentRoot);
MountedDeploymentOverlay overlay = overlays.get(relativeName);
Closeable closable = NO_OP_CLOSEABLE;
if (overlay != null) {
overlay.remountAsZip(false);
} else if (child.isFile()) {
closable = VFS.mountZip(child, child, TempFileProviderService.provider());
}
final MountHandle mountHandle = new MountHandle(closable);
final ResourceRoot childResource = new ResourceRoot(child, mountHandle);
ModuleRootMarker.mark(childResource);
deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, childResource);
resourceRoot.addToAttachmentList(Attachments.INDEX_IGNORE_PATHS, child.getPathNameRelativeTo(deploymentRoot));
}
} catch (IOException e) {
throw SarLogger.ROOT_LOGGER.failedToProcessSarChild(e, deploymentRoot);
}
}
Aggregations