/** * Check if the resource was changed from previous run. The implementation uses resource content * digest (hash) to check for change. * * @param resource the {@link Resource} to check. * @return true if the resource was changed. */ private boolean isChanged(final Resource resource, final String groupName) { LOG.debug("Check change for resource {}", resource.getUri()); try { final String uri = resource.getUri(); // using AtomicBoolean because we need to mutate this variable inside an anonymous class. final AtomicBoolean changeDetected = new AtomicBoolean(getResourceChangeDetector().checkChangeForGroup(uri, groupName)); if (!changeDetected.get() && resource.getType() == ResourceType.CSS) { final Reader reader = new InputStreamReader(locatorFactory.locate(uri)); LOG.debug("Check @import directive from {}", resource); createCssImportProcessor(changeDetected, groupName) .process(resource, reader, new StringWriter()); } return changeDetected.get(); } catch (final IOException e) { LOG.debug( "[FAIL] Cannot check {} resource (Exception message: {}). Assuming it is unchanged...", resource, e.getMessage()); return false; } }
/** {@inheritDoc} */ @Override protected void doContribution( final Group group, final ModelAndView modelAndView, final Map<String, Group> additionalGroups) throws IOException { String bundle = group.getName(); Map<String, Object> model = modelAndView.getModel(); StringBuilder buffer = new StringBuilder(); if (useCache()) { buffer.append(script("/bundle/" + bundle + ".js?v=" + version)); } else { List<Resource> candidates = group.getResources(); List<Resource> resources = new ArrayList<Resource>(); for (Resource resource : candidates) { if (resource.getType() == ResourceType.JS) { buffer.append(script(resource.getUri())); resources.add(resource); } } model.put(resourcesVarName(), resources); } // 2. Publish as a model attribute. model.put(varName(), buffer.toString()); logger.trace("Publishing {}:\n{}", varName(), buffer); }