private void mount(File file, DeploymentUnit unit, JarMountMap mountMap) throws IOException {
    VirtualFile mountPath =
        VFS.getChild(File.createTempFile(file.getName(), ".jar", tmpMountDir(unit)).toURI());
    log.debug(unit.getName() + ": mounting " + file);
    final ResourceRoot childResource =
        new ResourceRoot(
            mountPath,
            new MountHandle(VFS.mountZip(file, mountPath, TempFileProviderService.provider())));
    ModuleRootMarker.mark(childResource);
    unit.addToAttachmentList(Attachments.RESOURCE_ROOTS, childResource);

    mountMap.put(mountPath.toURL().toExternalForm(), file.toURI().toURL().toExternalForm());
  }
 /**
  * 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)
     throws DeploymentUnitProcessingException {
   try {
     final Closeable closable =
         file.isFile() ? VFS.mountZip(file, file, TempFileProviderService.provider()) : null;
     final MountHandle mountHandle = new MountHandle(closable);
     final ResourceRoot resourceRoot = new ResourceRoot(file, mountHandle);
     ModuleRootMarker.mark(resourceRoot);
     ResourceRootIndexer.indexResourceRoot(resourceRoot);
     return resourceRoot;
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
  @Override
  public Closeable mountDeploymentContent(
      String name,
      String runtimeName,
      byte[] deploymentHash,
      VirtualFile mountPoint,
      boolean mountExpanded)
      throws IOException {
    // Internal deployments have no hash, and are unique by name
    if (deploymentHash == null) {
      File file = new File(systemDeployDir, name);
      return VFS.mountZip(file, mountPoint, tempFileProvider);
    }

    final File external = getExternalFileReference(deploymentHash, false);
    if (external.exists()) {
      final InputStream is = new FileInputStream(external);
      try {
        final BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        final String fileName = reader.readLine();
        final File realRoot = new File(fileName);
        if (!realRoot.exists()) {
          throw new FileNotFoundException(fileName);
        }
        return VFS.mountReal(realRoot, mountPoint);
      } finally {
        safeClose(is);
      }
    }

    final File content = getDeploymentContentFile(deploymentHash);
    if (mountExpanded) {
      return VFS.mountZipExpanded(content, mountPoint, tempFileProvider);
    } else {
      return VFS.mountZip(content, mountPoint, tempFileProvider);
    }
  }
 @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 ServerMessages.MESSAGES.unknownMountType(type);
   }
 }
  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.getLowerCaseName();
    if (!deploymentRootName.endsWith(RAR_EXTENSION)) {
      return;
    }
    // we do not load classes from the module resource root
    ModuleRootMarker.mark(resourceRoot, false);

    try {
      final List<VirtualFile> childArchives = deploymentRoot.getChildren(CHILD_ARCHIVE_FILTER);

      for (final VirtualFile child : childArchives) {
        final Closeable closable =
            child.isFile()
                ? VFS.mountZip(child, child, TempFileProviderService.provider())
                : NO_OP_CLOSEABLE;
        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 new DeploymentUnitProcessingException(
          "Failed to process RA child archives for [" + deploymentRoot + "]", e);
    }
  }