/** * 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() + "/"; }
/** * 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()); }
/** * 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(); }
/** * 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); } }
/** * Install 2 default collector instances: (FileAssetPathCollector(WEBJARS_PATH_PREFIX), JarAssetPathCollector), * and a webjars resource finder. * * <p> * Factored out for easy (informal) pluggability. * </p> */ protected void configureWebJars() { IWebjarsSettings settings = new WebjarsSettings(); WicketWebjars.install(this, settings); }
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; }
public WebSphereWebjarsSettings() { super(); // WebSphere needs a trailing slash to list resources with ClassLoader#getResources(String) webjarsPath(webjarsPath() + "/"); //Adding custom AssetPathCollector AssetPathCollector[] webSphereAssetPathCollectors = new AssetPathCollector[] { new WebSphereClasspathAssetPathCollector(), new VfsAssetPathCollector(), new FileAssetPathCollector(webjarsPath()) }; assetPathCollectors(webSphereAssetPathCollectors); } }
/** * 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; }
/** * Construct. */ public WebjarsSettings() { this.resourceStreamProvider = ResourceStreamProvider.bestFitting(); this.webjarsPackage = "META-INF.resources.webjars"; this.webjarsPath = this.webjarsPackage.replace('.', '/'); this.resourcePattern = Pattern.compile("META-INF/resources/webjars/.*"); //META-INF/resources/webjars/projectname/ this.webjarsPathPattern = Pattern.compile(Helper.PATH_PREFIX + "([^\\/]*)\\/([^\\/]*)\\/(.*)"); this.recentVersionPlaceHolder = "current"; this.readFromCacheTimeout = Duration.seconds(3); this.useCdnResources = false; this.cdnUrl = DEFAULT_WEBJAR_CDN; this.assetPathCollectors = new AssetPathCollector[] { new ClasspathAssetPathCollector(), new VfsAssetPathCollector(), new FileAssetPathCollector(webjarsPath) }; }
/** * 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); } }
@Override public void init(WebApplication webApplication) { WebjarsSettings settings = new WebjarsSettings(); WicketWebjars.install(webApplication, settings); wicketEndpointRepository.add(new WicketAutoConfig.Builder(this.getClass()) .withDetail("properties", props) .build()); }
/** * 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()); }
/** * 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; }
public WebSphereWebjarsSettings() { super(); // WebSphere needs a trailing slash to list resources with ClassLoader#getResources(String) webjarsPath(webjarsPath() + "/"); //Adding custom AssetPathCollector AssetPathCollector[] webSphereAssetPathCollectors = new AssetPathCollector[] { new WebSphereClasspathAssetPathCollector(), new VfsAssetPathCollector(), new FileAssetPathCollector(webjarsPath()) }; assetPathCollectors(webSphereAssetPathCollectors); } }
/** * 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 void init(WebApplication webApplication) { WebjarsSettings settings = new WebjarsSettings(); WicketWebjars.install(webApplication, settings); wicketEndpointRepository.add(new WicketAutoConfig.Builder(this.getClass()) .withDetail("properties", props) .build()); }
@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; }
/** * https://github.com/l0rdn1kk0n/wicket-webjars/issues/22 * * Parse the version of the correct asset when there is an asset * with a similar name but with a prefix */ @Test public void correctVersion() { AssetsMap assetsMap = new AssetsMap(new WebjarsSettings()) { @Override public Set<String> listAssets(String folderPath) { Set<String> assets = new HashSet<String>(); assets.add("/webjars/realname/3.0.0/prefix.realname.js"); assets.add("/webjars/realname/2.0.0/realname.js"); return assets; } }; String versionFor = assetsMap.findRecentVersionFor("realname/current/realname.js"); assertThat(versionFor, is(equalTo("2.0.0"))); } }