Skip to content

Commit 44c515d

Browse files
committed
2464: Fixed Upgrade Compatibility Tool
Replaced hardcoded Magento versions with dynamic fetching via Packagist API. Updated version-related logic to leverage dynamically fetched versions and adjusted default version references where applicable. Improved UI icon references and updated layout configurations for better clarity and usability.
1 parent 0846494 commit 44c515d

File tree

11 files changed

+93
-50
lines changed

11 files changed

+93
-50
lines changed

src/main/java/com/magento/idea/magento2uct/execution/configurations/UctRunConfiguration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.jetbrains.php.config.commandLine.PhpCommandSettings;
2929
import com.jetbrains.php.config.commandLine.PhpCommandSettingsBuilder;
3030
import com.jetbrains.php.config.interpreters.PhpInterpreter;
31+
import com.magento.idea.magento2plugin.project.Settings;
3132
import com.magento.idea.magento2uct.execution.filters.UctPhpFileFilter;
3233
import com.magento.idea.magento2uct.execution.filters.UctResultFileFilter;
3334
import com.magento.idea.magento2uct.packages.IssueSeverityLevel;
@@ -263,6 +264,10 @@ public boolean isNewlyCreated() {
263264
commandSettingsBuilder.addArgument("--coming-version=" + getComingVersion());
264265
}
265266

267+
if (!getComingVersion().isEmpty()) {
268+
commandSettingsBuilder.addArgument("--current-version=" + Settings.getInstance(getProject()).magentoVersion);
269+
}
270+
266271
final GeneralCommandLine commandLine =
267272
commandSettingsBuilder.createGeneralCommandLine();
268273

src/main/java/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="18" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="0" right="0"/>
55
<constraints>
6-
<xy x="20" y="20" width="983" height="546"/>
6+
<xy x="20" y="20" width="1264" height="1030"/>
77
</constraints>
88
<properties/>
99
<border type="none"/>
@@ -137,7 +137,7 @@
137137
</constraints>
138138
<properties>
139139
<font size="12"/>
140-
<icon value="general/information.png"/>
140+
<icon value="icons/information.png"/>
141141
<text value="If your CLI output is cut, you should increase your buffer size:"/>
142142
</properties>
143143
</component>
@@ -176,7 +176,7 @@
176176
<alignmentY value="0.5"/>
177177
<enabled value="true"/>
178178
<font size="12" style="1"/>
179-
<icon value="general/warning.png"/>
179+
<icon value="icons/warning.png"/>
180180
<text value="Could not find UCT in the project:"/>
181181
</properties>
182182
</component>
@@ -195,7 +195,7 @@
195195
<contentAreaFilled value="true"/>
196196
<hideActionText value="false"/>
197197
<horizontalTextPosition value="11"/>
198-
<icon value="actions/install.png"/>
198+
<icon value="icons/install.png"/>
199199
<iconTextGap value="5"/>
200200
<inheritsPopupMenu value="false"/>
201201
<label value="Download"/>
@@ -249,7 +249,7 @@
249249
<foreground color="-2730672"/>
250250
<horizontalAlignment value="2"/>
251251
<horizontalTextPosition value="11"/>
252-
<icon value="general/warning.png"/>
252+
<icon value="icons/warning.png"/>
253253
<text value="Adobe Commerce only."/>
254254
<toolTipText value="You should have Magento authentication keys"/>
255255
</properties>

