Skip to content

Commit dfde4e4

Browse files
committed
Use Java 17
1 parent 523f195 commit dfde4e4

File tree

8 files changed

+167
-84
lines changed

8 files changed

+167
-84
lines changed

java/.mvn/jvm.config

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
2+
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
3+
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
4+
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
5+
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
6+
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
7+
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
8+
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
9+
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
10+
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED

java/pom.xml

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.cucumber</groupId>
77
<artifactId>cucumber-parent</artifactId>
8-
<version>4.5.0</version>
8+
<version>5.0.0-SNAPSHOT</version>
99
</parent>
1010

1111
<artifactId>html-formatter</artifactId>
@@ -44,14 +44,28 @@
4444
<type>pom</type>
4545
<scope>import</scope>
4646
</dependency>
47+
48+
<dependency>
49+
<groupId>org.assertj</groupId>
50+
<artifactId>assertj-bom</artifactId>
51+
<version>3.27.6</version>
52+
<type>pom</type>
53+
<scope>import</scope>
54+
</dependency>
4755
</dependencies>
4856
</dependencyManagement>
4957

5058
<dependencies>
59+
<dependency>
60+
<groupId>org.jspecify</groupId>
61+
<artifactId>jspecify</artifactId>
62+
<version>1.0.0</version>
63+
</dependency>
64+
5165
<dependency>
5266
<groupId>io.cucumber</groupId>
5367
<artifactId>messages</artifactId>
54-
<version>[18.0.0,31.0.0)</version>
68+
<version>[31.0.0-SNAPSHOT,32.0.0)</version>
5569
</dependency>
5670

5771
<dependency>
@@ -73,9 +87,8 @@
7387
</dependency>
7488

7589
<dependency>
76-
<groupId>org.hamcrest</groupId>
77-
<artifactId>hamcrest</artifactId>
78-
<version>3.0</version>
90+
<groupId>org.assertj</groupId>
91+
<artifactId>assertj-core</artifactId>
7992
<scope>test</scope>
8093
</dependency>
8194

@@ -85,4 +98,22 @@
8598
<scope>test</scope>
8699
</dependency>
87100
</dependencies>
101+
102+
<build>
103+
<plugins>
104+
<plugin>
105+
<groupId>org.apache.maven.plugins</groupId>
106+
<artifactId>maven-checkstyle-plugin</artifactId>
107+
<executions>
108+
<execution>
109+
<id>validate</id>
110+
<phase>validate</phase>
111+
<goals>
112+
<goal>check</goal>
113+
</goals>
114+
</execution>
115+
</executions>
116+
</plugin>
117+
</plugins>
118+
</build>
88119
</project>

java/src/main/java/io/cucumber/htmlformatter/JsonInHtmlWriter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package io.cucumber.htmlformatter;
22

3+
import org.jspecify.annotations.Nullable;
4+
35
import java.io.IOException;
46
import java.io.Writer;
7+
import java.util.Objects;
58

