4
4
import java .io .IOException ;
5
5
import java .net .URI ;
6
6
import java .nio .file .Path ;
7
- import java .util .Arrays ;
8
7
import java .util .Collections ;
9
8
import java .util .Objects ;
10
9
import java .util .concurrent .Callable ;
11
10
import java .util .regex .Matcher ;
12
11
import java .util .regex .Pattern ;
13
- import java .util .stream .Collectors ;
14
12
import lombok .Builder ;
15
13
import lombok .extern .slf4j .Slf4j ;
16
14
import me .itzg .helpers .errors .GenericException ;
19
17
import me .itzg .helpers .files .ManifestException ;
20
18
import me .itzg .helpers .files .Manifests ;
21
19
import me .itzg .helpers .files .ResultsFileWriter ;
22
- import me .itzg .helpers .http .FailedRequestException ;
23
20
import me .itzg .helpers .http .Fetch ;
21
+ import me .itzg .helpers .http .FileDownloadStatusHandler ;
24
22
import me .itzg .helpers .http .SharedFetch ;
25
23
import me .itzg .helpers .http .SharedFetchArgs ;
26
24
import me .itzg .helpers .json .ObjectMappers ;
27
- import me .itzg .helpers .paper .model . ReleaseChannel ;
25
+ import me .itzg .helpers .paper .PaperDownloadsClient . VersionBuildFile ;
28
26
import me .itzg .helpers .paper .model .VersionMeta ;
29
27
import me .itzg .helpers .sync .MultiCopyManifest ;
30
- import org .jetbrains .annotations .NotNull ;
31
28
import picocli .CommandLine ;
32
29
import picocli .CommandLine .ArgGroup ;
33
30
import picocli .CommandLine .Command ;
@@ -83,15 +80,16 @@ public void setVersion(String version) {
83
80
@ Option (names = "--build" )
84
81
Integer build ;
85
82
86
- @ Option (names = "--channel" , defaultValue = "default" )
87
- ReleaseChannel channel ;
83
+ @ Option (names = "--channel" , description = "This is ignored for now" ,
84
+ defaultValue = "default" )
85
+ RequestedChannel channel ;
88
86
}
89
87
}
90
88
91
89
@ Option (names = {"--output-directory" , "-o" }, defaultValue = "." )
92
90
Path outputDirectory ;
93
91
94
- @ Option (names = "--base-url" , defaultValue = "https://api .papermc.io" )
92
+ @ Option (names = "--base-url" , defaultValue = "https://fill .papermc.io" )
95
93
String baseUrl ;
96
94
97
95
@ Option (names = "--results-file" , description = ResultsFileWriter .OPTION_DESCRIPTION , paramLabel = "FILE" )
@@ -123,13 +121,12 @@ public Integer call() throws Exception {
123
121
else {
124
122
if (requestCheckUpdates ) {
125
123
return checkForUpdates (client , oldManifest ,
126
- inputs .coordinates .project , inputs .coordinates .version , inputs .coordinates .build ,
127
- inputs . coordinates . channel );
124
+ inputs .coordinates .project , inputs .coordinates .version , inputs .coordinates .build
125
+ );
128
126
}
129
127
130
128
result = downloadUsingCoordinates (client , inputs .coordinates .project ,
131
- inputs .coordinates .version , inputs .coordinates .build ,
132
- inputs .coordinates .channel
129
+ inputs .coordinates .version , inputs .coordinates .build
133
130
)
134
131
.block ();
135
132
}
@@ -155,8 +152,7 @@ public Integer call() throws Exception {
155
152
}
156
153
157
154
private Integer checkForUpdates (PaperDownloadsClient client , PaperManifest oldManifest ,
158
- String project , String version , Integer build ,
159
- ReleaseChannel channel
155
+ String project , String version , Integer build
160
156
) {
161
157
if (oldManifest != null && oldManifest .getCustomDownloadUrl () != null ) {
162
158
log .info ("Using custom download URL before" );
@@ -173,7 +169,7 @@ private Integer checkForUpdates(PaperDownloadsClient client, PaperManifest oldMa
173
169
}
174
170
}
175
171
else {
176
- return client .getLatestBuild (project , version , channel )
172
+ return client .getLatestBuild (project , version )
177
173
.map (resolvedBuild -> {
178
174
if (oldManifest == null ) {
179
175
return logVersion (project , version , resolvedBuild );
@@ -185,14 +181,11 @@ private Integer checkForUpdates(PaperDownloadsClient client, PaperManifest oldMa
185
181
return ExitCode .SOFTWARE ;
186
182
}
187
183
})
188
- .switchIfEmpty (Mono .error (() -> new InvalidParameterException (
189
- String .format ("No build found for version %s with channel %s" , version , channel )
190
- )))
191
184
.block ();
192
185
}
193
186
}
194
187
else {
195
- return client .getLatestVersionBuild (project , channel )
188
+ return client .getLatestVersionBuild (project )
196
189
.map (versionBuild -> {
197
190
if (oldManifest == null ) {
198
191
return logVersion (project , versionBuild .getVersion (), versionBuild .getBuild ());
@@ -204,9 +197,6 @@ private Integer checkForUpdates(PaperDownloadsClient client, PaperManifest oldMa
204
197
return ExitCode .SOFTWARE ;
205
198
}
206
199
})
207
- .switchIfEmpty (
208
- Mono .error (() -> new InvalidParameterException ("No build found with channel " + channel ))
209
- )
210
200
.block ();
211
201
}
212
202
return ExitCode .SOFTWARE ;
@@ -234,72 +224,48 @@ private static boolean mismatchingVersions(PaperManifest oldManifest, String pro
234
224
}
235
225
236
226
private Mono <Result > downloadUsingCoordinates (PaperDownloadsClient client , String project ,
237
- String version , Integer build , ReleaseChannel channel
227
+ String version , Integer build
238
228
) {
229
+ return
230
+ assembleDownload (client , project , version , build )
231
+ .map (result ->
232
+ Result .builder ()
233
+ .newManifest (
234
+ PaperManifest .builder ()
235
+ .project (project )
236
+ .minecraftVersion (result .getVersion ())
237
+ .build (result .getBuild ())
238
+ .files (Collections .singleton (Manifests .relativize (outputDirectory , result .getFile ())))
239
+ .build ()
240
+ )
241
+ .serverJar (result .getFile ())
242
+ .version (result .getVersion ())
243
+ .build ()
244
+ );
245
+ }
246
+
247
+ private Mono <VersionBuildFile > assembleDownload (PaperDownloadsClient client , String project , String version ,
248
+ Integer build
249
+ ) {
250
+ final FileDownloadStatusHandler downloadStatusHandler = Fetch .loggingDownloadStatusHandler (log );
251
+
239
252
if (isSpecificVersion (version )) {
240
253
if (build != null ) {
241
- return download (client , project , version , build )
242
- .onErrorMap (
243
- FailedRequestException ::isNotFound ,
244
- throwable -> new InvalidParameterException (
245
- String .format ("Requested version %s, build %d is not available" , version , build ))
246
- );
254
+ return client .download (project , outputDirectory , downloadStatusHandler , version , build );
247
255
}
248
256
else {
249
- return client .getLatestBuild (project , version , channel )
250
- .onErrorMap (
251
- FailedRequestException ::isNotFound ,
252
- throwable -> new InvalidParameterException (
253
- String .format ("Requested version %s is not available" , version ))
254
- )
255
- .switchIfEmpty (Mono .error (() -> new InvalidParameterException (
256
- String .format ("No build found for version %s with channel '%s'. Perhaps try with a different channel: %s" ,
257
- version , channel , channelsExcept (channel ))
258
- )))
259
- .flatMap (resolvedBuild -> download (client , project , version , resolvedBuild ));
257
+ return client .downloadLatestBuild (project , outputDirectory , downloadStatusHandler , version );
260
258
}
261
259
}
262
260
else {
263
- return client .getLatestVersionBuild (project , channel )
264
- .switchIfEmpty (
265
- Mono .error (() -> new InvalidParameterException (
266
- String .format ("No build found with channel '%s'. Perhaps try a different channel: %s" ,
267
- channel , channelsExcept (channel )
268
- )))
269
- )
270
- .flatMap (resolved -> download (client , project , resolved .getVersion (), resolved .getBuild ()));
261
+ return client .downloadLatest (project , outputDirectory , downloadStatusHandler );
271
262
}
272
263
}
273
264
274
- private String channelsExcept (ReleaseChannel channel ) {
275
- return Arrays .stream (ReleaseChannel .values ())
276
- .filter (c -> !Objects .equals (c , channel ))
277
- .map (ReleaseChannel ::toString )
278
- .collect (Collectors .joining (", " ));
279
- }
280
-
281
265
private static boolean isSpecificVersion (String version ) {
282
266
return version != null && !version .equalsIgnoreCase ("latest" );
283
267
}
284
268
285
- private @ NotNull Mono <Result > download (PaperDownloadsClient client , String project , String v , Integer b ) {
286
- return client .download (project , v , b , outputDirectory , Fetch .loggingDownloadStatusHandler (log ))
287
- .map (serverJar ->
288
- Result .builder ()
289
- .newManifest (
290
- PaperManifest .builder ()
291
- .project (project )
292
- .minecraftVersion (v )
293
- .build (b )
294
- .files (Collections .singleton (Manifests .relativize (outputDirectory , serverJar )))
295
- .build ()
296
- )
297
- .serverJar (serverJar )
298
- .version (v )
299
- .build ()
300
- );
301
- }
302
-
303
269
private Result downloadCustom (URI downloadUrl ) {
304
270
try (SharedFetch sharedFetch = Fetch .sharedFetch ("install-paper" , sharedFetchArgs .options ())) {
305
271
return sharedFetch
0 commit comments