16
16
import me .itzg .helpers .files .ManifestException ;
17
17
import me .itzg .helpers .files .Manifests ;
18
18
import me .itzg .helpers .files .ResultsFileWriter ;
19
+ import me .itzg .helpers .http .FailedRequestException ;
19
20
import me .itzg .helpers .http .Fetch ;
20
21
import me .itzg .helpers .http .SharedFetch ;
21
22
import me .itzg .helpers .http .SharedFetchArgs ;
22
23
import me .itzg .helpers .json .ObjectMappers ;
24
+ import me .itzg .helpers .paper .model .ReleaseChannel ;
23
25
import me .itzg .helpers .paper .model .VersionMeta ;
24
26
import me .itzg .helpers .sync .MultiCopyManifest ;
27
+ import org .jetbrains .annotations .NotNull ;
25
28
import picocli .CommandLine ;
26
29
import picocli .CommandLine .ArgGroup ;
27
30
import picocli .CommandLine .Command ;
@@ -73,6 +76,9 @@ public void setVersion(String version) {
73
76
74
77
@ Option (names = "--build" )
75
78
Integer build ;
79
+
80
+ @ Option (names = "--channel" , defaultValue = "default" )
81
+ ReleaseChannel channel ;
76
82
}
77
83
}
78
84
@@ -106,9 +112,11 @@ public Integer call() throws Exception {
106
112
result = downloadCustom (inputs .downloadUrl );
107
113
}
108
114
else {
109
- result = useCoordinates (client , inputs .coordinates .project ,
110
- inputs .coordinates .version , inputs .coordinates .build
111
- );
115
+ result = downloadUsingCoordinates (client , inputs .coordinates .project ,
116
+ inputs .coordinates .version , inputs .coordinates .build ,
117
+ inputs .coordinates .channel
118
+ )
119
+ .block ();
112
120
}
113
121
}
114
122
@@ -126,30 +134,60 @@ public Integer call() throws Exception {
126
134
return ExitCode .OK ;
127
135
}
128
136
129
- private Result useCoordinates (PaperDownloadsClient client , String project , String version , Integer build ) {
130
- return resolveVersion (client , project , version )
131
- .flatMap (v -> resolveBuild (client , project , v , build )
132
- .flatMap (b -> {
133
- log .info ("Resolved {} to version {} build {}" , project , v , b );
134
-
135
- return client .download (project , v , b , outputDirectory , Fetch .loggingDownloadStatusHandler (log ))
136
- .map (serverJar ->
137
- Result .builder ()
138
- .newManifest (
139
- PaperManifest .builder ()
140
- .project (project )
141
- .minecraftVersion (v )
142
- .build (b )
143
- .files (Collections .singleton (Manifests .relativize (outputDirectory , serverJar )))
144
- .build ()
145
- )
146
- .serverJar (serverJar )
147
- .version (v )
148
- .build ()
149
- );
150
- })
151
- )
152
- .block ();
137
+ private Mono <Result > downloadUsingCoordinates (PaperDownloadsClient client , String project ,
138
+ String version , Integer build , ReleaseChannel channel
139
+ ) {
140
+ if (isSpecificVersion (version )) {
141
+ if (build != null ) {
142
+ return download (client , project , version , build )
143
+ .onErrorMap (
144
+ FailedRequestException ::isNotFound ,
145
+ throwable -> new InvalidParameterException (
146
+ String .format ("Requested version %s, build %d is not available" , version , build ))
147
+ );
148
+ }
149
+ else {
150
+ return client .getLatestBuild (project , version , channel )
151
+ .onErrorMap (
152
+ FailedRequestException ::isNotFound ,
153
+ throwable -> new InvalidParameterException (
154
+ String .format ("Requested version %s is not available" , version ))
155
+ )
156
+ .switchIfEmpty (Mono .error (() -> new InvalidParameterException (
157
+ String .format ("No build found for version %s with channel %s" , version , channel )
158
+ )))
159
+ .flatMap (resolvedBuild -> download (client , project , version , resolvedBuild ));
160
+ }
161
+ }
162
+ else {
163
+ return client .getLatestVersionBuild (project , channel )
164
+ .switchIfEmpty (
165
+ Mono .error (() -> new InvalidParameterException ("No build found with channel " + channel ))
166
+ )
167
+ .flatMap (resolved -> download (client , project , resolved .getVersion (), resolved .getBuild ()));
168
+ }
169
+ }
170
+
171
+ private static boolean isSpecificVersion (String version ) {
172
+ return version != null && !version .equalsIgnoreCase ("latest" );
173
+ }
174
+
175
+ private @ NotNull Mono <Result > download (PaperDownloadsClient client , String project , String v , Integer b ) {
176
+ return client .download (project , v , b , outputDirectory , Fetch .loggingDownloadStatusHandler (log ))
177
+ .map (serverJar ->
178
+ Result .builder ()
179
+ .newManifest (
180
+ PaperManifest .builder ()
181
+ .project (project )
182
+ .minecraftVersion (v )
183
+ .build (b )
184
+ .files (Collections .singleton (Manifests .relativize (outputDirectory , serverJar )))
185
+ .build ()
186
+ )
187
+ .serverJar (serverJar )
188
+ .version (v )
189
+ .build ()
190
+ );
153
191
}
154
192
155
193
private Result downloadCustom (URI downloadUrl ) {
@@ -217,29 +255,4 @@ private PaperManifest loadOldManifest() {
217
255
}
218
256
}
219
257
220
- private Mono <String > resolveVersion (PaperDownloadsClient client , String project , String version ) {
221
- if (version .equals ("latest" )) {
222
- return client .getLatestProjectVersion (project );
223
- }
224
- return client .hasVersion (project , version )
225
- .flatMap (exists -> exists ? Mono .just (version ) : Mono .error (() -> new InvalidParameterException (
226
- String .format ("Version %s does not exist for the project %s" ,
227
- version , project
228
- ))));
229
- }
230
-
231
- private Mono <Integer > resolveBuild (PaperDownloadsClient client , String project , String version , Integer build ) {
232
- if (build == null ) {
233
- return client .getLatestBuild (project , version );
234
- }
235
- else {
236
- return client .hasBuild (project , version , build )
237
- .flatMap (exists -> exists ? Mono .just (build ) : Mono .error (() ->
238
- new InvalidParameterException (String .format ("Build %d does not exist for project %s version %s" ,
239
- build , project , version
240
- )
241
- )
242
- ));
243
- }
244
- }
245
258
}
0 commit comments