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] Use null safe-messages #2497

Merged
merged 26 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6cc61ba
WIP Use null safe-messages
mpkorstanje Mar 8, 2022
a0489a8
WIP Use null safe-messages
mpkorstanje Mar 8, 2022
a7fea9f
WIP Use null safe-messages
mpkorstanje Mar 8, 2022
22bcfc4
WIP Use null safe-messages
mpkorstanje Mar 8, 2022
a1f14f9
WIP Use null safe-messages
mpkorstanje Mar 31, 2022
2474231
WIP Use null safe-messages
mpkorstanje Apr 1, 2022
33719bb
WIP Use null safe-messages
mpkorstanje Apr 2, 2022
0ee339d
WIP Use null safe-messages
mpkorstanje Apr 3, 2022
43d9503
WIP Use null safe-messages
mpkorstanje Apr 3, 2022
94c6a9d
WIP Use null safe-messages
mpkorstanje Apr 3, 2022
cff5006
WIP Use null safe-messages
mpkorstanje Apr 3, 2022
21a8ea5
WIP Use null safe-messages
mpkorstanje Apr 3, 2022
90c572c
WIP Use null safe-messages
mpkorstanje Apr 3, 2022
227f0ed
WIP Use null safe-messages
mpkorstanje Apr 3, 2022
c3eedd1
WIP Use null safe-messages
mpkorstanje Apr 3, 2022
2d05077
Merge remote-tracking branch 'origin/main' into use-null-safe-messages
mpkorstanje Apr 3, 2022
f4d9109
Merge remote-tracking branch 'origin/main' into use-null-safe-messages
mpkorstanje Apr 10, 2022
5e2b2fb
Fix version
mpkorstanje Apr 17, 2022
3344cc8
Clean up
mpkorstanje Apr 17, 2022
305dd55
Clean up
mpkorstanje Apr 17, 2022
56b1511
Clean up
mpkorstanje Apr 17, 2022
b377da2
Merge remote-tracking branch 'origin/main' into use-null-safe-messages
mpkorstanje Apr 17, 2022
c2d21a8
Some revapi
mpkorstanje Apr 17, 2022
43123b2
Fix some revapi
mpkorstanje Apr 18, 2022
13893c1
Update changelog
mpkorstanje Apr 18, 2022
20f1f9d
Tests
mpkorstanje Apr 18, 2022
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
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<ci-environment.version>9.0.4</ci-environment.version>
<cucumber-expressions.version>15.0.2</cucumber-expressions.version>
<datatable.version>4.1.0</datatable.version>
<html-formatter.version>18.0.0</html-formatter.version>
<html-formatter.version>19.0.1-SNAPSHOT</html-formatter.version>
mpkorstanje marked this conversation as resolved.
Show resolved Hide resolved
<tag-expressions.version>4.1.0</tag-expressions.version>
</properties>

