/** * Construct. * * @param settings the settings to use. */ public AssetsMap(IWebjarsSettings settings) { this.settings = settings; this.collectors = settings.assetPathCollectors(); this.recentVersionPlaceHolder = settings.recentVersionPlaceHolder(); this.fullPathIndex = new TreeMap<>(); reindex(); }
public AssetsMap reindex() { final Pattern resourcePattern = settings.resourcePattern(); final ClassLoader[] classLoaders = settings.classLoaders(); final SortedMap<String, String> _fullPathIndex = createFullPathIndex(resourcePattern, classLoaders); fullPathIndex.clear(); fullPathIndex.putAll(_fullPathIndex); return this; }
/** * Construct. * * @param settings the webjars settings to use */ public WebjarsResourceFinder(IWebjarsSettings settings) { this.settings = settings; this.locator = newFullPathProvider(); this.resourceStreamProvider = settings.resourceStreamProvider().newInstance(settings.classLoaders()); int _hashCode = locator != null ? locator.hashCode() : 0; this.hashCode = 31 * (_hashCode + settings.hashCode()); }
/** * installs the webjars resource finder * * @param app the wicket application * @param settings the settings to use */ public static void install(WebApplication app, IWebjarsSettings settings) { final IWebjarsSettings existingSettings = settings(app); if (existingSettings == null) { if (settings == null) { settings = new WebjarsSettings(); } app.setMetaData(WEBJARS_SETTINGS_METADATA_KEY, settings); if (settings.useCdnResources()) { mountCDNMapper(app, settings.cdnUrl()); } final List<IResourceFinder> finders = app.getResourceSettings().getResourceFinders(); final WebjarsResourceFinder finder = new WebjarsResourceFinder(settings); if (!finders.contains(finder)) { finders.add(finder); } LOG.info("initialize wicket webjars with given settings: {}", settings); } }
/** * Return all {@link URL}s found in webjars directory, * either identifying JAR files or plain directories. */ private Set<URL> listWebjarsParentURLs(final ClassLoader[] classLoaders) { final Set<URL> urls = new HashSet<>(); final String webjarsPath = settings.webjarsPath(); for (final ClassLoader classLoader : classLoaders) { try { final Enumeration<URL> enumeration = classLoader.getResources(webjarsPath); while (enumeration.hasMoreElements()) { urls.add(enumeration.nextElement()); } } catch (IOException e) { throw new RuntimeException(e); } } return urls; }
/** * Convenience constructor that will form a locator for all resources on the current class path. */ public WebJarAssetLocator(final IWebjarsSettings settings) { this.assetMap = RecentVersionCallable.Holder.recentVersionProvider; this.recentVersionPlaceHolder = "/" + settings.recentVersionPlaceHolder() + "/"; }
@Override public String findRecentVersionFor(String path) { final String partialPath = Helper.prependWebjarsPathIfMissing(path); final Matcher partialPathMatcher = settings.webjarsPathPattern().matcher(partialPath); if (partialPathMatcher.find() && recentVersionPlaceHolder.equalsIgnoreCase(partialPathMatcher.group(2))) { final Set<String> assets = listAssets(partialPathMatcher.group(1)); final String fileName = "/" + partialPathMatcher.group(3); final List<String> versions = new ArrayList<>(); for (String asset : assets) { if (asset.endsWith(fileName)) { final Matcher matcher = settings.webjarsPathPattern().matcher(asset); if (matcher.find()) { versions.add(matcher.group(2)); } } } if (versions.size() == 1) { return versions.get(0); } else if (versions.size() > 1) { LOG.warn("more than one version of a dependency is not supported till now. webjars resource: {}; available versions: {}; using: {}", fileName, versions, versions.get(0)); return versions.get(0); } else { LOG.debug("no version found for webjars resource: {}", partialPath); } } else { LOG.trace("given webjars resource isn't a dynamic versioned one: {}", partialPath); } return null; }
/** * Construct. * * @param settings the webjars settings to use */ public WebjarsResourceFinder(IWebjarsSettings settings) { this.settings = settings; this.locator = newFullPathProvider(); this.resourceStreamProvider = settings.resourceStreamProvider().newInstance(settings.classLoaders()); int _hashCode = locator != null ? locator.hashCode() : 0; this.hashCode = 31 * (_hashCode + settings.hashCode()); }
/** * installs the webjars resource finder * * @param app the wicket application * @param settings the settings to use */ public static void install(WebApplication app, IWebjarsSettings settings) { final IWebjarsSettings existingSettings = settings(app); if (existingSettings == null) { if (settings == null) { settings = new WebjarsSettings(); } app.setMetaData(WEBJARS_SETTINGS_METADATA_KEY, settings); if (settings.useCdnResources()) { mountCDNMapper(app, settings.cdnUrl()); } final List<IResourceFinder> finders = app.getResourceSettings().getResourceFinders(); final WebjarsResourceFinder finder = new WebjarsResourceFinder(settings); if (!finders.contains(finder)) { finders.add(finder); } LOG.info("initialize wicket webjars with given settings: {}", settings); } }
/** * Return all {@link URL}s found in webjars directory, * either identifying JAR files or plain directories. */ private Set<URL> listWebjarsParentURLs(final ClassLoader[] classLoaders) { final Set<URL> urls = new HashSet<>(); final String webjarsPath = settings.webjarsPath(); for (final ClassLoader classLoader : classLoaders) { try { final Enumeration<URL> enumeration = classLoader.getResources(webjarsPath); while (enumeration.hasMoreElements()) { urls.add(enumeration.nextElement()); } } catch (IOException e) { throw new RuntimeException(e); } } return urls; }
/** * Convenience constructor that will form a locator for all resources on the current class path. */ public WebJarAssetLocator(final IWebjarsSettings settings) { this.assetMap = RecentVersionCallable.Holder.recentVersionProvider; this.recentVersionPlaceHolder = "/" + settings.recentVersionPlaceHolder() + "/"; }
@Override public String findRecentVersionFor(String path) { final String partialPath = Helper.prependWebjarsPathIfMissing(path); final Matcher partialPathMatcher = settings.webjarsPathPattern().matcher(partialPath); if (partialPathMatcher.find() && recentVersionPlaceHolder.equalsIgnoreCase(partialPathMatcher.group(2))) { final Set<String> assets = listAssets(partialPathMatcher.group(1)); final String fileName = "/" + partialPathMatcher.group(3); final List<String> versions = new ArrayList<>(); for (String asset : assets) { if (asset.endsWith(fileName)) { final Matcher matcher = settings.webjarsPathPattern().matcher(asset); if (matcher.find()) { versions.add(matcher.group(2)); } } } if (versions.size() == 1) { return versions.get(0); } else if (versions.size() > 1) { LOG.warn("more than one version of a dependency is not supported till now. webjars resource: {}; available versions: {}; using: {}", fileName, versions, versions.get(0)); return versions.get(0); } else { LOG.debug("no version found for webjars resource: {}", partialPath); } } else { LOG.trace("given webjars resource isn't a dynamic versioned one: {}", partialPath); } return null; }
/** * Construct. * * @param settings the settings to use. */ public AssetsMap(IWebjarsSettings settings) { this.settings = settings; this.collectors = settings.assetPathCollectors(); this.recentVersionPlaceHolder = settings.recentVersionPlaceHolder(); this.fullPathIndex = new TreeMap<>(); reindex(); }
public AssetsMap reindex() { final Pattern resourcePattern = settings.resourcePattern(); final ClassLoader[] classLoaders = settings.classLoaders(); final SortedMap<String, String> _fullPathIndex = createFullPathIndex(resourcePattern, classLoaders); fullPathIndex.clear(); fullPathIndex.putAll(_fullPathIndex); return this; }
@Override public Set<String> listAssets(final String folderPath) { final Collection<String> allAssets = getFullPathIndex().values(); final Set<String> assets = new HashSet<>(); final String prefix; final String webjarsPath = settings.webjarsPath(); if (webjarsPath.endsWith("/")) { prefix = webjarsPath + Helper.removeLeadingSlash(folderPath); } else { prefix = webjarsPath + Helper.appendLeadingSlash(folderPath); } for (final String asset : allAssets) { if (asset.startsWith(prefix)) { assets.add(asset); } } return assets; }
@Override public Set<String> listAssets(final String folderPath) { final Collection<String> allAssets = getFullPathIndex().values(); final Set<String> assets = new HashSet<>(); final String prefix; final String webjarsPath = settings.webjarsPath(); if (webjarsPath.endsWith("/")) { prefix = webjarsPath + Helper.removeLeadingSlash(folderPath); } else { prefix = webjarsPath + Helper.appendLeadingSlash(folderPath); } for (final String asset : allAssets) { if (asset.startsWith(prefix)) { assets.add(asset); } } return assets; }