38
38
import org .slf4j .LoggerFactory ;
39
39
40
40
/**
41
- * Downloader for the Rome executable:
42
- * <a href="https://github.com/rome/tools ">https://github.com/rome/tools </a>.
41
+ * Downloader for the Biome executable:
42
+ * <a href="https://github.com/biomejs/biome ">https://github.com/biomejs/biome </a>.
43
43
*/
44
44
final class RomeExecutableDownloader {
45
45
private static final Logger logger = LoggerFactory .getLogger (RomeExecutableDownloader .class );
@@ -51,15 +51,7 @@ final class RomeExecutableDownloader {
51
51
52
52
/**
53
53
* The pattern for {@link String#format(String, Object...) String.format()} for
54
- * the file name of a Rome executable for a certain version and architecure. The
55
- * first parameter is the platform, the second is the OS, the third is the
56
- * architecture.
57
- */
58
- private static final String DOWNLOAD_FILE_PATTERN = "rome-%s-%s-%s" ;
59
-
60
- /**
61
- * The pattern for {@link String#format(String, Object...) String.format()} for
62
- * the platform part of the Rome executable download URL. First parameter is the
54
+ * the platform part of the Biome executable download URL. First parameter is the
63
55
* OS, second parameter the architecture, the third the file extension.
64
56
*/
65
57
private static final String PLATFORM_PATTERN = "%s-%s%s" ;
@@ -70,39 +62,36 @@ final class RomeExecutableDownloader {
70
62
*/
71
63
private static final OpenOption [] READ_OPTIONS = {StandardOpenOption .READ };
72
64
73
- /**
74
- * The pattern for {@link String#format(String, Object...) String.format()} for
75
- * the URL where the Rome executables can be downloaded. The first parameter is
76
- * the version, the second parameter is the OS / platform.
77
- */
78
- private static final String URL_PATTERN = "https://github.com/rome/tools/releases/download/cli%%2Fv%s/rome-%s" ;
79
-
80
65
/**
81
66
* {@link OpenOption Open options} for creating a new file, overwriting the
82
67
* existing file if present.
83
68
*/
84
69
private static final OpenOption [] WRITE_OPTIONS = {StandardOpenOption .CREATE , StandardOpenOption .TRUNCATE_EXISTING ,
85
70
StandardOpenOption .WRITE };
86
71
87
- private Path downloadDir ;
72
+ private final Path downloadDir ;
73
+
74
+ private final EBiomeFlavor flavor ;
88
75
89
76
/**
90
- * Creates a new downloader for the Rome executable. The executable files are
77
+ * Creates a new downloader for the Biome executable. The executable files are
91
78
* stored in the given download directory.
92
79
*
93
- * @param downloadDir Directory where
80
+ * @param flavor Flavor of Biome to use.
81
+ * @param downloadDir Directory where to store the downloaded executable.
94
82
*/
95
- public RomeExecutableDownloader (Path downloadDir ) {
83
+ public RomeExecutableDownloader (EBiomeFlavor flavor , Path downloadDir ) {
84
+ this .flavor = flavor ;
96
85
this .downloadDir = downloadDir ;
97
86
}
98
87
99
88
/**
100
- * Downloads the Rome executable for the current platform from the network to
89
+ * Downloads the Biome executable for the current platform from the network to
101
90
* the download directory. When the executable exists already, it is
102
91
* overwritten.
103
92
*
104
- * @param version Desired Rome version.
105
- * @return The path to the Rome executable.
93
+ * @param version Desired Biome version.
94
+ * @return The path to the Biome executable.
106
95
* @throws IOException When the executable cannot be downloaded from
107
96
* the network or the file system could not be
108
97
* accessed.
@@ -121,7 +110,7 @@ public Path download(String version) throws IOException, InterruptedException {
121
110
if (executableDir != null ) {
122
111
Files .createDirectories (executableDir );
123
112
}
124
- logger .info ("Attempting to download Rome from '{}' to '{}'" , url , executablePath );
113
+ logger .info ("Attempting to download Biome from '{}' to '{}'" , url , executablePath );
125
114
var request = HttpRequest .newBuilder (URI .create (url )).GET ().build ();
126
115
var handler = BodyHandlers .ofFile (executablePath , WRITE_OPTIONS );
127
116
var response = HttpClient .newBuilder ().followRedirects (Redirect .NORMAL ).build ().send (request , handler );
@@ -133,19 +122,19 @@ public Path download(String version) throws IOException, InterruptedException {
133
122
throw new IOException ("Failed to download file from " + url + ", file is empty or does not exist" );
134
123
}
135
124
writeChecksumFile (downloadedFile , checksumPath );
136
- logger .debug ("Rome was downloaded successfully to '{}'" , downloadedFile );
125
+ logger .debug ("Biome was downloaded successfully to '{}'" , downloadedFile );
137
126
return downloadedFile ;
138
127
}
139
128
140
129
/**
141
- * Ensures that the Rome executable for the current platform exists in the
130
+ * Ensures that the Biome executable for the current platform exists in the
142
131
* download directory. When the executable does not exist in the download
143
- * directory, an attempt is made to download the Rome executable from the
132
+ * directory, an attempt is made to download the Biome executable from the
144
133
* network. When the executable exists already, no attempt to download it again
145
134
* is made.
146
135
*
147
- * @param version Desired Rome version.
148
- * @return The path to the Rome executable.
136
+ * @param version Desired Biome version.
137
+ * @return The path to the Biome executable.
149
138
* @throws IOException When the executable cannot be downloaded from
150
139
* the network or the file system could not be
151
140
* accessed.
@@ -157,23 +146,23 @@ public Path download(String version) throws IOException, InterruptedException {
157
146
*/
158
147
public Path ensureDownloaded (String version ) throws IOException , InterruptedException {
159
148
var platform = Platform .guess ();
160
- logger .debug ("Ensuring that Rome for platform '{}' is downloaded" , platform );
149
+ logger .debug ("Ensuring that Biome for platform '{}' is downloaded" , platform );
161
150
var existing = findDownloaded (version );
162
151
if (existing .isPresent ()) {
163
- logger .debug ("Rome was already downloaded, using executable at '{}'" , existing .get ());
152
+ logger .debug ("Biome was already downloaded, using executable at '{}'" , existing .get ());
164
153
return existing .get ();
165
154
} else {
166
- logger .debug ("Rome was not yet downloaded, attempting to download executable" );
155
+ logger .debug ("Biome was not yet downloaded, attempting to download executable" );
167
156
return download (version );
168
157
}
169
158
}
170
159
171
160
/**
172
- * Attempts to find the Rome executable for the current platform in the download
161
+ * Attempts to find the Biome executable for the current platform in the download
173
162
* directory. No attempt is made to download the executable from the network.
174
163
*
175
- * @param version Desired Rome version.
176
- * @return The path to the Rome executable.
164
+ * @param version Desired Biome version.
165
+ * @return The path to the Biome executable.
177
166
* @throws IOException When the executable does not exists in the
178
167
* download directory, or when the file system
179
168
* could not be accessed.
@@ -184,7 +173,7 @@ public Path ensureDownloaded(String version) throws IOException, InterruptedExce
184
173
public Optional <Path > findDownloaded (String version ) throws IOException {
185
174
var platform = Platform .guess ();
186
175
var executablePath = getExecutablePath (version , platform );
187
- logger .debug ("Checking rome executable at {}" , executablePath );
176
+ logger .debug ("Checking Biome executable at {}" , executablePath );
188
177
return checkFileWithChecksum (executablePath ) ? Optional .ofNullable (executablePath ) : Optional .empty ();
189
178
}
190
179
@@ -248,12 +237,12 @@ private String computeChecksum(Path file, String algorithm) throws IOException {
248
237
}
249
238
250
239
/**
251
- * Finds the code name for the given operating system used by the Rome
240
+ * Finds the code name for the given operating system used by the Biome
252
241
* executable download URL.
253
242
*
254
243
* @param os Desired operating system.
255
- * @return Code name for the Rome download URL.
256
- * @throws IOException When the given OS is not supported by Rome .
244
+ * @return Code name for the Biome download URL.
245
+ * @throws IOException When the given OS is not supported by Biome .
257
246
*/
258
247
private String getArchitectureCodeName (Architecture architecture ) throws IOException {
259
248
switch (architecture ) {
@@ -281,28 +270,28 @@ private Path getChecksumPath(Path file) {
281
270
}
282
271
283
272
/**
284
- * Finds the URL from which the Rome executable can be downloaded.
273
+ * Finds the URL from which the Biome executable can be downloaded.
285
274
*
286
- * @param version Desired Rome version.
275
+ * @param version Desired Biome version.
287
276
* @param platform Desired platform.
288
- * @return The URL for the Rome executable.
289
- * @throws IOException When the platform is not supported by Rome .
277
+ * @return The URL for the Biome executable.
278
+ * @throws IOException When the platform is not supported by Biome .
290
279
*/
291
280
private String getDownloadUrl (String version , Platform platform ) throws IOException {
292
281
var osCodeName = getOsCodeName (platform .getOs ());
293
282
var architectureCodeName = getArchitectureCodeName (platform .getArchitecture ());
294
283
var extension = getDownloadUrlExtension (platform .getOs ());
295
284
var platformString = String .format (PLATFORM_PATTERN , osCodeName , architectureCodeName , extension );
296
- return String .format (URL_PATTERN , version , platformString );
285
+ return String .format (flavor . getUrlPattern () , version , platformString );
297
286
}
298
287
299
288
/**
300
- * Finds the file extension of the Rome download URL for the given operating
289
+ * Finds the file extension of the Biome download URL for the given operating
301
290
* system.
302
291
*
303
292
* @param os Desired operating system.
304
- * @return Extension for the Rome download URL.
305
- * @throws IOException When the given OS is not supported by Rome .
293
+ * @return Extension for the Biome download URL.
294
+ * @throws IOException When the given OS is not supported by Biome .
306
295
*/
307
296
private String getDownloadUrlExtension (OS os ) throws IOException {
308
297
switch (os ) {
@@ -318,27 +307,27 @@ private String getDownloadUrlExtension(OS os) throws IOException {
318
307
}
319
308
320
309
/**
321
- * Finds the path on the file system for the Rome executable with a given
310
+ * Finds the path on the file system for the Biome executable with a given
322
311
* version and platform.
323
312
*
324
- * @param version Desired Rome version.
313
+ * @param version Desired Biome version.
325
314
* @param platform Desired platform.
326
- * @return The path for the Rome executable.
315
+ * @return The path for the Biome executable.
327
316
*/
328
317
private Path getExecutablePath (String version , Platform platform ) {
329
318
var os = platform .getOs ().name ().toLowerCase (Locale .ROOT );
330
319
var arch = platform .getArchitecture ().name ().toLowerCase (Locale .ROOT );
331
- var fileName = String .format (DOWNLOAD_FILE_PATTERN , os , arch , version );
320
+ var fileName = String .format (flavor . getDownloadFilePattern () , os , arch , version );
332
321
return downloadDir .resolve (fileName );
333
322
}
334
323
335
324
/**
336
- * Finds the code name for the given operating system used by the Rome
325
+ * Finds the code name for the given operating system used by the Biome
337
326
* executable download URL.
338
327
*
339
328
* @param os Desired operating system.
340
- * @return Code name for the Rome download URL.
341
- * @throws IOException When the given OS is not supported by Rome .
329
+ * @return Code name for the Biome download URL.
330
+ * @throws IOException When the given OS is not supported by Biome .
342
331
*/
343
332
private String getOsCodeName (OS os ) throws IOException {
344
333
switch (os ) {
0 commit comments