Skip to content

Commit d30c791

Browse files
authored
Merge pull request #2589 from 00110000/upgrade-compatibility-tool-fixes
Upgrade compatibility tool fixes
2 parents 85d1654 + f4bb50f commit d30c791

14 files changed

+99
-110
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ private String getStoredUctExecutablePath(
320320
private void initializeComboboxSources() {
321321
comingVersion.setToolTipText("Choose a target version");
322322

323-
for (final String version : SupportedVersion.getSupportedVersions()) {
324-
comingVersion.addItem(new ComboBoxItemData(version, version));
323+
for (final SupportedVersion version : SupportedVersion.getSupportedVersions()) {
324+
comingVersion.addItem(new ComboBoxItemData(version.getVersion(), version.getVersion()));
325325
}
326326

327327
for (final IssueSeverityLevel level : IssueSeverityLevel.getSeverityLabels()) {

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.magento.idea.magento2uct.versioning.processors.ExistenceIndexProcessor;
1414
import com.magento.idea.magento2uct.versioning.processors.IndexProcessor;
1515
import java.util.ArrayList;
16-
import java.util.Arrays;
1716
import java.util.List;
1817
import org.jetbrains.annotations.NotNull;
1918

@@ -22,32 +21,32 @@ public enum IndexRegistry {
2221
DEPRECATION(
2322
DeprecationStateIndex.class,
2423
new DeprecationIndexProcessor(),
25-
SupportedVersion.getSupportedVersions().toArray(new String[0])
24+
SupportedVersion.getSupportedVersionStrings()
2625
),
2726
EXISTENCE(
2827
ExistenceStateIndex.class,
2928
new ExistenceIndexProcessor(),
30-
SupportedVersion.getSupportedVersions().toArray(new String[0])
29+
SupportedVersion.getSupportedVersionStrings()
3130
),
3231
API_COVERAGE(
3332
ApiCoverageStateIndex.class,
3433
new ApiCoverageIndexProcessor(),
35-
SupportedVersion.getSupportedVersions().toArray(new String[0])
34+
SupportedVersion.getSupportedVersionStrings()
3635
);
3736

3837
private final String key;
3938
private final Class<?> type;
4039
private final IndexProcessor processor;
41-
private final String[] versions;
40+
private final List<String> versions;
4241

4342
IndexRegistry(
4443
final Class<?> type,
4544
final IndexProcessor processor,
46-
final String... versions
45+
final List<String> versions
4746
) {
4847
this.type = type;
4948
this.processor = processor;
50-
this.versions = Arrays.copyOf(versions, versions.length);
49+
this.versions = versions;
5150
key = this.toString();
5251
}
5352

@@ -84,7 +83,7 @@ public IndexProcessor getProcessor() {
8483
* @return List[String]
8584
*/
8685
public List<String> getVersions() {
87-
return Arrays.asList(versions);
86+
return versions;
8887
}
8988

9089
/**

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

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,64 +5,82 @@
55

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

8+
import org.jetbrains.annotations.NotNull;
9+
import org.jetbrains.annotations.Nullable;
10+
import org.json.JSONArray;
11+
import org.json.JSONObject;
812
import java.io.BufferedReader;
913
import java.io.IOException;
1014
import java.io.InputStreamReader;
1115
import java.net.HttpURLConnection;
1216
import java.net.URL;
1317
import java.util.ArrayList;
1418
import java.util.List;
15-
import org.jetbrains.annotations.NotNull;
16-
import org.jetbrains.annotations.Nullable;
17-
import org.json.JSONArray;
18-
import org.json.JSONObject;
19+
import java.util.concurrent.atomic.AtomicReference;
20+
21+
public final class SupportedVersion {
1922

20-
public enum SupportedVersion {
21-
;
2223
private final String version;
23-
private static final Integer SUCCESS_CODE = 200;
2424

25-
SupportedVersion(final String version) {
25+
private SupportedVersion(final String version) {
2626
this.version = version;
2727
}
2828

29-
/**
30-
* Get version.
31-
*
32-
* @return String
33-
*/
34-
public String getVersion() {
29+
public @NotNull String getVersion() {
3530
return version;
3631
}
3732

38-
/**
39-
* Get version ENUM by version code.
40-
*
41-
* @param versionCandidate String
42-
*
43-
* @return SupportedVersion
44-
*/
45-
public @Nullable static SupportedVersion getVersion(final @NotNull String versionCandidate) {
46-
for (final SupportedVersion version : SupportedVersion.values()) {
33+
private static final AtomicReference<List<SupportedVersion>> cachedVersions = new AtomicReference<>();
34+
35+
public static @NotNull List<SupportedVersion> getSupportedVersions() {
36+
List<SupportedVersion> versions = cachedVersions.get();
37+
38+
if (versions == null) {
39+
versions = new ArrayList<>();
40+
41+
try {
42+
for (final String versionStr : fetchRemoteSupportedVersions()) {
43+
versions.add(new SupportedVersion(versionStr));
44+
}
45+
} catch (Exception ignored) {
46+
}
47+
48+
cachedVersions.set(versions);
49+
}
50+
51+
return versions;
52+
}
53+
54+
public static List<String> getSupportedVersionStrings() {
55+
final List<String> versions = new ArrayList<>();
56+
57+
for (final SupportedVersion version : getSupportedVersions()) {
58+
versions.add(version.getVersion());
59+
}
60+
61+
return versions;
62+
}
63+
64+
public static @Nullable SupportedVersion getVersion(final @NotNull String versionCandidate) {
65+
for (final SupportedVersion version : getSupportedVersions()) {
4766
if (version.getVersion().equals(versionCandidate)) {
4867
return version;
4968
}
5069
}
70+
5171
return null;
5272
}
5373

54-
/**
55-
* Get supported versions.
56-
*
57-
* @return List[String]
58-
*/
59-
public static List<String> getSupportedVersions() {
60-
try {
61-
return fetchSupportedVersions();
62-
} catch (Exception e) { //NOPMD - suppressed AvoidCatchingGenericException
63-
// Return an empty list or log the exception
64-
return List.of();
74+
public static List<SupportedVersion> getPriorVersions(final SupportedVersion version) {
75+
final List<SupportedVersion> previousVersions = new ArrayList<>();
76+
77+
for (final SupportedVersion supportedVersion : getSupportedVersions()) {
78+
if (supportedVersion.getVersion().compareTo(version.toString()) < 0) {
79+
previousVersions.add(supportedVersion);
80+
}
6581
}
82+
83+
return previousVersions;
6684
}
6785

6886
/**
@@ -71,22 +89,22 @@ public static List<String> getSupportedVersions() {
7189
* from a predefined URL and parses it into a list of version strings.
7290
*
7391
* @return List[String] containing supported version strings
74-
* @throws IOException if an error occurs during HTTP connection or JSON parsing
7592
*/
76-
public static List<String> fetchSupportedVersions() throws IOException {
93+
private static List<String> fetchRemoteSupportedVersions() {
7794
final String url = "https://repo.packagist.org/p2/magento/community-edition.json";
7895
final List<String> versions = new ArrayList<>();
7996

8097
HttpURLConnection connection = null;
98+
8199
try {
82100
// Establish HTTP connection
83101
connection = (HttpURLConnection) new URL(url).openConnection();
84102
connection.setRequestMethod("GET");
85103
connection.setRequestProperty("Accept", "application/json");
86104

87-
if (connection.getResponseCode() != SUCCESS_CODE) {
105+
if (connection.getResponseCode() != 200) {
88106
throw new IOException(//NOPMD - suppressed AvoidThrowingRawExceptionTypes
89-
"Failed to fetch data, HTTP response code: " + connection.getResponseCode()
107+
"Failed to fetch data, HTTP response code: " + connection.getResponseCode()
90108
);
91109
}
92110

@@ -122,6 +140,7 @@ public static List<String> fetchSupportedVersions() throws IOException {
122140
versions.add(versionstring);
123141
}
124142
}
143+
} catch (IOException ignored) {
125144
} finally {
126145
if (connection != null) {
127146
connection.disconnect();
@@ -131,22 +150,4 @@ public static List<String> fetchSupportedVersions() throws IOException {
131150
return versions;
132151
}
133152

134-
/**
135-
* Get previous versions.
136-
*
137-
* @param version SupportedVersion
138-
*
139-
* @return List[SupportedVersion]
140-
*/
141-
public static List<SupportedVersion> getPriorVersions(final SupportedVersion version) {
142-
final List<SupportedVersion> previousVersions = new ArrayList<>();
143-
144-
for (final SupportedVersion supportedVersion : SupportedVersion.values()) {
145-
if (supportedVersion.compareTo(version) < 0) {
146-
previousVersions.add(supportedVersion);
147-
}
148-
}
149-
150-
return previousVersions;
151-
}
152-
}
153+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.magento.idea.magento2uct.packages.SupportedVersion;
1616
import org.jetbrains.annotations.NotNull;
1717
import org.jetbrains.annotations.Nullable;
18+
import java.util.List;
1819

1920
@State(name = "Magento2UctSettings", storages = @Storage(UctSettingsService.M2_UCT_SETTINGS_XML))
2021
public class UctSettingsService implements PersistentStateComponent<UctSettingsService> {
@@ -164,6 +165,7 @@ public void setCurrentVersion(final @Nullable SupportedVersion version) {
164165
if (currentVersion == null) {
165166
return null;
166167
}
168+
167169
return SupportedVersion.getVersion(currentVersion);
168170
}
169171

@@ -174,8 +176,9 @@ public void setCurrentVersion(final @Nullable SupportedVersion version) {
174176
*/
175177
public @NotNull SupportedVersion getCurrentVersionOrDefault() {
176178
final SupportedVersion currentVersion = getCurrentVersion();
179+
final @NotNull List<SupportedVersion> supportedVersions = SupportedVersion.getSupportedVersions();
177180

178-
return currentVersion == null ? SupportedVersion.valueOf("2.3.0") : currentVersion;
181+
return currentVersion == null ? supportedVersions.get(0) : currentVersion;
179182
}
180183

181184
/**
@@ -196,6 +199,7 @@ public void setTargetVersion(final @NotNull SupportedVersion version) {
196199
if (targetVersion == null) {
197200
return null;
198201
}
202+
199203
return SupportedVersion.getVersion(targetVersion);
200204
}
201205

src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.form

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
<properties>
115115
<enabled value="true"/>
116116
<font size="12"/>
117-
<icon value="general/information.png"/>
117+
<icon value="icons/information.png"/>
118118
<text value="To enable inspections in the real time, also enable inspections by path:"/>
119119
</properties>
120120
</component>

src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.awt.Color;
2626
import java.awt.event.KeyEvent;
2727
import java.util.Objects;
28-
import javax.swing.JButton;
2928
import javax.swing.JCheckBox;
3029
import javax.swing.JComboBox;
3130
import javax.swing.JComponent;
@@ -50,8 +49,6 @@ public class ConfigurationDialog extends AbstractDialog {
5049
private JComboBox<ComboBoxItemData> issueSeverityLevel;
5150

5251
private JPanel contentPanel;
53-
private JButton buttonCancel;
54-
private JButton buttonOk;
5552
private JLabel currentVersionLabel;//NOPMD
5653
private JLabel modulePathLabel;//NOPMD
5754
private JLabel targetVersionLabel;//NOPMD
@@ -77,8 +74,6 @@ public ConfigurationDialog(final @NotNull Project project) {
7774

7875
hasAdditionalPath.addActionListener(event ->
7976
refreshAdditionalFields(hasAdditionalPath.isSelected()));
80-
buttonOk.addActionListener(event -> onOK());
81-
buttonCancel.addActionListener(event -> onCancel());
8277

8378
// call onCancel() on ESCAPE
8479
contentPanel.registerKeyboardAction(
@@ -97,6 +92,8 @@ public ConfigurationDialog(final @NotNull Project project) {
9792
enableCommentPath.setForeground(JBColor.blue);
9893
setDefaultValues();
9994
refreshAdditionalFields(hasAdditionalPath.isSelected());
95+
96+
init();
10097
}
10198

10299
/**
@@ -270,14 +267,14 @@ private void setSelectedValueByItsKey(
270267
private void createUIComponents() {
271268
targetVersion = new ComboBox<>();
272269

273-
for (final String version : SupportedVersion.getSupportedVersions()) {
274-
targetVersion.addItem(new ComboBoxItemData(version, version));
270+
for (final SupportedVersion version : SupportedVersion.getSupportedVersions()) {
271+
targetVersion.addItem(new ComboBoxItemData(version.getVersion(), version.getVersion()));
275272
}
276273
currentVersion = new ComboBox<>();
277274
currentVersion.addItem(new ComboBoxItemData("", "Less than 2.3.0"));
278275

279-
for (final String version : SupportedVersion.getSupportedVersions()) {
280-
currentVersion.addItem(new ComboBoxItemData(version, version));
276+
for (final SupportedVersion version : SupportedVersion.getSupportedVersions()) {
277+
currentVersion.addItem(new ComboBoxItemData(version.getVersion(), version.getVersion()));
281278
}
282279
issueSeverityLevel = new ComboBox<>();
283280

src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import com.magento.idea.magento2uct.packages.IndexRegistry;
1717
import com.magento.idea.magento2uct.packages.SupportedVersion;
1818
import java.awt.event.KeyEvent;
19-
import javax.swing.JButton;
2019
import javax.swing.JComboBox;
2120
import javax.swing.JComponent;
2221
import javax.swing.JLabel;
@@ -32,15 +31,13 @@ public class ReindexDialog extends AbstractDialog {
3231
private JPanel contentPanel;
3332
private JComboBox<ComboBoxItemData> targetVersion;
3433
private JComboBox<ComboBoxItemData> targetIndex;
35-
private JButton buttonOk;
36-
private JButton buttonCancel;
3734
private JLabel targetVersionLabel;//NOPMD
3835
private JLabel targetIndexLabel;//NOPMD
3936

4037
/**
4138
* Reindexing dialog.
4239
*
43-
* @param project Project
40+
* @param project Project
4441
* @param directory PsiDirectory
4542
*/
4643
public ReindexDialog(
@@ -54,9 +51,6 @@ public ReindexDialog(
5451

5552
setTitle(ReindexVersionedIndexesAction.ACTION_NAME);
5653

57-
buttonOk.addActionListener(event -> onOK());
58-
buttonCancel.addActionListener(event -> onCancel());
59-
6054
// call onCancel() on ESCAPE
6155
contentPanel.registerKeyboardAction(
6256
event -> onCancel(),
@@ -70,7 +64,7 @@ public ReindexDialog(
7064
/**
7165
* Open reindexing dialog window.
7266
*
73-
* @param project Project
67+
* @param project Project
7468
* @param directory PsiDirectory
7569
*/
7670
public static void open(
@@ -132,8 +126,8 @@ protected void onWriteActionOK() {
132126
private void createUIComponents() {
133127
targetVersion = new ComboBox<>();
134128

135-
for (final String version : SupportedVersion.getSupportedVersions()) {
136-
targetVersion.addItem(new ComboBoxItemData(version, version));
129+
for (final SupportedVersion version : SupportedVersion.getSupportedVersions()) {
130+
targetVersion.addItem(new ComboBoxItemData(version.getVersion(), version.getVersion()));
137131
}
138132
targetIndex = new ComboBox<>();
139133
targetIndex.addItem(new ComboBoxItemData("", " --- Choose Target Index --- "));

0 commit comments

Comments
 (0)