Skip to content

Commit 256be5f

Browse files
authored
Merge pull request #23 from reportportal/develop
Release
2 parents 464fd5c + 850857f commit 256be5f

25 files changed

+97
-342
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ jobs:
3535
- name: Checkout repository
3636
uses: actions/checkout@v4
3737

38-
- name: Set up JDK 1.8
38+
- name: Set up JDK 11
3939
uses: actions/setup-java@v4
4040
with:
4141
distribution: 'temurin'
42-
java-version: '8'
42+
java-version: '11'
4343

4444
- name: Build with Gradle
4545
run: ./gradlew build

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ jobs:
4747
version-file: ${{ env.VERSION_FILE }}
4848
version-file-extraction-pattern: ${{ env.VERSION_EXTRACT_PATTERN }}
4949

50-
- name: Set up JDK 1.8
50+
- name: Set up JDK 11
5151
uses: actions/setup-java@v4
5252
with:
5353
distribution: 'temurin'
54-
java-version: '8'
54+
java-version: '11'
5555

5656
- name: Setup git credentials
5757
uses: oleksiyrudenko/gha-git-credentials@v2-latest

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Changelog
22

33
## [Unreleased]
4+
### Changed
5+
- Client version updated on [5.4.3](https://github.com/reportportal/client-java/releases/tag/5.4.3), by @HardNorth
6+
- Replace "jsr305" annotations with "jakarta.annotation-api", by @HardNorth
7+
- Switch on use of `Instant` class instead of `Date` to get more timestamp precision, by @HardNorth
8+
### Removed
9+
- Deprecated code, by @HardNorth
410

511
## [5.3.0]
612
### Changed

build.gradle

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,21 @@ project.ext.limits = [
2929
'class' : 60
3030
]
3131

32-
sourceCompatibility = JavaVersion.VERSION_1_8
33-
targetCompatibility = JavaVersion.VERSION_1_8
32+
sourceCompatibility = JavaVersion.VERSION_11
33+
targetCompatibility = JavaVersion.VERSION_11
3434

3535
repositories {
3636
mavenCentral()
3737
}
3838

3939
dependencies {
4040
compileOnly "com.epam.reportportal:client-java:${client_version}"
41-
compileOnly "com.google.code.findbugs:jsr305:${jsr305_version}"
4241

4342
implementation 'org.jsoup:jsoup:1.15.3'
43+
implementation 'org.apache.commons:commons-lang3:3.18.0'
4444

4545
testImplementation "com.epam.reportportal:client-java:${client_version}"
46-
testImplementation "com.google.code.findbugs:jsr305:${jsr305_version}"
47-
testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.12'
46+
testImplementation 'com.epam.reportportal:agent-java-test-utils:0.1.0'
4847

4948
testImplementation("org.junit.platform:junit-platform-runner:${junit5_runner_version}") {
5049
exclude module: 'junit'

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
version=5.3.1-SNAPSHOT
1+
version=5.4.0-SNAPSHOT
22
description=Report Portal Java formatting utils for Agents and Loggers
33
junit5_version=5.6.3
44
junit5_runner_version=1.6.3
55
mockito_version=4.5.1
6-
client_version=5.3.14
6+
client_version=5.4.3
77
jsr305_version=3.0.2
88
scripts_url=https://raw.githubusercontent.com/reportportal/gradle-scripts
99
scripts_branch=master

src/main/java/com/epam/reportportal/formatting/AbstractHttpFormatter.java

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@
3030
import com.epam.reportportal.service.step.StepReporter;
3131
import com.epam.reportportal.utils.files.ByteSource;
3232
import com.epam.reportportal.utils.http.ContentType;
33-
34-
import javax.annotation.Nonnull;
35-
import javax.annotation.Nullable;
36-
import java.util.*;
33+
import jakarta.annotation.Nonnull;
34+
import jakarta.annotation.Nullable;
35+
36+
import java.time.Instant;
37+
import java.util.Collections;
38+
import java.util.HashMap;
39+
import java.util.Map;
40+
import java.util.Optional;
3741
import java.util.function.Function;
3842

3943
import static com.epam.reportportal.formatting.http.Constants.BODY_TYPE_MAP;
@@ -55,18 +59,7 @@ public abstract class AbstractHttpFormatter<SELF extends AbstractHttpFormatter<S
5559
protected final Function<String, String> uriConverter;
5660

5761
private Map<String, Function<String, String>> contentPrettifiers = DEFAULT_PRETTIFIERS;
58-
59-
/**
60-
* @deprecated Use {@link #getContentPrettifiers()} instead
61-
*/
62-
@Deprecated
63-
protected Map<String, Function<String, String>> contentPrettiers = contentPrettifiers;
64-
65-
/**
66-
* @deprecated Use {@link #getBodyTypeMap()} instead
67-
*/
68-
@Deprecated
69-
protected Map<String, BodyType> bodyTypeMap = BODY_TYPE_MAP;
62+
private Map<String, BodyType> bodyTypeMap = BODY_TYPE_MAP;
7063

7164
/**
7265
* Create a formatter with the specific log level and converters.
@@ -93,26 +86,26 @@ protected AbstractHttpFormatter(@Nonnull LogLevel defaultLogLevel, @Nullable Fun
9386

9487
protected void attachAsBinary(@Nullable String message, @Nullable byte[] attachment, @Nonnull String contentType) {
9588
if (attachment == null) {
96-
ReportPortal.emitLog(message, logLevel, Calendar.getInstance().getTime());
89+
ReportPortal.emitLog(message, logLevel, Instant.now());
9790
} else {
9891
ReportPortal.emitLog(
9992
new ReportPortalMessage(ByteSource.wrap(attachment), contentType, message),
10093
logLevel,
101-
Calendar.getInstance().getTime()
94+
Instant.now()
10295
);
10396
}
10497
}
10598

10699
protected void logMultiPartRequest(@Nonnull HttpRequestFormatter formatter) {
107-
Date currentDate = Calendar.getInstance().getTime();
100+
Instant currentDate = Instant.now();
108101
String headers = formatter.formatHeaders() + formatter.formatCookies();
109102
if (!headers.isEmpty()) {
110103
ReportPortal.emitLog(headers, logLevel, currentDate);
111104
}
112105

113-
Date myDate = currentDate;
106+
Instant myDate = currentDate;
114107
for (HttpPartFormatter part : formatter.getMultipartBody()) {
115-
myDate = new Date(myDate.getTime() + 1);
108+
myDate = myDate.plusMillis(1);
116109
HttpPartFormatter.PartType partType = part.getType();
117110
switch (partType) {
118111
case TEXT:
@@ -128,11 +121,11 @@ protected void emitLog(HttpFormatter formatter) {
128121
BodyType type = formatter.getType();
129122
switch (type) {
130123
case NONE:
131-
ReportPortal.emitLog(formatter.formatHead(), logLevel, Calendar.getInstance().getTime());
124+
ReportPortal.emitLog(formatter.formatHead(), logLevel, Instant.now());
132125
break;
133126
case TEXT:
134127
case FORM:
135-
ReportPortal.emitLog(formatter.formatAsText(), logLevel, Calendar.getInstance().getTime());
128+
ReportPortal.emitLog(formatter.formatAsText(), logLevel, Instant.now());
136129
break;
137130
case BINARY:
138131
attachAsBinary(
@@ -149,7 +142,7 @@ protected void emitLog(HttpFormatter formatter) {
149142
sr.ifPresent(StepReporter::finishPreviousStep);
150143
break;
151144
default:
152-
ReportPortal.emitLog("Unknown entity type: " + type.name(), LogLevel.ERROR.name(), Calendar.getInstance().getTime());
145+
ReportPortal.emitLog("Unknown entity type: " + type.name(), LogLevel.ERROR.name(), Instant.now());
153146
}
154147
}
155148

@@ -165,7 +158,7 @@ protected void emitLog(HttpFormatter formatter) {
165158
@SuppressWarnings("unchecked")
166159
@Nonnull
167160
public SELF setBodyTypeMap(@Nonnull Map<String, BodyType> typeMap) {
168-
this.bodyTypeMap = Collections.unmodifiableMap(new HashMap<>(typeMap));
161+
this.bodyTypeMap = Map.copyOf(typeMap);
169162
return (SELF) this;
170163
}
171164

@@ -195,26 +188,9 @@ public Map<String, BodyType> getBodyTypeMap() {
195188
@Nonnull
196189
public SELF setContentPrettifiers(@Nonnull Map<String, Function<String, String>> contentPrettifiers) {
197190
this.contentPrettifiers = Collections.unmodifiableMap(new HashMap<>(contentPrettifiers));
198-
this.contentPrettiers = this.contentPrettifiers;
199191
return (SELF) this;
200192
}
201193

202-
/***
203-
* Set the content prettifiers for the formatter.
204-
* <p>
205-
* Content prettifiers are used to format the content of the request/response before logging it. The prettifiers are applied to the
206-
* content based on the content type.
207-
*
208-
* @param contentPrettifiers a map with the content type as a key and the prettifier function as a value
209-
* @return the formatter instance
210-
* @deprecated Use {@link #setContentPrettifiers(Map)} instead
211-
*/
212-
@Deprecated
213-
@Nonnull
214-
public SELF setContentPrettiers(@Nonnull Map<String, Function<String, String>> contentPrettifiers) {
215-
return setContentPrettifiers(contentPrettifiers);
216-
}
217-
218194
/**
219195
* Get the content prettifiers for the formatter.
220196
* <p>

src/main/java/com/epam/reportportal/formatting/http/Constants.java

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,20 @@ public class Constants {
6969
MULTIPART_TYPES.stream().collect(Collectors.toMap(k -> k, v -> BodyType.MULTIPART))
7070
).flatMap(m -> m.entrySet().stream()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
7171

72-
public static final Map<String, Function<String, String>> DEFAULT_PRETTIFIERS = Collections.unmodifiableMap(new HashMap<String, Function<String, String>>() {{
73-
put(ContentType.APPLICATION_XML, XmlPrettifier.INSTANCE);
74-
put(ContentType.APPLICATION_SOAP_XML, XmlPrettifier.INSTANCE);
75-
put(ContentType.APPLICATION_ATOM_XML, XmlPrettifier.INSTANCE);
76-
put(ContentType.APPLICATION_SVG_XML, XmlPrettifier.INSTANCE);
77-
put(ContentType.APPLICATION_XHTML_XML, XmlPrettifier.INSTANCE);
78-
put(ContentType.TEXT_XML, XmlPrettifier.INSTANCE);
79-
put(ContentType.APPLICATION_JSON, JsonPrettifier.INSTANCE);
80-
// Can't use ContentType.TEXT_JSON, etc. because client-java dependency marked as compileOnly
81-
put("text/json", JsonPrettifier.INSTANCE);
82-
put("application/x.reportportal.launch.v2+json", JsonPrettifier.INSTANCE);
83-
put("application/x.reportportal.test.v2+json", JsonPrettifier.INSTANCE);
84-
put(ContentType.TEXT_HTML, HtmlPrettifier.INSTANCE);
85-
}});
86-
87-
/**
88-
* @deprecated Use {@link #DEFAULT_PRETTIFIERS} instead
89-
*/
90-
@Deprecated
91-
public static final Map<String, Function<String, String>> DEFAULT_PRETTIERS = DEFAULT_PRETTIFIERS;
72+
public static final Map<String, Function<String, String>> DEFAULT_PRETTIFIERS = Map.ofEntries(
73+
Map.entry(ContentType.APPLICATION_XML, XmlPrettifier.INSTANCE),
74+
Map.entry(ContentType.APPLICATION_SOAP_XML, XmlPrettifier.INSTANCE),
75+
Map.entry(ContentType.APPLICATION_ATOM_XML, XmlPrettifier.INSTANCE),
76+
Map.entry(ContentType.APPLICATION_SVG_XML, XmlPrettifier.INSTANCE),
77+
Map.entry(ContentType.APPLICATION_XHTML_XML, XmlPrettifier.INSTANCE),
78+
Map.entry(ContentType.TEXT_XML, XmlPrettifier.INSTANCE),
79+
Map.entry(ContentType.APPLICATION_JSON, JsonPrettifier.INSTANCE),
80+
// Can't use ContentType.TEXT_JSON, etc. because client-java dependency marked as compileOnly
81+
Map.entry("text/json", JsonPrettifier.INSTANCE),
82+
Map.entry("application/x.reportportal.launch.v2+json", JsonPrettifier.INSTANCE),
83+
Map.entry("application/x.reportportal.test.v2+json", JsonPrettifier.INSTANCE),
84+
Map.entry(ContentType.TEXT_HTML, HtmlPrettifier.INSTANCE)
85+
);
9286

9387
private Constants() {
9488
throw new RuntimeException("No instances should exist for the class!");

src/main/java/com/epam/reportportal/formatting/http/HttpFormatUtils.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@
2424
import com.epam.reportportal.formatting.http.entities.Header;
2525
import com.epam.reportportal.formatting.http.entities.Param;
2626
import com.epam.reportportal.utils.http.ContentType;
27+
import jakarta.annotation.Nonnull;
28+
import jakarta.annotation.Nullable;
2729
import org.apache.commons.lang3.tuple.Pair;
2830

29-
import javax.annotation.Nonnull;
30-
import javax.annotation.Nullable;
31-
import java.io.UnsupportedEncodingException;
3231
import java.net.URLDecoder;
3332
import java.nio.charset.Charset;
3433
import java.nio.charset.StandardCharsets;
35-
import java.text.ParseException;
36-
import java.text.SimpleDateFormat;
34+
import java.time.Instant;
35+
import java.time.ZoneId;
36+
import java.time.ZonedDateTime;
37+
import java.time.format.DateTimeFormatter;
38+
import java.time.format.DateTimeParseException;
3739
import java.util.*;
3840
import java.util.function.Function;
3941
import java.util.stream.Collectors;
@@ -137,11 +139,7 @@ public static Header toHeader(@Nonnull String nameValuePair) {
137139
public static Stream<Pair<String, String>> toKeyValue(@Nonnull String headerValue) {
138140
return Arrays.stream(headerValue.split(";\\s*")).map(c -> c.split("=", 2)).map(kv -> {
139141
if (kv.length > 1) {
140-
try {
141-
return Pair.of(kv[0], URLDecoder.decode(kv[1], Charset.defaultCharset().name()));
142-
} catch (UnsupportedEncodingException e) {
143-
throw new IllegalStateException(e);
144-
}
142+
return Pair.of(kv[0], URLDecoder.decode(kv[1], Charset.defaultCharset()));
145143
}
146144
return Pair.of(kv[0], "");
147145
});
@@ -150,7 +148,7 @@ public static Stream<Pair<String, String>> toKeyValue(@Nonnull String headerValu
150148
@Nonnull
151149
public static Cookie toCookie(@Nonnull String name, @Nullable String value, @Nullable String comment, @Nullable String path,
152150
@Nullable String domain, @Nullable Long maxAge, @Nullable Boolean secured, @Nullable Boolean httpOnly,
153-
@Nullable Date expiryDate, @Nullable Integer version, @Nullable String sameSite) {
151+
@Nullable Instant expiryDate, @Nullable Integer version, @Nullable String sameSite) {
154152
Cookie cookie = new Cookie(name);
155153
cookie.setValue(value);
156154
cookie.setComment(comment);
@@ -180,10 +178,12 @@ public static Cookie toCookie(@Nonnull String headerValue) {
180178
Boolean httpOnly = cookieMetadata.containsKey("httponly");
181179
// Examples: Tue, 06 Sep 2022 09:32:51 GMT
182180
// Wed, 06-Sep-2023 11:22:09 GMT
183-
Date expiryDate = ofNullable(cookieMetadata.get("expires")).map(d -> {
181+
Instant expiryDate = ofNullable(cookieMetadata.get("expires")).map(d -> {
184182
try {
185-
return new SimpleDateFormat(DefaultCookieConverter.DEFAULT_COOKIE_DATE_FORMAT).parse(d.replace('-', ' '));
186-
} catch (ParseException e) {
183+
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DefaultCookieConverter.DEFAULT_COOKIE_DATE_FORMAT)
184+
.withZone(ZoneId.of(DefaultCookieConverter.DEFAULT_COOKIE_TIME_ZONE.getID()));
185+
return ZonedDateTime.parse(d.replace('-', ' '), formatter).toInstant();
186+
} catch (DateTimeParseException e) {
187187
return null;
188188
}
189189
}).orElse(null);
@@ -228,11 +228,7 @@ public static List<Param> toForm(@Nullable String formParameters, @Nullable Stri
228228
.map(param -> param.split("=", 2))
229229
.map(Arrays::stream)
230230
.map(param -> param.map(p -> {
231-
try {
232-
return URLDecoder.decode(p, charset.name());
233-
} catch (UnsupportedEncodingException e) {
234-
throw new IllegalStateException("Missed standard charset", e);
235-
}
231+
return URLDecoder.decode(p, charset);
236232
}).collect(Collectors.toList()))
237233
.map(param -> {
238234
if (param.isEmpty()) {

src/main/java/com/epam/reportportal/formatting/http/HttpFormatter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
package com.epam.reportportal.formatting.http;
1818

1919
import com.epam.reportportal.formatting.http.entities.BodyType;
20-
21-
import javax.annotation.Nonnull;
22-
import javax.annotation.Nullable;
20+
import jakarta.annotation.Nonnull;
21+
import jakarta.annotation.Nullable;
2322

2423
public interface HttpFormatter {
2524

0 commit comments

Comments
 (0)