org.jboss.vfs.VirtualFile Java Examples

The following examples show how to use org.jboss.vfs.VirtualFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DeploymentOverlayDeploymentUnitProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private boolean isExplodedSubUnitOverlay(DeploymentUnit deploymentUnit, VirtualFile mountPoint, String path) {
    final List<ResourceRoot> childRes = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
    if (childRes != null) {
        for (ResourceRoot rs: childRes) {
            if (path.startsWith(rs.getRoot().getName())) {
                String relativePath = mountPoint.getPathNameRelativeTo(rs.getRoot());
                if (relativePath != null
                        && relativePath.length() > 0
                        && SubExplodedDeploymentMarker.isSubExplodedResourceRoot(rs)) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example #2
Source File: ManifestClassPathProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Creates a {@link ResourceRoot} for the passed {@link VirtualFile file} and adds it to the list of {@link ResourceRoot}s
 * in the {@link DeploymentUnit deploymentUnit}
 *
 *
 * @param file           The file for which the resource root will be created
 * @return Returns the created {@link ResourceRoot}
 * @throws java.io.IOException
 */
private synchronized ResourceRoot createResourceRoot(final VirtualFile file, final DeploymentUnit deploymentUnit, final VirtualFile deploymentRoot) throws DeploymentUnitProcessingException {
    try {
        Map<String, MountedDeploymentOverlay> overlays = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_OVERLAY_LOCATIONS);

        String relativeName = file.getPathNameRelativeTo(deploymentRoot);
        MountedDeploymentOverlay overlay = overlays.get(relativeName);
        Closeable closable = null;
        if(overlay != null) {
            overlay.remountAsZip(false);
        } else if(file.isFile()) {
            closable = VFS.mountZip(file, file, TempFileProviderService.provider());
        }
        final MountHandle mountHandle = MountHandle.create(closable);
        final ResourceRoot resourceRoot = new ResourceRoot(file, mountHandle);
        ModuleRootMarker.mark(resourceRoot);
        ResourceRootIndexer.indexResourceRoot(resourceRoot);
        return resourceRoot;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #3
Source File: ManagedDMRContentTypeResource.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void loadContent(byte[] initialHash) {
    VirtualFile vf = contentRepository.getContent(initialHash);
    if (vf == null) {
        throw ManagedDMRContentLogger.ROOT_LOGGER.noContentFoundWithHash(HashUtil.bytesToHexString(initialHash));
    }
    InputStream is = null;
    try {
        is = vf.openStream();
        ModelNode node = ModelNode.fromStream(is);
        if (node.isDefined()) {
            for (Property prop : node.asPropertyList()) {
                ModelNode value = prop.getValue();
                byte[] hash = hashContent(value);
                synchronized (content) {
                    content.put(prop.getName(), new ManagedContent(value, hash));
                }
            }
        }
        this.model.get(ModelDescriptionConstants.HASH).set(initialHash);
        contentRepository.addContentReference(new ContentReference(address.toCLIStyleString(), initialHash));
    } catch (IOException e) {
        throw new ContentStorageException(e);
    } finally {
        safeClose(is);
    }
}
 
Example #4
Source File: ManifestClassPathProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void handlingExistingClassPathEntry(final ArrayDeque<RootEntry> resourceRoots, final DeploymentUnit topLevelDeployment, final VirtualFile topLevelRoot, final Map<VirtualFile, ResourceRoot> subDeployments, final Map<VirtualFile, AdditionalModuleSpecification> additionalModules, final Set<VirtualFile> existingAccessibleRoots, final ResourceRoot resourceRoot, final Attachable target, final VirtualFile classPathFile) throws DeploymentUnitProcessingException {
    if (existingAccessibleRoots.contains(classPathFile)) {
        ServerLogger.DEPLOYMENT_LOGGER.debugf("Class-Path entry %s in %s ignored, as target is already accessible", classPathFile, resourceRoot.getRoot());
    } else if (additionalModules.containsKey(classPathFile)) {
        final AdditionalModuleSpecification moduleSpecification = additionalModules.get(classPathFile);
        //as class path entries are exported, transitive dependencies will also be available
        target.addToAttachmentList(Attachments.CLASS_PATH_ENTRIES, moduleSpecification.getModuleIdentifier());
    } else if (subDeployments.containsKey(classPathFile)) {
        //now we need to calculate the sub deployment module identifier
        //unfortunately the sub deployment has not been setup yet, so we cannot just
        //get it from the sub deployment directly
        final ResourceRoot otherRoot = subDeployments.get(classPathFile);
        target.addToAttachmentList(Attachments.CLASS_PATH_ENTRIES, ModuleIdentifierProcessor.createModuleIdentifier(otherRoot.getRootName(), otherRoot, topLevelDeployment, topLevelRoot, false));
    } else {
        ModuleIdentifier identifier = createAdditionalModule(resourceRoot, topLevelDeployment, topLevelRoot, additionalModules, classPathFile, resourceRoots);
        target.addToAttachmentList(Attachments.CLASS_PATH_ENTRIES, identifier);
    }
}
 
Example #5
Source File: ClassLoaderUtil.java    From mrgeo with Apache License 2.0 6 votes vote down vote up
public static List<URL> loadVfs(URL resource) throws IOException
{
  List<URL> result = new LinkedList<>();

  try
  {
    VirtualFile r = VFS.getChild(resource.toURI());
    if (r.exists() && r.isDirectory())
    {
      for (VirtualFile f : r.getChildren())
      {
        result.add(f.asFileURL());
      }
    }
  }
  catch (URISyntaxException e)
  {
    System.out.println("Problem reading resource '" + resource + "':\n " + e.getMessage());
    log.error("Exception thrown", e);
  }

  return result;
}
 
Example #6
Source File: VFSResourceLoader.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/** {@inheritDoc} */
public Resource getResource(final String name) {
    return doPrivileged(new PrivilegedAction<Resource>() {
        public Resource run() {
            try {
                final VirtualFile file = getExistentVirtualFile(PathUtils.canonicalize(name));
                if (file == null) {
                    return null;
                }
                return new VFSEntryResource(file.getPathNameRelativeTo(root), file, file.toURL());
            } catch (MalformedURLException e) {
                // must be invalid...?  (todo: check this out)
                return null;
            }
        }
    });
}
 
Example #7
Source File: ModuleSpecProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void addResourceRoot(final ModuleSpec.Builder specBuilder, final ResourceRoot resource, final List<PermissionFactory> permFactories)
        throws DeploymentUnitProcessingException {
    try {
        final VirtualFile root = resource.getRoot();
        if (resource.getExportFilters().isEmpty()) {
            specBuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(new VFSResourceLoader(resource
                    .getRootName(), root, resource.isUsePhysicalCodeSource())));
        } else {
            final MultiplePathFilterBuilder filterBuilder = PathFilters.multiplePathFilterBuilder(true);
            for (final FilterSpecification filter : resource.getExportFilters()) {
                filterBuilder.addFilter(filter.getPathFilter(), filter.isInclude());
            }
            specBuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(new VFSResourceLoader(resource
                    .getRootName(), root, resource.isUsePhysicalCodeSource()), filterBuilder.create()));
        }
        // start with the root
        permFactories.add(new ImmediatePermissionFactory(
                new VirtualFilePermission(root.getPathName(), VirtualFilePermission.FLAG_READ)));
        // also include all children, recursively
        permFactories.add(new ImmediatePermissionFactory(
                new VirtualFilePermission(root.getChild("-").getPathName(), VirtualFilePermission.FLAG_READ)));
    } catch (IOException e) {
        throw ServerLogger.ROOT_LOGGER.failedToCreateVFSResourceLoader(resource.getRootName(), e);
    }
}
 
Example #8
Source File: DeferredDeploymentOverlayDeploymentUnitProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void handleExplodedEntryWithDirParent(DeploymentUnit deploymentUnit, VirtualFile content, VirtualFile mountPoint,
        Map<String, MountedDeploymentOverlay> mounts, String overLayPath) throws IOException {
    Closeable handle = VFS.mountReal(content.getPhysicalFile(), mountPoint);
    MountedDeploymentOverlay mounted = new MountedDeploymentOverlay(handle, content.getPhysicalFile(), mountPoint, TempFileProviderService.provider());
    deploymentUnit.addToAttachmentList(MOUNTED_FILES, mounted);
    mounts.put(overLayPath, mounted);
}
 
Example #9
Source File: PathContentServitor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static ServiceController<VirtualFile> addService(OperationContext context, final ServiceTarget serviceTarget, final ServiceName serviceName, final String path, final String relativeTo) {
    final PathContentServitor service = new PathContentServitor(path, relativeTo);
    return serviceTarget.addService(serviceName, service)
            .addDependency(context.getCapabilityServiceName("org.wildfly.management.path-manager", PathManager.class),
                    PathManager.class, service.pathManagerValue)
            .install();
}
 
Example #10
Source File: ManagedExplodedContentServitor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ManagedExplodedContentServitor(final String managementName, final byte[] hash,
                                       final Consumer<VirtualFile> virtualFileConsumer,
                                       final Supplier<ContentRepository> contentRepositorySupplier,
                                       final Supplier<ServerEnvironment> serverEnvironmentSupplier,
                                       final Supplier<ExecutorService> executorSupplier) {
    this.managementName = managementName;
    this.hash = hash;
    this.virtualFileConsumer = virtualFileConsumer;
    this.contentRepositorySupplier = contentRepositorySupplier;
    this.serverEnvironmentSupplier = serverEnvironmentSupplier;
    this.executorSupplier = executorSupplier;
}
 
Example #11
Source File: ServiceLoaderProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void processRoot(final ResourceRoot resourceRoot, final Map<String, List<String>> foundServices) throws DeploymentUnitProcessingException {
    final VirtualFile virtualFile = resourceRoot.getRoot();
    final VirtualFile child = virtualFile.getChild("META-INF/services");
    for (VirtualFile serviceType : child.getChildren()) {
        final String name = serviceType.getName();
        try {
            List<String> list = foundServices.get(name);
            if (list == null) {
                foundServices.put(name, list = new ArrayList<String>());
            }
            final InputStream stream = serviceType.openStream();
            try {
                final BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
                String line;
                while ((line = reader.readLine()) != null) {
                    final int commentIdx = line.indexOf('#');
                    final String className;
                    if (commentIdx == -1) {
                        className = line.trim();
                    } else {
                        className = line.substring(0, commentIdx).trim();
                    }
                    if (className.length() == 0) {
                        continue;
                    }
                    list.add(className);
                }
            } finally {
                VFSUtils.safeClose(stream);
            }
        } catch (IOException e) {
            throw ServerLogger.ROOT_LOGGER.failedToReadVirtualFile(child, e);
        }
    }
}
 
Example #12
Source File: SimpleContentProvider.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public VirtualFile getContent(int index) {
    if (index >= this.contents.size()) {
        return null;
    }

    return this.contents.get(index);
}
 
Example #13
Source File: LoadLibs.java    From tess4j with Apache License 2.0 5 votes vote down vote up
/**
 * Copies resources to target folder.
 *
 * @param resourceUrl
 * @param targetPath
 * @return
 */
static void copyResources(URL resourceUrl, File targetPath) throws IOException, URISyntaxException {
    if (resourceUrl == null) {
        return;
    }

    URLConnection urlConnection = resourceUrl.openConnection();

    /**
     * Copy resources either from inside jar or from project folder.
     */
    if (urlConnection instanceof JarURLConnection) {
        copyJarResourceToPath((JarURLConnection) urlConnection, targetPath);
    } else if (VFS_PROTOCOL.equals(resourceUrl.getProtocol())) {
        VirtualFile virtualFileOrFolder = VFS.getChild(resourceUrl.toURI());
        copyFromWarToFolder(virtualFileOrFolder, targetPath);
    } else {
        File file = new File(resourceUrl.getPath());
        if (file.isDirectory()) {
            for (File resourceFile : FileUtils.listFiles(file, null, true)) {
                int index = resourceFile.getPath().lastIndexOf(targetPath.getName()) + targetPath.getName().length();
                File targetFile = new File(targetPath, resourceFile.getPath().substring(index));
                if (!targetFile.exists() || targetFile.length() != resourceFile.length() || targetFile.lastModified() != resourceFile.lastModified()) {
                    if (resourceFile.isFile()) {
                        FileUtils.copyFile(resourceFile, targetFile, true);
                    }
                }
            }
        } else {
            if (!targetPath.exists() || targetPath.length() != file.length() || targetPath.lastModified() != file.lastModified()) {
                FileUtils.copyFile(file, targetPath, true);
            }
        }
    }
}
 
Example #14
Source File: VfsResourceIterator.java    From web-data-extractor with Apache License 2.0 5 votes vote down vote up
@Override
public InputStream next() throws IOException {
    while (true) {
        if (++index >= files.size()) {
            // no files
            return null;
        }
        final VirtualFile f = files.get(index);
        if (f.isFile() && f.getName().endsWith(".class")) {
            return f.openStream();
        }
    }
}
 
Example #15
Source File: CamelContextDescriptorsProcessor.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {

    final DeploymentUnit depUnit = phaseContext.getDeploymentUnit();
    final String runtimeName = depUnit.getName();

    CamelDeploymentSettings.Builder depSettings = depUnit.getAttachment(CamelDeploymentSettings.BUILDER_ATTACHMENT_KEY);
    if (depSettings.isDisabledByJbossAll() || !depSettings.isDeploymentValid() || runtimeName.endsWith(".ear")) {
        return;
    }

    try {
        boolean addedAny = false;
        if (runtimeName.endsWith(CamelConstants.CAMEL_CONTEXT_FILE_SUFFIX)) {
            URL fileURL = depUnit.getAttachment(Attachments.DEPLOYMENT_CONTENTS).asFileURL();
            addedAny |= addConditionally(depUnit, depSettings, fileURL);
        } else {
            VirtualFileFilter filter = new VirtualFileFilter() {
                public boolean accepts(VirtualFile child) {
                    return child.isFile() && child.getName().endsWith(CamelConstants.CAMEL_CONTEXT_FILE_SUFFIX);
                }
            };
            VirtualFile rootFile = depUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
            for (VirtualFile vfile : rootFile.getChildrenRecursively(filter)) {
                addedAny |= addConditionally(depUnit, depSettings, vfile.asFileURL());
            }
        }

        if (addedAny) {
            LOGGER.info("Camel context descriptors found");
        }
    } catch (IOException ex) {
        throw new IllegalStateException("Cannot create camel context: " + runtimeName, ex);
    }
}
 
Example #16
Source File: VfsProcessApplicationScanner.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected VirtualFile getVirtualFileForUrl(final URL url) {
  try {
    return  VFS.getChild(url.toURI());
  }
  catch (URISyntaxException e) {
    throw LOG.exceptionWhileGettingVirtualFolder(url, e);
  }
}
 
Example #17
Source File: SyncModelServerStateTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public VirtualFile getContent(byte[] hash) {
    if (hash[0] == 1) {
        return vf;

    }
    return null;
}
 
Example #18
Source File: ReadContentHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    Resource resource = context.getOriginalRootResource();
    for(final PathElement element : address) {
        resource = resource.getChild(element);
    }
    byte[] content = resource.getModel().get(CONTENT).asBytes();
    final VirtualFile file = contentRepository.getContent(content);
    try {
        context.getResult().set(readFile(file));
    } catch (IOException e) {
        throw ServerLogger.ROOT_LOGGER.failedToLoadFile(file, e);
    }
}
 
Example #19
Source File: ManagedExplodedContentServitor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static ServiceController<?> addService(final ServiceTarget serviceTarget, final ServiceName serviceName, final String managementName, final byte[] hash) {
    final ServiceBuilder<?> sb = serviceTarget.addService(serviceName);
    final Consumer<VirtualFile> vfConsumer = sb.provides(serviceName);
    final Supplier<ContentRepository> crSupplier = sb.requires(ContentRepository.SERVICE_NAME);
    final Supplier<ServerEnvironment> seSupplier = sb.requires(ServerEnvironmentService.SERVICE_NAME);
    final Supplier<ExecutorService> esSupplier = requireServerExecutor(sb);
    sb.setInstance(new ManagedExplodedContentServitor(managementName, hash, vfConsumer, crSupplier, seSupplier, esSupplier));
    return sb.install();
}
 
Example #20
Source File: DeploymentMountProvider.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Closeable mountDeploymentContent(final VirtualFile contents, VirtualFile mountPoint, MountType type) throws IOException {
    // according to the javadoc contents can not be null
    assert contents != null : "null contents";
    switch (type) {
        case ZIP:
            return VFS.mountZip(contents, mountPoint, tempFileProvider);
        case EXPANDED:
            return VFS.mountZipExpanded(contents, mountPoint, tempFileProvider);
        case REAL:
            return VFS.mountReal(contents.getPhysicalFile(), mountPoint);
        default:
            throw ServerLogger.ROOT_LOGGER.unknownMountType(type);
    }
}
 
Example #21
Source File: ProcessApplicationDeploymentProcessor.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected Map<String, byte[]> getDeploymentResources(ProcessArchiveXml processArchive, DeploymentUnit deploymentUnit, VirtualFile processesXmlFile) {

    final Module module = deploymentUnit.getAttachment(MODULE);

    Map<String, byte[]> resources = new HashMap<String, byte[]>();

    // first, add all resources listed in the processe.xml
    List<String> process = processArchive.getProcessResourceNames();
    ModuleClassLoader classLoader = module.getClassLoader();

    for (String resource : process) {
      InputStream inputStream = null;
      try {
        inputStream = classLoader.getResourceAsStream(resource);
        resources.put(resource, IoUtil.readInputStream(inputStream, resource));
      } finally {
        IoUtil.closeSilently(inputStream);
      }
    }

    // scan for process definitions
    if(PropertyHelper.getBooleanProperty(processArchive.getProperties(), ProcessArchiveXml.PROP_IS_SCAN_FOR_PROCESS_DEFINITIONS, process.isEmpty())) {

      //always use VFS scanner on JBoss
      final VfsProcessApplicationScanner scanner = new VfsProcessApplicationScanner();

      String resourceRootPath = processArchive.getProperties().get(ProcessArchiveXml.PROP_RESOURCE_ROOT_PATH);
      String[] additionalResourceSuffixes = StringUtil.split(processArchive.getProperties().get(ProcessArchiveXml.PROP_ADDITIONAL_RESOURCE_SUFFIXES), ProcessArchiveXml.PROP_ADDITIONAL_RESOURCE_SUFFIXES_SEPARATOR);
      URL processesXmlUrl = vfsFileAsUrl(processesXmlFile);
      resources.putAll(scanner.findResources(classLoader, resourceRootPath, processesXmlUrl, additionalResourceSuffixes));
    }

    return resources;
  }
 
Example #22
Source File: Seam2Processor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Lookup Seam integration resource loader.
 * @return the Seam integration resource loader
 * @throws DeploymentUnitProcessingException for any error
 */
protected synchronized ResourceRoot getSeamIntResourceRoot() throws DeploymentUnitProcessingException {
    try {
        if (seamIntResourceRoot == null) {
            final ModuleLoader moduleLoader = Module.getBootModuleLoader();
            Module extModule = moduleLoader.loadModule(EXT_CONTENT_MODULE);
            URL url = extModule.getExportedResource(SEAM_INT_JAR);
            if (url == null)
                throw ServerLogger.ROOT_LOGGER.noSeamIntegrationJarPresent(extModule);

            File file = new File(url.toURI());
            VirtualFile vf = VFS.getChild(file.toURI());
            final Closeable mountHandle = VFS.mountZip(file, vf, TempFileProviderService.provider());
            Service<Closeable> mountHandleService = new Service<Closeable>() {
                public void start(StartContext startContext) throws StartException {
                }

                public void stop(StopContext stopContext) {
                    VFSUtils.safeClose(mountHandle);
                }

                public Closeable getValue() throws IllegalStateException, IllegalArgumentException {
                    return mountHandle;
                }
            };
            ServiceBuilder<Closeable> builder = serviceTarget.addService(ServiceName.JBOSS.append(SEAM_INT_JAR),
                    mountHandleService);
            builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
            serviceTarget = null; // our cleanup service install work is done

            MountHandle dummy = MountHandle.create(null); // actual close is done by the MSC service above
            seamIntResourceRoot = new ResourceRoot(vf, dummy);
        }
        return seamIntResourceRoot;
    } catch (Exception e) {
        throw new DeploymentUnitProcessingException(e);
    }
}
 
Example #23
Source File: ProcessApplicationDeploymentProcessor.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected URL vfsFileAsUrl(VirtualFile processesXmlFile)  {
  try {
    return processesXmlFile.toURL();
  } catch (MalformedURLException e) {
    throw new RuntimeException(e);
  }
}
 
Example #24
Source File: ProcessesXmlProcessor.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected VirtualFile getFile(URL processesXmlResource) throws DeploymentUnitProcessingException {
  try {
    return VFS.getChild(processesXmlResource.toURI());
  } catch(Exception e) {
    throw new DeploymentUnitProcessingException(e);
  }
}
 
Example #25
Source File: JBossAllXMLParsingProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);

    VirtualFile descriptor = null;
    for (final String loc : DEPLOYMENT_STRUCTURE_DESCRIPTOR_LOCATIONS) {
        final VirtualFile file = root.getRoot().getChild(loc);
        if (file.exists()) {
            descriptor = file;
            break;
        }
    }
    if(descriptor == null) {
        return;
    }
    final XMLMapper mapper = XMLMapper.Factory.create();
    final Map<QName, AttachmentKey<?>> namespaceAttachments = new HashMap<QName, AttachmentKey<?>>();
    for(final JBossAllXMLParserDescription<?> parser : deploymentUnit.getAttachmentList(JBossAllXMLParserDescription.ATTACHMENT_KEY)) {
        namespaceAttachments.put(parser.getRootElement(), parser.getAttachmentKey());
        mapper.registerRootElement(parser.getRootElement(), new JBossAllXMLElementReader(parser));
    }
    mapper.registerRootElement(new QName(Namespace.JBOSS_1_0.getUriString(), JBOSS), Parser.INSTANCE);
    mapper.registerRootElement(new QName(Namespace.NONE.getUriString(), JBOSS), Parser.INSTANCE);

    final JBossAllXmlParseContext context = new JBossAllXmlParseContext(deploymentUnit);
    parse(descriptor, mapper, context);

    //we use this map to detect the presence of two different but functionally equivalent namespaces
    final Map<AttachmentKey<?>, QName> usedNamespaces = new HashMap<AttachmentKey<?>, QName>();
    for(Map.Entry<QName, Object> entry : context.getParseResults().entrySet()) {
        final AttachmentKey attachmentKey = namespaceAttachments.get(entry.getKey());
        if(usedNamespaces.containsKey(attachmentKey)) {
            throw ServerLogger.ROOT_LOGGER.equivalentNamespacesInJBossXml(entry.getKey(), usedNamespaces.get(attachmentKey));
        }
        usedNamespaces.put(attachmentKey, entry.getKey());
        deploymentUnit.putAttachment(attachmentKey, entry.getValue());
    }
}
 
