/** * @see de.matrixweb.smaller.resource.Resource#getPath() */ @Override public String getPath() { return this.resources.get(0).getPath(); }
/** * @see de.matrixweb.smaller.resource.Resource#getPath() */ @Override public String getPath() { return this.resources.isEmpty() ? "" : this.resources.get(0).getPath(); }
private List<String> scanResource(final Resource resource, final Map<String, Object> options) throws IOException { final List<String> results = new ArrayList<String>(); final Map<String, Object> opts = new HashMap<String, Object>(options); opts.remove("version"); final Map<String, Object> params = new HashMap<String, Object>(); params.put("source", resource.getContents()); params.put("options", opts); final StringWriter writer = new StringWriter(); this.executor .run(new StringReader(new ObjectMapper().writeValueAsString(params)), writer); final JsHintResult result = new ObjectMapper().readValue(writer.toString(), JsHintResult.class); if (result.errors != null) { for (final JsHintError error : result.errors) { results.add(resource.getPath() + " line " + error.line + ": " + error.reason + "\n\t" + error.evidence); } } return results; }
@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; }
@Override public void call(final Reader reader, final Writer writer) throws IOException { String root = resource.getPath(); final int idx = root.lastIndexOf('/'); root = root.substring(0, idx + 1); final int processorOptions = CSSURLEmbedder.DATAURI_OPTION | CSSURLEmbedder.SKIP_MISSING_OPTION; final int maxUriLength = getMaxUriLength(options); final int maxImageSize = getMaxImageSize(options); new Embedder(resource, new StringReader(resource.getContents()), processorOptions, true, maxUriLength, maxImageSize) .embedImages(writer, root); } });
command.put("indir", infolder.getAbsolutePath()); if (resource != null) { command.put("file", resource.getPath());
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())); }
boolean foundNonJs = false; for (final Resource resource : resources) { foundJs |= FilenameUtils.isExtension(resource.getPath(), "js"); foundNonJs |= !FilenameUtils.isExtension(resource.getPath(), "js"); 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);
/** * @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; } }
FilenameUtils.removeExtension(resource.getPath()) + "." + resultType) : null; } catch (final IOException e) {
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 { 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); }
/** * @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; } }
injectGlobalOptionsFallback(version, manifest, proc.getName(), proc.getOptions())); input = result == null ? null : result.getPath(); } finally { MDC.clear();