Skip to content

Commit 4eb16d5

Browse files
author
Vitaliy
authored
Merge pull request #277 from magento/270-fix-endless-loop
270: fixed endless loop of notifications
2 parents 09fc19e + b77ed97 commit 4eb16d5

File tree

8 files changed

+145
-68
lines changed

8 files changed

+145
-68
lines changed

build.gradle

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
plugins {
7-
id 'org.jetbrains.intellij' version '0.4.15'
7+
id 'org.jetbrains.intellij' version '0.4.22'
88
id 'checkstyle'
99
id 'pmd'
1010
}
@@ -31,7 +31,16 @@ intellij {
3131
version ideaVersion
3232
type 'IU'
3333
pluginName 'com.magento.idea.magento2plugin'
34-
plugins = ["com.jetbrains.php:$phpPluginVersion", 'yaml', 'java-i18n', 'properties', 'CSS', 'JavaScriptLanguage', 'com.intellij.lang.jsgraphql:2.3.0']
34+
plugins = [
35+
"com.jetbrains.php:$phpPluginVersion",
36+
'yaml',
37+
'java-i18n',
38+
'properties',
39+
'CSS',
40+
'JavaScriptLanguage',
41+
'com.intellij.lang.jsgraphql:2.3.0',
42+
'platform-images'
43+
]
3544
updateSinceUntilBuild false
3645
sameSinceUntilBuild false
3746
downloadSources !Boolean.valueOf(System.getenv('CI'))

resources/META-INF/plugin.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<depends>com.jetbrains.php</depends>
3535
<depends>JavaScript</depends>
3636
<depends>com.intellij.modules.platform</depends>
37+
<depends>com.intellij.platform.images</depends>
3738
<depends optional="true" config-file="withJsGraphQl.xml">com.intellij.lang.jsgraphql</depends>
3839

3940
<actions>
@@ -194,6 +195,8 @@
194195
<internalFileTemplate name="Magento Module Controller Backend Class"/>
195196
<internalFileTemplate name="Magento Module Controller Frontend Class"/>
196197
<internalFileTemplate name="Magento Module Cron Groups Xml"/>
198+
199+
<postStartupActivity implementation="com.magento.idea.magento2plugin.project.startup.CheckIfMagentoPathIsValidActivity"/>
197200
</extensions>
198201

199202
<extensions defaultExtensionNs="com.jetbrains.php">

src/com/magento/idea/magento2plugin/generation/php/NewModuleForm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public MagentoProjectGeneratorSettings getSettings() {
116116
final Settings.State state = new Settings.State();
117117
state.setPluginEnabled(true);
118118
state.setMftfSupportEnabled(true);
119-
state.setDefaultLicenseName(Settings.DEFAULT_LICENSE);
119+
state.setDefaultLicenseName(Settings.defaultLicense);
120120
state.setMagentoPathAndUpdateLastUsed(this.magentoPath.getTextField().getText().trim());
121121

122122
return new MagentoProjectGeneratorSettings(

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

Lines changed: 89 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,111 @@
1-
/**
1+
/*
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
package com.magento.idea.magento2plugin.project;
67

78
import com.intellij.ide.util.PropertiesComponent;
8-
import com.intellij.openapi.components.*;
9+
import com.intellij.openapi.components.PersistentStateComponent;
10+
import com.intellij.openapi.components.ServiceManager;
11+
import com.intellij.openapi.components.State;
12+
import com.intellij.openapi.components.Storage;
913
import com.intellij.openapi.project.Project;
1014
import com.intellij.openapi.util.text.StringUtil;
1115
import com.intellij.util.EventDispatcher;
1216
import com.intellij.util.xmlb.annotations.Attribute;
1317
import com.intellij.util.xmlb.annotations.Tag;
14-
import com.magento.idea.magento2plugin.init.ConfigurationManager;
15-
import com.magento.idea.magento2plugin.util.magento.MagentoBasePathUtil;
18+
import java.util.EventListener;
1619
import org.jetbrains.annotations.NotNull;
1720
import org.jetbrains.annotations.Nullable;
18-
import java.util.EventListener;
1921

2022
@State(
21-
name = "Magento2PluginSettings",
22-
storages = {
23-
@Storage("magento2plugin.xml")
24-
}
23+
name = "Magento2PluginSettings",
24+
storages = {
25+
@Storage("magento2plugin.xml")
26+
}
2527
)
2628
public class Settings implements PersistentStateComponent<Settings.State> {
27-
private final EventDispatcher<MagentoModuleDataListener> myEventDispatcher = EventDispatcher.create(MagentoModuleDataListener.class);
28-
public boolean pluginEnabled = false;
29-
public static String DEFAULT_LICENSE = "Proprietary";
29+
private final EventDispatcher<MagentoModuleDataListener> myEventDispatcher
30+
= EventDispatcher.create(MagentoModuleDataListener.class);
31+
public boolean pluginEnabled;
32+
public static String defaultLicense = "Proprietary";
3033
public String magentoPath;
31-
public boolean mftfSupportEnabled = false;
32-
public boolean myDoNotAskContentConfigAgain = false;
33-
public String magentoVersion = null;
34+
public boolean mftfSupportEnabled;
35+
public boolean myDoNotAskContentConfigAgain;
36+
public String magentoVersion;
3437

38+
@Override
3539
@Nullable
3640
public Settings.State getState() {
3741
return new Settings.State(
3842
this.pluginEnabled,
3943
this.magentoPath,
40-
DEFAULT_LICENSE,
44+
defaultLicense,
4145
this.mftfSupportEnabled,
4246
this.myDoNotAskContentConfigAgain,
4347
this.magentoVersion
4448
);
4549
}
4650

47-
public void setState(State state) {
48-
State oldState = this.getState();
51+
/**
52+
* State setter.
53+
*
54+
* @param state State
55+
*/
56+
public void setState(final State state) {
57+
final State oldState = this.getState();
4958
this.loadState(state);
5059
this.notifyListeners(state, oldState);
5160
}
5261

53-
public void loadState(@NotNull Settings.State state) {
62+
@Override
63+
public void loadState(final @NotNull Settings.State state) {
5464
this.pluginEnabled = state.isPluginEnabled();
5565
this.magentoPath = state.getMagentoPath();
56-
this.DEFAULT_LICENSE = state.getDefaultLicenseName();
66+
this.defaultLicense = state.getDefaultLicenseName();
5767
this.mftfSupportEnabled = state.isMftfSupportEnabled();
5868
this.myDoNotAskContentConfigAgain = state.isDoNotAskContentConfigAgain();
5969
this.magentoVersion = state.getMagentoVersion();
6070
}
6171

62-
public void addListener(MagentoModuleDataListener listener) {
72+
public void addListener(final MagentoModuleDataListener listener) {
6373
this.myEventDispatcher.addListener(listener);
6474
}
6575

66-
private void notifyListeners(State state, State oldState) {
76+
private void notifyListeners(final State state, final State oldState) {
6777
if (!state.equals(oldState)) {
6878
this.myEventDispatcher.getMulticaster().stateChanged(state, oldState);
6979
}
7080
}
7181

72-
public void setDoNotAskContentConfigurationAgain(boolean doNotAskContentConfigurationAgain) {
82+
public void setDoNotAskContentConfigurationAgain(
83+
final boolean doNotAskContentConfigurationAgain
84+
) {
7385
this.myDoNotAskContentConfigAgain = doNotAskContentConfigurationAgain;
7486
}
7587

76-
public void setMagentoPath(String magentoPath) {
88+
public void setMagentoPath(final String magentoPath) {
7789
this.magentoPath = magentoPath;
7890
}
7991

8092
public interface MagentoModuleDataListener extends EventListener {
8193
void stateChanged(State state, State oldState);
8294
}
8395

84-
public static Settings getInstance(Project project) {
96+
public static Settings getInstance(final Project project) {
8597
return ServiceManager.getService(project, Settings.class);
8698
}
8799

88-
public static boolean isEnabled(@NotNull Project project) {
100+
public static boolean isEnabled(final @NotNull Project project) {
89101
return getInstance(project).pluginEnabled;
90102
}
91103

92-
public static String getDefaultLicenseName(@NotNull Project project) {
93-
return getInstance(project).DEFAULT_LICENSE;
104+
public static String getDefaultLicenseName(final @NotNull Project project) {
105+
return getInstance(project).defaultLicense;
94106
}
95107

96-
public static boolean isMftfSupportEnabled(@NotNull Project project) {
108+
public static boolean isMftfSupportEnabled(final @NotNull Project project) {
97109
return getInstance(project).mftfSupportEnabled;
98110
}
99111

@@ -103,21 +115,11 @@ public static String getLastMagentoPath() {
103115
}
104116

105117
@Nullable
106-
public static String getMagentoPath(@NotNull Project project) {
107-
Settings settings = getInstance(project);
108-
String path = settings.magentoPath;
109-
if (path == null || path.isEmpty()) {
110-
if (MagentoBasePathUtil.isMagentoFolderValid(project.getBasePath())) {
111-
settings.setMagentoPath(project.getBasePath());
112-
} else {
113-
settings.pluginEnabled = false;
114-
ConfigurationManager.suggestToConfigureMagentoPath(project);
115-
return null;
116-
}
117-
}
118-
return settings.magentoPath;
118+
public static String getMagentoPath(final @NotNull Project project) {
119+
return getInstance(project).magentoPath;
119120
}
120121

122+
@SuppressWarnings({"PMD.DataClass"})
121123
@Tag
122124
public static class State {
123125
public boolean pluginEnabled;
@@ -127,16 +129,26 @@ public static class State {
127129
public boolean myDoNotAskContentConfigAgain;
128130
public String magentoVersion;
129131

130-
public State() {
132+
public State() {//NOPMD
131133
}
132134

135+
/**
136+
* Settings State.
137+
*
138+
* @param pluginEnabled boolean
139+
* @param magentoPath String
140+
* @param defaultLicenseName String
141+
* @param mftfSupportEnabled boolean
142+
* @param myDoNotAskContentConfigAgain boolean
143+
* @param magentoVersion String
144+
*/
133145
public State(
134-
boolean pluginEnabled,
135-
String magentoPath,
136-
String defaultLicenseName,
137-
boolean mftfSupportEnabled,
138-
boolean myDoNotAskContentConfigAgain,
139-
String magentoVersion
146+
final boolean pluginEnabled,
147+
final String magentoPath,
148+
final String defaultLicenseName,
149+
final boolean mftfSupportEnabled,
150+
final boolean myDoNotAskContentConfigAgain,
151+
final String magentoVersion
140152
) {
141153
this.pluginEnabled = pluginEnabled;
142154
this.magentoPath = magentoPath;
@@ -151,7 +163,7 @@ public boolean isPluginEnabled() {
151163
return this.pluginEnabled;
152164
}
153165

154-
public void setPluginEnabled(boolean enabled) {
166+
public void setPluginEnabled(final boolean enabled) {
155167
this.pluginEnabled = enabled;
156168
}
157169

@@ -160,7 +172,7 @@ public String getMagentoPath() {
160172
}
161173

162174
@Tag("magentoPath")
163-
public void setMagentoPath(String magentoPath) {
175+
public void setMagentoPath(final String magentoPath) {
164176
this.magentoPath = magentoPath;
165177
}
166178

@@ -169,22 +181,28 @@ public String getMagentoVersion() {
169181
}
170182

171183
@Tag("magentoVersion")
172-
public void setMagentoVersion(String magentoVersion) {
184+
public void setMagentoVersion(final String magentoVersion) {
173185
this.magentoVersion = magentoVersion;
174186
}
175187

176-
public void setMagentoPathAndUpdateLastUsed(String magentoPath) {
188+
/**
189+
* Last Used Magento Path setter.
190+
*
191+
* @param magentoPath String
192+
*/
193+
public void setMagentoPathAndUpdateLastUsed(final String magentoPath) {
177194
this.setMagentoPath(magentoPath);
178195
if (!StringUtil.isEmptyOrSpaces(magentoPath)) {
179-
PropertiesComponent.getInstance().setValue("magento.support.magentoPath", magentoPath);
196+
PropertiesComponent.getInstance()
197+
.setValue("magento.support.magentoPath", magentoPath);
180198
}
181199
}
182200

183201
public String getDefaultLicenseName() {
184202
return this.defaultLicenseName;
185203
}
186204

187-
public void setDefaultLicenseName(String defaultLicenseName) {
205+
public void setDefaultLicenseName(final String defaultLicenseName) {
188206
this.defaultLicenseName = defaultLicenseName;
189207
}
190208

@@ -196,40 +214,50 @@ public boolean isDoNotAskContentConfigAgain() {
196214
return this.myDoNotAskContentConfigAgain;
197215
}
198216

199-
public void setMftfSupportEnabled(boolean mftfSupportEnabled) {
217+
public void setMftfSupportEnabled(final boolean mftfSupportEnabled) {
200218
this.mftfSupportEnabled = mftfSupportEnabled;
201219
}
202220

203-
public boolean equals(Object objectToCompare) {
221+
@SuppressWarnings({"PMD.ConfusingTernary"})
222+
@Override
223+
public boolean equals(final Object objectToCompare) {
204224
if (this == objectToCompare) {
205225
return true;
206226
} else if (objectToCompare != null && this.getClass() == objectToCompare.getClass()) {
207-
State state = (State) objectToCompare;
227+
final State state = (State) objectToCompare;
208228
if (this.isPluginEnabled() != state.isPluginEnabled()) {
209229
return false;
210230
} else if (this.isMftfSupportEnabled() != state.isMftfSupportEnabled()) {
211231
return false;
212-
} else if (this.isDoNotAskContentConfigAgain() != state.isDoNotAskContentConfigAgain()) {
232+
} else if (
233+
this.isDoNotAskContentConfigAgain() != state.isDoNotAskContentConfigAgain()
234+
) {
213235
return false;
214236
} else {
215237
if (this.magentoPath != null) {
216238
return this.magentoPath.equals(state.magentoPath);
217239
}
218240
if (this.defaultLicenseName != null) {
219241
return this.defaultLicenseName.equals(state.defaultLicenseName);
220-
} else return state.defaultLicenseName == null;
242+
} else {
243+
return state.defaultLicenseName == null;
244+
}
221245
}
222246
} else {
223247
return false;
224248
}
225249
}
226250

251+
@SuppressWarnings({"PMD.ConfusingTernary"})
252+
@Override
227253
public int hashCode() {
228254
int result = this.isPluginEnabled() ? 1 : 0;
229255
result = 31 * result + (this.magentoPath != null ? this.magentoPath.hashCode() : 0);
230256
result = 31 * result + (this.isMftfSupportEnabled() ? 1 : 0);
231257
result = 31 * result + (this.isDoNotAskContentConfigAgain() ? 1 : 0);
232-
result = 31 * result + (this.defaultLicenseName != null ? this.defaultLicenseName.hashCode() : 0);
258+
result = 31 * result + (
259+
this.defaultLicenseName != null ? this.defaultLicenseName.hashCode() : 0
260+
);
233261
return result;
234262
}
235263
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void mouseClicked(final MouseEvent event) {
8484
new RegenerateUrnMapListener(project)
8585
);
8686

87-
moduleDefaultLicenseName.setText(getSettings().DEFAULT_LICENSE);
87+
moduleDefaultLicenseName.setText(getSettings().defaultLicense);
8888
mftfSupportEnabled.setSelected(getSettings().mftfSupportEnabled);
8989
magentoPath.getTextField().setText(getSettings().magentoPath);
9090
resolveMagentoVersion();
@@ -103,7 +103,7 @@ protected void reindex() {
103103
@Override
104104
public boolean isModified() {
105105
final boolean licenseChanged = !moduleDefaultLicenseName.getText().equals(
106-
Settings.DEFAULT_LICENSE
106+
Settings.defaultLicense
107107
);
108108
final boolean statusChanged = !pluginEnabled.isSelected() == getSettings().pluginEnabled;
109109
final boolean mftfSupportChanged = mftfSupportEnabled.isSelected()
@@ -139,7 +139,7 @@ public void apply() throws ConfigurationException {
139139

140140
private void saveSettings() {
141141
getSettings().pluginEnabled = pluginEnabled.isSelected();
142-
getSettings().DEFAULT_LICENSE = moduleDefaultLicenseName.getText();
142+
getSettings().defaultLicense = moduleDefaultLicenseName.getText();
143143
getSettings().mftfSupportEnabled = mftfSupportEnabled.isSelected();
144144
getSettings().magentoPath = getMagentoPath();
145145
getSettings().magentoVersion = getMagentoVersion();

0 commit comments

Comments
 (0)