@@ -47,16 +47,17 @@ public class MCEFResourceManager {
47
47
private static final String JAVA_CEF_CHECKSUM_DOWNLOAD_URL =
48
48
"${host}/mcef-cef/${java-cef-commit}/${platform}/checksum" ;
49
49
50
- private final String host ;
50
+ private final String [] hosts ;
51
51
private final String javaCefCommitHash ;
52
52
private final MCEFPlatform platform ;
53
53
public final MCEFProgressTracker progressTracker = new MCEFProgressTracker ();
54
+ public int hostCounter = 0 ;
54
55
55
56
private final File commitDirectory ;
56
57
private final File platformDirectory ;
57
58
58
- private MCEFResourceManager (String host , String javaCefCommitHash , MCEFPlatform platform , File directory ) {
59
- this .host = host ;
59
+ private MCEFResourceManager (String [] hosts , String javaCefCommitHash , MCEFPlatform platform , File directory ) {
60
+ this .hosts = hosts ;
60
61
this .javaCefCommitHash = javaCefCommitHash ;
61
62
this .platform = platform ;
62
63
this .commitDirectory = new File (directory , javaCefCommitHash );
@@ -75,7 +76,7 @@ static MCEFResourceManager newResourceManager() throws IOException {
75
76
MCEF .INSTANCE .getLogger ().info ("JCEF Commit: " + javaCefCommit );
76
77
var settings = MCEF .INSTANCE .getSettings ();
77
78
78
- return new MCEFResourceManager (settings .getDownloadMirror ( ), javaCefCommit ,
79
+ return new MCEFResourceManager (settings .getHosts (). toArray ( new String [ 0 ] ), javaCefCommit ,
79
80
MCEFPlatform .getPlatform (), settings .getLibrariesDirectory ());
80
81
}
81
82
@@ -90,6 +91,11 @@ public boolean requiresDownload() throws IOException {
90
91
91
92
var checksumFile = new File (commitDirectory , platform .getNormalizedName () + ".tar.gz.sha256" );
92
93
94
+ // If checksum file doesn't exist, we need to download JCEF
95
+ if (!checksumFile .exists ()) {
96
+ return true ;
97
+ }
98
+
93
99
// We always download the checksum for the java-cef build
94
100
// We will compare this with <platform>.tar.gz.sha256
95
101
// If the contents of the files differ (or it doesn't exist locally), we know we need to redownload JCEF
@@ -104,14 +110,14 @@ public boolean requiresDownload() throws IOException {
104
110
}
105
111
var platformDirectoryExists = platformDirectory .exists ();
106
112
107
- MCEF .INSTANCE .getLogger ().info ("Checksum matches: " + checksumMatches );
108
- MCEF .INSTANCE .getLogger ().info ("Platform directory exists: " + platformDirectoryExists );
113
+ MCEF .INSTANCE .getLogger ().info ("Checksum matches: {}" , checksumMatches );
114
+ MCEF .INSTANCE .getLogger ().info ("Platform directory exists: {}" , platformDirectoryExists );
109
115
110
116
return !checksumMatches || !platformDirectoryExists ;
111
117
}
112
118
113
119
public void downloadJcef () throws IOException {
114
- var retry = 0 ;
120
+ hostCounter = 0 ;
115
121
116
122
while (true ) {
117
123
try {
@@ -126,19 +132,26 @@ public void downloadJcef() throws IOException {
126
132
}
127
133
}
128
134
129
- // Checksum file should have been created by [compareChecksum] call in [requiresDownload]
130
- // However if not, we either attempt to download it again.
131
- if (!checksumFile .exists ()) {
135
+ if (checksumFile .exists ()) {
132
136
try {
133
- downloadFile ( getJavaCefChecksumDownloadUrl (), checksumFile , progressTracker );
137
+ FileUtils . forceDelete ( checksumFile );
134
138
} catch (Exception e ) {
135
- MCEF .INSTANCE .getLogger ().error ("Failed to download checksum file" , e );
136
- throw e ;
139
+ MCEF .INSTANCE .getLogger ().warn ("Failed to delete existing .tar.gz file" , e );
137
140
}
138
141
}
139
142
143
+ // Download checksum file
144
+ MCEF .INSTANCE .getLogger ().info ("Downloading checksum file... [{}/{}]" , hostCounter + 1 , hosts .length );
145
+ progressTracker .setTask ("Downloading Checksum" );
146
+ try {
147
+ downloadFile (getJavaCefChecksumDownloadUrl (), checksumFile , progressTracker );
148
+ } catch (Exception e ) {
149
+ MCEF .INSTANCE .getLogger ().error ("Failed to download checksum file" , e );
150
+ throw e ;
151
+ }
152
+
140
153
// Download JCEF from file hosting
141
- MCEF .INSTANCE .getLogger ().info ("Downloading JCEF..." );
154
+ MCEF .INSTANCE .getLogger ().info ("Downloading JCEF... [{}/{}]" , hostCounter + 1 , hosts . length );
142
155
progressTracker .setTask ("Downloading JCEF" );
143
156
downloadFile (getJavaCefDownloadUrl (), tarGzArchive , progressTracker );
144
157
@@ -173,10 +186,9 @@ public void downloadJcef() throws IOException {
173
186
break ;
174
187
} catch (Exception e ) {
175
188
MCEF .INSTANCE .getLogger ().error ("Failed to download and extract JCEF" , e );
176
- retry ++;
177
189
178
- // Retry up to 3 times
179
- if (retry >= 3 ) {
190
+ hostCounter ++;
191
+ if (hostCounter >= hosts . length ) {
180
192
throw e ;
181
193
}
182
194
}
@@ -185,8 +197,8 @@ public void downloadJcef() throws IOException {
185
197
progressTracker .done ();
186
198
}
187
199
188
- public String getHost () {
189
- return host ;
200
+ public String [] getHosts () {
201
+ return hosts ;
190
202
}
191
203
192
204
public String getJavaCefDownloadUrl () {
@@ -199,7 +211,7 @@ public String getJavaCefChecksumDownloadUrl() {
199
211
200
212
private String formatURL (String url ) {
201
213
return url
202
- .replace ("${host}" , host )
214
+ .replace ("${host}" , hosts [ hostCounter ] )
203
215
.replace ("${java-cef-commit}" , javaCefCommitHash )
204
216
.replace ("${platform}" , platform .getNormalizedName ());
205
217
}
0 commit comments