Java源码示例:org.jboss.vfs.VFS

示例1
/**
 * 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);
    }
}
 
示例2
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;
}
 
示例3
@Override
public void start(StartContext startContext) throws StartException {
    this.fsMount = VFS.getChild("wildfly-swarm-deployments");
    try {
        this.fsCloseable = VFS.mount(this.fsMount, this.fs);
    } catch (IOException e) {
        throw new StartException(e);
    }
}
 
示例4
/**
 * 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);
            }
        }
    }
}
 
示例5
void addRolloutPlan(ModelNode dmr) throws Exception {
    File systemTmpDir = new File(System.getProperty("java.io.tmpdir"));
    File tempDir = new File(systemTmpDir, "test" + System.currentTimeMillis());
    tempDir.mkdir();
    File file = new File(tempDir, "content");
    this.vf = VFS.getChild(file.toURI());

    try (final PrintWriter out = new PrintWriter(Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8))){
        dmr.writeString(out, true);
    }
}
 
示例6
@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);
}
 
示例7
/**
 * 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);
    }
}
 
示例8
public void remountAsZip(boolean expanded) throws IOException {
    IoUtils.safeClose(closeable);
    if(expanded) {
        closeable = VFS.mountZipExpanded(realFile, mountPoint, tempFileProvider);
    } else {
        closeable = VFS.mountZip(realFile, mountPoint, tempFileProvider);
    }
}
 
示例9
protected VirtualFile getVirtualFileForUrl(final URL url) {
  try {
    return  VFS.getChild(url.toURI());
  }
  catch (URISyntaxException e) {
    throw LOG.exceptionWhileGettingVirtualFolder(url, e);
  }
}
 
示例10
protected VirtualFile getFile(URL processesXmlResource) throws DeploymentUnitProcessingException {
  try {
    return VFS.getChild(processesXmlResource.toURI());
  } catch(Exception e) {
    throw new DeploymentUnitProcessingException(e);
  }
}
 
示例11
protected VirtualFile getFile(URL processesXmlResource) throws DeploymentUnitProcessingException {
  try {
    return VFS.getChild(processesXmlResource.toURI());
  } catch(Exception e) {
    throw new DeploymentUnitProcessingException(e);
  }
}
 
示例12
@Override
public VirtualFile getContent(byte[] sha1Bytes) {
    String key = toKey(sha1Bytes);
    VirtualFile result = VFS.getChild(this.index.get(key));
    return result;
}
 
示例13
public void removeAllContent() throws IOException {
    for (URI uri : this.index.values()) {
        VirtualFile file = VFS.getChild(uri);
        file.delete();
    }
}
 
示例14
@Override
public VirtualFile getContent(byte[] hash) {
    Assert.checkNotNullParam("hash", hash);
    return VFS.getChild(getDeploymentContentFile(hash, true).toUri());
}
 
示例15
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if(deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT) != null) {
        return;
    }
    final DeploymentMountProvider deploymentMountProvider = deploymentUnit.getAttachment(Attachments.SERVER_DEPLOYMENT_REPOSITORY);
    if(deploymentMountProvider == null) {
        throw ServerLogger.ROOT_LOGGER.noDeploymentRepositoryAvailable();
    }

    final String deploymentName = deploymentUnit.getName();
    final VirtualFile deploymentContents = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_CONTENTS);

    // internal deployments do not have any contents, so there is nothing to mount
    if (deploymentContents == null)
        return;

    final VirtualFile deploymentRoot;
    final MountHandle mountHandle;
    if (deploymentContents.isDirectory()) {
        // use the contents directly
        deploymentRoot = deploymentContents;
        // nothing was mounted
        mountHandle = null;
        ExplodedDeploymentMarker.markAsExplodedDeployment(deploymentUnit);

    } else {
        // The mount point we will use for the repository file
        deploymentRoot = VFS.getChild("content/" + deploymentName);

        boolean failed = false;
        Closeable handle = null;
        try {
            final boolean mountExploded = MountExplodedMarker.isMountExploded(deploymentUnit);
            final MountType type;
            if(mountExploded) {
                type = MountType.EXPANDED;
            } else if (deploymentName.endsWith(".xml")) {
                type = MountType.REAL;
            } else {
                type = MountType.ZIP;
            }
            handle = deploymentMountProvider.mountDeploymentContent(deploymentContents, deploymentRoot, type);
            mountHandle = MountHandle.create(handle);
        } catch (IOException e) {
            failed = true;
            throw ServerLogger.ROOT_LOGGER.deploymentMountFailed(e);
        } finally {
            if(failed) {
                VFSUtils.safeClose(handle);
            }
        }
    }
    final ResourceRoot resourceRoot = new ResourceRoot(deploymentRoot, mountHandle);
    ModuleRootMarker.mark(resourceRoot);
    deploymentUnit.putAttachment(Attachments.DEPLOYMENT_ROOT, resourceRoot);
    deploymentUnit.putAttachment(Attachments.MODULE_SPECIFICATION, new ModuleSpecification());
}
 
示例16
@Override
public VirtualFile getValue() throws IllegalStateException, IllegalArgumentException {
    return VFS.getChild(resolvePath());
}
 
示例17
protected MountHandle extractArchive(File archive, TempFileProvider tempFileProvider) throws IOException {
    return ((MountHandle)VFS.mountZipExpanded(archive, VFS.getChild("cli"), tempFileProvider));
}
 
示例18
static MountHandle extractArchive(File archive,
        TempFileProvider tempFileProvider, String name) throws IOException {
    return ((MountHandle) VFS.mountZipExpanded(archive, VFS.getChild(name),
            tempFileProvider));
}