Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -28,51 +25,40 @@
/**
* @author Adrien Brault <adrien.brault@gmail.com>
*/
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<ServiceContainerLoader> SERVICE_CONTAINER_POINT_NAME = new ExtensionPointName<>("fr.adrienbrault.idea.symfony2plugin.extension.ServiceContainerLoader");
public static final ExtensionPointName<PluginConfigurationExtension> 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<ServiceContainerLoader> SERVICE_CONTAINER_POINT_NAME = new ExtensionPointName<>("fr.adrienbrault.idea.symfony2plugin.extension.ServiceContainerLoader");
public static final ExtensionPointName<PluginConfigurationExtension> 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<File> getContainerFiles() {
public static Collection<File> getContainerFiles(@NotNull Project project) {
Collection<ContainerFile> containerFiles = new ArrayList<>();

ServiceContainerLoaderParameter containerLoaderExtensionParameter = new ServiceContainerLoaderParameter(project, containerFiles);
Expand All @@ -88,25 +74,25 @@ public Collection<File> getContainerFiles() {

Collection<File> 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");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static boolean isValidForIndex(FileContent inputData, PsiFile psiFile) {
}

// dont add configured service paths
Collection<File> settingsServiceFiles = psiFile.getProject().getComponent(Symfony2ProjectComponent.class).getContainerFiles();
Collection<File> settingsServiceFiles = Symfony2ProjectComponent.getContainerFiles(psiFile.getProject());
for(File file: settingsServiceFiles) {
if(VfsUtil.isAncestor(VfsUtil.virtualToIoFile(inputData.getFile()), file, false)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ private boolean isModified(Collection<File> serviceFiles) {

@Nullable
synchronized public <T extends ServiceParserInterface> T parser(Class<T> serviceParser) {

Symfony2ProjectComponent symfony2ProjectComponent = this.project.getComponent(Symfony2ProjectComponent.class);

Collection<File> settingsServiceFiles = symfony2ProjectComponent.getContainerFiles();
Collection<File> settingsServiceFiles = Symfony2ProjectComponent.getContainerFiles(this.project);

if (this.serviceParserInstance != null && !this.isModified(settingsServiceFiles)) {
return (T) this.serviceParserInstance;
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/pay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<idea-plugin url="https://www.jetbrains.com/idea">

<extensionPoints>
<extensionPoint name="extension.PluginConfigurationExtension" interface="fr.adrienbrault.idea.symfony2plugin.extension.PluginConfigurationExtension"/>
<extensionPoint name="extension.TwigFileUsage" interface="fr.adrienbrault.idea.symfony2plugin.extension.TwigFileUsage"/>
<extensionPoint dynamic="true" name="extension.PluginConfigurationExtension" interface="fr.adrienbrault.idea.symfony2plugin.extension.PluginConfigurationExtension"/>
<extensionPoint dynamic="true" name="extension.TwigFileUsage" interface="fr.adrienbrault.idea.symfony2plugin.extension.TwigFileUsage"/>


</extensionPoints>
Expand Down
39 changes: 19 additions & 20 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@

<statusBarWidgetFactory implementation="fr.adrienbrault.idea.symfony2plugin.ui.SymfonyStatusbarWidgetFactory" />

<postStartupActivity implementation="fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent$PostStartupActivity"/>
<projectService
serviceImplementation="fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent$ProjectCloseService"/>


<localInspection groupPath="Symfony" shortName="PhpRouteMissingInspection" displayName="Route Missing"
groupName="Route"
enabledByDefault="true" level="WARNING"
Expand Down Expand Up @@ -544,20 +549,20 @@
</extensions>

<extensionPoints>
<extensionPoint name="extension.ServiceContainerLoader" interface="fr.adrienbrault.idea.symfony2plugin.extension.ServiceContainerLoader"/>
<extensionPoint name="extension.DoctrineModelProvider" interface="fr.adrienbrault.idea.symfony2plugin.extension.DoctrineModelProvider"/>
<extensionPoint name="extension.MethodSignatureTypeProviderExtension" interface="fr.adrienbrault.idea.symfony2plugin.extension.MethodSignatureTypeProviderExtension"/>
<extensionPoint name="extension.MethodParameterReferenceContributorExtension" interface="fr.adrienbrault.idea.symfony2plugin.extension.MethodParameterReferenceContributorExtension"/>
<extensionPoint name="extension.ControllerActionGotoRelatedCollector" interface="fr.adrienbrault.idea.symfony2plugin.extension.ControllerActionGotoRelatedCollector"/>
<extensionPoint name="extension.GotoCompletionRegistrar" interface="fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionRegistrar"/>
<extensionPoint name="extension.TwigNamespaceExtension" interface="fr.adrienbrault.idea.symfony2plugin.extension.TwigNamespaceExtension"/>
<extensionPoint name="extension.RoutingLoader" interface="fr.adrienbrault.idea.symfony2plugin.extension.RoutingLoader"/>
<extensionPoint name="extension.CompiledServiceBuilderFactory" interface="fr.adrienbrault.idea.symfony2plugin.extension.CompiledServiceBuilderFactory"/>
<extensionPoint name="extension.ServiceCollector" interface="fr.adrienbrault.idea.symfony2plugin.extension.ServiceCollector"/>
<extensionPoint name="extension.ServiceParameterCollector" interface="fr.adrienbrault.idea.symfony2plugin.extension.ServiceParameterCollector"/>
<extensionPoint name="extension.ServiceDefinitionLocator" interface="fr.adrienbrault.idea.symfony2plugin.extension.ServiceDefinitionLocator"/>
<extensionPoint name="extension.TwigVariableCollector" interface="fr.adrienbrault.idea.symfony2plugin.templating.variable.TwigFileVariableCollector"/>
<extensionPoint name="extension.TranslatorProvider" interface="fr.adrienbrault.idea.symfony2plugin.extension.TranslatorProvider"/>
<extensionPoint dynamic="true" name="extension.ServiceContainerLoader" interface="fr.adrienbrault.idea.symfony2plugin.extension.ServiceContainerLoader"/>
<extensionPoint dynamic="true" name="extension.DoctrineModelProvider" interface="fr.adrienbrault.idea.symfony2plugin.extension.DoctrineModelProvider"/>
<extensionPoint dynamic="true" name="extension.MethodSignatureTypeProviderExtension" interface="fr.adrienbrault.idea.symfony2plugin.extension.MethodSignatureTypeProviderExtension"/>
<extensionPoint dynamic="true" name="extension.MethodParameterReferenceContributorExtension" interface="fr.adrienbrault.idea.symfony2plugin.extension.MethodParameterReferenceContributorExtension"/>
<extensionPoint dynamic="true" name="extension.ControllerActionGotoRelatedCollector" interface="fr.adrienbrault.idea.symfony2plugin.extension.ControllerActionGotoRelatedCollector"/>
<extensionPoint dynamic="true" name="extension.GotoCompletionRegistrar" interface="fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionRegistrar"/>
<extensionPoint dynamic="true" name="extension.TwigNamespaceExtension" interface="fr.adrienbrault.idea.symfony2plugin.extension.TwigNamespaceExtension"/>
<extensionPoint dynamic="true" name="extension.RoutingLoader" interface="fr.adrienbrault.idea.symfony2plugin.extension.RoutingLoader"/>
<extensionPoint dynamic="true" name="extension.CompiledServiceBuilderFactory" interface="fr.adrienbrault.idea.symfony2plugin.extension.CompiledServiceBuilderFactory"/>
<extensionPoint dynamic="true" name="extension.ServiceCollector" interface="fr.adrienbrault.idea.symfony2plugin.extension.ServiceCollector"/>
<extensionPoint dynamic="true" name="extension.ServiceParameterCollector" interface="fr.adrienbrault.idea.symfony2plugin.extension.ServiceParameterCollector"/>
<extensionPoint dynamic="true" name="extension.ServiceDefinitionLocator" interface="fr.adrienbrault.idea.symfony2plugin.extension.ServiceDefinitionLocator"/>
<extensionPoint dynamic="true" name="extension.TwigVariableCollector" interface="fr.adrienbrault.idea.symfony2plugin.templating.variable.TwigFileVariableCollector"/>
<extensionPoint dynamic="true" name="extension.TranslatorProvider" interface="fr.adrienbrault.idea.symfony2plugin.extension.TranslatorProvider"/>
</extensionPoints>

<extensions defaultExtensionNs="fr.adrienbrault.idea.symfony2plugin.extension">
Expand Down Expand Up @@ -658,12 +663,6 @@
<PhpToolboxTargetLocator implementation="fr.adrienbrault.idea.symfony2plugin.external.locator.BundleFileToolboxTargetLocator"/>
</extensions>

<project-components>
<component>
<implementation-class>fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent</implementation-class>
</component>
</project-components>

<actions>

<action id="Symfony.Menu" class="fr.adrienbrault.idea.symfony2plugin.action.SymfonyContainerServiceBuilder">
Expand Down