69
/**
710
* Writes json with the forward slash ({@code /}) escaped. Assumes
@@ -10,10 +13,10 @@
1013
class JsonInHtmlWriter extends Writer {
1114
private static final int BUFFER_SIZE = 1024;
1215
private final Writer delegate;
13-
private char[] escapeBuffer;
16+
private char @Nullable[] escapeBuffer;
1417

1518
JsonInHtmlWriter(Writer delegate) {
16-
this.delegate = delegate;
19+
this.delegate = Objects.requireNonNull(delegate);
1720
}
1821

1922
@Override

java/src/main/java/io/cucumber/htmlformatter/MessagesToHtmlWriter.java

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.cucumber.htmlformatter;
22

33
import io.cucumber.messages.types.Envelope;
4+
import org.jspecify.annotations.Nullable;
45

56
import java.io.BufferedReader;
67
import java.io.BufferedWriter;
@@ -39,20 +40,6 @@ public final class MessagesToHtmlWriter implements AutoCloseable {
3940
private boolean firstMessageWritten = false;
4041
private boolean streamClosed = false;
4142

42-
@Deprecated
43-
public MessagesToHtmlWriter(OutputStream outputStream, Serializer serializer) throws IOException {
44-
this(
45-
createWriter(outputStream),
46-
requireNonNull(serializer),
47-
() -> createInputStream("Cucumber"),
48-
() -> getResource("icon.url"),
49-
() -> getResource("main.css"),
50-
MessagesToHtmlWriter::createEmptyInputStream,
51-
() -> getResource("main.js"),
52-
MessagesToHtmlWriter::createEmptyInputStream
53-
);
54-
}
55-
5643
private MessagesToHtmlWriter(
5744
OutputStreamWriter writer,
5845
Serializer serializer,
@@ -88,7 +75,7 @@ private static String readTemplate() {
8875
InputStream resource = getResource("index.mustache.html");
8976
writeResource(writer, resource);
9077
}
91-
return new String(baos.toByteArray(), UTF_8);
78+
return baos.toString(UTF_8);
9279
} catch (IOException e) {
9380
throw new RuntimeException("Could not read resource index.mustache.html", e);
9481
}
@@ -108,24 +95,14 @@ private static InputStream getResource(String name) {
10895
return resource;
10996
}
11097

111-
private void writePreMessage() throws IOException {
112-
writeTemplateBetween(writer, template, null, "{{title}}");
113-
writeResource(writer, title);
114-
writeTemplateBetween(writer, template, "{{title}}", "{{icon}}");
115-
writeResource(writer, icon);
116-
writeTemplateBetween(writer, template, "{{icon}}", "{{css}}");
117-
writeResource(writer, css);
118-
writeTemplateBetween(writer, template, "{{css}}", "{{custom_css}}");
119-
writeResource(writer, customCss);
120-
writeTemplateBetween(writer, template, "{{custom_css}}", "{{messages}}");
121-
}
122-
123-
private void writePostMessage() throws IOException {
124-
writeTemplateBetween(writer, template, "{{messages}}", "{{script}}");
125-
writeResource(writer, script);
126-
writeTemplateBetween(writer, template, "{{script}}", "{{custom_script}}");
127-
writeResource(writer, customScript);
128-
writeTemplateBetween(writer, template, "{{custom_script}}", null);
98+
/**
99+
* Creates a builder to construct this writer.
100+
*
101+
* @param serializer used to convert messages into json.
102+
* @return a new builder
103+
*/
104+
public static Builder builder(Serializer serializer) {
105+
return new Builder(serializer);
129106
}
130107

131108
/**
@@ -153,6 +130,18 @@ public void write(Envelope envelope) throws IOException {
153130
serializer.writeValue(jsonInHtmlWriter, envelope);
154131
}
155132

133+
private void writePreMessage() throws IOException {
134+
writeTemplateBetween(writer, template, null, "{{title}}");
135+
writeResource(writer, title);
136+
writeTemplateBetween(writer, template, "{{title}}", "{{icon}}");
137+
writeResource(writer, icon);
138+
writeTemplateBetween(writer, template, "{{icon}}", "{{css}}");
139+
writeResource(writer, css);
140+
writeTemplateBetween(writer, template, "{{css}}", "{{custom_css}}");
141+
writeResource(writer, customCss);
142+
writeTemplateBetween(writer, template, "{{custom_css}}", "{{messages}}");
143+
}
144+
156145
/**
157146
* Closes the stream, flushing it first. Once closed further write()
158147
* invocations will cause an IOException to be thrown. Closing a closed
@@ -183,7 +172,15 @@ public void close() throws IOException {
183172
}
184173
}
185174

186-
private static void writeTemplateBetween(Writer writer, String template, String begin, String end)
175+
private void writePostMessage() throws IOException {
176+
writeTemplateBetween(writer, template, "{{messages}}", "{{script}}");
177+
writeResource(writer, script);
178+
writeTemplateBetween(writer, template, "{{script}}", "{{custom_script}}");
179+
writeResource(writer, customScript);
180+
writeTemplateBetween(writer, template, "{{custom_script}}", null);
181+
}
182+
183+
private static void writeTemplateBetween(Writer writer, String template, @Nullable String begin, @Nullable String end)
187184
throws IOException {
188185
int beginIndex = begin == null ? 0 : template.indexOf(begin) + begin.length();
189186
int endIndex = end == null ? template.length() : template.indexOf(end);
@@ -229,16 +226,6 @@ public interface Serializer {
229226

230227
}
231228

232-
/**
233-
* Creates a builder to construct this writer.
234-
*
235-
* @param serializer used to convert messages into json.
236-
* @return a new builder
237-
*/
238-
public static Builder builder(Serializer serializer) {
239-
return new Builder(serializer);
240-
}
241-
242229
public static final class Builder {
243230
private final Serializer serializer;
244231
private Supplier<InputStream> title = () -> createInputStream("Cucumber");
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@NullMarked
2+
package io.cucumber.htmlformatter;
3+
4+
import org.jspecify.annotations.NullMarked;

java/src/test/java/io/cucumber/htmlformatter/Jackson.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.cucumber.htmlformatter;
22

33
import com.fasterxml.jackson.annotation.JsonCreator.Mode;
4-
import com.fasterxml.jackson.annotation.JsonInclude.Include;
54
import com.fasterxml.jackson.core.JsonGenerator;
65
import com.fasterxml.jackson.databind.DeserializationFeature;
76
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -11,11 +10,14 @@
1110
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
1211
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
1312

13+
import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_ABSENT;
14+
import static com.fasterxml.jackson.annotation.JsonInclude.Value.construct;
15+
1416
final class Jackson {
1517
public static final ObjectMapper OBJECT_MAPPER = JsonMapper.builder()
1618
.addModule(new Jdk8Module())
1719
.addModule(new ParameterNamesModule(Mode.PROPERTIES))
18-
.serializationInclusion(Include.NON_ABSENT)
20+
.defaultPropertyInclusion(construct(NON_ABSENT, NON_ABSENT))
1921
.constructorDetector(ConstructorDetector.USE_PROPERTIES_BASED)
2022
.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING)
2123
.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING)

