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

com.github.searls.jasmine.io.scripts.BasicScriptResolver 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.io.scripts;

import com.github.searls.jasmine.model.ScriptSearch;
import org.codehaus.plexus.util.StringUtils;

import java.io.File;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

public class BasicScriptResolver implements ScriptResolver {

  private static final ResolvesLocationOfPreloadSources RESOLVES_PRELOAD_SOURCES = new ResolvesLocationOfPreloadSources();
  private static final FindsScriptLocationsInDirectory FINDS_SCRIPT_LOCATIONS = new FindsScriptLocationsInDirectory();

  private final File baseDirectory;
  private final ScriptSearch sourceScriptSearch;
  private final ScriptSearch specScriptSearch;
  private final List preloadList;

  private Set sources;
  private Set specs;
  private Set preloads;

  public BasicScriptResolver(File baseDirectory,
                             ScriptSearch sourceScriptSearch,
                             ScriptSearch specScriptSearch,
                             List preloadList) {
    this.baseDirectory = baseDirectory;
    this.sourceScriptSearch = sourceScriptSearch;
    this.specScriptSearch = specScriptSearch;
    this.preloadList = preloadList;
    resolveScripts();
  }

  private void resolveScripts() {
    this.preloads = new LinkedHashSet(RESOLVES_PRELOAD_SOURCES.resolve(
      this.preloadList,
      this.sourceScriptSearch.getDirectory(),
      this.specScriptSearch.getDirectory()));
    this.sources = new LinkedHashSet(FINDS_SCRIPT_LOCATIONS.find(this.sourceScriptSearch));
    this.sources.removeAll(this.preloads);

    this.specs = new LinkedHashSet(FINDS_SCRIPT_LOCATIONS.find(this.specScriptSearch));
    this.specs.removeAll(this.preloads);
  }

  @Override
  public String getSourceDirectory() {
    return directoryToString(this.sourceScriptSearch.getDirectory());
  }

  @Override
  public String getSpecDirectory() {
    return directoryToString(this.specScriptSearch.getDirectory());
  }

  @Override
  public String getBaseDirectory() {
    return directoryToString(this.baseDirectory);
  }

  @Override
  public Set getSources() {
    return sources;
  }

  @Override
  public Set getSpecs() {
    return specs;
  }

  @Override
  public Set getPreloads() {
    return preloads;
  }

  @Override
  public Set getAllScripts() {
    LinkedHashSet allScripts = new LinkedHashSet();
    allScripts.addAll(this.getPreloads());
    allScripts.addAll(this.getSources());
    allScripts.addAll(this.getSpecs());
    return allScripts;
  }

  private String directoryToString(File directory) {
    return StringUtils.stripEnd(directory.toURI().toString(), "/");
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy