1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package searls.jasmine;
22
23 import java.io.File;
24 import java.io.IOException;
25
26 import org.apache.commons.io.FileUtils;
27 import org.apache.maven.plugin.MojoExecutionException;
28 import org.apache.maven.plugin.MojoFailureException;
29
30 import searls.jasmine.format.JasmineResultLogger;
31 import searls.jasmine.model.JasmineResult;
32 import searls.jasmine.runner.SpecRunnerExecutor;
33 import searls.jasmine.runner.SpecRunnerHtmlGenerator;
34 import searls.jasmine.runner.SpecRunnerHtmlGenerator.ReporterType;
35
36
37
38
39
40 public class JasmineMojo extends AbstractJasmineMojo {
41
42 public void execute() throws MojoExecutionException, MojoFailureException {
43 if(!jasmineTestSourceDirectory.exists()) {
44 getLog().info("No Jasmine tests, skipping Jasmine tests execution.");
45 return;
46 }
47
48 if (skipTests)
49 {
50 getLog().warn( "Skipping Jasmine tests." );
51 return;
52 }
53
54 getLog().info("Executing Jasmine Tests");
55 JasmineResult result;
56 if(browsers == null) {
57 browsers = new String[] { "FF3.6" };
58 }
59 for(String browser : browsers) {
60 try {
61 File runnerFile = writeSpecRunnerToOutputDirectory();
62 result = new SpecRunnerExecutor().execute(runnerFile.toURI().toURL(),browser);
63 } catch (Exception e) {
64 throw new MojoExecutionException("There was a problem executing Jasmine specs",e);
65 }
66 logResults(result,browser);
67 if(!testFailureIgnore && !result.didPass()) {
68 throw new MojoFailureException("There were Jasmine spec failures.");
69 }
70 }
71 }
72
73 private void logResults(JasmineResult result, String browser) {
74 JasmineResultLogger resultLogger = new JasmineResultLogger();
75 resultLogger.setBrowser(browser);
76 resultLogger.setLog(getLog());
77 resultLogger.log(result);
78 }
79
80 private File writeSpecRunnerToOutputDirectory() throws IOException {
81 SpecRunnerHtmlGenerator htmlGenerator = new SpecRunnerHtmlGenerator(preloadSources,new File(jasmineTargetDir,srcDirectoryName),new File(
82 jasmineTargetDir,specDirectoryName),new File(jasmineTargetDir,libsDirectory), jasmineTargetDir);
83 String html = htmlGenerator.generate(pluginArtifacts, ReporterType.JsApiReporter);
84
85 getLog().debug("Writing out Spec Runner HTML " + html + " to directory " + jasmineTargetDir);
86 File runnerFile = new File(jasmineTargetDir,specRunnerHtmlFileName);
87 FileUtils.writeStringToFile(runnerFile, html);
88 return runnerFile;
89 }
90
91 }