Example #26
Source File: ProcessApplicationDeploymentProcessor.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected URL vfsFileAsUrl(VirtualFile processesXmlFile)  {
  try {
    return processesXmlFile.toURL();
  } catch (MalformedURLException e) {
    throw new RuntimeException(e);
  }
}
 
Example #27
Source File: ManifestClassPathProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ModuleIdentifier createAdditionalModule(final ResourceRoot resourceRoot, final DeploymentUnit topLevelDeployment, final VirtualFile topLevelRoot, final Map<VirtualFile, AdditionalModuleSpecification> additionalModules, final VirtualFile classPathFile, final ArrayDeque<RootEntry> resourceRoots) throws DeploymentUnitProcessingException {
    final ResourceRoot root = createResourceRoot(classPathFile, topLevelDeployment, topLevelRoot);
    final String pathName = root.getRoot().getPathNameRelativeTo(topLevelRoot);
    ModuleIdentifier identifier = ModuleIdentifier.create(ServiceModuleLoader.MODULE_PREFIX + topLevelDeployment.getName() + "." + pathName);
    AdditionalModuleSpecification module = new AdditionalModuleSpecification(identifier, root);
    topLevelDeployment.addToAttachmentList(Attachments.ADDITIONAL_MODULES, module);
    additionalModules.put(classPathFile, module);
    resourceRoot.addToAttachmentList(Attachments.CLASS_PATH_RESOURCE_ROOTS, root);

    //add this to the list of roots to be processed, so transitive class path entries will be respected
    resourceRoots.add(new RootEntry(module, root));
    return identifier;

}
 
