Skip to content

Commit 579f2b5

Browse files
committed
Merge remote-tracking branch 'origin/master' into feat/use-hc5-file-download
# Conflicts: # src/main/java/me/itzg/helpers/http/FetchBuilderBase.java # src/main/java/me/itzg/helpers/http/SharedFetch.java
2 parents f3ca986 + e48605d commit 579f2b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1455
-3107
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ jobs:
1818
with:
1919
arguments: test
2020
include-test-report: true
21+
retest-showing-standard-streams: true

DEVELOPMENT.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,23 @@ Beyond the unit tests, ad hoc "integration testing" can be done by running via G
66
./gradlew run --args="assert fileExists build.gradle"
77
```
88

9+
### Using IntelliJ
10+
11+
Create an "Application" run configuration, such as shown here:
12+
13+
![intellij-run-config](docs/intellij-run-config.png)
14+
15+
### Build and use application script
16+
17+
Build and install the distribution script
18+
19+
```shell
20+
./gradlew installDist
21+
```
22+
23+
Run the script using:
24+
25+
```shell
26+
./build/install/mc-image-helper/bin/mc-image-helper ...args...
27+
```
28+

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -761,15 +761,17 @@ Usage: mc-image-helper manage-users [-fh] [--existing=<existingFileBehavior>]
761761
>] -t=<type>
762762
[--user-api-provider=<userApiProvider>]
763763
[--version=<version>]
764+
[--offline]
764765
[[--http-response-timeout=DURATION]
765766
[--tls-handshake-timeout=DURATION]
766767
[--connection-pool-pending-acquire-timeout=D
767768
URATION]
768769
[--connection-pool-max-idle-timeout=DURATION
769770
]] [INPUT[,INPUT...]...]
770771
[INPUT[,INPUT...]...] One or more Mojang usernames, UUID, or ID (UUID
771-
without dashes); however, when offline, only
772-
UUID/IDs can be provided.
772+
without dashes); flags are listed after a colon
773+
separated by comma:
774+
<username/UUID/ID>:flag1,flag2
773775
When input is a file, only one local file path or
774776
URL can be provided
775777
--connection-pool-max-idle-timeout=DURATION
@@ -798,6 +800,8 @@ Usage: mc-image-helper manage-users [-fh] [--existing=<existingFileBehavior>]
798800
Allowed: mojang, playerdb
799801
--version=<version> Minecraft game version. If not provided, assumes
800802
JSON format
803+
--offline Server is in offline mode, for users that have the
804+
offline flag the UUID is generated locally
801805
```
802806

803807
### maven-download
@@ -847,9 +851,11 @@ Downloads a maven artifact from a Maven repository
847851
### mcopy
848852

