Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor logic to copy CoverageHTMLReporter-assets
Introduced ReporterOptionsAware-Interface which might be used in future
improvements
  • Loading branch information
pesse committed Mar 13, 2018
commit fef81efbd0f27697ead6886fbfbdbbffc3a0835b
20 changes: 20 additions & 0 deletions src/main/java/org/utplsql/cli/ReporterFactoryProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.utplsql.cli;

import org.utplsql.api.compatibility.CompatibilityProxy;
import org.utplsql.api.reporter.CoreReporters;
import org.utplsql.api.reporter.ReporterFactory;
import org.utplsql.cli.reporters.LocalAssetsCoverageHTMLReporter;

/** A simple class to provide a ReporterFactory for the RunCommand
*
* @author pesse
*/
public class ReporterFactoryProvider {

public static ReporterFactory createReporterFactory(CompatibilityProxy proxy ) {
ReporterFactory reporterFactory = ReporterFactory.createDefault(proxy);
reporterFactory.registerReporterFactoryMethod(CoreReporters.UT_COVERAGE_HTML_REPORTER.name(), LocalAssetsCoverageHTMLReporter::new, "Will copy all necessary assets to a folder named after the Output-File");

return reporterFactory;
}
}
12 changes: 4 additions & 8 deletions src/main/java/org/utplsql/cli/RunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
import org.utplsql.api.compatibility.CompatibilityProxy;
import org.utplsql.api.exception.SomeTestsFailedException;
import org.utplsql.api.reporter.CoreReporters;
import org.utplsql.api.reporter.CoverageHTMLReporter;
import org.utplsql.api.reporter.Reporter;
import org.utplsql.api.reporter.ReporterFactory;
import org.utplsql.cli.exception.DatabaseConnectionFailed;
import org.utplsql.cli.reporters.ReporterOptionsAware;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
Expand Down Expand Up @@ -159,7 +158,7 @@ public int run() throws Exception {

// First of all do a compatibility check and fail-fast
compatibilityProxy = checkFrameworkCompatibility(conn);
reporterFactory = ReporterFactory.createDefault(compatibilityProxy);
reporterFactory = ReporterFactoryProvider.createReporterFactory(compatibilityProxy);

reporterList = initReporters(conn, reporterOptionsList);

Expand Down Expand Up @@ -226,14 +225,11 @@ private List<Reporter> initReporters( Connection conn, List<ReporterOptions> rep
for (ReporterOptions ro : reporterOptionsList) {
Reporter reporter = reporterFactory.createReporter(ro.getReporterName());

if ( reporter instanceof ReporterOptionsAware )
((ReporterOptionsAware) reporter).setReporterOptions(ro);

reporter.init(conn, compatibilityProxy, reporterFactory);

// Quick-hack for CoverageHTML Reporter
if ( reporter instanceof CoverageHTMLReporter && ro.outputToFile() ) {
((CoverageHTMLReporter)reporter).setAssetsPath(ro.getOutputFileName()+"_assets/");
CoverageHTMLReporter.writeReportAssetsTo(Paths.get(ro.getOutputFileName()+"_assets/"));
}
ro.setReporterObj(reporter);
reporterList.add(reporter);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.utplsql.cli.reporters;

import org.utplsql.api.compatibility.CompatibilityProxy;
import org.utplsql.api.reporter.CoverageHTMLReporter;
import org.utplsql.api.reporter.Reporter;
import org.utplsql.api.reporter.ReporterFactory;
import org.utplsql.cli.ReporterOptions;

import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.SQLException;

/** Simple replacement of the CoverageHTMLReporter which writes the necessary assets to a folder
* named after the Output File's name.
*
* @author pesse
*/
public class LocalAssetsCoverageHTMLReporter extends CoverageHTMLReporter implements ReporterOptionsAware {

private ReporterOptions options;

public LocalAssetsCoverageHTMLReporter(String selfType, Object[] attributes) {
super(selfType, attributes);
}

@Override
public Reporter init(Connection con, CompatibilityProxy compatibilityProxy, ReporterFactory reporterFactory) throws SQLException {
super.init(con, compatibilityProxy, reporterFactory);

if ( options != null && options.outputToFile() )
writeReportAssetsTo(Paths.get(getAssetsPath()));

return this;
}

private void setAssetsPathFromOptions() {
if ( options != null && options.outputToFile() )
setAssetsPath(options.getOutputFileName()+"_assets/");
}

@Override
public void setReporterOptions(ReporterOptions options) {
this.options = options;
setAssetsPathFromOptions();
}

@Override
protected void setAttributes(Object[] attributes) {
super.setAttributes(attributes);
setAssetsPathFromOptions();
}
}
11 changes: 11 additions & 0 deletions src/main/java/org/utplsql/cli/reporters/ReporterOptionsAware.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.utplsql.cli.reporters;

import org.utplsql.cli.ReporterOptions;

/** Reporters implementing this interface will get their specific ReporterOptions before initialization
*
* @author pesse
*/
public interface ReporterOptionsAware {
void setReporterOptions(ReporterOptions options);
}