1- /**
1+ /*
22 * Copyright © Magento, Inc. All rights reserved.
33 * See COPYING.txt for license details.
44 */
5+
56package com .magento .idea .magento2plugin .project ;
67
78import 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 ;
913import com .intellij .openapi .project .Project ;
1014import com .intellij .openapi .util .text .StringUtil ;
1115import com .intellij .util .EventDispatcher ;
1216import com .intellij .util .xmlb .annotations .Attribute ;
1317import 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 ;
1619import org .jetbrains .annotations .NotNull ;
1720import 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)
2628public 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 }
0 commit comments