Skip to content

Commit dc988c6

Browse files
committed
Reformat
1 parent b915bbd commit dc988c6

21 files changed

+51
-301
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- Client version updated on [5.4.3](https://github.com/reportportal/client-java/releases/tag/5.4.3), by @HardNorth
66
- Replace "jsr305" annotations with "jakarta.annotation-api", by @HardNorth
77
- Switch on use of `Instant` class instead of `Date` to get more timestamp precision, by @HardNorth
8+
### Removed
9+
- Deprecated code, by @HardNorth
810

911
## [5.3.0]
1012
### Changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ dependencies {
4040
compileOnly "com.epam.reportportal:client-java:${client_version}"
4141

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

4545
testImplementation "com.epam.reportportal:client-java:${client_version}"
4646
testImplementation 'com.epam.reportportal:agent-java-test-utils:0.1.0'

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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

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

Lines changed: 15 additions & 39 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-
3433
import jakarta.annotation.Nonnull;
3534
import jakarta.annotation.Nullable;
36-
import java.util.*;
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,24 +86,24 @@ 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, java.time.Instant.now());
89+
ReportPortal.emitLog(message, logLevel, Instant.now());
9790
} else {
9891
ReportPortal.emitLog(
9992
new ReportPortalMessage(ByteSource.wrap(attachment), contentType, message),
10093
logLevel,
101-
java.time.Instant.now()
94+
Instant.now()
10295
);
10396
}
10497
}
10598

