3232 */
3333public 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