All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.searls.jasmine.thirdpartylibs.WebJarResourceHandler Maven / Gradle / Ivy

Go to download

A JavaScript unit test plugin that processes JavaScript sources and Jasmine specs, prepares test runner HTML files, executes Jasmine specs headlessly with HtmlUnit, and produces JUnit XML reports

There is a newer version: 3.0-beta-02
Show newest version
package com.github.searls.jasmine.thirdpartylibs;

import org.webjars.WebJarAssetLocator;

import java.io.InputStream;
import java.util.SortedMap;
import java.util.regex.Pattern;

import static org.webjars.WebJarAssetLocator.getFullPathIndex;

public class WebJarResourceHandler extends AbstractThirdPartyLibsResourceHandler {

  private final WebJarAssetLocator webJarAssetLocator;
  private final ClassLoader projectClassLoader;

  public WebJarResourceHandler(ClassLoader projectClassLoader) {
    this.projectClassLoader = projectClassLoader;
    webJarAssetLocator = createWebJarAssetLocator();
  }

  @Override
  protected InputStream findResource(String resourcePath) {
    String fullPath;
    try {
      fullPath = webJarAssetLocator.getFullPath(resourcePath);
    } catch (Exception ignoreToRespondWith404) {
      return null;
    }
    return projectClassLoader.getResourceAsStream(fullPath);
  }

  private WebJarAssetLocator createWebJarAssetLocator() {
    SortedMap fullPathIndex = getFullPathIndex(Pattern.compile(".*"), projectClassLoader);
    return new WebJarAssetLocator(fullPathIndex);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy