1010import java .io .BufferedReader ;
1111import java .io .IOException ;
1212import java .io .InputStreamReader ;
13+ import java .net .URI ;
14+ import java .net .URISyntaxException ;
1315import java .net .URL ;
1416
1517import static java .net .HttpURLConnection .HTTP_OK ;
@@ -33,20 +35,23 @@ public class GithubVersionChecker {
3335 * @param currentVersion The current version running
3436 * @param includePreReleases Whether pre releases should be tested (default: false)
3537 */
36- public GithubVersionChecker (String username , String repo , ReleaseVersion currentVersion , boolean includePreReleases ) {
38+ public GithubVersionChecker (String username , String repo , ReleaseVersion currentVersion ,
39+ boolean includePreReleases ) {
3740 this .username = username ;
3841 this .repo = repo ;
3942 this .currentVersion = currentVersion ;
4043 this .includePreReleases = includePreReleases ;
4144
4245 try {
43- URL url = new URL (String .format ("https://api.github.com/repos/%s/%s" , this .username , this .repo ));
46+ URL url = new URI (
47+ String .format ("https://api.github.com/repos/%s/%s" , this .username , this .repo ))
48+ .toURL ();
4449 HttpsURLConnection con = (HttpsURLConnection ) url .openConnection ();
4550 con .setRequestMethod ("GET" );
4651 if (con .getResponseCode () != HTTP_OK ) {
4752 throw new RepoNotFoundException (this .username , this .repo );
4853 }
49- } catch (IOException e ) {
54+ } catch (IOException | URISyntaxException e ) {
5055 e .printStackTrace ();
5156 }
5257 }
@@ -65,24 +70,27 @@ public CheckResult check() {
6570 if (this .includePreReleases )
6671 queryURL = "https://api.github.com/repos/%s/%s/releases?per_page=1" ;
6772 try {
68- URL url = new URL (String .format (queryURL , this .username , this .repo ));
73+ URL url = new URI (String .format (queryURL , this .username , this .repo )). toURL ( );
6974 HttpsURLConnection con = (HttpsURLConnection ) url .openConnection ();
7075 con .setRequestMethod ("GET" );
71- if (con .getResponseCode () != HTTP_OK ) throw new NoReleaseFoundException (this .username , this .repo );
76+ if (con .getResponseCode () != HTTP_OK )
77+ throw new NoReleaseFoundException (this .username , this .repo );
7278
7379 BufferedReader in = new BufferedReader (new InputStreamReader (con .getInputStream ()));
7480
7581 JsonObject releaseData ;
7682 if (this .includePreReleases ) {
7783 JsonArray jsonArray = JsonParser .parseReader (in ).getAsJsonArray ();
78- if (jsonArray .size () == 0 ) throw new NoReleaseFoundException (this .username , this .repo );
84+ if (jsonArray .size () == 0 )
85+ throw new NoReleaseFoundException (this .username , this .repo );
7986 releaseData = jsonArray .get (0 ).getAsJsonObject ();
8087 } else
8188 releaseData = JsonParser .parseReader (in ).getAsJsonObject ();
8289 in .close ();
8390 con .disconnect ();
8491
85- ReleaseVersion githubVersion = new ReleaseVersion (releaseData .get ("tag_name" ).getAsString ());
92+ ReleaseVersion githubVersion =
93+ new ReleaseVersion (releaseData .get ("tag_name" ).getAsString ());
8694 String pageLink = releaseData .get ("html_url" ).getAsString ();
8795 switch (this .currentVersion .compareTo (githubVersion )) {
8896 case -1 :
@@ -95,7 +103,7 @@ public CheckResult check() {
95103 return null ;
96104 }
97105
98- } catch (IOException e ) {
106+ } catch (IOException | URISyntaxException e ) {
99107 e .printStackTrace ();
100108 }
101109 return null ;
0 commit comments