1
1
package fr .adrienbrault .idea .symfony2plugin ;
2
2
3
- import com .intellij .notification .Notification ;
4
- import com .intellij .notification .NotificationType ;
5
- import com .intellij .notification .Notifications ;
6
- import com .intellij .openapi .components .ProjectComponent ;
3
+ import com .intellij .openapi .Disposable ;
7
4
import com .intellij .openapi .diagnostic .Logger ;
8
5
import com .intellij .openapi .extensions .ExtensionPointName ;
9
6
import com .intellij .openapi .project .Project ;
28
25
/**
29
26
* @author Adrien Brault <[email protected] >
30
27
*/
31
- public class Symfony2ProjectComponent implements ProjectComponent {
28
+ public class Symfony2ProjectComponent {
29
+ public static class PostStartupActivity implements com .intellij .openapi .startup .StartupActivity {
30
+ @ Override
31
+ public void runActivity (@ NotNull Project project ) {
32
+ checkProject (project );
32
33
33
- public static String HELP_URL = "http://symfony2-plugin.espend.de/" ;
34
- final private static Logger LOG = Logger .getInstance ("Symfony-Plugin" );
35
- private static final ExtensionPointName <ServiceContainerLoader > SERVICE_CONTAINER_POINT_NAME = new ExtensionPointName <>("fr.adrienbrault.idea.symfony2plugin.extension.ServiceContainerLoader" );
36
- public static final ExtensionPointName <PluginConfigurationExtension > PLUGIN_CONFIGURATION_EXTENSION = new ExtensionPointName <>("fr.adrienbrault.idea.symfony2plugin.extension.PluginConfigurationExtension" );
37
-
38
- private final Project project ;
39
-
40
- public Symfony2ProjectComponent (Project project ) {
41
- this .project = project ;
42
- }
43
-
44
- @ NotNull
45
- public String getComponentName () {
46
- return "Symfony2ProjectComponent" ;
34
+ }
47
35
}
48
36
49
- public void projectOpened () {
50
- this .checkProject ();
51
- }
37
+ public static class ProjectCloseService implements Disposable {
38
+ private final Project project ;
52
39
53
- public void projectClosed () {
54
- ServiceXmlParserFactory .cleanInstance (project );
40
+ public ProjectCloseService (@ NotNull Project project ) {
41
+ this .project = project ;
42
+ }
55
43
56
- // clean routing
57
- if (RouteHelper .COMPILED_CACHE .containsKey (project )) {
44
+ @ Override
45
+ public void dispose () {
46
+ ServiceXmlParserFactory .cleanInstance (this .project );
47
+ // clean routing
58
48
RouteHelper .COMPILED_CACHE .remove (project );
59
49
}
60
50
}
61
51
52
+ public static String HELP_URL = "http://symfony2-plugin.espend.de/" ;
53
+ final private static Logger LOG = Logger .getInstance ("Symfony-Plugin" );
54
+ private static final ExtensionPointName <ServiceContainerLoader > SERVICE_CONTAINER_POINT_NAME = new ExtensionPointName <>("fr.adrienbrault.idea.symfony2plugin.extension.ServiceContainerLoader" );
55
+ public static final ExtensionPointName <PluginConfigurationExtension > PLUGIN_CONFIGURATION_EXTENSION = new ExtensionPointName <>("fr.adrienbrault.idea.symfony2plugin.extension.PluginConfigurationExtension" );
56
+
62
57
public static Logger getLogger () {
63
58
return LOG ;
64
59
}
65
60
66
- public void showInfoNotification (String content ) {
67
- Notification errorNotification = new Notification ("Symfony Plugin" , "Symfony Plugin" , content , NotificationType .INFORMATION );
68
- Notifications .Bus .notify (errorNotification , this .project );
69
- }
70
-
71
- private boolean isEnabled () {
72
- return Settings .getInstance (project ).pluginEnabled ;
73
- }
74
-
75
- public Collection <File > getContainerFiles () {
61
+ public static Collection <File > getContainerFiles (@ NotNull Project project ) {
76
62
Collection <ContainerFile > containerFiles = new ArrayList <>();
77
63
78
64
ServiceContainerLoaderParameter containerLoaderExtensionParameter = new ServiceContainerLoaderParameter (project , containerFiles );
@@ -88,25 +74,25 @@ public Collection<File> getContainerFiles() {
88
74
89
75
Collection <File > validFiles = new ArrayList <>();
90
76
for (ContainerFile containerFile : containerFiles ) {
91
- if (containerFile .exists (this . project )) {
92
- validFiles .add (containerFile .getFile (this . project ));
77
+ if (containerFile .exists (project )) {
78
+ validFiles .add (containerFile .getFile (project ));
93
79
}
94
80
}
95
81
96
82
return validFiles ;
97
83
}
98
84
99
- private void checkProject () {
100
- if (!this . isEnabled ()
85
+ private static void checkProject (@ NotNull Project project ) {
86
+ if (!isEnabled (project )
101
87
&& !Settings .getInstance (project ).dismissEnableNotification
102
- && VfsUtil .findRelativeFile (ProjectUtil .getProjectDir (this . project ), "vendor" , "symfony" ) != null
88
+ && VfsUtil .findRelativeFile (ProjectUtil .getProjectDir (project ), "vendor" , "symfony" ) != null
103
89
) {
104
90
105
91
IdeHelper .notifyEnableMessage (project );
106
92
return ;
107
93
}
108
94
109
- if (this . getContainerFiles ().size () == 0 ) {
95
+ if (getContainerFiles (project ).size () == 0 ) {
110
96
Symfony2ProjectComponent .getLogger ().warn ("missing at least one container file" );
111
97
}
112
98
}
0 commit comments