Skip to content

Upgrade compatibility tool fixes #2589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: 5.4.0-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ private String getStoredUctExecutablePath(
private void initializeComboboxSources() {
comingVersion.setToolTipText("Choose a target version");

for (final String version : SupportedVersion.getSupportedVersions()) {
comingVersion.addItem(new ComboBoxItemData(version, version));
for (final SupportedVersion version : SupportedVersion.getSupportedVersions()) {
comingVersion.addItem(new ComboBoxItemData(version.getVersion(), version.getVersion()));
}

for (final IssueSeverityLevel level : IssueSeverityLevel.getSeverityLabels()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.magento.idea.magento2uct.versioning.processors.ExistenceIndexProcessor;
import com.magento.idea.magento2uct.versioning.processors.IndexProcessor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.jetbrains.annotations.NotNull;

Expand All @@ -22,32 +21,32 @@ public enum IndexRegistry {
DEPRECATION(
DeprecationStateIndex.class,
new DeprecationIndexProcessor(),
SupportedVersion.getSupportedVersions().toArray(new String[0])
SupportedVersion.getSupportedVersionStrings()
),
EXISTENCE(
ExistenceStateIndex.class,
new ExistenceIndexProcessor(),
SupportedVersion.getSupportedVersions().toArray(new String[0])
SupportedVersion.getSupportedVersionStrings()
),
API_COVERAGE(
ApiCoverageStateIndex.class,
new ApiCoverageIndexProcessor(),
SupportedVersion.getSupportedVersions().toArray(new String[0])
SupportedVersion.getSupportedVersionStrings()
);

private final String key;
private final Class<?> type;
private final IndexProcessor processor;
private final String[] versions;
private final List<String> versions;

IndexRegistry(
final Class<?> type,
final IndexProcessor processor,
final String... versions
final List<String> versions
) {
this.type = type;
this.processor = processor;
this.versions = Arrays.copyOf(versions, versions.length);
this.versions = versions;
key = this.toString();
}

Expand Down Expand Up @@ -84,7 +83,7 @@ public IndexProcessor getProcessor() {
* @return List[String]
*/
public List<String> getVersions() {
return Arrays.asList(versions);
return versions;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,82 @@

package com.magento.idea.magento2uct.packages;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.concurrent.atomic.AtomicReference;

public final class SupportedVersion {

public enum SupportedVersion {
;
private final String version;
private static final Integer SUCCESS_CODE = 200;

SupportedVersion(final String version) {
private SupportedVersion(final String version) {
this.version = version;
}

/**
* Get version.
*
* @return String
*/
public String getVersion() {
public @NotNull String getVersion() {
return version;
}

/**
* Get version ENUM by version code.
*
* @param versionCandidate String
*
* @return SupportedVersion
*/
public @Nullable static SupportedVersion getVersion(final @NotNull String versionCandidate) {
for (final SupportedVersion version : SupportedVersion.values()) {
private static final AtomicReference<List<SupportedVersion>> cachedVersions = new AtomicReference<>();

public static @NotNull List<SupportedVersion> getSupportedVersions() {
List<SupportedVersion> versions = cachedVersions.get();

if (versions == null) {
versions = new ArrayList<>();

try {
for (final String versionStr : fetchRemoteSupportedVersions()) {
versions.add(new SupportedVersion(versionStr));
}
} catch (Exception ignored) {
}

cachedVersions.set(versions);
}

return versions;
}

public static List<String> getSupportedVersionStrings() {
final List<String> versions = new ArrayList<>();

for (final SupportedVersion version : getSupportedVersions()) {
versions.add(version.getVersion());
}

return versions;
}

public static @Nullable SupportedVersion getVersion(final @NotNull String versionCandidate) {
for (final SupportedVersion version : getSupportedVersions()) {
if (version.getVersion().equals(versionCandidate)) {
return version;
}
}

return null;
}

/**
* Get supported versions.
*
* @return List[String]
*/
public static List<String> getSupportedVersions() {
try {
return fetchSupportedVersions();
} catch (Exception e) { //NOPMD - suppressed AvoidCatchingGenericException
// Return an empty list or log the exception
return List.of();
public static List<SupportedVersion> getPriorVersions(final SupportedVersion version) {
final List<SupportedVersion> previousVersions = new ArrayList<>();

for (final SupportedVersion supportedVersion : getSupportedVersions()) {
if (supportedVersion.getVersion().compareTo(version.toString()) < 0) {
previousVersions.add(supportedVersion);
}
}

return previousVersions;
}

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

HttpURLConnection connection = null;

try {
// Establish HTTP connection
connection = (HttpURLConnection) new URL(url).openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", "application/json");

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

Expand Down Expand Up @@ -122,6 +140,7 @@ public static List<String> fetchSupportedVersions() throws IOException {
versions.add(versionstring);
}
}
} catch (IOException ignored) {
} finally {
if (connection != null) {
connection.disconnect();
Expand All @@ -131,22 +150,4 @@ public static List<String> fetchSupportedVersions() throws IOException {
return versions;
}

/**
* Get previous versions.
*
* @param version SupportedVersion
*
* @return List[SupportedVersion]
*/
public static List<SupportedVersion> getPriorVersions(final SupportedVersion version) {
final List<SupportedVersion> previousVersions = new ArrayList<>();

for (final SupportedVersion supportedVersion : SupportedVersion.values()) {
if (supportedVersion.compareTo(version) < 0) {
previousVersions.add(supportedVersion);
}
}

return previousVersions;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.magento.idea.magento2uct.packages.SupportedVersion;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;

@State(name = "Magento2UctSettings", storages = @Storage(UctSettingsService.M2_UCT_SETTINGS_XML))
public class UctSettingsService implements PersistentStateComponent<UctSettingsService> {
Expand Down Expand Up @@ -164,6 +165,7 @@ public void setCurrentVersion(final @Nullable SupportedVersion version) {
if (currentVersion == null) {
return null;
}

return SupportedVersion.getVersion(currentVersion);
}

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

return currentVersion == null ? SupportedVersion.valueOf("2.3.0") : currentVersion;
return currentVersion == null ? supportedVersions.get(0) : currentVersion;
}

/**
Expand All @@ -196,6 +199,7 @@ public void setTargetVersion(final @NotNull SupportedVersion version) {
if (targetVersion == null) {
return null;
}

return SupportedVersion.getVersion(targetVersion);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<properties>
<enabled value="true"/>
<font size="12"/>
<icon value="general/information.png"/>
<icon value="icons/information.png"/>
<text value="To enable inspections in the real time, also enable inspections by path:"/>
</properties>
</component>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.awt.Color;
import java.awt.event.KeyEvent;
import java.util.Objects;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
Expand All @@ -50,8 +49,6 @@ public class ConfigurationDialog extends AbstractDialog {
private JComboBox<ComboBoxItemData> issueSeverityLevel;

private JPanel contentPanel;
private JButton buttonCancel;
private JButton buttonOk;
private JLabel currentVersionLabel;//NOPMD
private JLabel modulePathLabel;//NOPMD
private JLabel targetVersionLabel;//NOPMD
Expand All @@ -77,8 +74,6 @@ public ConfigurationDialog(final @NotNull Project project) {

hasAdditionalPath.addActionListener(event ->
refreshAdditionalFields(hasAdditionalPath.isSelected()));
buttonOk.addActionListener(event -> onOK());
buttonCancel.addActionListener(event -> onCancel());

// call onCancel() on ESCAPE
contentPanel.registerKeyboardAction(
Expand All @@ -97,6 +92,8 @@ public ConfigurationDialog(final @NotNull Project project) {
enableCommentPath.setForeground(JBColor.blue);
setDefaultValues();
refreshAdditionalFields(hasAdditionalPath.isSelected());

init();
}

/**
Expand Down Expand Up @@ -270,14 +267,14 @@ private void setSelectedValueByItsKey(
private void createUIComponents() {
targetVersion = new ComboBox<>();

for (final String version : SupportedVersion.getSupportedVersions()) {
targetVersion.addItem(new ComboBoxItemData(version, version));
for (final SupportedVersion version : SupportedVersion.getSupportedVersions()) {
targetVersion.addItem(new ComboBoxItemData(version.getVersion(), version.getVersion()));
}
currentVersion = new ComboBox<>();
currentVersion.addItem(new ComboBoxItemData("", "Less than 2.3.0"));

for (final String version : SupportedVersion.getSupportedVersions()) {
currentVersion.addItem(new ComboBoxItemData(version, version));
for (final SupportedVersion version : SupportedVersion.getSupportedVersions()) {
currentVersion.addItem(new ComboBoxItemData(version.getVersion(), version.getVersion()));
}
issueSeverityLevel = new ComboBox<>();

Expand Down
14 changes: 4 additions & 10 deletions src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.magento.idea.magento2uct.packages.IndexRegistry;
import com.magento.idea.magento2uct.packages.SupportedVersion;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
Expand All @@ -32,15 +31,13 @@ public class ReindexDialog extends AbstractDialog {
private JPanel contentPanel;
private JComboBox<ComboBoxItemData> targetVersion;
private JComboBox<ComboBoxItemData> targetIndex;
private JButton buttonOk;
private JButton buttonCancel;
private JLabel targetVersionLabel;//NOPMD
private JLabel targetIndexLabel;//NOPMD

/**
* Reindexing dialog.
*
* @param project Project
* @param project Project
* @param directory PsiDirectory
*/
public ReindexDialog(
Expand All @@ -54,9 +51,6 @@ public ReindexDialog(

setTitle(ReindexVersionedIndexesAction.ACTION_NAME);

buttonOk.addActionListener(event -> onOK());
buttonCancel.addActionListener(event -> onCancel());

// call onCancel() on ESCAPE
contentPanel.registerKeyboardAction(
event -> onCancel(),
Expand All @@ -70,7 +64,7 @@ public ReindexDialog(
/**
* Open reindexing dialog window.
*
* @param project Project
* @param project Project
* @param directory PsiDirectory
*/
public static void open(
Expand Down Expand Up @@ -132,8 +126,8 @@ protected void onWriteActionOK() {
private void createUIComponents() {
targetVersion = new ComboBox<>();

for (final String version : SupportedVersion.getSupportedVersions()) {
targetVersion.addItem(new ComboBoxItemData(version, version));
for (final SupportedVersion version : SupportedVersion.getSupportedVersions()) {
targetVersion.addItem(new ComboBoxItemData(version.getVersion(), version.getVersion()));
}
targetIndex = new ComboBox<>();
targetIndex.addItem(new ComboBoxItemData("", " --- Choose Target Index --- "));
Expand Down
Loading