1
- /**
1
+ /*
2
2
* Copyright © Magento, Inc. All rights reserved.
3
3
* See COPYING.txt for license details.
4
4
*/
5
+
5
6
package com .magento .idea .magento2plugin .project ;
6
7
7
8
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 ;
9
13
import com .intellij .openapi .project .Project ;
10
14
import com .intellij .openapi .util .text .StringUtil ;
11
15
import com .intellij .util .EventDispatcher ;
12
16
import com .intellij .util .xmlb .annotations .Attribute ;
13
17
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 ;
16
19
import org .jetbrains .annotations .NotNull ;
17
20
import org .jetbrains .annotations .Nullable ;
18
- import java .util .EventListener ;
19
21
20
22
@ State (
21
- name = "Magento2PluginSettings" ,
22
- storages = {
23
- @ Storage ("magento2plugin.xml" )
24
- }
23
+ name = "Magento2PluginSettings" ,
24
+ storages = {
25
+ @ Storage ("magento2plugin.xml" )
26
+ }
25
27
)
26
28
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" ;
30
33
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 ;
34
37
38
+ @ Override
35
39
@ Nullable
36
40
public Settings .State getState () {
37
41
return new Settings .State (
38
42
this .pluginEnabled ,
39
43
this .magentoPath ,
40
- DEFAULT_LICENSE ,
44
+ defaultLicense ,
41
45
this .mftfSupportEnabled ,
42
46
this .myDoNotAskContentConfigAgain ,
43
47
this .magentoVersion
44
48
);
45
49
}
46
50
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 ();
49
58
this .loadState (state );
50
59
this .notifyListeners (state , oldState );
51
60
}
52
61
53
- public void loadState (@ NotNull Settings .State state ) {
62
+ @ Override
63
+ public void loadState (final @ NotNull Settings .State state ) {
54
64
this .pluginEnabled = state .isPluginEnabled ();
55
65
this .magentoPath = state .getMagentoPath ();
56
- this .DEFAULT_LICENSE = state .getDefaultLicenseName ();
66
+ this .defaultLicense = state .getDefaultLicenseName ();
57
67
this .mftfSupportEnabled = state .isMftfSupportEnabled ();
58
68
this .myDoNotAskContentConfigAgain = state .isDoNotAskContentConfigAgain ();
59
69
this .magentoVersion = state .getMagentoVersion ();
60
70
}
61
71
62
- public void addListener (MagentoModuleDataListener listener ) {
72
+ public void addListener (final MagentoModuleDataListener listener ) {
63
73
this .myEventDispatcher .addListener (listener );
64
74
}
65
75
66
- private void notifyListeners (State state , State oldState ) {
76
+ private void notifyListeners (final State state , final State oldState ) {
67
77
if (!state .equals (oldState )) {
68
78
this .myEventDispatcher .getMulticaster ().stateChanged (state , oldState );
69
79
}
70
80
}
71
81
72
- public void setDoNotAskContentConfigurationAgain (boolean doNotAskContentConfigurationAgain ) {
82
+ public void setDoNotAskContentConfigurationAgain (
83
+ final boolean doNotAskContentConfigurationAgain
84
+ ) {
73
85
this .myDoNotAskContentConfigAgain = doNotAskContentConfigurationAgain ;
74
86
}
75
87
76
- public void setMagentoPath (String magentoPath ) {
88
+ public void setMagentoPath (final String magentoPath ) {
77
89
this .magentoPath = magentoPath ;
78
90
}
79
91
80
92
public interface MagentoModuleDataListener extends EventListener {
81
93
void stateChanged (State state , State oldState );
82
94
}
83
95
84
- public static Settings getInstance (Project project ) {
96
+ public static Settings getInstance (final Project project ) {
85
97
return ServiceManager .getService (project , Settings .class );
86
98
}
87
99
88
- public static boolean isEnabled (@ NotNull Project project ) {
100
+ public static boolean isEnabled (final @ NotNull Project project ) {
89
101
return getInstance (project ).pluginEnabled ;
90
102
}
91
103
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 ;
94
106
}
95
107
96
- public static boolean isMftfSupportEnabled (@ NotNull Project project ) {
108
+ public static boolean isMftfSupportEnabled (final @ NotNull Project project ) {
97
109
return getInstance (project ).mftfSupportEnabled ;
98
110
}
99
111
@@ -103,21 +115,11 @@ public static String getLastMagentoPath() {
103
115
}
104
116
105
117
@ 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 ;
119
120
}
120
121
122
+ @ SuppressWarnings ({"PMD.DataClass" })
121
123
@ Tag
122
124
public static class State {
123
125
public boolean pluginEnabled ;
@@ -127,16 +129,26 @@ public static class State {
127
129
public boolean myDoNotAskContentConfigAgain ;
128
130
public String magentoVersion ;
129
131
130
- public State () {
132
+ public State () {//NOPMD
131
133
}
132
134
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
+ */
133
145
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
140
152
) {
141
153
this .pluginEnabled = pluginEnabled ;
142
154
this .magentoPath = magentoPath ;
@@ -151,7 +163,7 @@ public boolean isPluginEnabled() {
151
163
return this .pluginEnabled ;
152
164
}
153
165
154
- public void setPluginEnabled (boolean enabled ) {
166
+ public void setPluginEnabled (final boolean enabled ) {
155
167
this .pluginEnabled = enabled ;
156
168
}
157
169
@@ -160,7 +172,7 @@ public String getMagentoPath() {
160
172
}
161
173
162
174
@ Tag ("magentoPath" )
163
- public void setMagentoPath (String magentoPath ) {
175
+ public void setMagentoPath (final String magentoPath ) {
164
176
this .magentoPath = magentoPath ;
165
177
}
166
178
@@ -169,22 +181,28 @@ public String getMagentoVersion() {
169
181
}
170
182
171
183
@ Tag ("magentoVersion" )
172
- public void setMagentoVersion (String magentoVersion ) {
184
+ public void setMagentoVersion (final String magentoVersion ) {
173
185
this .magentoVersion = magentoVersion ;
174
186
}
175
187
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 ) {
177
194
this .setMagentoPath (magentoPath );
178
195
if (!StringUtil .isEmptyOrSpaces (magentoPath )) {
179
- PropertiesComponent .getInstance ().setValue ("magento.support.magentoPath" , magentoPath );
196
+ PropertiesComponent .getInstance ()
197
+ .setValue ("magento.support.magentoPath" , magentoPath );
180
198
}
181
199
}
182
200
183
201
public String getDefaultLicenseName () {
184
202
return this .defaultLicenseName ;
185
203
}
186
204
187
- public void setDefaultLicenseName (String defaultLicenseName ) {
205
+ public void setDefaultLicenseName (final String defaultLicenseName ) {
188
206
this .defaultLicenseName = defaultLicenseName ;
189
207
}
190
208
@@ -196,40 +214,50 @@ public boolean isDoNotAskContentConfigAgain() {
196
214
return this .myDoNotAskContentConfigAgain ;
197
215
}
198
216
199
- public void setMftfSupportEnabled (boolean mftfSupportEnabled ) {
217
+ public void setMftfSupportEnabled (final boolean mftfSupportEnabled ) {
200
218
this .mftfSupportEnabled = mftfSupportEnabled ;
201
219
}
202
220
203
- public boolean equals (Object objectToCompare ) {
221
+ @ SuppressWarnings ({"PMD.ConfusingTernary" })
222
+ @ Override
223
+ public boolean equals (final Object objectToCompare ) {
204
224
if (this == objectToCompare ) {
205
225
return true ;
206
226
} else if (objectToCompare != null && this .getClass () == objectToCompare .getClass ()) {
207
- State state = (State ) objectToCompare ;
227
+ final State state = (State ) objectToCompare ;
208
228
if (this .isPluginEnabled () != state .isPluginEnabled ()) {
209
229
return false ;
210
230
} else if (this .isMftfSupportEnabled () != state .isMftfSupportEnabled ()) {
211
231
return false ;
212
- } else if (this .isDoNotAskContentConfigAgain () != state .isDoNotAskContentConfigAgain ()) {
232
+ } else if (
233
+ this .isDoNotAskContentConfigAgain () != state .isDoNotAskContentConfigAgain ()
234
+ ) {
213
235
return false ;
214
236
} else {
215
237
if (this .magentoPath != null ) {
216
238
return this .magentoPath .equals (state .magentoPath );
217
239
}
218
240
if (this .defaultLicenseName != null ) {
219
241
return this .defaultLicenseName .equals (state .defaultLicenseName );
220
- } else return state .defaultLicenseName == null ;
242
+ } else {
243
+ return state .defaultLicenseName == null ;
244
+ }
221
245
}
222
246
} else {
223
247
return false ;
224
248
}
225
249
}
226
250
251
+ @ SuppressWarnings ({"PMD.ConfusingTernary" })
252
+ @ Override
227
253
public int hashCode () {
228
254
int result = this .isPluginEnabled () ? 1 : 0 ;
229
255
result = 31 * result + (this .magentoPath != null ? this .magentoPath .hashCode () : 0 );
230
256
result = 31 * result + (this .isMftfSupportEnabled () ? 1 : 0 );
231
257
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
+ );
233
261
return result ;
234
262
}
235
263
}
0 commit comments