Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Deprecate Formatter interface #1407

Merged
merged 7 commits into from
Jul 27, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import cucumber.api.Result;
import cucumber.api.TestCase;
import cucumber.api.event.EventHandler;
import cucumber.api.event.EventListener;
import cucumber.api.event.EventPublisher;
import cucumber.api.event.TestCaseFinished;
import cucumber.api.event.TestCaseStarted;
import cucumber.api.event.TestSourceRead;
import cucumber.api.event.TestStepFinished;
import cucumber.api.formatter.Formatter;
import cucumber.runtime.UndefinedStepsTracker;
import cucumber.runtime.Utils;

Expand Down Expand Up @@ -41,7 +41,7 @@
* hook threw an exception other than an {@link AssertionError}</li>
* </ul>
*/
public final class AndroidInstrumentationReporter implements Formatter {
public final class AndroidInstrumentationReporter implements EventListener {

/**
* Tests status keys.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import android.util.Log;
import cucumber.api.PickleStepTestStep;
import cucumber.api.event.EventHandler;
import cucumber.api.event.EventListener;
import cucumber.api.event.EventPublisher;
import cucumber.api.event.TestCaseStarted;
import cucumber.api.event.TestRunFinished;
import cucumber.api.event.TestStepStarted;
import cucumber.api.formatter.Formatter;
import cucumber.runtime.UndefinedStepsTracker;

/**
* Logs information about the currently executed statements to androids logcat.
*/
public final class AndroidLogcatReporter implements Formatter {
public final class AndroidLogcatReporter implements EventListener {

/**
* The log tag to be used when logging to logcat.
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/cucumber/api/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* <ul>
* <li>{@link cucumber.api.StepDefinitionReporter}</li>
* <li>{@link cucumber.api.SummaryPrinter}</li>
* <li>{@link cucumber.api.formatter.Formatter}</li>
* </ul>
* <p>
* Plugins are added to the runtime from the command line or @{@link CucumberOptions} and may be provided with a
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/cucumber/api/event/EventListener.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package cucumber.api.event;

import cucumber.api.Plugin;

/**
* This is the interface you should implement if your plugin listens to cucumber execution events
*/
public interface EventListener {
public interface EventListener extends Plugin {

/**
* Set the event publisher. The formatter can register event listeners with the publisher.
* Set the event publisher. The plugin can register event listeners with the publisher.
*
* @param publisher the event publisher
*/
Expand Down
10 changes: 6 additions & 4 deletions core/src/main/java/cucumber/api/formatter/ColorAware.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package cucumber.api.formatter;

import cucumber.api.Plugin;

/**
* Interface for Formatters that use ANSI escape codes to print coloured output.
* Interface for Plugins that use ANSI escape codes to print coloured output.
*/
public interface ColorAware extends Formatter {
public interface ColorAware extends Plugin {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\o/

/**
* When set to monochrome the formatter should not use colored output.
* When set to monochrome the plugin should not use colored output.
* <p>
* For the benefit of systems that do not support ANSI escape codes.
*
* @param monochrome true iff monochrome output should be used
* @param monochrome true if monochrome output should be used
*/
void setMonochrome(boolean monochrome);
}
8 changes: 3 additions & 5 deletions core/src/main/java/cucumber/api/formatter/Formatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import cucumber.api.event.EventListener;

/**
* This is the interface you should implement if you want your own custom
* formatter.
*
* @see EventListener
* @see Plugin
* @deprecated as of version 4.0.0; use {@link EventListener } and {@link Plugin } instead.
* Optionally, use {@link ColorAware } and/or {@link StrictAware } instead of {@link Plugin }.
*/
@Deprecated
public interface Formatter extends EventListener, Plugin {
}
10 changes: 6 additions & 4 deletions core/src/main/java/cucumber/api/formatter/StrictAware.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package cucumber.api.formatter;

import cucumber.api.Plugin;

/**
* Interface for Formatters that need to know if the Runtime is strict.
* Interface for Plugins that need to know if the Runtime is strict.
*/
public interface StrictAware extends Formatter {
public interface StrictAware extends Plugin {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it would be a good idea for all marker interfaces to extend from Plugin?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean; did I miss anything?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EventListner I believe

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EventListener is not a marker interface; it has a method: void setEventPublisher(EventPublisher publisher);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one.

Would it be a good idea to make EventListener extend from Plugin?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. (Updated)

/**
* When set to strict the formatter should indicate failure for undefined and pending steps
* When set to strict the plugin should indicate failure for undefined and pending steps
*
* @param strict true iff the runtime is in strict mode
* @param strict true if the runtime is in strict mode
*/
void setStrict(boolean strict);
}
3 changes: 1 addition & 2 deletions core/src/main/java/cucumber/runtime/RuntimeOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -343,7 +342,7 @@ public void addPluginName(String name, boolean isAddPlugin) {
stepDefinitionReporterNames.addName(name, isAddPlugin);
} else if (PluginFactory.isSummaryPrinterName(name)) {
summaryPrinterNames.addName(name, isAddPlugin);
} else if (PluginFactory.isFormatterName(name)) {
} else if (PluginFactory.isPluginName(name)) {
formatterNames.addName(name, isAddPlugin);
} else {
throw new CucumberException("Unrecognized plugin: " + name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ private void addPlugins(CucumberOptions options, List<String> args) {
for (String plugin : plugins) {
args.add("--plugin");
args.add(plugin);
if (PluginFactory.isFormatterName(plugin)) {
pluginSpecified = true;
}
pluginSpecified = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package cucumber.runtime.formatter;

import cucumber.api.HookTestStep;
import cucumber.api.PickleStepTestStep;
import cucumber.api.Result;
import cucumber.api.TestCase;
import cucumber.api.PickleStepTestStep;
import cucumber.api.event.EmbedEvent;
import cucumber.api.event.EventHandler;
import cucumber.api.event.EventListener;
import cucumber.api.event.EventPublisher;
import cucumber.api.event.TestCaseStarted;
import cucumber.api.event.TestRunFinished;
import cucumber.api.event.TestSourceRead;
import cucumber.api.event.TestStepFinished;
import cucumber.api.event.TestStepStarted;
import cucumber.api.event.WriteEvent;
import cucumber.api.formatter.Formatter;
import cucumber.api.formatter.NiceAppendable;
import cucumber.runtime.CucumberException;
import cucumber.runtime.io.URLOutputStream;
Expand Down Expand Up @@ -50,7 +50,7 @@
import java.util.List;
import java.util.Map;

final class HTMLFormatter implements Formatter {
final class HTMLFormatter implements EventListener {
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
private static final String JS_FORMATTER_VAR = "formatter";
private static final String JS_REPORT_FILENAME = "report.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

import cucumber.api.HookTestStep;
import cucumber.api.HookType;
import cucumber.api.PickleStepTestStep;
import cucumber.api.Result;
import cucumber.api.TestStep;
import cucumber.api.TestCase;
import cucumber.api.PickleStepTestStep;
import cucumber.api.TestStep;
import cucumber.api.event.EmbedEvent;
import cucumber.api.event.EventHandler;
import cucumber.api.event.EventListener;
import cucumber.api.event.EventPublisher;
import cucumber.api.event.TestCaseStarted;
import cucumber.api.event.TestRunFinished;
import cucumber.api.event.TestSourceRead;
import cucumber.api.event.TestStepFinished;
import cucumber.api.event.TestStepStarted;
import cucumber.api.event.WriteEvent;
import cucumber.api.formatter.Formatter;
import cucumber.api.formatter.NiceAppendable;
import gherkin.ast.Background;
import gherkin.ast.DocString;
Expand All @@ -37,7 +37,7 @@
import java.util.List;
import java.util.Map;

final class JSONFormatter implements Formatter {
final class JSONFormatter implements EventListener {
private String currentFeatureFile;
private List<Map<String, Object>> featureMaps = new ArrayList<Map<String, Object>>();
private List<Map<String, Object>> currentElementsList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package cucumber.runtime.formatter;

import cucumber.api.Result;
import cucumber.api.PickleStepTestStep;
import cucumber.api.Result;
import cucumber.api.event.EventHandler;
import cucumber.api.event.EventListener;
import cucumber.api.event.EventPublisher;
import cucumber.api.event.TestCaseFinished;
import cucumber.api.event.TestCaseStarted;
import cucumber.api.event.TestRunFinished;
import cucumber.api.event.TestSourceRead;
import cucumber.api.event.TestStepFinished;
import cucumber.api.formatter.Formatter;
import cucumber.api.formatter.StrictAware;
import cucumber.runtime.CucumberException;
import cucumber.runtime.Utils;
Expand Down Expand Up @@ -39,7 +39,7 @@
import java.util.List;
import java.util.Locale;

final class JUnitFormatter implements Formatter, StrictAware {
final class JUnitFormatter implements EventListener, StrictAware {
private final Writer out;
private final Document doc;
private final Element rootElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cucumber.runtime.formatter;

import cucumber.api.event.EventListener;
import cucumber.api.event.EventPublisher;
import cucumber.api.formatter.Formatter;

final class NullFormatter implements Formatter {
final class NullFormatter implements EventListener {
public NullFormatter() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import cucumber.api.Plugin;
import cucumber.api.StepDefinitionReporter;
import cucumber.api.SummaryPrinter;
import cucumber.api.formatter.Formatter;
import cucumber.api.event.EventListener;
import cucumber.runtime.CucumberException;
import cucumber.runtime.io.URLOutputStream;
import cucumber.runtime.io.UTF8OutputStreamWriter;
Expand Down Expand Up @@ -195,9 +195,9 @@ private Appendable defaultOutOrFailIfAlreadyUsed(String formatterString) {
}
}

public static boolean isFormatterName(String name) {
public static boolean isPluginName(String name) {
Class pluginClass = getPluginClass(name);
return Formatter.class.isAssignableFrom(pluginClass);
return EventListener.class.isAssignableFrom(pluginClass);
}

public static boolean isStepDefinitionReporterName(String name) {
Expand Down
6 changes: 2 additions & 4 deletions core/src/main/java/cucumber/runtime/formatter/Plugins.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
import cucumber.api.StepDefinitionReporter;
import cucumber.api.event.EventListener;
import cucumber.api.formatter.ColorAware;
import cucumber.api.formatter.Formatter;
import cucumber.api.formatter.StrictAware;
import cucumber.runner.EventBus;
import cucumber.runtime.RuntimeOptions;
import cucumber.runtime.Utils;
import cucumber.runtime.formatter.PluginFactory;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -89,8 +87,8 @@ private void setStrictOnStrictAwarePlugins(Object plugin) {

private void setEventBusOnEventListenerPlugins(Object plugin) {
if (plugin instanceof EventListener && bus != null) {
Formatter formatter = (Formatter) plugin;
formatter.setEventPublisher(bus);
EventListener eventListener = (EventListener) plugin;
eventListener.setEventPublisher(bus);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package cucumber.runtime.formatter;

import cucumber.api.Argument;
import cucumber.api.PickleStepTestStep;
import cucumber.api.Result;
import cucumber.api.TestStep;
import cucumber.api.TestCase;
import cucumber.api.PickleStepTestStep;
import cucumber.api.TestStep;
import cucumber.api.event.EventHandler;
import cucumber.api.event.EventListener;
import cucumber.api.event.EventPublisher;
import cucumber.api.event.TestCaseStarted;
import cucumber.api.event.TestRunFinished;
Expand All @@ -14,7 +15,6 @@
import cucumber.api.event.TestStepStarted;
import cucumber.api.event.WriteEvent;
import cucumber.api.formatter.ColorAware;
import cucumber.api.formatter.Formatter;
import cucumber.api.formatter.NiceAppendable;
import cucumber.util.FixJava;
import cucumber.util.Mapper;
Expand All @@ -29,7 +29,7 @@

import java.util.List;

final class PrettyFormatter implements Formatter, ColorAware {
final class PrettyFormatter implements EventListener, ColorAware {
private static final String SCENARIO_INDENT = " ";
private static final String STEP_INDENT = " ";
private static final String EXAMPLES_INDENT = " ";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package cucumber.runtime.formatter;

import cucumber.api.Result;
import cucumber.api.PickleStepTestStep;
import cucumber.api.Result;
import cucumber.api.event.EventHandler;
import cucumber.api.event.EventListener;
import cucumber.api.event.EventPublisher;
import cucumber.api.event.TestRunFinished;
import cucumber.api.event.TestStepFinished;
import cucumber.api.event.WriteEvent;
import cucumber.api.formatter.AnsiEscapes;
import cucumber.api.formatter.ColorAware;
import cucumber.api.formatter.Formatter;
import cucumber.api.formatter.NiceAppendable;

import java.util.HashMap;
import java.util.Map;

final class ProgressFormatter implements Formatter, ColorAware {
final class ProgressFormatter implements EventListener, ColorAware {
private static final Map<Result.Type, Character> CHARS = new HashMap<Result.Type, Character>() {{
put(Result.Type.PASSED, '.');
put(Result.Type.UNDEFINED, 'U');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import cucumber.api.TestCase;
import cucumber.api.event.EventHandler;
import cucumber.api.event.EventListener;
import cucumber.api.event.EventPublisher;
import cucumber.api.event.TestCaseFinished;
import cucumber.api.event.TestRunFinished;
import cucumber.api.formatter.Formatter;
import cucumber.api.formatter.NiceAppendable;
import cucumber.api.formatter.StrictAware;

Expand All @@ -19,7 +19,7 @@
* Formatter for reporting all failed test cases and print their locations
* Failed means: results that make the exit code non-zero.
*/
final class RerunFormatter implements Formatter, StrictAware {
final class RerunFormatter implements EventListener, StrictAware {
private final NiceAppendable out;
private Map<String, ArrayList<Integer>> featureAndFailedLinesMapping = new HashMap<String, ArrayList<Integer>>();
private boolean isStrict = false;
Expand Down
Loading