Expand Down
96 changes: 58 additions & 38 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<properties>
<project.Automatic-Module-Name>io.cucumber.core</project.Automatic-Module-Name>
<apiguardian-api.version>1.1.2</apiguardian-api.version>
<jackson-databind.version>2.13.2.2</jackson-databind.version>
<jackson-databind.version>2.13.2.20220328</jackson-databind.version>
<jsoup.version>1.14.3</jsoup.version>
<junit-jupiter.version>5.8.2</junit-jupiter.version>
<xmlunit.version>2.9.0</xmlunit.version>
Expand All @@ -41,6 +41,13 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>${jackson-databind.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -90,6 +97,14 @@
<artifactId>apiguardian-api</artifactId>
<version>${apiguardian-api.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
</dependency>

<dependency>
<groupId>org.xmlunit</groupId>
Expand Down Expand Up @@ -131,42 +146,12 @@
<artifactId>vertx-web</artifactId>
<version>${vertx.version}</version>
<scope>test</scope>
<exclusions>
<!-- Fix dependency convergence -->
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-junit5</artifactId>
<version>${vertx.version}</version>
<scope>test</scope>
<exclusions>
<!-- Fix dependency convergence -->
<exclusion>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
</exclusion>
<exclusion>
<groupId>org.reactivestreams</groupId>
<artifactId>reactive-streams</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Fix dependency convergence -->
<dependency>
Expand Down Expand Up @@ -199,13 +184,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind.version}</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -263,13 +241,21 @@
<artifactSet>
<includes>
<include>io.cucumber:gherkin</include>
<include>com.fasterxml.jackson.core:jackson-databind</include>
<include>com.fasterxml.jackson.core:jackson-core</include>
<include>com.fasterxml.jackson.core:jackson-annotations</include>
<include>com.fasterxml.jackson.datatype:jackson-datatype-jdk8</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>gherkin</pattern>
<shadedPattern>io.cucumber.core.internal.gherkin</shadedPattern>
</relocation>
<relocation>
<pattern>com.fasterxml</pattern>
<shadedPattern>io.cucumber.core.internal.com.fasterxml</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
Expand All @@ -278,6 +264,40 @@
<exclude>META-INF/MANIFEST.MF</exclude>
</excludes>
</filter>
<filter>
<artifact>com.fasterxml.jackson.core:jackson-databind</artifact>
<excludes>
<exclude>**/module-info.class</exclude>
<exclude>META-INF/MANIFEST.MF</exclude>
<exclude>META-INF/LICENSE</exclude>
<exclude>META-INF/NOTICE</exclude>
</excludes>
</filter>
<filter>
<artifact>com.fasterxml.jackson.core:jackson-core</artifact>
<excludes>
<exclude>**/module-info.class</exclude>
<exclude>META-INF/MANIFEST.MF</exclude>
<exclude>META-INF/LICENSE</exclude>
<exclude>META-INF/NOTICE</exclude>
</excludes>
</filter>
<filter>
<artifact>com.fasterxml.jackson.core:jackson-annotations</artifact>
<excludes>
<exclude>**/module-info.class</exclude>
<exclude>META-INF/MANIFEST.MF</exclude>
<exclude>META-INF/LICENSE</exclude>
</excludes>
</filter>
<filter>
<artifact>com.fasterxml.jackson.datatype:jackson-datatype-jdk8</artifact>
<excludes>
<exclude>**/module-info.class</exclude>
<exclude>META-INF/MANIFEST.MF</exclude>
<exclude>META-INF/LICENSE</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import io.cucumber.core.logging.Logger;
import io.cucumber.core.logging.LoggerFactory;
import io.cucumber.datatable.DataTable;
import io.cucumber.datatable.DataTableFormatter;
import io.cucumber.gherkin.GherkinDialect;
import io.cucumber.gherkin.GherkinDialectProvider;
import io.cucumber.gherkin.IGherkinDialectProvider;
import io.cucumber.tagexpressions.TagExpressionParser;

import java.io.BufferedReader;
Expand Down Expand Up @@ -198,7 +198,7 @@ private String removeArgFor(String arg, List<String> args) {
}

private byte printI18n(String language) {
IGherkinDialectProvider dialectProvider = new GherkinDialectProvider();
GherkinDialectProvider dialectProvider = new GherkinDialectProvider();
List<String> languages = dialectProvider.getLanguages();

if (language.equalsIgnoreCase("help")) {
Expand Down Expand Up @@ -233,7 +233,7 @@ private String loadUsageText() {
BufferedReader br = new BufferedReader(new InputStreamReader(usageResourceStream, UTF_8))) {
return br.lines().collect(joining(System.lineSeparator()));
} catch (Exception e) {
return "Could not load usage text: " + e.toString();
return "Could not load usage text: " + e;
}
}

Expand Down Expand Up @@ -271,8 +271,11 @@ private byte printKeywordsFor(GherkinDialect dialect) {
addCodeKeywordRow(table, "then", dialect.getThenKeywords());
addCodeKeywordRow(table, "and", dialect.getAndKeywords());
addCodeKeywordRow(table, "but", dialect.getButKeywords());
DataTable.create(table).print(builder);
out.println(builder.toString());
DataTableFormatter.builder()
.prefixRow(" ")
.build()
.formatTo(DataTable.create(table), builder);
out.println(builder);
return 0x0;
}

Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/io/cucumber/core/plugin/HtmlFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public final class HtmlFormatter implements ConcurrentEventListener {

@SuppressWarnings("WeakerAccess") // Used by PluginFactory
public HtmlFormatter(OutputStream out) throws IOException {
this.writer = new MessagesToHtmlWriter(new UTF8OutputStreamWriter(out));
this.writer = new MessagesToHtmlWriter(out, Jackson.OBJECT_MAPPER::writeValue);
}

@Override
Expand All @@ -25,7 +25,8 @@ public void setEventPublisher(EventPublisher publisher) {
private void write(Envelope event) {
// Workaround to reduce the size of the report
// See: https://github.com/cucumber/cucumber/issues/1232
if (event.getStepDefinition() != null || event.getHook() != null || event.getParameterType() != null) {
if (event.getStepDefinition().isPresent() || event.getHook().isPresent()
|| event.getParameterType().isPresent()) {
return;
}

Expand All @@ -37,7 +38,7 @@ private void write(Envelope event) {

// TODO: Plugins should implement the closable interface
// and be closed by Cucumber
if (event.getTestRunFinished() != null) {
if (event.getTestRunFinished().isPresent()) {
try {
writer.close();
} catch (IOException e) {
Expand Down
27 changes: 27 additions & 0 deletions core/src/main/java/io/cucumber/core/plugin/Jackson.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.cucumber.core.plugin;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.cfg.ConstructorDetector;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;

final class Jackson {
public static final ObjectMapper OBJECT_MAPPER = JsonMapper.builder()
.addModule(new Jdk8Module())
.serializationInclusion(Include.NON_ABSENT)
.constructorDetector(ConstructorDetector.USE_PROPERTIES_BASED)
.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING)
.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING)
.enable(DeserializationFeature.USE_LONG_FOR_INTS)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET)
.build();

private Jackson() {
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.cucumber.core.plugin;

import io.cucumber.messages.JSON;
import io.cucumber.messages.types.Background;
import io.cucumber.messages.types.Feature;
import io.cucumber.messages.types.Scenario;
Expand Down Expand Up @@ -145,7 +144,7 @@ private void finishReport(TestRunFinished event) {
}

try {
JSON.writeValue(writer, featureMaps);
Jackson.OBJECT_MAPPER.writeValue(writer, featureMaps);
writer.close();
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.cucumber.core.plugin;

import io.cucumber.messages.JSON;
import io.cucumber.messages.types.Envelope;
import io.cucumber.plugin.ConcurrentEventListener;
import io.cucumber.plugin.event.EventPublisher;
Expand All @@ -24,10 +23,10 @@ public void setEventPublisher(EventPublisher publisher) {

private void writeMessage(Envelope envelope) {
try {
JSON.writeValue(writer, envelope);
Jackson.OBJECT_MAPPER.writeValue(writer, envelope);
writer.write("\n");
writer.flush();
if (envelope.getTestRunFinished() != null) {
if (envelope.getTestRunFinished().isPresent()) {
writer.close();
}
} catch (IOException e) {
Expand Down
Loading