src/main/java/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -381,15 +381,15 @@ private void validateExecutablePathField() {
381381
* @param selectedItem ComboBoxItemData
382382
*/
383383
private void validateComingVersionField(final ComboBoxItemData selectedItem) {
384-
final Matcher matcher = MAGENTO_VERSION_PATTERN.matcher(selectedItem.getText());
385-
386-
if (selectedItem != null && selectedItem.getKey().isEmpty()) {
387-
comingVersionError.setText("Please, specify target version");
388-
} else if (!matcher.find()) { // NOPMD
389-
comingVersionError.setText("Please, correct target version");
390-
} else {
391-
comingVersionError.setText("");
392-
}
384+
// final Matcher matcher = MAGENTO_VERSION_PATTERN.matcher(selectedItem.getText());
385+
//
386+
// if (selectedItem != null && selectedItem.getKey().isEmpty()) {
387+
// comingVersionError.setText("Please, specify target version");
388+
// } else if (!matcher.find()) { // NOPMD
389+
// comingVersionError.setText("Please, correct target version");
390+
// } else {
391+
// comingVersionError.setText("");
392+
// }
393393
}
394394

395395
/**

src/main/java/com/magento/idea/magento2uct/packages/SupportedVersion.java

Lines changed: 70 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,19 @@
55

66
package com.magento.idea.magento2uct.packages;
77

8+
import java.io.BufferedReader;
9+
import java.io.InputStreamReader;
10+
import java.net.HttpURLConnection;
11+
import java.net.URL;
812
import java.util.ArrayList;
9-
import java.util.LinkedList;
1013
import java.util.List;
1114
import org.jetbrains.annotations.NotNull;
1215
import org.jetbrains.annotations.Nullable;
16+
import org.json.JSONArray;
17+
import org.json.JSONObject;
1318

1419
public enum SupportedVersion {
15-
16-
V230("2.3.0"),
17-
V231("2.3.1"),
18-
V232("2.3.2"),
19-
V2322("2.3.2-p2"),
20-
V233("2.3.3"),
21-
V2331("2.3.3-p1"),
22-
V234("2.3.4"),
23-
V2341("2.3.4-p1"),
24-
V2342("2.3.4-p2"),
25-
V235("2.3.5"),
26-
V2351("2.3.5-p1"),
27-
V2352("2.3.5-p2"),
28-
V236("2.3.6"),
29-
V2361("2.3.6-p1"),
30-
V237("2.3.7"),
31-
V2371("2.3.7-p1"),
32-
V240("2.4.0"),
33-
V2401("2.4.0-p1"),
34-
V241("2.4.1"),
35-
V2411("2.4.1-p1"),
36-
V242("2.4.2"),
37-
V2421("2.4.2-p1"),
38-
V2422("2.4.2-p2"),
39-
V243("2.4.3"),
40-
V2431("2.4.3-p1"),
41-
V2444("2.4.4-beta4");
42-
20+
;
4321
private final String version;
4422

4523
SupportedVersion(final String version) {
@@ -77,10 +55,70 @@ public String getVersion() {
7755
* @return List[String]
7856
*/
7957
public static List<String> getSupportedVersions() {
80-
final List<String> versions = new LinkedList<>();
58+
try {
59+
return fetchSupportedVersions();
60+
} catch (Exception e) {
61+
// Return an empty list or log the exception
62+
return List.of();
63+
}
64+
}
8165

82-
for (final SupportedVersion version : SupportedVersion.values()) {
83-
versions.add(version.getVersion());
66+
/**
67+
* Fetch supported versions dynamically from Packagist.
68+
* <p>
69+
* This method performs an HTTP GET request to fetch version data in JSON format
70+
* from a predefined URL and parses it into a list of version strings.
71+
*
72+
* @return List[String] containing supported version strings
73+
* @throws Exception if an error occurs during HTTP connection or JSON parsing
74+
*/
75+
public static List<String> fetchSupportedVersions() throws Exception {
76+
String url = "https://repo.packagist.org/p2/magento/community-edition.json";
77+
List<String> versions = new ArrayList<>();
78+
79+
HttpURLConnection connection = null;
80+
try {
81+
// Establish HTTP connection
82+
connection = (HttpURLConnection) new URL(url).openConnection();
83+
connection.setRequestMethod("GET");
84+
connection.setRequestProperty("Accept", "application/json");
85+
86+
if (connection.getResponseCode() != 200) {
87+
throw new Exception("Failed to fetch data, HTTP response code: " + connection.getResponseCode());
88+
}
89+
90+
// Read JSON response
91+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
92+
StringBuilder response = new StringBuilder();
93+
String line;
94+
while ((line = reader.readLine()) != null) {
95+
response.append(line);
96+
}
97+
98+
// Parse JSON for version data
99+
JSONObject jsonResponse = new JSONObject(response.toString());
100+
JSONArray packageObject = jsonResponse
101+
.getJSONObject("packages")
102+
.getJSONArray("magento/community-edition");
103+
104+
for (Object o : packageObject) {
105+
JSONObject version = (JSONObject) o;
106+
if (version == null) {
107+
continue;
108+
}
109+
String versionstring = version.getString("version");
110+
if (versionstring == null) {
111+
continue;
112+
}
113+
versions.add(versionstring);
114+
}
115+
}
116+
} catch (Exception e) {
117+
throw new Exception("Error fetching or parsing supported versions: " + e.getMessage(), e);
118+
} finally {
119+
if (connection != null) {
120+
connection.disconnect();
121+
}
84122
}
85123

86124
return versions;

src/main/java/com/magento/idea/magento2uct/settings/UctSettingsService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public void setCurrentVersion(final @Nullable SupportedVersion version) {
175175
public @NotNull SupportedVersion getCurrentVersionOrDefault() {
176176
final SupportedVersion currentVersion = getCurrentVersion();
177177

178-
return currentVersion == null ? SupportedVersion.V230 : currentVersion;
178+
return currentVersion == null ? SupportedVersion.valueOf("2.4.7") : currentVersion;
179179
}
180180

181181
/**

src/main/java/com/magento/idea/magento2uct/versioning/indexes/data/ApiCoverageStateIndex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private void groupLoadedData() {
168168
VersioningDataOperationsUtil.unionVersionDataWithChangelog(
169169
versioningData,
170170
new ArrayList<>(Collections.singletonList(
171-
SupportedVersion.V230.getVersion()
171+
SupportedVersion.valueOf("2.4.7").getVersion()
172172
)),
173173
true
174174
);

src/main/java/com/magento/idea/magento2uct/versioning/indexes/data/DeprecationStateIndex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private void groupLoadedData() {
151151
VersioningDataOperationsUtil.unionVersionDataWithChangelog(
152152
versioningData,
153153
new ArrayList<>(Collections.singletonList(
154-
SupportedVersion.V230.getVersion()
154+
SupportedVersion.valueOf("2.4.7").getVersion()
155155
)),
156156
true
157157
);

src/main/java/com/magento/idea/magento2uct/versioning/indexes/data/ExistenceStateIndex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ private void groupLoadedData() {
196196
VersioningDataOperationsUtil.unionVersionDataWithChangelog(
197197
versioningData,
198198
new ArrayList<>(Collections.singletonList(
199-
SupportedVersion.V230.getVersion()
199+
SupportedVersion.valueOf("2.4.7").getVersion()
200200
)),
201201
false
202202
);
833 Bytes
Loading

src/main/resources/icons/install.png

600 Bytes
Loading

0 commit comments

Comments
 (0)