Java Code Examples for org.jboss.vfs.VirtualFile

The following examples show how to use org.jboss.vfs.VirtualFile. These examples are extracted from open source projects. 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
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 2
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 3
/** {@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 4
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
/**
 * 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 6
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 7
Source Project: mrgeo   Source File: ClassLoaderUtil.java    License: 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 8
Source Project: thorntail   Source File: ShrinkWrapFileSystem.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean delete(VirtualFile mountPoint, VirtualFile target) {
    getEntry(mountPoint, target)
            .ifPresent(e -> {
                try {
                    e.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            });
    return true;
}
 
Example 9
@Override
public VirtualFile getContent(int index) {
    if (index >= this.contents.size()) {
        return null;
    }

    return this.contents.get(index);
}
 
Example 10
Source Project: web-data-extractor   Source File: VfsResourceIterator.java    License: 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 11
Source Project: tess4j   Source File: LoadLibs.java    License: 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 12
/**
 * Finds the configuration file to be used and returns the first one found.
 * <p/>
 * Preference is for {@literal logging.properties} or {@literal jboss-logging.properties}.
 *
 * @param resourceRoot the resource to check.
 *
 * @return the configuration file if found, otherwise {@code null}.
 *
 * @throws DeploymentUnitProcessingException if an error occurs.
 */
private VirtualFile findConfigFile(ResourceRoot resourceRoot) throws DeploymentUnitProcessingException {
    final VirtualFile root = resourceRoot.getRoot();
    // First check META-INF
    VirtualFile file = root.getChild("META-INF");
    VirtualFile result = findConfigFile(file);
    if (result == null) {
        file = root.getChild("WEB-INF/classes");
        result = findConfigFile(file);
    }
    return result;
}
 
Example 13
private static String resolveRelativePath(final ResourceRoot root, final VirtualFile configFile) {
    // Get the parent of the root resource so the deployment name will be included in the path
    final VirtualFile deployment = root.getRoot().getParent();
    if (deployment != null) {
        return configFile.getPathNameRelativeTo(deployment);
    }
    // This shouldn't be reached, but a fallback is always safe
    return configFile.getPathNameRelativeTo(root.getRoot());
}
 
Example 14
@Override
public VirtualFile getContent(byte[] hash) {
    if (hash[0] == 1) {
        return vf;

    }
    return null;
}
 
Example 15
@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 16
@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 17
/**
 * 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 18
protected URL vfsFileAsUrl(VirtualFile processesXmlFile)  {
  try {
    return processesXmlFile.toURL();
  } catch (MalformedURLException e) {
    throw new RuntimeException(e);
  }
}
 
Example 19
protected VirtualFile getFile(URL processesXmlResource) throws DeploymentUnitProcessingException {
  try {
    return VFS.getChild(processesXmlResource.toURI());
  } catch(Exception e) {
    throw new DeploymentUnitProcessingException(e);
  }
}
 
Example 20
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 21
protected VirtualFile getFile(URL processesXmlResource) throws DeploymentUnitProcessingException {
  try {
    return VFS.getChild(processesXmlResource.toURI());
  } catch(Exception e) {
    throw new DeploymentUnitProcessingException(e);
  }
}
 
Example 22
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 23
@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);
}
 
Example 24
protected URL vfsFileAsUrl(VirtualFile processesXmlFile)  {
  try {
    return processesXmlFile.toURL();
  } catch (MalformedURLException e) {
    throw new RuntimeException(e);
  }
}
 
Example 25
@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
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 27
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 28
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 29
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 30
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);
        }
    }
}