Example #28
Source File: ProcessesXmlProcessor.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected VirtualFile getFile(URL processesXmlResource) throws DeploymentUnitProcessingException {
  try {
    return VFS.getChild(processesXmlResource.toURI());
  } catch(Exception e) {
    throw new DeploymentUnitProcessingException(e);
  }
}
 
Example #29
Source File: VfsProcessApplicationScanner.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private void addResource(VirtualFile virtualFile, VirtualFile processArchiveRoot, Map<String, byte[]> resources) {
  String resourceName = virtualFile.getPathNameRelativeTo(processArchiveRoot);
  try {
    InputStream inputStream = virtualFile.openStream();
    byte[] bytes = IoUtil.readInputStream(inputStream, resourceName);
    IoUtil.closeSilently(inputStream);
    resources.put(resourceName, bytes);
  }
  catch (IOException e) {
    LOG.cannotReadInputStreamForFile(resourceName, processArchiveRoot, e);
  }
}
 
Example #30
Source File: ModuleIdentifierProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    final DeploymentUnit parent = deploymentUnit.getParent();
    final DeploymentUnit topLevelDeployment = parent == null ? deploymentUnit : parent;
    final VirtualFile toplevelRoot = topLevelDeployment.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
    final ModuleIdentifier moduleIdentifier = createModuleIdentifier(deploymentUnit.getName(), deploymentRoot, topLevelDeployment, toplevelRoot, deploymentUnit.getParent() == null);
    deploymentUnit.putAttachment(Attachments.MODULE_IDENTIFIER, moduleIdentifier);
}