10699
protected void logMultiPartRequest(@Nonnull HttpRequestFormatter formatter) {
107-
java.time.Instant currentDate = java.time.Instant.now();
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-
java.time.Instant myDate = currentDate;
106+
Instant myDate = currentDate;
114107
for (HttpPartFormatter part : formatter.getMultipartBody()) {
115108
myDate = myDate.plusMillis(1);
116109
HttpPartFormatter.PartType partType = part.getType();
@@ -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, java.time.Instant.now());
124+
ReportPortal.emitLog(formatter.formatHead(), logLevel, Instant.now());
132125
break;
133126
case TEXT:
134127
case FORM:
135-
ReportPortal.emitLog(formatter.formatAsText(), logLevel, java.time.Instant.now());
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(), java.time.Instant.now());
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: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
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 org.apache.commons.lang3.tuple.Pair;
28-
2927
import jakarta.annotation.Nonnull;
3028
import jakarta.annotation.Nullable;
31-
import java.io.UnsupportedEncodingException;
29+
import org.apache.commons.lang3.tuple.Pair;
30+
3231
import java.net.URLDecoder;
3332
import java.nio.charset.Charset;
3433
import java.nio.charset.StandardCharsets;
@@ -140,11 +139,7 @@ public static Header toHeader(@Nonnull String nameValuePair) {
140139
public static Stream<Pair<String, String>> toKeyValue(@Nonnull String headerValue) {
141140
return Arrays.stream(headerValue.split(";\\s*")).map(c -> c.split("=", 2)).map(kv -> {
142141
if (kv.length > 1) {
143-
try {
144-
return Pair.of(kv[0], URLDecoder.decode(kv[1], Charset.defaultCharset().name()));
145-
} catch (UnsupportedEncodingException e) {
146-
throw new IllegalStateException(e);
147-
}
142+
return Pair.of(kv[0], URLDecoder.decode(kv[1], Charset.defaultCharset()));
148143
}
149144
return Pair.of(kv[0], "");
150145
});
@@ -233,11 +228,7 @@ public static List<Param> toForm(@Nullable String formParameters, @Nullable Stri
233228
.map(param -> param.split("=", 2))
234229
.map(Arrays::stream)
235230
.map(param -> param.map(p -> {
236-
try {
237-
return URLDecoder.decode(p, charset.name());
238-
} catch (UnsupportedEncodingException e) {
239-
throw new IllegalStateException("Missed standard charset", e);
240-
}
231+
return URLDecoder.decode(p, charset);
241232
}).collect(Collectors.toList()))
242233
.map(param -> {
243234
if (param.isEmpty()) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.epam.reportportal.formatting.http;
1818

1919
import com.epam.reportportal.formatting.http.entities.BodyType;
20-
2120
import jakarta.annotation.Nonnull;
2221
import jakarta.annotation.Nullable;
2322

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

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,8 @@
1818

1919
import com.epam.reportportal.formatting.http.converters.DefaultHttpHeaderConverter;
2020
import com.epam.reportportal.formatting.http.entities.Header;
21-
import com.epam.reportportal.message.TypeAwareByteSource;
22-
import com.epam.reportportal.utils.files.Utils;
23-
2421
import jakarta.annotation.Nonnull;
25-
import java.io.File;
26-
import java.io.IOException;
22+
2723
import java.util.ArrayList;
2824
import java.util.List;
2925
import java.util.Map;
@@ -132,15 +128,6 @@ public void setPrettifiers(Map<String, Function<String, String>> prettifiers) {
132128
this.prettifiers = prettifiers;
133129
}
134130

135-
/**
136-
* @param prettifiers a map with the content type as a key and the prettifier function as a value
137-
* @deprecated Use {@link #setPrettifiers(Map)} instead
138-
*/
139-
@Deprecated
140-
public void setPrettiers(Map<String, Function<String, String>> prettifiers) {
141-
setPrettifiers(prettifiers);
142-
}
143-
144131
public enum PartType {
145132
TEXT,
146133
BINARY
@@ -159,18 +146,6 @@ public static class Builder {
159146
private Function<Header, String> headerConverter;
160147
private Map<String, Function<String, String>> prettifiers;
161148

162-
/***
163-
*
164-
* @deprecated the constructor does not accept charset and should be removed
165-
*/
166-
@Deprecated
167-
public Builder(@Nonnull PartType partType, @Nonnull File body) throws IOException {
168-
type = partType;
169-
TypeAwareByteSource file = Utils.getFile(body);
170-
this.mimeType = file.getMediaType();
171-
payload = file.read();
172-
}
173-
174149
public Builder(@Nonnull PartType partType, @Nonnull String mimeType, @Nonnull Object body) {
175150
type = partType;
176151
this.mimeType = mimeType;
@@ -212,16 +187,6 @@ public Builder prettifiers(Map<String, Function<String, String>> formatPrettifie
212187
return this;
213188
}
214189

215-
/**
216-
* @param formatPrettifiers a map with the content type as a key and the prettifier function as a value
217-
* @return the builder instance
218-
* @deprecated Use {@link #prettifiers(Map)} instead
219-
*/
220-
@Deprecated
221-
public Builder prettiers(Map<String, Function<String, String>> formatPrettifiers) {
222-
return prettifiers(formatPrettifiers);
223-
}
224-
225190
public HttpPartFormatter build() {
226191
HttpPartFormatter formatter = new HttpPartFormatter(type, mimeType, payload);
227192
formatter.setControlName(controlName);

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import com.epam.reportportal.formatting.http.entities.Header;
2626
import com.epam.reportportal.formatting.http.entities.Param;
2727
import com.epam.reportportal.utils.http.ContentType;
28-
2928
import jakarta.annotation.Nonnull;
3029
import jakarta.annotation.Nullable;
30+
3131
import java.util.*;
3232
import java.util.function.Function;
3333

@@ -179,15 +179,6 @@ public void setPrettifiers(Map<String, Function<String, String>> prettifiers) {
179179
this.prettifiers = prettifiers;
180180
}
181181

182-
/**
183-
* @param prettifiers a map with the content type as a key and the prettifier function as a value
184-
* @deprecated Use {@link #setPrettifiers(Map)} instead
185-
*/
186-
@Deprecated
187-
public void setPrettiers(Map<String, Function<String, String>> prettifiers) {
188-
setPrettifiers(prettifiers);
189-
}
190-
191182
public static class Builder {
192183
private final String method;
193184
private final String uri;
@@ -317,16 +308,6 @@ public Builder prettifiers(Map<String, Function<String, String>> formatPrettifie
317308
return this;
318309
}
319310

320-
/**
321-
* @param formatPrettifiers a map with the content type as a key and the prettifier function as a value
322-
* @return the builder instance
323-
* @deprecated Use {@link #prettifiers(Map)} instead
324-
*/
325-
@Deprecated
326-
public Builder prettiers(Map<String, Function<String, String>> formatPrettifiers) {
327-
return prettifiers(formatPrettifiers);
328-
}
329-
330311
public HttpRequestFormatter build() {
331312
HttpRequestFormatter result = new HttpRequestFormatter(method, uri);
332313
result.setUriConverter(ofNullable(uriConverter).orElse(DefaultUriConverter.INSTANCE));

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import com.epam.reportportal.formatting.http.entities.BodyType;
2222
import com.epam.reportportal.formatting.http.entities.Cookie;
2323
import com.epam.reportportal.formatting.http.entities.Header;
24-
2524
import jakarta.annotation.Nonnull;
2625
import jakarta.annotation.Nullable;
26+
2727
import java.util.ArrayList;
2828
import java.util.List;
2929
import java.util.Map;
@@ -145,15 +145,6 @@ public void setPrettifiers(Map<String, Function<String, String>> prettifiers) {
145145
this.prettifiers = prettifiers;
146146
}
147147

148-
/**
149-
* @param prettifiers a map with the content type as a key and the prettifier function as a value
150-
* @deprecated Use {@link #setPrettifiers(Map)} instead
151-
*/
152-
@Deprecated
153-
public void setPrettiers(Map<String, Function<String, String>> prettifiers) {
154-
setPrettifiers(prettifiers);
155-
}
156-
157148
public static class Builder {
158149
private final int code;
159150
private final String phrase;
@@ -240,16 +231,6 @@ public Builder prettifiers(Map<String, Function<String, String>> formatPrettifie
240231
return this;
241232
}
242233

243-
/**
244-
* @param formatPrettifiers a map with the content type as a key and the prettifier function as a value
245-
* @return the builder instance
246-
* @deprecated Use {@link #prettifiers(Map)} instead
247-
*/
248-
@Deprecated
249-
public Builder prettiers(Map<String, Function<String, String>> formatPrettifiers) {
250-
return prettifiers(formatPrettifiers);
251-
}
252-
253234
public HttpResponseFormatter build() {
254235
HttpResponseFormatter result = new HttpResponseFormatter(code, phrase);
255236
result.setHeaderConverter(ofNullable(headerConverter).orElse(DefaultHttpHeaderConverter.INSTANCE));

0 commit comments

Comments
 (0)