org.jboss.vfs.VFS Java Examples

The following examples show how to use org.jboss.vfs.VFS. 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: 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 #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: 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 #4
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 #5
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 #6
Source File: MountedDeploymentOverlay.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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);
    }
}
 
Example #7
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 #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: SyncModelServerStateTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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);
    }
}
 
Example #10
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 #11
Source File: SwarmContentRepository.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #12
Source File: DeploymentRootMountProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
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());
}
 
Example #13
Source File: ContentRepositoryImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public VirtualFile getContent(byte[] hash) {
    Assert.checkNotNullParam("hash", hash);
    return VFS.getChild(getDeploymentContentFile(hash, true).toUri());
}
 
Example #14
Source File: PathContentServitor.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public VirtualFile getValue() throws IllegalStateException, IllegalArgumentException {
    return VFS.getChild(resolvePath());
}
 
Example #15
Source File: DeploymentHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected MountHandle extractArchive(File archive, TempFileProvider tempFileProvider) throws IOException {
    return ((MountHandle)VFS.mountZipExpanded(archive, VFS.getChild("cli"), tempFileProvider));
}
 
Example #16
Source File: DeployArchiveCommand.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
static MountHandle extractArchive(File archive,
        TempFileProvider tempFileProvider, String name) throws IOException {
    return ((MountHandle) VFS.mountZipExpanded(archive, VFS.getChild(name),
            tempFileProvider));
}
 
Example #17
Source File: SwarmContentRepository.java    From thorntail with Apache License 2.0 4 votes vote down vote up
public void removeAllContent() throws IOException {
    for (URI uri : this.index.values()) {
        VirtualFile file = VFS.getChild(uri);
        file.delete();
    }
}
 
Example #18
Source File: SwarmContentRepository.java    From thorntail with Apache License 2.0 4 votes vote down vote up
@Override
public VirtualFile getContent(byte[] sha1Bytes) {
    String key = toKey(sha1Bytes);
    VirtualFile result = VFS.getChild(this.index.get(key));
    return result;
}