java/src/test/java/io/cucumber/htmlformatter/Main.java

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,34 @@
44
import io.cucumber.messages.NdjsonToMessageIterable;
55
import io.cucumber.messages.NdjsonToMessageIterable.Deserializer;
66
import io.cucumber.messages.types.Envelope;
7+
import org.jspecify.annotations.NullMarked;
78

89
import java.io.FileInputStream;
910
import java.io.IOException;
1011
import java.io.InputStream;
12+
import java.io.OutputStream;
1113

1214
import static io.cucumber.htmlformatter.Jackson.OBJECT_MAPPER;
1315

1416
public final class Main {
15-
private static final Deserializer deserializer = (json) -> OBJECT_MAPPER.readValue(json, Envelope.class);
17+
private static final Deserializer deserializer = json -> OBJECT_MAPPER.readValue(json, Envelope.class);
1618
private static final Serializer serializer = OBJECT_MAPPER::writeValue;
1719

20+
private Main() {
21+
// main class
22+
}
23+
1824
public static void main(String[] args) throws IOException {
19-
InputStream in = System.in;
20-
if (args.length == 1) {
25+
InputStream in;
26+
if (args.length != 1) {
27+
in = new NonClosableInputStream(System.in);
28+
} else {
2129
in = new FileInputStream(args[0]);
2230
}
2331
try (NdjsonToMessageIterable envelopes = new NdjsonToMessageIterable(in, deserializer)) {
2432
MessagesToHtmlWriter.Builder builder = MessagesToHtmlWriter.builder(serializer);
25-
try (MessagesToHtmlWriter htmlWriter = builder.build(System.out)) {
33+
OutputStream out = new NonClosableOutputStream(System.out);
34+
try (MessagesToHtmlWriter htmlWriter = builder.build(out)) {
2635
for (Envelope envelope : envelopes) {
2736
htmlWriter.write(envelope);
2837
}
@@ -33,4 +42,44 @@ public static void main(String[] args) throws IOException {
3342
System.exit(1);
3443
}
3544
}
45+
46+
@NullMarked
47+
private static class NonClosableInputStream extends InputStream {
48+
49+
private final InputStream delegate;
50+
51+
NonClosableInputStream(InputStream delegate) {
52+
this.delegate = delegate;
53+
}
54+
55+
@Override
56+
public int read() throws IOException {
57+
return delegate.read();
58+
}
59+
60+
@Override
61+
public int read(byte[] b, int off, int len) throws IOException {
62+
return delegate.read(b, off, len);
63+
}
64+
}
65+
66+
@NullMarked
67+
private static class NonClosableOutputStream extends OutputStream {
68+
69+
private final OutputStream delegate;
70+
71+
NonClosableOutputStream(OutputStream delegate) {
72+
this.delegate = delegate;
73+
}
74+
75+
@Override
76+
public void write(int b) throws IOException {
77+
delegate.write(b);
78+
}
79+
80+
@Override
81+
public void write(byte[] b, int off, int len) throws IOException {
82+
delegate.write(b, off, len);
83+
}
84+
}
3685
}

0 commit comments

Comments
 (0)