From fc473f0f29393136215c2349cd84d9626bbf6bcd Mon Sep 17 00:00:00 2001 From: Daniel Espendiller Date: Sat, 9 Apr 2022 16:25:04 +0200 Subject: [PATCH] replace the project component to allow the plugin be dynamic --- .../Symfony2ProjectComponent.java | 70 ++++++++----------- .../factory/LocalProfilerFactory.java | 3 +- .../indexes/ServicesDefinitionStubIndex.java | 2 +- .../util/service/ServiceXmlParserFactory.java | 5 +- src/main/resources/META-INF/pay.xml | 4 +- src/main/resources/META-INF/plugin.xml | 39 +++++------ 6 files changed, 52 insertions(+), 71 deletions(-) diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/Symfony2ProjectComponent.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/Symfony2ProjectComponent.java index 54dfa1b26..9850349ff 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/Symfony2ProjectComponent.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/Symfony2ProjectComponent.java @@ -1,9 +1,6 @@ package fr.adrienbrault.idea.symfony2plugin; -import com.intellij.notification.Notification; -import com.intellij.notification.NotificationType; -import com.intellij.notification.Notifications; -import com.intellij.openapi.components.ProjectComponent; +import com.intellij.openapi.Disposable; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.project.Project; @@ -28,51 +25,40 @@ /** * @author Adrien Brault */ -public class Symfony2ProjectComponent implements ProjectComponent { +public class Symfony2ProjectComponent { + public static class PostStartupActivity implements com.intellij.openapi.startup.StartupActivity { + @Override + public void runActivity(@NotNull Project project) { + checkProject(project); - public static String HELP_URL = "http://symfony2-plugin.espend.de/"; - final private static Logger LOG = Logger.getInstance("Symfony-Plugin"); - private static final ExtensionPointName SERVICE_CONTAINER_POINT_NAME = new ExtensionPointName<>("fr.adrienbrault.idea.symfony2plugin.extension.ServiceContainerLoader"); - public static final ExtensionPointName PLUGIN_CONFIGURATION_EXTENSION = new ExtensionPointName<>("fr.adrienbrault.idea.symfony2plugin.extension.PluginConfigurationExtension"); - - private final Project project; - - public Symfony2ProjectComponent(Project project) { - this.project = project; - } - - @NotNull - public String getComponentName() { - return "Symfony2ProjectComponent"; + } } - public void projectOpened() { - this.checkProject(); - } + public static class ProjectCloseService implements Disposable { + private final Project project; - public void projectClosed() { - ServiceXmlParserFactory.cleanInstance(project); + public ProjectCloseService(@NotNull Project project) { + this.project = project; + } - // clean routing - if(RouteHelper.COMPILED_CACHE.containsKey(project)) { + @Override + public void dispose() { + ServiceXmlParserFactory.cleanInstance(this.project); + // clean routing RouteHelper.COMPILED_CACHE.remove(project); } } + public static String HELP_URL = "http://symfony2-plugin.espend.de/"; + final private static Logger LOG = Logger.getInstance("Symfony-Plugin"); + private static final ExtensionPointName SERVICE_CONTAINER_POINT_NAME = new ExtensionPointName<>("fr.adrienbrault.idea.symfony2plugin.extension.ServiceContainerLoader"); + public static final ExtensionPointName PLUGIN_CONFIGURATION_EXTENSION = new ExtensionPointName<>("fr.adrienbrault.idea.symfony2plugin.extension.PluginConfigurationExtension"); + public static Logger getLogger() { return LOG; } - public void showInfoNotification(String content) { - Notification errorNotification = new Notification("Symfony Plugin", "Symfony Plugin", content, NotificationType.INFORMATION); - Notifications.Bus.notify(errorNotification, this.project); - } - - private boolean isEnabled() { - return Settings.getInstance(project).pluginEnabled; - } - - public Collection getContainerFiles() { + public static Collection getContainerFiles(@NotNull Project project) { Collection containerFiles = new ArrayList<>(); ServiceContainerLoaderParameter containerLoaderExtensionParameter = new ServiceContainerLoaderParameter(project, containerFiles); @@ -88,25 +74,25 @@ public Collection getContainerFiles() { Collection validFiles = new ArrayList<>(); for(ContainerFile containerFile : containerFiles) { - if(containerFile.exists(this.project)) { - validFiles.add(containerFile.getFile(this.project)); + if(containerFile.exists(project)) { + validFiles.add(containerFile.getFile(project)); } } return validFiles; } - private void checkProject() { - if(!this.isEnabled() + private static void checkProject(@NotNull Project project) { + if(!isEnabled(project) && !Settings.getInstance(project).dismissEnableNotification - && VfsUtil.findRelativeFile(ProjectUtil.getProjectDir(this.project), "vendor", "symfony") != null + && VfsUtil.findRelativeFile(ProjectUtil.getProjectDir(project), "vendor", "symfony") != null ) { IdeHelper.notifyEnableMessage(project); return; } - if(this.getContainerFiles().size() == 0) { + if(getContainerFiles(project).size() == 0) { Symfony2ProjectComponent.getLogger().warn("missing at least one container file"); } } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/profiler/factory/LocalProfilerFactory.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/profiler/factory/LocalProfilerFactory.java index 2cc6c433b..5111356aa 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/profiler/factory/LocalProfilerFactory.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/profiler/factory/LocalProfilerFactory.java @@ -58,8 +58,7 @@ private File findCsvProfilerFile(@NotNull Project project) { @Nullable protected File getCsvIndex(@NotNull Project project) { - Symfony2ProjectComponent symfony2ProjectComponent = project.getComponent(Symfony2ProjectComponent.class); - for(File file: symfony2ProjectComponent.getContainerFiles()) { + for(File file: Symfony2ProjectComponent.getContainerFiles(project)) { if(file.exists()) { File csvFile = new File(file.getParentFile().getPath() + "/profiler/index.csv"); if (csvFile.exists()) { diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/ServicesDefinitionStubIndex.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/ServicesDefinitionStubIndex.java index eb9985deb..53eb28814 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/ServicesDefinitionStubIndex.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/ServicesDefinitionStubIndex.java @@ -106,7 +106,7 @@ public static boolean isValidForIndex(FileContent inputData, PsiFile psiFile) { } // dont add configured service paths - Collection settingsServiceFiles = psiFile.getProject().getComponent(Symfony2ProjectComponent.class).getContainerFiles(); + Collection settingsServiceFiles = Symfony2ProjectComponent.getContainerFiles(psiFile.getProject()); for(File file: settingsServiceFiles) { if(VfsUtil.isAncestor(VfsUtil.virtualToIoFile(inputData.getFile()), file, false)) { return false; diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/service/ServiceXmlParserFactory.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/service/ServiceXmlParserFactory.java index 0dc730f3c..7cdef491c 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/service/ServiceXmlParserFactory.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/service/ServiceXmlParserFactory.java @@ -65,10 +65,7 @@ private boolean isModified(Collection serviceFiles) { @Nullable synchronized public T parser(Class serviceParser) { - - Symfony2ProjectComponent symfony2ProjectComponent = this.project.getComponent(Symfony2ProjectComponent.class); - - Collection settingsServiceFiles = symfony2ProjectComponent.getContainerFiles(); + Collection settingsServiceFiles = Symfony2ProjectComponent.getContainerFiles(this.project); if (this.serviceParserInstance != null && !this.isModified(settingsServiceFiles)) { return (T) this.serviceParserInstance; diff --git a/src/main/resources/META-INF/pay.xml b/src/main/resources/META-INF/pay.xml index 7c1e02440..54309404b 100644 --- a/src/main/resources/META-INF/pay.xml +++ b/src/main/resources/META-INF/pay.xml @@ -2,8 +2,8 @@ - - + + diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 309b3011a..96128aeb7 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -252,6 +252,11 @@ + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + @@ -658,12 +663,6 @@ - - - fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent - - -