View Javadoc
1   package com.github.searls.jasmine.mojo;
2   
3   import com.github.searls.jasmine.model.FileSystemReporter;
4   import com.github.searls.jasmine.model.Reporter;
5   import com.google.inject.Inject;
6   import org.apache.maven.plugin.MojoExecutionException;
7   import org.apache.maven.project.MavenProject;
8   
9   import java.io.File;
10  import java.util.List;
11  
12  public class ReporterRetriever {
13    public static final String STANDARD_REPORTER = "/lib/buildReport.js";
14    private static final String STANDARD_REPORTER_KEY = "STANDARD";
15  
16    private static final String JUNIT_XML_FILENAME = "TEST-jasmine.xml";
17    private static final String JUNIT_XML_KEY = "JUNIT_XML";
18    public static final String JUNIT_XML_REPORTER = "lib/createJunitXml.js";
19  
20    private final ResourceRetriever resourceRetriever;
21  
22    @Inject
23    public ReporterRetriever(final ResourceRetriever resourceRetriever) {
24      this.resourceRetriever = resourceRetriever;
25    }
26  
27    List<FileSystemReporter> retrieveFileSystemReporters(final List<FileSystemReporter> reporters, final File targetDirectory, final MavenProject mavenProject) throws MojoExecutionException {
28      if (reporters.isEmpty()) {
29        reporters.add(new FileSystemReporter(JUNIT_XML_FILENAME, JUNIT_XML_KEY));
30      }
31  
32      for (FileSystemReporter reporter : reporters) {
33        if (JUNIT_XML_KEY.equals(reporter.reporterName)) {
34          reporter.reporterName = JUNIT_XML_REPORTER;
35        }
36        reporter.reporterFile = getReporter(reporter.reporterName, mavenProject);
37        reporter.file = new File(targetDirectory, reporter.fileName);
38      }
39  
40      return reporters;
41    }
42  
43    List<Reporter> retrieveReporters(final List<Reporter> reporters, final MavenProject mavenProject) throws MojoExecutionException {
44      if (reporters.isEmpty()) {
45        reporters.add(new Reporter(STANDARD_REPORTER_KEY));
46      }
47  
48      for (Reporter reporter : reporters) {
49        if (STANDARD_REPORTER_KEY.equals(reporter.reporterName)) {
50          reporter.reporterName = STANDARD_REPORTER;
51        }
52        reporter.reporterFile = getReporter(reporter.reporterName, mavenProject);
53      }
54  
55      return reporters;
56    }
57  
58    private File getReporter(final String reporter, final MavenProject mavenProject) throws MojoExecutionException {
59      return resourceRetriever.getResourceAsFile("reporter", reporter, mavenProject);
60    }
61  }