com.github.searls.jasmine.io.scripts.ContextPathScriptResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jasmine-maven-plugin Show documentation
Show all versions of jasmine-maven-plugin Show documentation
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
package com.github.searls.jasmine.io.scripts;
import java.util.LinkedHashSet;
import java.util.Set;
public class ContextPathScriptResolver implements ScriptResolver {
private final ScriptResolver scriptResolver;
private final String baseContextPath;
private final String sourceContextPath;
private final String specContextPath;
public ContextPathScriptResolver(ScriptResolver scriptResolver,
String sourceContextPath,
String specContextPath) {
this(scriptResolver, "", sourceContextPath, specContextPath);
}
public ContextPathScriptResolver(ScriptResolver scriptResolver,
String baseContextPath,
String sourceContextPath,
String specContextPath) {
this.scriptResolver = scriptResolver;
this.baseContextPath = baseContextPath;
this.sourceContextPath = sourceContextPath;
this.specContextPath = specContextPath;
}
@Override
public String getSourceDirectory() {
return this.sourceContextPath;
}
@Override
public String getSpecDirectory() {
return this.specContextPath;
}
@Override
public String getBaseDirectory() {
return this.baseContextPath;
}
@Override
public Set getSources() throws ScriptResolverException {
return relativeToContextPath(
this.scriptResolver.getSourceDirectory(),
this.sourceContextPath,
this.scriptResolver.getSources());
}
@Override
public Set getSpecs() throws ScriptResolverException {
return relativeToContextPath(
this.scriptResolver.getSpecDirectory(),
this.specContextPath,
this.scriptResolver.getSpecs());
}
@Override
public Set getPreloads() throws ScriptResolverException {
Set scripts = this.scriptResolver.getPreloads();
scripts = relativeToContextPath(
this.scriptResolver.getSourceDirectory(),
this.sourceContextPath,
scripts);
scripts = relativeToContextPath(
this.scriptResolver.getSpecDirectory(),
this.specContextPath,
scripts);
scripts = relativeToContextPath(
this.scriptResolver.getBaseDirectory(),
this.baseContextPath,
scripts);
return scripts;
}
@Override
public Set getAllScripts() throws ScriptResolverException {
LinkedHashSet allScripts = new LinkedHashSet();
allScripts.addAll(this.getPreloads());
allScripts.addAll(this.getSources());
allScripts.addAll(this.getSpecs());
return allScripts;
}
private Set relativeToContextPath(String realPath, String contextPath, Set absoluteScripts) {
Set relativeScripts = new LinkedHashSet();
for (String absoluteScript : absoluteScripts) {
relativeScripts.add(absoluteScript.replace(realPath, contextPath));
}
return relativeScripts;
}
}