Package de.matrixweb.vfs

Examples of de.matrixweb.vfs.VFile


      } catch (final IOException e) {
        throw new SmallerException("Failed to merge files", e);
      }
    }

    final VFile snapshot = vfs.stack();
    try {
      final VFile file = vfs.find(resource.getPath());
      VFSUtils.write(file, resource.getContents());
      return resource.getResolver().resolve(file.getPath());
    } catch (final IOException e) {
      vfs.rollback(snapshot);
      throw e;
    }
  }
View Full Code Here


    }

    final ResourceGroup group = (ResourceGroup) resource;
    final Resource input = group.getResources().get(0);

    final VFile snapshot = vfs.stack();
    try {
      final VFile target = vfs.find(input.getPath());
      final Writer writer = VFSUtils.createWriter(target);
      try {
        writer.write(group.getMerger().merge(group.getResources()));
      } finally {
        IOUtils.closeQuietly(writer);
      }
      return input.getResolver().resolve(target.getPath());
    } catch (final IOException e) {
      vfs.rollback(snapshot);
      throw e;
    }
  }
View Full Code Here

   * @return Returns a file path into the {@link VFS} to the temp file
   * @throws IOException
   */
  public String getMergedJsonFile(final VFS vfs,
      final ResourceResolver resolver, final String in) throws IOException {
    final VFile file = vfs.find("/__temp__json__input");
    final List<Resource> resources = getJsonSourceFiles(resolver.resolve(in));

    // Hack which tries to replace all non-js sources with js sources in case of
    // mixed json-input file
    boolean foundJs = false;
    boolean foundNonJs = false;
    for (final Resource resource : resources) {
      foundJs |= FilenameUtils.isExtension(resource.getPath(), "js");
      foundNonJs |= !FilenameUtils.isExtension(resource.getPath(), "js");
    }
    if (foundJs && foundNonJs) {
      for (int i = 0, n = resources.size(); i < n; i++) {
        final Resource resource = resources.get(i);
        if (!FilenameUtils.isExtension(resource.getPath(), "js")) {
          final Resource jsResource = resource.getResolver().resolve(
              FilenameUtils.getName(FilenameUtils.removeExtension(resource
                  .getPath()) + ".js"));
          resources.add(resources.indexOf(resource), jsResource);
          resources.remove(resource);
        }
      }
    }

    VFSUtils.write(file, merge(resources));
    return file.getPath();
  }
View Full Code Here

   * @throws IOException
   */
  public static Resource process(final VFS vfs, final Resource input,
      final String sourceType, final String resultType,
      final ProcessorCallback callback) throws IOException {
    final VFile snapshot = vfs.stack();
    try {
      final VFile source = vfs.find(input.getPath());
      final VFile target = vfs.find(FilenameUtils.removeExtension(input
          .getPath()) + "." + resultType);
      VFSUtils.pipe(source, target, new Pipe() {
        @Override
        public void exec(final Reader reader, final Writer writer)
            throws IOException {
          callback.call(reader, writer);
        }
      });
      if (target.exists()) {
        LOGGER.warn("Return processed result '{}'", target);
      } else {
        LOGGER.warn("Processing result '{}' does not exists", target);
      }
      return input.getResolver().resolve(target.getPath());
    } catch (final IOException e) {
      vfs.rollback(snapshot);
      throw e;
    }
  }
View Full Code Here

   */
  public static Resource processAllFilesOfType(final VFS vfs,
      final Resource resource, final String sourceType,
      final String resultType, final ProcessorCallback callback)
      throws IOException {
    final VFile snapshot = vfs.stack();
    try {
      // For all '.<sourceType>' files...
      for (final VFile file : ResourceUtil.getFilesByExtension(vfs, sourceType)) {
        final VFile target = vfs.find(FilenameUtils.removeExtension(file
            .getPath()) + "." + resultType);

        // ... call <processorCallback>
        VFSUtils.pipe(file, target, new Pipe() {
          @Override
View Full Code Here

      final Task task) throws IOException {
    final Resources resources = new Resources();
    for (final String out : task.getOut()) {
      LOGGER.info("Preparing output file: {}", out);
      final String ext = FilenameUtils.getExtension(out);
      final VFile file = findLastModified(vfs.find("/"), ext);
      if (file != null) {
        final VFile target = vfs.find('/' + out);
        LOGGER.info("Copy '{}' -> '{}'", file, target);
        VFSUtils.copy(file, target);
        resources.addResource(resolver.resolve(target.getPath()));
      }
    }
    return new Result(resources);
  }
View Full Code Here

    return new Result(resources);
  }

  private VFile findLastModified(final VFile file, final String ext)
      throws IOException {
    VFile newest = null;
    if (file.isDirectory()) {
      for (final VFile child : file.getChildren()) {
        final VFile temp = findLastModified(child, ext);
        if (newest == null || temp != null
            && temp.getLastModified() > newest.getLastModified()) {
          newest = temp;
        }
      }
    } else if (ext.equals(FilenameUtils.getExtension(file.getName()))) {
      newest = file;
View Full Code Here

      }
    }
    final String outfile = this.node.run(vfs,
        resource != null ? resource.getPath() : null, options);
    if (outfile != null) {
      final VFile file = vfs.find('/' + outfile);
      if (!file.exists()) {
        throw new SmallerException("BrowserifyProcessor result does not exists");
      }
    }
    return resource == null || outfile == null ? resource : resource
        .getResolver().resolve('/' + outfile);
View Full Code Here

        this.node = null;
        throw new SmallerException("Failed to setup node for uglify", e);
      }
    }

    final VFile infile = vfs.find(resource.getPath());
    if (!infile.exists()) {
      throw new SmallerException("Uglify input '" + infile
          + "' does not exists");
    }

    final String resultPath = this.node.run(vfs, resource.getPath(), options);
    final VFile outfile = vfs.find('/' + resultPath);
    if (!outfile.exists()) {
      throw new SmallerException("Uglify result '" + outfile
          + "' does not exists");
    }
    return resource.getResolver().resolve(outfile.getPath());
  }
View Full Code Here

TOP

Related Classes of de.matrixweb.vfs.VFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.