@@ -57,7 +57,7 @@ public String getVersion() {
57
57
public static List <String > getSupportedVersions () {
58
58
try {
59
59
return fetchSupportedVersions ();
60
- } catch (Exception e ) {
60
+ } catch (Exception e ) { //NOPMD - suppressed AvoidCatchingGenericException
61
61
// Return an empty list or log the exception
62
62
return List .of ();
63
63
}
@@ -71,9 +71,9 @@ public static List<String> getSupportedVersions() {
71
71
* @return List[String] containing supported version strings
72
72
* @throws Exception if an error occurs during HTTP connection or JSON parsing
73
73
*/
74
- public static List <String > fetchSupportedVersions () throws Exception {
75
- String url = "https://repo.packagist.org/p2/magento/community-edition.json" ;
76
- List <String > versions = new ArrayList <>();
74
+ public static List <String > fetchSupportedVersions () throws Exception { //NOPMD - suppressed SignatureDeclareThrowsException
75
+ final String url = "https://repo.packagist.org/p2/magento/community-edition.json" ;
76
+ final List <String > versions = new ArrayList <>();
77
77
78
78
HttpURLConnection connection = null ;
79
79
try {
@@ -82,8 +82,8 @@ public static List<String> fetchSupportedVersions() throws Exception {
82
82
connection .setRequestMethod ("GET" );
83
83
connection .setRequestProperty ("Accept" , "application/json" );
84
84
85
- if (connection .getResponseCode () != 200 ) {
86
- throw new Exception (
85
+ if (connection .getResponseCode () != 200 ) { //NOPMD - suppressed AvoidLiteralsInIfCondition
86
+ throw new Exception ( //NOPMD - suppressed AvoidThrowingRawExceptionTypes
87
87
"Failed to fetch data, HTTP response code: " + connection .getResponseCode ()
88
88
);
89
89
}
@@ -92,35 +92,30 @@ public static List<String> fetchSupportedVersions() throws Exception {
92
92
try (BufferedReader reader = new BufferedReader (
93
93
new InputStreamReader (connection .getInputStream ()))
94
94
) {
95
- StringBuilder response = new StringBuilder ();
95
+ final StringBuilder response = new StringBuilder ();
96
96
String line ;
97
- while ((line = reader .readLine ()) != null ) {
97
+ while ((line = reader .readLine ()) != null ) { //NOPMD - suppressed AssignmentInOperand
98
98
response .append (line );
99
99
}
100
100
101
101
// Parse JSON for version data
102
- JSONObject jsonResponse = new JSONObject (response .toString ());
103
- JSONArray packageObject = jsonResponse
102
+ final JSONObject jsonResponse = new JSONObject (response .toString ());
103
+ final JSONArray packageObject = jsonResponse
104
104
.getJSONObject ("packages" )
105
105
.getJSONArray ("magento/community-edition" );
106
106
107
- for (Object o : packageObject ) {
108
- JSONObject version = (JSONObject ) o ;
107
+ for (final Object o : packageObject ) {
108
+ final JSONObject version = (JSONObject ) o ;
109
109
if (version == null ) {
110
110
continue ;
111
111
}
112
- String versionstring = version .getString ("version" );
112
+ final String versionstring = version .getString ("version" );
113
113
if (versionstring == null ) {
114
114
continue ;
115
115
}
116
116
versions .add (versionstring );
117
117
}
118
118
}
119
- } catch (Exception e ) {
120
- throw new Exception (
121
- "Error fetching or parsing supported versions: " + e .getMessage (),
122
- e
123
- );
124
119
} finally {
125
120
if (connection != null ) {
126
121
connection .disconnect ();
0 commit comments