private Map<String, Object> addVersionToOptions( final Map<String, Object> options, final Version version) { options.put("version", version.toString()); return options; }
private Version getVersion(final Map<String, Object> options) { final Object value = options.get("version"); return value == null ? Version.UNDEFINED : Version.getVersion(value .toString()); }
/** * @param str * @return Return the given str as {@link Version} of {@link #UNDEFINED} if * not parsable. */ public static Version getVersion(final String str) { try { final String[] parts = str.split("\\."); final String ver = "_" + parts[0] + "_" + parts[1] + "_" + parts[2]; return valueOf(ver); } catch (final Exception e) { // In any error case return undefined } return UNDEFINED; }
/** * @param version * The spec version to execute * @param resolver * The {@link ResourceResolver} to use for resource resolving * @param task * The input {@link Task} * @return Returns the resolved input resources * @throws IOException */ public static Resources createResourceGroup(final Version version, final ResourceResolver resolver, final Task task) throws IOException { if (version.isAtLeast(Version._1_0_0)) { // Since version 1.1.0 no multi-resources return createResourceGroupImpl0(resolver, new SourceMerger(GlobalOptions.isSourceOnce(task)), new ArrayList<String>(Arrays.asList(task.getIn()))); } return createResourceGroup(resolver, task); }
/** * @param host * @param port * @param proxyhost * @param proxyport * @param bytes * @return the response as {@link InputStream} * @throws ExecutionException */ public byte[] send(final String host, final String port, final String proxyhost, final String proxyport, final byte[] bytes) throws ExecutionException { try { final Request request = Request.Post("http://" + host + ":" + port) .socketTimeout(0).connectTimeout(0); if (proxyhost != null && proxyport != null) { request.viaProxy(new HttpHost(proxyhost, Integer.valueOf(proxyport))); } final HttpResponse response = request .addHeader(Version.HEADER, Version.getCurrentVersion().toString()) .bodyByteArray(bytes).execute().returnResponse(); return handleResponse(response); } catch (final Exception e) { if (e instanceof SmallerException) { throw (SmallerException) e; } throw new ExecutionException("Failed to send zip file", e); } }
/** * @param version * The {@link Version} to compare this to * @return Returns true if this {@link Version} is at least the given * {@link Version}, false otherwise */ public boolean isAtLeast(final Version version) { final List<Version> versions = Arrays.asList(Version.values()); return versions.indexOf(this) >= versions.indexOf(version); }
@Deprecated private Result execute(final Version version, final VFS vfs, final ResourceResolver resolver, final Resources resources, final Task task) { try { validate(task); final List<ProcessorOptions> entries = setupProcessors(version, task); if (version.isAtLeast(Version._1_0_0)) { execute1_0(vfs, resolver, resources, entries, task); } else { execute0_0(vfs, resources, entries); } LOGGER.info("Finished executing pipeline"); return prepareResult(vfs, resolver, task); } catch (final IOException e) { throw new SmallerException("Failed to run processor chain", e); } }
/** * @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; } }
/** * This is a migration method for global to processor options. Currently used * by the merge-processor which gets the 'source:once' option from the global * scope. */ private Map<String, Object> injectGlobalOptionsFallback( final Version version, final Manifest manifest, final String name, final Map<String, Object> options) { final Map<String, Object> copy = new HashMap<String, Object>(options); copy.put("version", version.toString()); if (manifest != null) { if ("merge".equals(name)) { copy.put("source", GlobalOptions.isSourceOnce(manifest) ? "once" : ""); } } return copy; }