Skip to content

Commit

Permalink
[Core] Implement TeamCity output format plugin
Browse files Browse the repository at this point in the history
This plugin inserts markers that can be picked up by IDEA and
Teamcity. These in turn can then use this information to display a
test tree and show the output grouped by scenario.

This is plugin is nessesary because Intelij keeps using reflection
to extract more information from the plugin system then what would
normally be available. By substituting the CucumberJvm[1-5]SMFormatter
with this plugin we avoid runtime errors.

Unfortunately the teamcity format is poorly documented[1]. Reverse
engingeering[2][3] the format from the plugin yields some information
but the exact function is rather opaque.

1. https://confluence.jetbrains.com/display/TCD9/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-MessageFlowId
2. https://github.com/JetBrains/intellij-community/tree/master/plugins/cucumber-jvm-formatter5/src/org/jetbrains/plugins/cucumber/java/run
3. https://github.com/mpkorstanje/intellij-community/blob/master/plugins/cucumber-jvm-formatter/src/org/jetbrains/plugins/cucumber/java/run
  • Loading branch information
mpkorstanje committed Dec 14, 2019
1 parent de3f234 commit c6c8360
Show file tree
Hide file tree
Showing 19 changed files with 629 additions and 69 deletions.
18 changes: 10 additions & 8 deletions core/src/main/java/io/cucumber/core/options/PluginOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.cucumber.core.plugin.PrettyFormatter;
import io.cucumber.core.plugin.ProgressFormatter;
import io.cucumber.core.plugin.RerunFormatter;
import io.cucumber.core.plugin.TeamCityPlugin;
import io.cucumber.core.plugin.TestNGFormatter;
import io.cucumber.core.plugin.TimelineFormatter;
import io.cucumber.core.plugin.UnusedStepsSummaryPrinter;
Expand Down Expand Up @@ -44,15 +45,16 @@ public class PluginOption implements Options.Plugin {
put("timeline", TimelineFormatter.class);
put("unused", UnusedStepsSummaryPrinter.class);
put("usage", UsageFormatter.class);
put("teamcity", UsageFormatter.class);
}};

// Refuse plugins known to implement the old API
private static final HashMap<String, Class<? extends Plugin>> OLD_INTELLIJ_IDEA_PLUGIN_CLASSES = new HashMap<String, Class<? extends Plugin>>() {{
put("org.jetbrains.plugins.cucumber.java.run.CucumberJvmSMFormatter", PrettyFormatter.class);
put("org.jetbrains.plugins.cucumber.java.run.CucumberJvm2SMFormatter", PrettyFormatter.class);
put("org.jetbrains.plugins.cucumber.java.run.CucumberJvm3SMFormatter", PrettyFormatter.class);
put("org.jetbrains.plugins.cucumber.java.run.CucumberJvm4SMFormatter", PrettyFormatter.class);
put("org.jetbrains.plugins.cucumber.java.run.CucumberJvm5SMFormatter", PrettyFormatter.class);
private static final HashMap<String, Class<? extends Plugin>> INCOMPATIBLE_INTELLIJ_IDEA_PLUGIN_CLASSES = new HashMap<String, Class<? extends Plugin>>() {{
put("org.jetbrains.plugins.cucumber.java.run.CucumberJvmSMFormatter", TeamCityPlugin.class);
put("org.jetbrains.plugins.cucumber.java.run.CucumberJvm2SMFormatter", TeamCityPlugin.class);
put("org.jetbrains.plugins.cucumber.java.run.CucumberJvm3SMFormatter", TeamCityPlugin.class);
put("org.jetbrains.plugins.cucumber.java.run.CucumberJvm4SMFormatter", TeamCityPlugin.class);
put("org.jetbrains.plugins.cucumber.java.run.CucumberJvm5SMFormatter", TeamCityPlugin.class);
}};

private final String pluginString;
Expand All @@ -76,9 +78,9 @@ public static PluginOption parse(String pluginArgumentPattern) {
}

private static Class<? extends Plugin> parsePluginName(String pluginName) {
Class<? extends Plugin> oldApiPlugin = OLD_INTELLIJ_IDEA_PLUGIN_CLASSES.get(pluginName);
Class<? extends Plugin> oldApiPlugin = INCOMPATIBLE_INTELLIJ_IDEA_PLUGIN_CLASSES.get(pluginName);
if (oldApiPlugin != null) {
log.warn(() -> "Incompatible IntelliJ IDEA Plugin detected. Falling back to pretty formatter");
log.debug(() -> "Incompatible IntelliJ IDEA Plugin detected. Falling back to teamcity plugin");
return oldApiPlugin;
}

Expand Down
Loading

0 comments on commit c6c8360

Please sign in to comment.