li.rudin.mavenjs.plugin.TestMojo Maven / Gradle / Ivy
package li.rudin.mavenjs.plugin;
import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId;
import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration;
import static org.twdata.maven.mojoexecutor.MojoExecutor.element;
import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo;
import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment;
import static org.twdata.maven.mojoexecutor.MojoExecutor.goal;
import static org.twdata.maven.mojoexecutor.MojoExecutor.groupId;
import static org.twdata.maven.mojoexecutor.MojoExecutor.name;
import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin;
import static org.twdata.maven.mojoexecutor.MojoExecutor.version;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import li.rudin.mavenjs.plugin.util.DirCopyVisitor;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
@Mojo(requiresDependencyResolution=ResolutionScope.TEST, defaultPhase=LifecyclePhase.TEST, name="test")
public class TestMojo extends AbstractMavenjsMojo
{
/**
* Maven js build dir
*/
@Parameter(defaultValue="${project.build.directory}/mavenjstest") String mavenjsTestDir;
@Override
public void execute() throws MojoExecutionException, MojoFailureException
{
//https://github.com/TimMoore/mojo-executor
Log logger = getLog();
//Copy dependencies to target folder
executeMojo(
plugin(
groupId("org.apache.maven.plugins"),
artifactId("maven-dependency-plugin"),
version("2.8")
),
goal("unpack-dependencies"),
configuration(
element(name("outputDirectory"), mavenjsBuildDir),
element(name("excludes"), "**\\/*.class")
),
executionEnvironment(
project,
session,
pluginManager
)
);
try
{
//Copy main resources
if (new File(project.getBuild().getOutputDirectory()).exists())
Files.walkFileTree(Paths.get(project.getBuild().getOutputDirectory()), new DirCopyVisitor(Paths.get(mavenjsBuildDir), logger));
//Copy test resources
if (new File(project.getBuild().getTestOutputDirectory()).exists())
Files.walkFileTree(Paths.get(project.getBuild().getTestOutputDirectory()), new DirCopyVisitor(Paths.get(mavenjsTestDir), logger));
//Invoke jasmine
executeMojo(
plugin(
groupId("com.github.searls"),
artifactId("jasmine-maven-plugin"),
version("1.3.1.3")
),
goal("test"),
configuration(
element(name("jsTestSrcDir"), mavenjsTestDir + "/js"),
element(name("jsSrcDir"), mavenjsBuildDir + "/js"),
element(name("specRunnerTemplate"), "REQUIRE_JS"),
element(name("preloadSources"),
element(name("source"), "require.js")
)
// element(name("specIncludes"),
// element(name("include"), "**/*.test.js")
// )
),
executionEnvironment(
project,
session,
pluginManager
)
);
}
catch (IOException e)
{
logger.error(e);
throw new MojoFailureException("optimize", e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy