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

com.github.searls.jasmine.mojo.ReporterRetriever 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.mojo;

import com.github.searls.jasmine.model.FileSystemReporter;
import com.github.searls.jasmine.model.Reporter;
import com.google.inject.Inject;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;

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

public class ReporterRetriever {
  public static final String STANDARD_REPORTER = "/lib/buildReport.js";
  private static final String STANDARD_REPORTER_KEY = "STANDARD";

  private static final String JUNIT_XML_FILENAME = "TEST-jasmine.xml";
  private static final String JUNIT_XML_KEY = "JUNIT_XML";
  public static final String JUNIT_XML_REPORTER = "lib/createJunitXml.js";

  private final ResourceRetriever resourceRetriever;

  @Inject
  public ReporterRetriever(final ResourceRetriever resourceRetriever) {
    this.resourceRetriever = resourceRetriever;
  }

  List retrieveFileSystemReporters(final List reporters, final File targetDirectory, final MavenProject mavenProject) throws MojoExecutionException {
    if (reporters.isEmpty()) {
      reporters.add(new FileSystemReporter(JUNIT_XML_FILENAME, JUNIT_XML_KEY));
    }

    for (FileSystemReporter reporter : reporters) {
      if (JUNIT_XML_KEY.equals(reporter.reporterName)) {
        reporter.reporterName = JUNIT_XML_REPORTER;
      }
      reporter.reporterFile = getReporter(reporter.reporterName, mavenProject);
      reporter.file = new File(targetDirectory, reporter.fileName);
    }

    return reporters;
  }

  List retrieveReporters(final List reporters, final MavenProject mavenProject) throws MojoExecutionException {
    if (reporters.isEmpty()) {
      reporters.add(new Reporter(STANDARD_REPORTER_KEY));
    }

    for (Reporter reporter : reporters) {
      if (STANDARD_REPORTER_KEY.equals(reporter.reporterName)) {
        reporter.reporterName = STANDARD_REPORTER;
      }
      reporter.reporterFile = getReporter(reporter.reporterName, mavenProject);
    }

    return reporters;
  }

  private File getReporter(final String reporter, final MavenProject mavenProject) throws MojoExecutionException {
    return resourceRetriever.getResourceAsFile("reporter", reporter, mavenProject);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy