/** * @see de.matrixweb.smaller.resource.Resource#getResolver() */ @Override public ResourceResolver getResolver() { return this.resources.get(0).getResolver(); }
private List<Resource> getJsonSourceFiles(final Resource resource) throws IOException { final List<Resource> list = new ArrayList<Resource>(); final Set<String> alreadyHandled = new HashSet<String>(); for (final String s : new ObjectMapper().readValue(resource.getContents(), String[].class)) { if (!isUniqueFileResolved(alreadyHandled, s)) { list.add(resource.getResolver().resolve(s)); alreadyHandled.add(s); } } return list; }
private Resource executeSimpleMerge(final VFS vfs, final Resource resource, final Map<String, Object> options) throws IOException { return resource.getResolver() .resolve( new SourceMerger("once".equals(options.get("source")) ? true : false).getMergedJsonFile(vfs, resource.getResolver(), resource.getPath())); }
@Deprecated private List<Resource> getSourceFiles(final ResourceResolver resolver, final List<String> in) throws IOException { final List<Resource> inputs = new ArrayList<Resource>(); for (final String s : in) { final Resource resource = resolver.resolve(s); if (resource.getPath().endsWith("json")) { inputs.addAll(getJsonSourceFiles(resource.getResolver(), resource)); } else { inputs.add(resource); } } return inputs; }
imgurl = new URL(url); } else { Resource img = this.resource.getResolver().resolve(url); imgurl = img.getURL(); if (imgurl == null) { img = this.resource.getResolver().resolve(originalUrl); imgurl = img.getURL();
vfs.stack(); vfs.importFS(outfolder); return resultPath == null ? input : input.getResolver().resolve(resultPath); } catch (NodeJsException e) { return resource;
/** * @see de.matrixweb.smaller.resource.Processor#execute(de.matrixweb.vfs.VFS, * de.matrixweb.smaller.resource.Resource, java.util.Map) */ @Override public Resource execute(final VFS vfs, final Resource resource, final Map<String, Object> options) throws IOException { if (this.node == null) { try { this.node = new NodeJsExecutor(); this.node.setModule(getClass(), "coffeescript-" + this.version, "coffeescript.js"); } catch (final IOException e) { this.node = null; throw new SmallerException("Failed to setup node for coffeescript", e); } } final String outfile = this.node.run(vfs, resource != null ? resource.getPath() : null, options); Resource result = resource; if (resource != null) { if (outfile != null) { result = resource.getResolver().resolve(outfile); } else if (FilenameUtils.isExtension(resource.getPath(), "coffee")) { result = resource.getResolver().resolve( FilenameUtils.removeExtension(resource.getPath()) + ".js"); } } return result; }
private Resource executeComplexMerge(final VFS vfs, final Resource resource, final Map<String, Object> options) throws IOException { final Object typeOption = options.get("type"); if (!(resource instanceof ResourceGroup) || typeOption != null && resource.getType() != Type.valueOf(typeOption.toString())) { return resource; } 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; } }
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"));
return resource != null ? resource.getResolver().resolve( FilenameUtils.removeExtension(resource.getPath()) + "." + resultType) : null;
LOGGER.warn("Processing result '{}' does not exists", target); return input.getResolver().resolve(target.getPath()); } catch (final IOException e) { vfs.rollback(snapshot);
/** * @see de.matrixweb.smaller.resource.Processor#execute(de.matrixweb.vfs.VFS, * de.matrixweb.smaller.resource.Resource, java.util.Map) */ @Override public Resource execute(final VFS vfs, final Resource resource, final Map<String, Object> options) throws IOException { if (this.node == null) { try { this.node = new NodeJsExecutor(); this.node.setModule(getClass(), "sweetjs-" + this.version, null); } catch (final IOException e) { this.node = null; throw new SmallerException("Failed to setup node for sweetjs", e); } } 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("SweetjsProcessor result does not exists"); } } return resource == null || outfile == null ? resource : resource.getResolver().resolve('/' + outfile); }
/** * @see de.matrixweb.smaller.resource.Processor#execute(de.matrixweb.vfs.VFS, * de.matrixweb.smaller.resource.Resource, java.util.Map) */ @Override public Resource execute(final VFS vfs, final Resource resource, final Map<String, Object> options) throws IOException { if (this.node == null) { try { this.node = new NodeJsExecutor(); this.node.setModule(getClass(), "svgo-" + this.version, null); } catch (final IOException e) { this.node = null; throw new SmallerException("Failed to setup node for svgo", e); } } 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("SvgoProcessor result does not exists"); } } return resource == null || outfile == null ? resource : resource.getResolver().resolve('/' + outfile); }
/** * @see de.matrixweb.smaller.resource.Processor#execute(de.matrixweb.vfs.VFS, * de.matrixweb.smaller.resource.Resource, java.util.Map) */ @Override public Resource execute(final VFS vfs, final Resource resource, final Map<String, Object> options) throws IOException { if (this.node == null) { try { this.node = new NodeJsExecutor(); this.node.setModule(getClass(), "browserify-" + this.version, "browserify.js"); } catch (final IOException e) { this.node = null; throw new SmallerException("Failed to setup node for browserify", e); } } 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); }
private Resource executeWithNode(final VFS vfs, final Resource resource, final Map<String, Object> options) throws IOException { if (this.node == null) { try { this.node = new NodeJsExecutor(); this.node.setModule(getClass(), "uglifyjs-" + this.version); } catch (final IOException e) { 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()); }
/** * @see de.matrixweb.smaller.resource.Processor#execute(de.matrixweb.vfs.VFS, * de.matrixweb.smaller.resource.Resource, java.util.Map) */ @Override public Resource execute(final VFS vfs, final Resource resource, final Map<String, Object> options) throws IOException { // Version 1.0.0 handling if (getVersion(options).isAtLeast(Version._1_0_0)) { try { if (!(resource instanceof ResourceGroup) && resource != null && FilenameUtils.isExtension(resource.getPath(), "json")) { return executeSimpleMerge(vfs, resource, options); } return executeComplexMerge(vfs, resource, options); } 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; } }