Skip to content

Commit f38b837

Browse files
committed
cleanup
1 parent 8185fbc commit f38b837

File tree

5 files changed

+37
-37
lines changed

5 files changed

+37
-37
lines changed

src/main/java/io/github/fvarrui/javapackager/utils/updater/AdoptV3API.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
package io.github.fvarrui.javapackager.utils.updater;
1010

1111
import com.google.gson.JsonArray;
12-
import com.google.gson.JsonElement;
1312
import com.google.gson.JsonObject;
1413

1514
import java.io.IOException;
@@ -29,12 +28,12 @@ public JsonObject getAvailableReleases() throws IOException {
2928

3029
public String getLatestLTSRelease() throws IOException {
3130
JsonArray arr = getAvailableReleases().getAsJsonArray("available_lts_releases");
32-
return arr.get(arr.size()-1).getAsString();
31+
return arr.get(arr.size() - 1).getAsString();
3332
}
3433

3534
public String getLatestRelease() throws IOException {
3635
JsonArray arr = getAvailableReleases().getAsJsonArray("available_releases");
37-
return arr.get(arr.size()-1).getAsString();
36+
return arr.get(arr.size() - 1).getAsString();
3837
}
3938

4039
/**

src/main/java/io/github/fvarrui/javapackager/utils/updater/Github.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ public class Github {
1515

1616
/**
1717
* Searches the latest GitHub release and returns a {@link SearchResult} object with all the relevant information.
18-
* @param repoName GitHub repository name.
19-
* @param currentVersion current version of the installed software.
18+
*
19+
* @param repoName GitHub repository name.
20+
* @param currentVersion current version of the installed software.
2021
* @param assetNamePredicate predicate that contains the asset name and ist used to determine the asset to download.
2122
*/
2223
public static SearchResult searchUpdate(String repoName, String currentVersion, Predicate<String> assetNamePredicate) {

src/main/java/io/github/fvarrui/javapackager/utils/updater/Json.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ public class Json {
1414
/**
1515
* Reads/Parses the provided String to a {@link JsonElement}.
1616
*/
17-
public static JsonElement from(String s){
17+
public static JsonElement from(String s) {
1818
return JsonParser.parseString(s);
1919
}
2020

2121
/**
2222
* Writes/Parses the provided {@link JsonElement} to a String.
2323
*/
24-
public static String toString(JsonElement el){
24+
public static String toString(JsonElement el) {
2525
return new Gson().toJson(el);
2626
}
2727

@@ -46,7 +46,7 @@ public static JsonElement fromUrl(String url) throws IOException {
4646
element = JsonParser.parseReader(inr);
4747
}
4848
} else {
49-
throw new IOException("error: "+con.getResponseCode()+" message: \""+con.getResponseMessage()+ "\" url: " + url);
49+
throw new IOException("error: " + con.getResponseCode() + " message: \"" + con.getResponseMessage() + "\" url: " + url);
5050
}
5151
} catch (IOException e) {
5252
if (con != null) con.disconnect();

src/main/java/io/github/fvarrui/javapackager/utils/updater/TaskJavaDownload.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public class TaskJavaDownload {
3535
private AdoptV3API.OperatingSystemType osType;
3636

3737
/**
38-
* @param url the download-url.
39-
* @param dest the downloads final destination. Note that the file name must end with '.file', because
40-
* the actual file type gets set when there is download information available.
38+
* @param url the download-url.
39+
* @param dest the downloads final destination. Note that the file name must end with '.file', because
40+
* the actual file type gets set when there is download information available.
4141
*/
4242
public void execute(String url, File dest, AdoptV3API.OperatingSystemType osType) throws Exception {
4343
this.url = url;

src/main/java/io/github/fvarrui/javapackager/utils/updater/TaskJavaUpdater.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*/
3333
public class TaskJavaUpdater {
3434

35-
public File downloadsDir = new File(NativeUtils.getUserTempFolder()+"/downloads");
35+
public File downloadsDir = new File(NativeUtils.getUserTempFolder() + "/downloads");
3636
public File jdkPath;
3737
public Platform platform;
3838
public AdoptV3API.OperatingSystemType osType;
@@ -41,15 +41,15 @@ public TaskJavaUpdater(Platform platform) {
4141
this.platform = platform;
4242
switch (platform) {
4343
case linux:
44-
jdkPath = new File(NativeUtils.getUserTempFolder()+"/jdk/linux");
44+
jdkPath = new File(NativeUtils.getUserTempFolder() + "/jdk/linux");
4545
osType = AdoptV3API.OperatingSystemType.LINUX;
4646
break;
4747
case mac:
48-
jdkPath = new File(NativeUtils.getUserTempFolder()+"/jdk/mac");
48+
jdkPath = new File(NativeUtils.getUserTempFolder() + "/jdk/mac");
4949
osType = AdoptV3API.OperatingSystemType.MAC;
5050
break;
5151
case windows:
52-
jdkPath = new File(NativeUtils.getUserTempFolder()+"/jdk/win");
52+
jdkPath = new File(NativeUtils.getUserTempFolder() + "/jdk/win");
5353
osType = AdoptV3API.OperatingSystemType.WINDOWS;
5454
break;
5555
default:
@@ -61,14 +61,14 @@ public TaskJavaUpdater(Platform platform) {
6161
public void execute(String javaVersion, String javaVendor) throws Exception {
6262
Objects.requireNonNull(javaVersion);
6363
Objects.requireNonNull(javaVendor);
64-
if(javaVendor.equals(Const.graalvm)){
64+
if (javaVendor.equals(Const.graalvm)) {
6565
Logger.info("Checking java installation...");
6666

6767
String currentVersion = getBuildID(javaVersion, javaVendor);
6868
String osName = (platform.equals(Platform.linux) ? "linux" :
6969
platform.equals(Platform.mac) ? "darwin" :
70-
platform.equals(Platform.windows) ? "windows" :
71-
null);
70+
platform.equals(Platform.windows) ? "windows" :
71+
null);
7272
Objects.requireNonNull(osName);
7373
Pattern pattern = Pattern.compile("(java)(\\d+)"); // matches java11 or java17 for example
7474
SearchResult result = Github.searchUpdate("graalvm/graalvm-ce-builds", currentVersion,
@@ -77,13 +77,13 @@ public void execute(String javaVersion, String javaVendor) throws Exception {
7777
&& new UtilsVersion().isLatestBiggerOrEqual(javaVersion, pattern.matcher(assetName).group())
7878
&& !assetName.endsWith(".sha256")
7979
&& !assetName.endsWith(".jar"));
80-
if(result.exception!=null) throw result.exception;
80+
if (result.exception != null) throw result.exception;
8181
if (!result.isUpdateAvailable) {
8282
Logger.info("Your Java installation is on the latest version!");
8383
return;
8484
}
8585

86-
if (result.downloadUrl == null){
86+
if (result.downloadUrl == null) {
8787
Logger.error("Couldn't find a matching asset to download.");
8888
return;
8989
}
@@ -92,7 +92,7 @@ && new UtilsVersion().isLatestBiggerOrEqual(javaVersion, pattern.matcher(assetNa
9292
currentVersion, result.latestVersion,
9393
javaVersion, javaVendor);
9494

95-
} else if(javaVendor.equals(Const.adoptium)){
95+
} else if (javaVendor.equals(Const.adoptium)) {
9696
Logger.info("Checking java installation...");
9797

9898
AdoptV3API.OperatingSystemArchitectureType osArchitectureType = AdoptV3API.OperatingSystemArchitectureType.X64;
@@ -121,7 +121,7 @@ && new UtilsVersion().isLatestBiggerOrEqual(javaVersion, pattern.matcher(assetNa
121121
}
122122
}
123123

124-
if (jsonLatestRelease == null){
124+
if (jsonLatestRelease == null) {
125125
Logger.error("Couldn't find a matching major version to '" + javaVersion + "'.");
126126
return;
127127
}
@@ -163,12 +163,12 @@ && new UtilsVersion().isLatestBiggerOrEqual(javaVersion, pattern.matcher(assetNa
163163
);
164164

165165
download(downloadURL, checksum,
166-
""+currentBuildId, ""+latestBuildId,
166+
"" + currentBuildId, "" + latestBuildId,
167167
javaVersion, javaVendor);
168168

169-
} else{
170-
throw new IllegalArgumentException("The provided Java vendor '"+javaVendor+"' is currently not supported!" +
171-
" Supported: "+Const.adoptium+" and "+Const.graalvm+".");
169+
} else {
170+
throw new IllegalArgumentException("The provided Java vendor '" + javaVendor + "' is currently not supported!" +
171+
" Supported: " + Const.adoptium + " and " + Const.graalvm + ".");
172172
}
173173
}
174174

@@ -177,12 +177,12 @@ private void download(String downloadURL, String expectedSha256,
177177
String javaVersion, String javaVendor) throws Exception {
178178
Logger.info("Update found " + currentVersion + " -> " + latestVersion);
179179
File final_dir_dest = jdkPath;
180-
File cache_dest = new File(downloadsDir + "/" + javaVendor + "-" + javaVersion + "-"+ latestVersion + ".file");
180+
File cache_dest = new File(downloadsDir + "/" + javaVendor + "-" + javaVersion + "-" + latestVersion + ".file");
181181
TaskJavaDownload download = new TaskJavaDownload();
182182
download.execute(downloadURL, cache_dest, osType);
183183

184184
Logger.info("Java update downloaded. Checking hash...");
185-
if(!download.compareWithSHA256(expectedSha256))
185+
if (!download.compareWithSHA256(expectedSha256))
186186
throw new IOException("Hash of downloaded Java update is not valid!");
187187
Logger.info("Hash is valid, removing old installation...");
188188
FileUtils.deleteDirectory(final_dir_dest);
@@ -197,29 +197,29 @@ private void download(String downloadURL, String expectedSha256,
197197
// The zip/archive contains another folder inside like /jdk8+189
198198
// thus we need to move that folders content to its parent dir
199199
archiver.extract(download.getNewCacheDest(), final_dir_dest);
200-
setBuildID(""+latestVersion, javaVersion, javaVendor);
200+
setBuildID("" + latestVersion, javaVersion, javaVendor);
201201
File actualJdkPath = null;
202202
for (File file : jdkPath.listFiles()) {
203-
if(file.isDirectory()){
203+
if (file.isDirectory()) {
204204
actualJdkPath = file;
205205
break;
206206
}
207207
}
208208
for (File file : actualJdkPath.listFiles()) {
209-
Files.move(file, new File(jdkPath+"/"+file.getName()));
209+
Files.move(file, new File(jdkPath + "/" + file.getName()));
210210
}
211211
FileUtils.deleteDirectory(actualJdkPath);
212212
FileUtils.deleteDirectory(downloadsDir);
213-
Logger.info("Java update was installed successfully (" + currentVersion + " -> " + latestVersion + ") at "+jdkPath);
213+
Logger.info("Java update was installed successfully (" + currentVersion + " -> " + latestVersion + ") at " + jdkPath);
214214
}
215215

216-
private String getFileNameWithoutID(String javaVersion, String javaVendor){
217-
return "java_packager_jdk_"+javaVersion+"_"+javaVendor+"_build_id";
216+
private String getFileNameWithoutID(String javaVersion, String javaVendor) {
217+
return "java_packager_jdk_" + javaVersion + "_" + javaVendor + "_build_id";
218218
}
219219

220220
private String getBuildID(String javaVersion, String javaVendor) throws IOException {
221221
for (File file : jdkPath.listFiles()) {
222-
if(file.getName().startsWith(getFileNameWithoutID(javaVersion, javaVendor))){
222+
if (file.getName().startsWith(getFileNameWithoutID(javaVersion, javaVendor))) {
223223
return file.getName().split(" ")[1];
224224
}
225225
}
@@ -229,11 +229,11 @@ private String getBuildID(String javaVersion, String javaVendor) throws IOExcept
229229

230230
private void setBuildID(String id, String javaVersion, String javaVendor) throws IOException {
231231
for (File file : jdkPath.listFiles()) {
232-
if(file.getName().startsWith(getFileNameWithoutID(javaVersion, javaVendor))){
232+
if (file.getName().startsWith(getFileNameWithoutID(javaVersion, javaVendor))) {
233233
file.delete();
234234
}
235235
}
236-
File file = new File(jdkPath+"/"+getFileNameWithoutID(javaVersion, javaVendor)+" "+id);
236+
File file = new File(jdkPath + "/" + getFileNameWithoutID(javaVersion, javaVendor) + " " + id);
237237
file.createNewFile();
238238
}
239239

0 commit comments

Comments
 (0)