Skip to content

Commit ecc0e4b

Browse files
committed
Remove support for mclogs v1 instances
1 parent d84a3fa commit ecc0e4b

9 files changed

Lines changed: 77 additions & 166 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- `LimitedReader` and `Util` are now internal
1313
- `LogReader` has been split into multiple classes in the `reader` package.
1414
- Removed deprecated constants and constructor from the `Log` class.
15+
- Mclogs instances running v1 are no longer supported.
1516

1617
## New Features
1718
- You can now specify a source and other metadata when uploading logs. By default, this is filled with the project name

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,7 @@ System.out.println("Detected problems: " + analysisResult.getAnalysis().getProbl
136136

137137
### Using a self-hosted instance of mclogs
138138
```java
139-
Instance instance = new Instance()
140-
.setApiBaseUrl("https://api.logs.example.com")
141-
.setViewLogUrl("https://api.logs.example.com");
142-
client.setInstance(instance);
139+
client.setInstance(new Instance("https://api.logs.example.com"));
143140
```
144141

145142
### Checking the storage limits of the current instance

src/main/java/gs/mclo/api/Instance.java

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,22 @@
22

33
import org.jetbrains.annotations.Nullable;
44

5-
@SuppressWarnings("NotNullFieldNotInitialized")
65
public final class Instance {
76
private String apiBaseUrl;
8-
private String viewLogUrl;
97

108
/**
119
* Create a new Instance with the default API base URL and view log URL
1210
*/
1311
public Instance() {
14-
this(null, null);
12+
this(null);
1513
}
1614

1715
/**
1816
* Create a new Instance with a custom API base URL and view log URL
1917
* @param apiBaseUrl the base URL for the API (e.g. <a href="https://api.mclo.gs/">https://api.mclo.gs/</a>)
20-
* @param viewLogUrl the base URL for viewing logs (e.g. <a href="https://mclo.gs/">https://mclo.gs/</a>)
2118
*/
22-
public Instance(@Nullable String apiBaseUrl, @Nullable String viewLogUrl) {
23-
this.setApiBaseUrl(apiBaseUrl)
24-
.setViewLogUrl(viewLogUrl);
25-
}
26-
27-
private String ensureEndsWithSlash(String url) {
28-
if (!url.endsWith("/"))
29-
url += "/";
30-
return url;
19+
public Instance(@Nullable String apiBaseUrl) {
20+
this.setApiBaseUrl(apiBaseUrl);
3121
}
3222

3323
/**
@@ -51,35 +41,6 @@ public Instance setApiBaseUrl(@Nullable String apiBaseUrl) {
5141
return this;
5242
}
5343

54-
/**
55-
* Get the base URL for viewing logs
56-
* @return the base URL for viewing logs
57-
*/
58-
public String getViewLogUrl() {
59-
return viewLogUrl;
60-
}
61-
62-
/**
63-
* Get the URL for viewing a log
64-
* @param id the ID of the log (e.g. HpAwPry)
65-
* @return the base URL for viewing logs (e.g. <a href="https://mclo.gs/HpAwPry">https://mclo.gs/HpAwPry</a>)
66-
*/
67-
public String getViewLogUrl(String id) {
68-
return viewLogUrl + id;
69-
}
70-
71-
/**
72-
* Set the base URL for viewing logs
73-
* @param viewLogUrl the base URL for viewing logs (e.g. <a href="https://mclo.gs/">https://mclo.gs/</a>)
74-
* @return this
75-
*/
76-
public Instance setViewLogUrl(@Nullable String viewLogUrl) {
77-
if (viewLogUrl == null || viewLogUrl.isEmpty())
78-
viewLogUrl = "https://mclo.gs/";
79-
this.viewLogUrl = ensureEndsWithSlash(viewLogUrl);
80-
return this;
81-
}
82-
8344
/**
8445
* Get the URL for uploading a log
8546
* @return the URL for uploading a log (e.g. <a href="https://api.mclo.gs/1/log">https://api.mclo.gs/1/log</a>)
@@ -130,4 +91,10 @@ public String getStorageLimitUrl() {
13091
public String getLogUrl(String id) {
13192
return apiBaseUrl + "1/log/" + id;
13293
}
94+
95+
private String ensureEndsWithSlash(String url) {
96+
if (!url.endsWith("/"))
97+
url += "/";
98+
return url;
99+
}
133100
}

src/main/java/gs/mclo/api/MclogsClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public CompletableFuture<GetLogResponse> getLog(String id, LogField... fields) {
319319
* @param token deletion token of the log to delete
320320
* @return a future that completes when the log is deleted
321321
*/
322-
public CompletableFuture<Void> deleteLog(String id, @Nullable String token) {
322+
public CompletableFuture<Void> deleteLog(String id, String token) {
323323
HttpRequest request = requestBuilder.request(instance.getLogUrl(id))
324324
.header("Authorization", "Bearer " + token)
325325
.DELETE()

src/main/java/gs/mclo/api/response/CommonLogResponse.java

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.jetbrains.annotations.ApiStatus;
88
import org.jetbrains.annotations.Nullable;
99

10+
import java.time.Instant;
1011
import java.util.HashSet;
1112
import java.util.Objects;
1213
import java.util.Set;
@@ -19,6 +20,13 @@ public class CommonLogResponse implements Initializable {
1920

2021
private String id;
2122
private @Nullable String source;
23+
private Instant created;
24+
private Instant expires;
25+
private long size;
26+
private int lines;
27+
private int errors;
28+
private String url;
29+
private String raw;
2230
private Set<Metadata<?>> metadata = new HashSet<>();
2331

2432
/**
@@ -40,12 +48,48 @@ public String getId() {
4048
}
4149

4250
/**
43-
* Get the metadata associated with this log
51+
* Get the creation time of the log
4452
*
45-
* @return the metadata associated with this log
53+
* @return the creation time of the log
4654
*/
47-
public Set<Metadata<?>> getMetadata() {
48-
return metadata;
55+
public Instant getCreated() {
56+
return created;
57+
}
58+
59+
/**
60+
* Get the expiration time of the log
61+
*
62+
* @return the expiration time of the log
63+
*/
64+
public Instant getExpires() {
65+
return expires;
66+
}
67+
68+
/**
69+
* Get the size of the log in bytes
70+
*
71+
* @return the size of the log in bytes
72+
*/
73+
public long getSize() {
74+
return size;
75+
}
76+
77+
/**
78+
* Get the number of lines in the log
79+
*
80+
* @return the number of lines in the log
81+
*/
82+
public int getLines() {
83+
return lines;
84+
}
85+
86+
/**
87+
* Get the number of error lines detected in the log
88+
*
89+
* @return the number of error lines detected in the log
90+
*/
91+
public int getErrors() {
92+
return errors;
4993
}
5094

5195
/**
@@ -54,7 +98,7 @@ public Set<Metadata<?>> getMetadata() {
5498
* @return the url to view this log (e.g. <a href="https://mclo.gs/HpAwPry">https://mclo.gs/HpAwPry</a>)
5599
*/
56100
public String getUrl() {
57-
return client().getInstance().getViewLogUrl(id);
101+
return url;
58102
}
59103

60104
/**
@@ -63,7 +107,16 @@ public String getUrl() {
63107
* @return the url to view this log raw (e.g. <a href="https://mclo.gs/raw/HpAwPry">https://mclo.gs/raw/HpAwPry</a>)
64108
*/
65109
public String getRawUrl() {
66-
return client().getInstance().getRawLogUrl(id);
110+
return raw;
111+
}
112+
113+
/**
114+
* Get the metadata associated with this log
115+
*
116+
* @return the metadata associated with this log
117+
*/
118+
public Set<Metadata<?>> getMetadata() {
119+
return metadata;
67120
}
68121

69122
/**

src/main/java/gs/mclo/api/response/GetLogResponse.java

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,15 @@
33
import gs.mclo.api.response.log.LogContent;
44
import org.jetbrains.annotations.Nullable;
55

6-
import java.time.Instant;
7-
8-
@SuppressWarnings({"unused", "NotNullFieldNotInitialized"})
6+
@SuppressWarnings({"unused"})
97
public final class GetLogResponse extends CommonLogResponse {
10-
private Instant created;
11-
private Instant expires;
12-
private long size;
13-
private int lines;
14-
private int errors;
158

169
private @Nullable LogContent content;
1710

1811
private GetLogResponse() {
1912

2013
}
2114

22-
/**
23-
* Get the creation time of the log
24-
*
25-
* @return the creation time of the log
26-
*/
27-
public Instant getCreated() {
28-
return created;
29-
}
30-
31-
/**
32-
* Get the expiration time of the log
33-
*
34-
* @return the expiration time of the log
35-
*/
36-
public Instant getExpires() {
37-
return expires;
38-
}
39-
40-
/**
41-
* Get the size of the log in bytes
42-
*
43-
* @return the size of the log in bytes
44-
*/
45-
public long getSize() {
46-
return size;
47-
}
48-
49-
/**
50-
* Get the number of lines in the log
51-
*
52-
* @return the number of lines in the log
53-
*/
54-
public int getLines() {
55-
return lines;
56-
}
57-
58-
/**
59-
* Get the number of error lines detected in the log
60-
*
61-
* @return the number of error lines detected in the log
62-
*/
63-
public int getErrors() {
64-
return errors;
65-
}
66-
6715
/**
6816
* Get the content of the log
6917
*

src/main/java/gs/mclo/api/response/UploadLogResponse.java

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,21 @@
11
package gs.mclo.api.response;
22

3-
import org.jetbrains.annotations.Nullable;
4-
5-
import java.time.Instant;
63
import java.util.concurrent.CompletableFuture;
74

8-
@SuppressWarnings({"unused"})
5+
@SuppressWarnings({"unused", "NotNullFieldNotInitialized"})
96
public final class UploadLogResponse extends CommonLogResponse {
10-
private @Nullable Instant created;
11-
private @Nullable Instant expires;
12-
private @Nullable Long size;
13-
private @Nullable Integer lines;
14-
private @Nullable Integer errors;
15-
private @Nullable String token;
7+
private String token;
168

179
private UploadLogResponse() {
1810

1911
}
2012

21-
/**
22-
* Get the creation time of the log
23-
*
24-
* @return the creation time of the log or null if this instance is outdated
25-
*/
26-
public @Nullable Instant getCreated() {
27-
return created;
28-
}
29-
30-
/**
31-
* Get the expiration time of the log
32-
*
33-
* @return the expiration time of the log or null if this instance is outdated
34-
*/
35-
public @Nullable Instant getExpires() {
36-
return expires;
37-
}
38-
39-
/**
40-
* Get the size of the log in bytes
41-
*
42-
* @return the size of the log in bytes or null if this instance is outdated
43-
*/
44-
public @Nullable Long getSize() {
45-
return size;
46-
}
47-
48-
/**
49-
* Get the number of lines in the log
50-
*
51-
* @return the number of lines in the log or null if this instance is outdated
52-
*/
53-
public @Nullable Integer getLines() {
54-
return lines;
55-
}
56-
57-
/**
58-
* Get the number of error lines detected in the log
59-
*
60-
* @return the number of error lines detected in the log or null if this instance is outdated
61-
*/
62-
public @Nullable Integer getErrors() {
63-
return errors;
64-
}
65-
6613
/**
6714
* Get the token for deleting the log
6815
*
6916
* @return the token for deleting the log or null if this instance is outdated
7017
*/
71-
public @Nullable String getToken() {
18+
public String getToken() {
7219
return token;
7320
}
7421

src/test/java/gs/mclo/api/ApiTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ protected void setUp() throws InterruptedException {
1313
var logViewUrl = System.getenv("MCLOGS_LOG_VIEW_URL");
1414

1515
if ((apiUrl != null && !apiUrl.isBlank()) || (logViewUrl != null && !logViewUrl.isBlank())) {
16-
client.setInstance(new Instance(apiUrl, logViewUrl));
16+
client.setInstance(new Instance(apiUrl));
1717
}
1818

1919
Thread.sleep(50); // Avoid rate limiting

src/test/java/gs/mclo/api/MclogsClientTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,7 @@ void userAgents() {
168168
void customInstance() {
169169
String content = TestUtil.getFileContents("src/test/resources/logs/one.log");
170170

171-
Instance instance = new Instance("https://api.mclo.gs", "https://mclo.gs")
172-
.setApiBaseUrl("https://api.mclo.gs")
173-
.setViewLogUrl("https://mclo.gs");
171+
Instance instance = new Instance("https://api.mclo.gs");
174172

175173
MclogsClient client = new MclogsClient("aternos/mclogs-java-tests")
176174
.setInstance(instance);

0 commit comments

Comments
 (0)