本文整理汇总了Java中org.webjars.WebJarAssetLocator类的典型用法代码示例。如果您正苦于以下问题:Java WebJarAssetLocator类的具体用法?Java WebJarAssetLocator怎么用?Java WebJarAssetLocator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebJarAssetLocator类属于org.webjars包,在下文中一共展示了WebJarAssetLocator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveURL
import org.webjars.WebJarAssetLocator; //导入依赖的package包/类
private void resolveURL() {
try {
upgradeReadLockToWriteLock();
if (!urlResolved) {
String path = getPath();
if (path.startsWith(WebJarAssetLocator.WEBJARS_PATH_PREFIX)) {
url = classLoader.getResource(path);
validateURL(url);
}
urlResolved = true;
}
} finally {
downgradeWriteLockToReadLock();
}
}
示例2: HumptyBootstrap
import org.webjars.WebJarAssetLocator; //导入依赖的package包/类
public HumptyBootstrap(Configuration configuration, Object... resources) {
this.configuration = configuration;
this.resources = resources;
this.humptyOptions = configuration.getOptionsFor(this);
this.pipelineElements = loadPipelineElements();
this.bundleResolvers = getElements(BundleResolver.class, getConfiguration("bundleResolvers"));
this.resolvers = getElements(Resolver.class, Optional.empty());
this.sourceProcessors = getElements(SourceProcessor.class, getConfiguration("sources"));
this.assetProcessors = getElements(AssetProcessor.class, getConfiguration("assets"));
this.bundleProcessors = getElements(BundleProcessor.class, getConfiguration("bundles"));
this.pipelineListeners = getElements(PipelineListener.class, getConfiguration("listeners"));
this.locator = Arrays.stream(resources)
.filter(resource -> resource instanceof WebJarAssetLocator)
.map(resource -> (WebJarAssetLocator) resource)
.findFirst()
.orElseGet(this::getDefaultLocator);
this.pipeline = new Pipeline(bundleResolvers, resolvers, sourceProcessors, assetProcessors, bundleProcessors, pipelineListeners);
bundleResolvers.forEach(this::inject);
resolvers.forEach(this::inject);
sourceProcessors.forEach(this::inject);
assetProcessors.forEach(this::inject);
bundleProcessors.forEach(this::inject);
pipelineListeners.forEach(this::inject);
}
示例3: inject
import org.webjars.WebJarAssetLocator; //导入依赖的package包/类
private void inject(PipelineElement element) {
Stream.of(element.getClass().getMethods())
.filter(m -> m.isAnnotationPresent(Inject.class))
.forEach(method -> {
Class<?>[] parameterTypes = method.getParameterTypes();
Object[] args = new Object[parameterTypes.length];
for (int i = 0; i < parameterTypes.length; i++) {
Class<?> parameterType = parameterTypes[i];
if (parameterType == Pipeline.class) {
args[i] = pipeline;
} else if (parameterType == WebJarAssetLocator.class) {
args[i] = locator;
} else if (parameterType == Configuration.class) {
args[i] = configuration;
} else if (parameterType == Configuration.Options.class) {
args[i] = configuration.getOptionsFor(element);
} else if (parameterType == Configuration.GlobalOptions.class) {
args[i] = configuration.getGlobalOptions();
} else {
args[i] = getExtra(parameterType).orElseThrow(() -> new IllegalArgumentException("Cannot inject the type " + parameterType.getName() + " into " + element.getClass().getName()));
}
}
try {
method.invoke(element, args);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
示例4: getDefaultLocator
import org.webjars.WebJarAssetLocator; //导入依赖的package包/类
private WebJarAssetLocator getDefaultLocator() {
try {
String assetsDir = configuration.getGlobalOptions().getAssetsDir().toString();
Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(assetsDir);
if (!assetsDir.startsWith("/")) {
assetsDir = "/" + assetsDir;
}
if (!assetsDir.endsWith("/")) {
assetsDir += "/";
}
String fullAssetsDir = assetsDir;
Set<String> assetPaths = new HashSet<>();
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
Files.walk(Paths.get(url.getFile()))
.filter(path -> path.toFile().isFile())
.map(Path::toString)
.map(path -> path.substring(path.indexOf(fullAssetsDir) + 1))
.forEach(assetPaths::add);
}
assetPaths.addAll(new WebJarAssetLocator().getFullPathIndex().values());
return new WebJarAssetLocator(assetPaths);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例5: should_not_provide_minified_asset_when_preferMin_is_false
import org.webjars.WebJarAssetLocator; //导入依赖的package包/类
@Test
public void should_not_provide_minified_asset_when_preferMin_is_false() throws Exception {
HashMap<String, Object> options = new HashMap<String, Object>();
options.put("preferMin", Boolean.FALSE);
resolver.configure(new WebJarAssetLocator(), new Configuration.Options(options));
Context context = new Context(Configuration.Mode.PRODUCTION, libs);
List<String> assetFilePaths = resolver.resolve("jquery.js", context).stream().map(AssetFile::getPath).collect(toList());
assetFilePaths.addAll(resolver.resolve("web_server.js", context).stream().map(AssetFile::getPath).collect(toList()));
assertThat(assetFilePaths, contains("META-INF/resources/webjars/jquery/2.1.1/jquery.js", "META-INF/resources/webjars/humpty/1.0.0/web_server.js"));
}
示例6: createFromRequestPath
import org.webjars.WebJarAssetLocator; //导入依赖的package包/类
public Resource createFromRequestPath(final String path) {
return new WebjarsResource(WebJarAssetLocator.WEBJARS_PATH_PREFIX + "/" + path, assetPathResolver, classLoader);
}
示例7: createAsset
import org.webjars.WebJarAssetLocator; //导入依赖的package包/类
@Override
public Asset createAsset(final Resource resource) {
return createAsset(resource, "webjars",
((WebjarsResource) resource).getPath().substring(WebJarAssetLocator.WEBJARS_PATH_PREFIX.length() + 1));
}
示例8: AssetPathResolverImpl
import org.webjars.WebJarAssetLocator; //导入依赖的package包/类
public AssetPathResolverImpl(final WebJarAssetLocator webJarAssetLocator, final LoggerSource loggerSource) {
this.webJarAssetLocator = webJarAssetLocator;
this.logger = loggerSource.getLogger(AssetPathResolverImpl.class);
this.webjars = Collections.unmodifiableMap(webJarAssetLocator.getWebJars());
}
示例9: buildWebJarAssetLocator
import org.webjars.WebJarAssetLocator; //导入依赖的package包/类
@EagerLoad
public static WebJarAssetLocator buildWebJarAssetLocator() {
SortedMap<String, String> pathIndex = WebJarAssetLocator.getFullPathIndex(Pattern.compile(".*"),
Thread.currentThread().getContextClassLoader());
return new WebJarAssetLocator(pathIndex);
}
示例10: build
import org.webjars.WebJarAssetLocator; //导入依赖的package包/类
public static AssetPathResolver build(final WebJarAssetLocator webJarAssetLocator, final LoggerSource loggerSource) {
return new AssetPathResolverImpl(webJarAssetLocator, loggerSource);
}
示例11: configure
import org.webjars.WebJarAssetLocator; //导入依赖的package包/类
@Inject
public void configure(Configuration configuration, WebJarAssetLocator locator) {
this.locator = locator;
this.bundles = configuration.getBundles();
}
示例12: configure
import org.webjars.WebJarAssetLocator; //导入依赖的package包/类
@Inject
public void configure(WebJarAssetLocator webJarAssetLocator, Configuration.Options options) {
this.webJarAssetLocator = webJarAssetLocator;
this.preferMin = options.get("preferMin");
}
示例13: should_find_source_maps
import org.webjars.WebJarAssetLocator; //导入依赖的package包/类
@Test
public void should_find_source_maps() throws Exception {
String sourceMap = pipeline.process("jquery.min.map").getAsset();
assertEquals(IOUtils.toString(getClass().getClassLoader().getResourceAsStream(new WebJarAssetLocator().getFullPath("jquery.min.map"))), sourceMap.trim());
}
示例14: should_find_loose_webjar
import org.webjars.WebJarAssetLocator; //导入依赖的package包/类
@Test
public void should_find_loose_webjar() throws Exception {
String jquery = pipeline.process("jquery.min.js").getAsset();
assertEquals(IOUtils.toString(getClass().getClassLoader().getResourceAsStream(new WebJarAssetLocator().getFullPath("jquery.min.js"))).trim(), jquery.trim());
}
示例15: should_reject_existing_bundle
import org.webjars.WebJarAssetLocator; //导入依赖的package包/类
public void should_reject_existing_bundle() {
WebJarAssetBundleResolver resolver = new WebJarAssetBundleResolver();
resolver.configure(Configuration.load("/humpty-special-bundles.toml"), new WebJarAssetLocator());
assertFalse(resolver.accepts("asset.js"));
}