Skip to content

Commit 6140228

Browse files
authored
Merge pull request #751 from Iamwade/update-platform-version-in-setting-form
Update Platform Version In Setting Form
2 parents b17d5ab + 1f5f6f8 commit 6140228

File tree

6 files changed

+93
-19
lines changed

6 files changed

+93
-19
lines changed

src/com/magento/idea/magento2plugin/magento/packages/code/MagentoVersion.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,24 @@
1111

1212
public enum MagentoVersion {
1313

14-
ENTERPRISE_EDITION("magento/product-enterprise-edition", 1),
15-
COMMUNITY_EDITION("magento/product-community-edition", 2);
14+
ENTERPRISE_EDITION("magento/product-enterprise-edition", 1, "Adobe Commerce"),
15+
COMMUNITY_EDITION("magento/product-community-edition", 2, "Magento Open Source");
1616

1717
private final String name;
1818
private final int priority;
19+
private final String displayName;
1920

2021
/**
2122
* Magento version Enum constructor.
2223
*
2324
* @param name String
2425
* @param priority int
26+
* @param displayName String
2527
*/
26-
MagentoVersion(final String name, final int priority) {
28+
MagentoVersion(final String name, final int priority, final String displayName) {
2729
this.name = name;
2830
this.priority = priority;
31+
this.displayName = displayName;
2932
}
3033

3134
public String getName() {
@@ -36,6 +39,10 @@ public int getPriority() {
3639
return priority;
3740
}
3841

42+
public String getDisplayName() {
43+
return displayName;
44+
}
45+
3946
/**
4047
* Get Magento Versions List.
4148
*

src/com/magento/idea/magento2plugin/project/Settings.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class Settings implements PersistentStateComponent<Settings.State> {
3434
public boolean mftfSupportEnabled;
3535
public boolean myDoNotAskContentConfigAgain;
3636
public String magentoVersion;
37+
public String magentoEdition;
3738

3839
@Override
3940
@Nullable
@@ -44,7 +45,8 @@ public Settings.State getState() {
4445
defaultLicense,
4546
this.mftfSupportEnabled,
4647
this.myDoNotAskContentConfigAgain,
47-
this.magentoVersion
48+
this.magentoVersion,
49+
this.magentoEdition
4850
);
4951
}
5052

@@ -67,6 +69,7 @@ public void loadState(final @NotNull Settings.State state) {
6769
this.mftfSupportEnabled = state.isMftfSupportEnabled();
6870
this.myDoNotAskContentConfigAgain = state.isDoNotAskContentConfigAgain();
6971
this.magentoVersion = state.getMagentoVersion();
72+
this.magentoEdition = state.getMagentoEdition();
7073
}
7174

7275
public void addListener(final MagentoModuleDataListener listener) {
@@ -128,6 +131,7 @@ public static class State {
128131
public boolean mftfSupportEnabled;
129132
public boolean myDoNotAskContentConfigAgain;
130133
public String magentoVersion;
134+
public String magentoEdition;
131135

132136
public State() {//NOPMD
133137
}
@@ -141,21 +145,24 @@ public State() {//NOPMD
141145
* @param mftfSupportEnabled boolean
142146
* @param myDoNotAskContentConfigAgain boolean
143147
* @param magentoVersion String
148+
* @param magentoEdition String
144149
*/
145150
public State(
146151
final boolean pluginEnabled,
147152
final String magentoPath,
148153
final String defaultLicenseName,
149154
final boolean mftfSupportEnabled,
150155
final boolean myDoNotAskContentConfigAgain,
151-
final String magentoVersion
156+
final String magentoVersion,
157+
final String magentoEdition
152158
) {
153159
this.pluginEnabled = pluginEnabled;
154160
this.magentoPath = magentoPath;
155161
this.defaultLicenseName = defaultLicenseName;
156162
this.mftfSupportEnabled = mftfSupportEnabled;
157163
this.myDoNotAskContentConfigAgain = myDoNotAskContentConfigAgain;
158164
this.magentoVersion = magentoVersion;
165+
this.magentoEdition = magentoEdition;
159166
}
160167

161168
@Attribute("enabled")
@@ -185,6 +192,15 @@ public void setMagentoVersion(final String magentoVersion) {
185192
this.magentoVersion = magentoVersion;
186193
}
187194

195+
public String getMagentoEdition() {
196+
return magentoEdition;
197+
}
198+
199+
@Tag("magentoEdition")
200+
public void setMagentoEdition(final String magentoEdition) {
201+
this.magentoEdition = magentoEdition;
202+
}
203+
188204
/**
189205
* Last Used Magento Path setter.
190206
*

src/com/magento/idea/magento2plugin/project/SettingsForm.form

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
<forms/>
9999
</constraints>
100100
<properties>
101-
<text value="Magento version:"/>
101+
<text value="Platform Version:"/>
102102
</properties>
103103
</component>
104104
</children>

src/com/magento/idea/magento2plugin/project/SettingsForm.java

+29-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
@@ -12,6 +12,7 @@
1212
import com.intellij.openapi.ui.ComponentWithBrowseButton;
1313
import com.intellij.openapi.ui.TextComponentAccessor;
1414
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
15+
import com.intellij.openapi.util.Pair;
1516
import com.intellij.openapi.vfs.VirtualFile;
1617
import com.jetbrains.php.frameworks.PhpFrameworkConfigurable;
1718
import com.magento.idea.magento2plugin.indexes.IndexManager;
@@ -38,6 +39,9 @@
3839
"PMD.TooManyMethods"
3940
})
4041
public class SettingsForm implements PhpFrameworkConfigurable {
42+
43+
private static final String DEFAULT_MAGENTO_EDITION_LABEL = "Platform Version:";
44+
4145
private final Project project;
4246
private JCheckBox pluginEnabled;
4347
private JButton buttonReindex;
@@ -48,6 +52,7 @@ public class SettingsForm implements PhpFrameworkConfigurable {
4852
private JCheckBox mftfSupportEnabled;
4953
private TextFieldWithBrowseButton magentoPath;
5054
private final SettingsFormValidator validator = new SettingsFormValidator(this);
55+
private String magentoEdition;
5156
private JLabel magentoVersionLabel;//NOPMD
5257
private JLabel magentoPathLabel;//NOPMD
5358

@@ -95,6 +100,12 @@ public void mouseClicked(final MouseEvent event) {
95100
addPathListener();
96101
addMagentoVersionListener();
97102

103+
final String storedMagentoEdition = getSettings().magentoEdition;
104+
105+
magentoVersionLabel.setText(
106+
storedMagentoEdition == null ? DEFAULT_MAGENTO_EDITION_LABEL : storedMagentoEdition
107+
);
108+
98109
return (JComponent) panel;
99110
}
100111

@@ -159,6 +170,7 @@ private void saveSettings() {
159170
getSettings().mftfSupportEnabled = mftfSupportEnabled.isSelected();
160171
getSettings().magentoPath = getMagentoPath();
161172
getSettings().magentoVersion = getMagentoVersion();
173+
getSettings().magentoEdition = getMagentoEdition();
162174
buttonReindex.setEnabled(getSettings().pluginEnabled);
163175
regenerateUrnMapButton.setEnabled(getSettings().pluginEnabled);
164176
}
@@ -168,6 +180,10 @@ public String getMagentoVersion() {
168180
return magentoVersion.getText().trim();
169181
}
170182

183+
public @NotNull String getMagentoEdition() {
184+
return magentoEdition == null ? DEFAULT_MAGENTO_EDITION_LABEL : magentoEdition;
185+
}
186+
171187
@NotNull
172188
public String getMagentoPath() {
173189
return magentoPath.getTextField().getText().trim();
@@ -233,8 +249,19 @@ public void changedUpdate(final DocumentEvent documentEvent) {
233249
*/
234250
public void updateMagentoVersion() {
235251
final String magentoPathValue = this.magentoPath.getTextField().getText();
236-
final String resolvedVersion = MagentoVersionUtil.get(project, magentoPathValue);
252+
final Pair<String, String> version = MagentoVersionUtil.getVersionData(
253+
project,
254+
magentoPathValue
255+
);
256+
final String resolvedVersion = version.getFirst();
257+
final String resolvedEdition = version.getSecond() == null
258+
? DEFAULT_MAGENTO_EDITION_LABEL
259+
: version.getSecond();
237260
magentoVersion.setText(resolvedVersion);
261+
magentoVersionLabel.setText(resolvedEdition);
262+
263+
magentoEdition = resolvedEdition;
264+
getSettings().magentoEdition = getMagentoEdition();
238265
}
239266

240267
@Override

src/com/magento/idea/magento2plugin/project/util/GetMagentoVersionUtil.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.intellij.json.psi.JsonObject;
99
import com.intellij.json.psi.JsonProperty;
10+
import com.intellij.openapi.util.Pair;
1011
import com.intellij.psi.util.PsiTreeUtil;
1112
import com.magento.idea.magento2plugin.magento.files.ComposerLock;
1213
import com.magento.idea.magento2plugin.magento.packages.code.MagentoVersion;
@@ -28,10 +29,10 @@ private GetMagentoVersionUtil() {
2829
*
2930
* @param object JsonObject
3031
*
31-
* @return String
32+
* @return Pair[String, String]
3233
*/
3334
@SuppressWarnings("PMD.CyclomaticComplexity")
34-
public static @Nullable String getVersion(final @NotNull JsonObject object) {
35+
public static @Nullable Pair<String, String> getVersion(final @NotNull JsonObject object) {
3536
final JsonProperty packagesProperty = object.findProperty(ComposerLock.PACKAGES_PROP);
3637

3738
if (packagesProperty == null) {
@@ -77,7 +78,10 @@ private GetMagentoVersionUtil() {
7778

7879
for (final MagentoVersion version : versions) {
7980
if (foundMagentoPackages.containsKey(version.getName())) {
80-
return foundMagentoPackages.get(version.getName());
81+
return new Pair<>(
82+
foundMagentoPackages.get(version.getName()),
83+
version.getDisplayName()
84+
);
8185
}
8286
}
8387

src/com/magento/idea/magento2plugin/util/magento/MagentoVersionUtil.java

+28-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.intellij.json.psi.JsonFile;
99
import com.intellij.json.psi.JsonObject;
1010
import com.intellij.openapi.project.Project;
11+
import com.intellij.openapi.util.Pair;
1112
import com.intellij.openapi.vfs.LocalFileSystem;
1213
import com.intellij.openapi.vfs.VirtualFile;
1314
import com.intellij.psi.PsiFile;
@@ -31,14 +32,34 @@ private MagentoVersionUtil() {}
3132
* @return String
3233
*/
3334
public static String get(final Project project, final String magentoPath) {
35+
final Pair<String, String> version = getVersionData(
36+
project,
37+
magentoPath
38+
);
39+
40+
return version.getFirst();
41+
}
42+
43+
/**
44+
* Parse composer.lock to detect Magento 2 version
45+
*
46+
* @param project Project
47+
* @param magentoPath String
48+
*
49+
* @return Pair[String, String]
50+
*/
51+
public static Pair<String, String> getVersionData(
52+
final Project project,
53+
final String magentoPath
54+
) {
3455
final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(
3556
getFilePath(magentoPath)
3657
);
58+
final Pair<String, String> versionData = new Pair<>(DEFAULT_VERSION, null);
3759

3860
if (file == null) {
39-
return DEFAULT_VERSION;
61+
return versionData;
4062
}
41-
4263
final PsiManager psiManager = PsiManager.getInstance(project);
4364
final PsiFile composerFile = psiManager.findFile(file);
4465

@@ -50,15 +71,14 @@ public static String get(final Project project, final String magentoPath) {
5071
);
5172

5273
if (jsonObject == null) {
53-
return DEFAULT_VERSION;
74+
return versionData;
5475
}
76+
final Pair<String, String> version = GetMagentoVersionUtil.getVersion(jsonObject);
5577

56-
final String version = GetMagentoVersionUtil.getVersion(jsonObject);
57-
58-
return version == null ? DEFAULT_VERSION : version;
78+
return version == null ? versionData : version;
5979
}
6080

61-
return DEFAULT_VERSION;
81+
return versionData;
6282
}
6383

6484
private static String getFilePath(final String magentoPath) {
@@ -74,7 +94,7 @@ private static String getFilePath(final String magentoPath) {
7494
* the value {@code false} if the argument version1 is less than to version2.
7595
*/
7696
public static boolean compare(final String version1, final String version2) {
77-
if (version1.equals(DEFAULT_VERSION)) {
97+
if (DEFAULT_VERSION.equals(version1)) {
7898
return true;
7999
}
80100
if (version1.equals(version2)) {

0 commit comments

Comments
 (0)