/**
  * 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);
   }
 }
  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);
    }
  }
Ejemplo n.º 3
0
 /** {@inheritDoc} */
 public boolean isFile(final VirtualFile mountPoint, final VirtualFile target) {
   final VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
   return assemblyFile != null && assemblyFile.isFile();
 }