849853
```
850-
Usage: mc-image-helper mcopy [-hz] [--file-is-listing] [--skip-existing]
851-
[--glob=GLOB] [--scope=<manifestId>] --to=<dest>
852-
SRC[,|<nl>SRC...]...
854+
Usage: mc-image-helper mcopy [-hz] [--file-is-listing]
855+
[--ignore-missing-sources] [--quiet-when-skipped]
856+
[--skip-existing] [--glob=GLOB]
857+
[--scope=<manifestId>] --to=<dest> SRC[,
858+
|<nl>SRC...]...
853859
Multi-source file copy operation with with managed cleanup. Supports
854860
auto-detected sourcing from file list, directories, and URLs
855861
SRC[,|<nl>SRC...]... Any mix of source file, directory, or URLs.
@@ -861,6 +867,10 @@ auto-detected sourcing from file list, directories, and URLs
861867
--glob=GLOB When a source is a directory, this filename glob
862868
will be applied to select files.
863869
-h, --help
870+
--ignore-missing-sources
871+
Don't log or fail exit code when any or all
872+
sources are missing
873+
--quiet-when-skipped Don't log when file exists or is up to date
864874
--scope, --manifest-id=<manifestId>
865875
If managed cleanup is required, this is the
866876
identifier used for qualifying manifest filename

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
id 'java'
33
id 'application'
44
id 'idea'
5-
id "io.freefair.lombok" version '8.13.1'
5+
id "io.freefair.lombok" version '8.14'
66
// https://github.com/qoomon/gradle-git-versioning-plugin
77
id 'me.qoomon.git-versioning' version '6.4.4'
88
// https://github.com/itzg/github-releaser-gradle-plugin
@@ -80,7 +80,7 @@ repositories {
8080
dependencies {
8181
def picocliVersion = '4.7.7'
8282

83-
implementation(platform('com.fasterxml.jackson:jackson-bom:2.18.3'))
83+
implementation(platform('com.fasterxml.jackson:jackson-bom:2.19.1'))
8484
// 1.4.+ requires Java 11 and we are stuck on 8
8585
implementation(platform('ch.qos.logback:logback-parent:[1.3.5,1.4)'))
8686

@@ -97,8 +97,8 @@ dependencies {
9797
implementation 'com.kjetland:mbknor-jackson-jsonschema_2.13:1.0.39'
9898
implementation 'com.jayway.jsonpath:json-path:2.9.0'
9999
implementation 'org.apache.httpcomponents.client5:httpclient5:5.5'
100-
implementation 'io.projectreactor.netty:reactor-netty-http:1.2.6'
101-
implementation 'org.apache.maven:maven-artifact:3.9.9'
100+
implementation 'io.projectreactor.netty:reactor-netty-http:1.2.7'
101+
implementation 'org.apache.maven:maven-artifact:3.9.10'
102102
implementation 'commons-codec:commons-codec:1.18.0'
103103
// for RFC5987 parsing of content-disposition filename*
104104
// 3.5.x is last of Java8 compatible: https://cxf.apache.org/download.html

docs/intellij-run-config.png

69.2 KB
Loading

src/main/java/me/itzg/helpers/curseforge/CurseForgeInstaller.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static me.itzg.helpers.singles.MoreCollections.safeStreamFrom;
99

1010
import com.fasterxml.jackson.databind.JsonMappingException;
11+
import io.netty.channel.ChannelException;
1112
import java.io.File;
1213
import java.io.IOException;
1314
import java.io.InputStream;
@@ -753,10 +754,12 @@ private Mono<DownloadOrResolveResult> buildRetryableDownload(InstallContext con
753754
)
754755
// retry the deferred part above if one of the expected failure cases
755756
.retryWhen(
756-
Retry.fixedDelay(BAD_FILE_ATTEMPTS, BAD_FILE_DELAY)
757+
Retry.backoff(BAD_FILE_ATTEMPTS, BAD_FILE_DELAY)
757758
.filter(throwable ->
758759
throwable instanceof FileHashInvalidException ||
759-
throwable instanceof FailedRequestException
760+
throwable instanceof FailedRequestException ||
761+
throwable instanceof IOException ||
762+
throwable instanceof ChannelException
760763
)
761764
.doBeforeRetry(retrySignal ->
762765
log.warn("Retrying to download {} @ {}:{}",

src/main/java/me/itzg/helpers/http/FailedRequestException.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.netty.handler.codec.http.HttpHeaders;
44
import io.netty.handler.codec.http.HttpResponseStatus;
55
import java.net.URI;
6+
import java.net.URISyntaxException;
67
import lombok.Getter;
78
import lombok.ToString;
89

@@ -19,14 +20,23 @@ public class FailedRequestException extends RuntimeException {
1920
*/
2021
public FailedRequestException(HttpResponseStatus status, URI uri, String body, String msg, HttpHeaders headers) {
2122
super(
22-
String.format("HTTP request of %s failed with %s: %s", uri, status, msg)
23+
String.format("HTTP request of %s failed with %s: %s", obfuscate(uri), status, msg)
2324
);
2425
this.uri = uri;
2526
this.statusCode = status.code();
2627
this.body = body;
2728
this.headers = headers;
2829
}
2930

31+
public static String obfuscate(URI uri) {
32+
try {
33+
return new URI(uri.getScheme(), uri.getUserInfo() != null ? "*:*" : null, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment())
34+
.toString();
35+
} catch (URISyntaxException e) {
36+
return "???";
37+
}
38+
}
39+
3040
@SuppressWarnings("unused")
3141
public static boolean isNotFound(Throwable throwable) {
3242
return isStatus(throwable, HttpResponseStatus.NOT_FOUND);

src/main/java/me/itzg/helpers/http/FetchBuilderBase.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ protected URI uri() {
145145
return state.uri;
146146
}
147147

148+
protected URI uriForFile() {
149+
if (state.sharedFetch == null) {
150+
return state.uri;
151+
}
152+
153+
final URI filesViaUrl = state.sharedFetch.getFilesViaUrl();
154+
return filesViaUrl != null ? filesViaUrl.resolve(state.uri.getPath())
155+
: state.uri;
156+
}
157+
148158
public Set<String> getAcceptContentTypes() {
149159
return state.acceptContentTypes;
150160
}

src/main/java/me/itzg/helpers/http/SharedFetch.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class SharedFetch implements AutoCloseable {
3838
private final CloseableHttpAsyncClient hcAsyncClient;
3939
private boolean hcAsyncClientStarted = false;
4040

41+
private final URI filesViaUrl;
42+
4143
public SharedFetch(String forCommand, Options options) {
4244
final String userAgent = String.format("%s/%s/%s (cmd=%s)",
4345
"itzg",
@@ -80,6 +82,8 @@ public SharedFetch(String forCommand, Options options) {
8082

8183
headers.put("x-fetch-session", fetchSessionId);
8284

85+
this.filesViaUrl = options.getFilesViaUrl();
86+
8387
hcAsyncClient = HttpAsyncClients.createSystem();
8488
}
8589

@@ -138,14 +142,20 @@ public static class Options {
138142

139143
private final Map<String,String> extraHeaders;
140144

145+
/**
146+
* Can be set for unit testing file downloads where the original URL's path is resolved
147+
* against this given URL.
148+
*/
149+
private final URI filesViaUrl;
150+
141151
public Options withHeader(String key, String value) {
142152
final Map<String, String> newHeaders = extraHeaders != null ?
143153
new HashMap<>(extraHeaders) : new HashMap<>();
144154
newHeaders.put(key, value);
145155

146156
return new Options(
147157
responseTimeout, tlsHandshakeTimeout, maxIdleTimeout, pendingAcquireTimeout,
148-
newHeaders
158+
newHeaders, filesViaUrl
149159
);
150160
}
151161
}

src/main/java/me/itzg/helpers/http/SpecificFileFetchBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public Path execute() throws IOException {
5454
}
5555

5656
public Mono<Path> assemble() {
57-
final URI uri = uri();
57+
final URI uri = uriForFile();
5858

5959
if (skipExisting && Files.exists(file)) {
6060
log.debug("Skipping file={} that already exists due to request", file);

0 commit comments

Comments
 (0)