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