IDEA-76142: Gradle support - cannot update IDEA projects once one of build.gradle...
authorDenis.Zhdanov <Denis.Zhdanov@jetbrains.com>
Thu, 2 Feb 2012 08:54:17 +0000 (12:54 +0400)
committerDenis.Zhdanov <Denis.Zhdanov@jetbrains.com>
Thu, 2 Feb 2012 08:55:18 +0000 (12:55 +0400)
Removed static dependency to the Application from the 'sync project changes' code. The reason is to avoid global setup changes during the tests processing

14 files changed:
plugins/gradle/src/META-INF/plugin.xml
plugins/gradle/src/org/jetbrains/plugins/gradle/bootstrap/GradleBootstrap.java
plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleColorAndFontPreviewPanel.java
plugins/gradle/src/org/jetbrains/plugins/gradle/config/GradleToolWindowPanel.java
plugins/gradle/src/org/jetbrains/plugins/gradle/diff/GradleModuleStructureChangesCalculator.java
plugins/gradle/src/org/jetbrains/plugins/gradle/diff/GradleProjectStructureChangesCalculator.java
plugins/gradle/src/org/jetbrains/plugins/gradle/diff/GradleProjectStructureHelperImpl.java
plugins/gradle/src/org/jetbrains/plugins/gradle/diff/PlatformFacade.java [moved from plugins/gradle/src/org/jetbrains/plugins/gradle/diff/GradleProjectStructureHelper.java with 81% similarity]
plugins/gradle/src/org/jetbrains/plugins/gradle/importing/wizard/adjust/GradleProjectStructureFactory.java
plugins/gradle/src/org/jetbrains/plugins/gradle/sync/GradleProjectStructureChangesPanel.java
plugins/gradle/src/org/jetbrains/plugins/gradle/sync/GradleProjectStructureTreeModel.java
plugins/gradle/src/org/jetbrains/plugins/gradle/ui/GradleIcons.java
plugins/gradle/testSources/org/jetbrains/plugins/gradle/sync/GradleProjectStructureChangesModelTest.groovy
plugins/gradle/testSources/org/jetbrains/plugins/gradle/testutil/IntellijProjectBuilder.groovy

index aa9dc8db216558b75ff08db9a82054ed31d61c4d..e347b9db23486be6d754d0d550d812ffbc13e525 100644 (file)
@@ -40,7 +40,7 @@
                         serviceImplementation="org.jetbrains.plugins.gradle.diff.GradleProjectStructureChangesCalculator"/>
     <applicationService serviceImplementation="org.jetbrains.plugins.gradle.diff.GradleModuleStructureChangesCalculator"/>
     <applicationService serviceImplementation="org.jetbrains.plugins.gradle.diff.GradleLibraryDependencyStructureChangesCalculator"/>
-    <applicationService serviceInterface="org.jetbrains.plugins.gradle.diff.GradleProjectStructureHelper"
+    <applicationService serviceInterface="org.jetbrains.plugins.gradle.diff.PlatformFacade"
                         serviceImplementation="org.jetbrains.plugins.gradle.diff.GradleProjectStructureHelperImpl"/>
     <applicationService serviceInterface="org.jetbrains.plugins.gradle.notification.GradleProgressNotificationManager"
                         serviceImplementation="org.jetbrains.plugins.gradle.notification.GradleProgressNotificationManagerImpl"/>
index 8280bcbc400b0aa8bb1182119e430054e010a791..6472130b5019367ed4e1f325854ff72979dd1dae 100644 (file)
@@ -9,7 +9,7 @@ import com.intellij.openapi.wm.ToolWindowAnchor;
 import com.intellij.openapi.wm.ex.ToolWindowManagerEx;
 import com.intellij.ui.content.impl.ContentImpl;
 import org.jetbrains.annotations.NotNull;
-import org.jetbrains.plugins.gradle.diff.GradleProjectStructureHelper;
+import org.jetbrains.plugins.gradle.diff.PlatformFacade;
 import org.jetbrains.plugins.gradle.sync.GradleProjectStructureChangesModel;
 import org.jetbrains.plugins.gradle.sync.GradleProjectStructureChangesPanel;
 import org.jetbrains.plugins.gradle.ui.GradleIcons;
@@ -26,11 +26,11 @@ public class GradleBootstrap extends AbstractProjectComponent {
   private static final String GRADLE_TOOL_WINDOW_ID = GradleBundle.message("gradle.name");
   
   private final GradleProjectStructureChangesModel myChangesModel;
-  private final GradleProjectStructureHelper myProjectStructureHelper;
+  private final PlatformFacade myProjectStructureHelper;
   
   public GradleBootstrap(@NotNull Project project,
                          @NotNull GradleProjectStructureChangesModel changesModel,
-                         @NotNull GradleProjectStructureHelper projectStructureHelper) {
+                         @NotNull PlatformFacade projectStructureHelper) {
     super(project);
     myChangesModel = changesModel;
     myProjectStructureHelper = projectStructureHelper;
index 1b4f09513de0b104e6774a3166cc907da1609f6c..7ee329145955139e3697b43912869599674f3c6a 100644 (file)
@@ -7,8 +7,10 @@ import com.intellij.application.options.colors.PreviewPanel;
 import com.intellij.ide.projectView.PresentationData;
 import com.intellij.ide.util.treeView.NodeRenderer;
 import com.intellij.openapi.application.ApplicationNamesInfo;
+import com.intellij.openapi.application.ex.ApplicationInfoEx;
 import com.intellij.openapi.editor.colors.EditorColorsScheme;
 import com.intellij.openapi.editor.colors.TextAttributesKey;
+import com.intellij.openapi.util.IconLoader;
 import com.intellij.openapi.util.Pair;
 import com.intellij.openapi.util.Ref;
 import com.intellij.ui.components.JBScrollPane;
@@ -59,7 +61,11 @@ public class GradleColorAndFontPreviewPanel implements PreviewPanel {
   private Pair<Tree, DefaultTreeModel> init() {
     myContent.removeAll();
     String projectName = GradleBundle.message("gradle.settings.color.text.sample.conflict.node.name");
-    DefaultMutableTreeNode root = createNode(projectName, GradleIcons.PROJECT_ICON, GradleTextAttributes.GRADLE_CHANGE_CONFLICT);
+    DefaultMutableTreeNode root = createNode(
+      projectName,
+      IconLoader.getIcon(ApplicationInfoEx.getInstanceEx().getSmallIconUrl()),
+      GradleTextAttributes.GRADLE_CHANGE_CONFLICT
+    );
 
     String moduleName = GradleBundle.message("gradle.settings.color.text.sample.node.confirmed.name");
     DefaultMutableTreeNode module = createNode(moduleName, GradleIcons.MODULE_ICON, GradleTextAttributes.GRADLE_CONFIRMED_CONFLICT);
index 585e30522962b431fd187585b684959b30420ba8..7db8c237d79d7e8dfc227d597162dc1e05611cd4 100644 (file)
@@ -9,7 +9,7 @@ import com.intellij.ui.ScrollPaneFactory;
 import com.intellij.util.messages.MessageBusConnection;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
-import org.jetbrains.plugins.gradle.diff.GradleProjectStructureHelper;
+import org.jetbrains.plugins.gradle.diff.PlatformFacade;
 import org.jetbrains.plugins.gradle.util.GradleBundle;
 import org.jetbrains.plugins.gradle.ui.RichTextControlBuilder;
 
@@ -43,10 +43,10 @@ public abstract class GradleToolWindowPanel extends SimpleToolWindowPanel {
   private final JPanel     myContent = new JPanel(myLayout);
 
   private final Project                      myProject;
-  private final GradleProjectStructureHelper myProjectStructureHelper;
+  private final PlatformFacade myProjectStructureHelper;
   
   protected GradleToolWindowPanel(@NotNull Project project,
-                                  @Nullable GradleProjectStructureHelper projectStructureHelper,
+                                  @Nullable PlatformFacade projectStructureHelper,
                                   @NotNull String place)
   {
     super(true);
@@ -98,7 +98,7 @@ public abstract class GradleToolWindowPanel extends SimpleToolWindowPanel {
   }
 
   @NotNull
-  public GradleProjectStructureHelper getProjectStructureHelper() {
+  public PlatformFacade getProjectStructureHelper() {
     return myProjectStructureHelper;
   }
 
index 28f5ec482cba3da58ee1b6eb9af7e95c3708e774..87f9231b289d713ef73cfa8242c264a1667cb20a 100644 (file)
@@ -35,10 +35,10 @@ import java.util.Set;
 public class GradleModuleStructureChangesCalculator implements GradleStructureChangesCalculator<GradleModule, Module> {
   
   private final GradleLibraryDependencyStructureChangesCalculator myLibraryDependencyCalculator;
-  private final GradleProjectStructureHelper myStructureHelper;
+  private final PlatformFacade myStructureHelper;
 
   public GradleModuleStructureChangesCalculator(@NotNull GradleLibraryDependencyStructureChangesCalculator libraryDependencyCalculator,
-                                                @NotNull GradleProjectStructureHelper structureHelper)
+                                                @NotNull PlatformFacade structureHelper)
   {
     myLibraryDependencyCalculator = libraryDependencyCalculator;
     myStructureHelper = structureHelper;
index ad9bc2827854c32f9e9f8534391e7797f617e2a5..c8f3236b71de0325c2696fa0d3ecfb0a566940f6 100644 (file)
@@ -21,10 +21,10 @@ import java.util.Set;
 public class GradleProjectStructureChangesCalculator implements GradleStructureChangesCalculator<GradleProject, Project> {
 
   private final GradleModuleStructureChangesCalculator myModuleChangesCalculator;
-  private final GradleProjectStructureHelper           myStructureHelper;
+  private final PlatformFacade myStructureHelper;
 
   public GradleProjectStructureChangesCalculator(@NotNull GradleModuleStructureChangesCalculator moduleCalculator,
-                                                 @NotNull GradleProjectStructureHelper structureHelper) {
+                                                 @NotNull PlatformFacade structureHelper) {
     myModuleChangesCalculator = moduleCalculator;
     myStructureHelper = structureHelper;
   }
index 6b30b59c57f6f0a4bfa35dffd1c1d79ea8c173a1..ff3fb2ada17a1113421605452791da6e7f397254 100644 (file)
@@ -1,14 +1,17 @@
 package org.jetbrains.plugins.gradle.diff;
 
+import com.intellij.openapi.application.ex.ApplicationInfoEx;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.module.ModuleManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.roots.LanguageLevelProjectExtension;
 import com.intellij.openapi.roots.ModuleRootManager;
 import com.intellij.openapi.roots.OrderEntry;
+import com.intellij.openapi.util.IconLoader;
 import com.intellij.pom.java.LanguageLevel;
 import org.jetbrains.annotations.NotNull;
 
+import javax.swing.*;
 import java.util.Arrays;
 import java.util.Collection;
 
@@ -16,7 +19,7 @@ import java.util.Collection;
  * @author Denis Zhdanov
  * @since 1/26/12 11:54 AM
  */
-public class GradleProjectStructureHelperImpl implements GradleProjectStructureHelper {
+public class GradleProjectStructureHelperImpl implements PlatformFacade {
 
   @NotNull
   @Override
@@ -35,4 +38,10 @@ public class GradleProjectStructureHelperImpl implements GradleProjectStructureH
   public Collection<OrderEntry> getOrderEntries(@NotNull Module module) {
     return Arrays.asList(ModuleRootManager.getInstance(module).getOrderEntries());
   }
+
+  @NotNull
+  @Override
+  public Icon getProjectIcon() {
+    return IconLoader.getIcon(ApplicationInfoEx.getInstanceEx().getSmallIconUrl());
+  }
 }
similarity index 81%
rename from plugins/gradle/src/org/jetbrains/plugins/gradle/diff/GradleProjectStructureHelper.java
rename to plugins/gradle/src/org/jetbrains/plugins/gradle/diff/PlatformFacade.java
index f0c81df791118567db884aaef07cc413c8baf4f2..c03c12035d59d01b7d55a0ed97bb7f6a4fba725c 100644 (file)
@@ -6,6 +6,7 @@ import com.intellij.openapi.roots.OrderEntry;
 import com.intellij.pom.java.LanguageLevel;
 import org.jetbrains.annotations.NotNull;
 
+import javax.swing.*;
 import java.util.Collection;
 
 /**
@@ -17,14 +18,14 @@ import java.util.Collection;
  * That means that it's not possible to test target classes in isolation if corresponding infrastructure is not set up.
  * However, we don't want to set it up if we execute a simple standalone test.
  * <p/>
- * This interface is intended to encapsulate access to the underlying project infrastructure.
+ * This interface is intended to encapsulate access to the underlying IntelliJ functionality.
  * <p/>
  * Implementations of this interface are expected to be thread-safe.
  * 
  * @author Denis Zhdanov
  * @since 1/26/12 11:32 AM
  */
-public interface GradleProjectStructureHelper {
+public interface PlatformFacade {
 
   @NotNull
   LanguageLevel getLanguageLevel(@NotNull Project project);
@@ -34,4 +35,10 @@ public interface GradleProjectStructureHelper {
 
   @NotNull
   Collection<OrderEntry> getOrderEntries(@NotNull Module module);
+
+  /**
+   * @return    icon that should be used for representation project root node at the tree UI controls used by the gradle integration
+   */
+  @NotNull
+  Icon getProjectIcon();
 }
index dd51ef3480cf420756ace726d84d3403631a073a..a488a328071b8b0907f5e27950146f41e3a3300d 100644 (file)
@@ -1,5 +1,7 @@
 package org.jetbrains.plugins.gradle.importing.wizard.adjust;
 
+import com.intellij.openapi.application.ex.ApplicationInfoEx;
+import com.intellij.openapi.util.IconLoader;
 import com.intellij.openapi.util.Ref;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.plugins.gradle.model.*;
@@ -35,7 +37,9 @@ public class GradleProjectStructureFactory {
     entity.invite(new GradleEntityVisitor() {
       @Override
       public void visit(@NotNull GradleProject project) {
-        result.set(new GradleProjectStructureNodeDescriptor<GradleEntity>(project, project.getName(), GradleIcons.PROJECT_ICON));
+        result.set(new GradleProjectStructureNodeDescriptor<GradleEntity>(
+          project, project.getName(), IconLoader.getIcon(ApplicationInfoEx.getInstanceEx().getSmallIconUrl())
+        ));
       }
 
       @Override
index 65fb403362514c1c4b49e9295b94bf906be23660..d2bc50a5ff416a1ac9d4ae6f805bc711b3892f1e 100644 (file)
@@ -7,7 +7,7 @@ import com.intellij.util.ui.UIUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.plugins.gradle.config.GradleToolWindowPanel;
 import org.jetbrains.plugins.gradle.diff.GradleProjectStructureChange;
-import org.jetbrains.plugins.gradle.diff.GradleProjectStructureHelper;
+import org.jetbrains.plugins.gradle.diff.PlatformFacade;
 import org.jetbrains.plugins.gradle.util.GradleConstants;
 
 import javax.swing.*;
@@ -27,7 +27,7 @@ public class GradleProjectStructureChangesPanel extends GradleToolWindowPanel {
 
   public GradleProjectStructureChangesPanel(@NotNull Project project,
                                             @NotNull GradleProjectStructureChangesModel model,
-                                            @NotNull GradleProjectStructureHelper projectStructureHelper)
+                                            @NotNull PlatformFacade projectStructureHelper)
   {
     super(project, projectStructureHelper, GradleConstants.TOOL_WINDOW_TOOLBAR_PLACE);
     model.addListener(new GradleProjectStructureChangeListener() {
index e851aba7a94124af79c87b97eb5e5f25a29a4606..5327468b119c249322efedf8eea2017f6545bb51 100644 (file)
@@ -53,13 +53,13 @@ public class GradleProjectStructureTreeModel extends DefaultTreeModel {
   private final TreeNode[] myNodeHolder  = new TreeNode[1];
   private final int[]      myIndexHolder = new int[1];
 
-  private final Project                      myProject;
-  private final GradleProjectStructureHelper myProjectStructureHelper;
+  private final Project        myProject;
+  private final PlatformFacade myPlatformFacade;
 
-  public GradleProjectStructureTreeModel(@NotNull Project project, @NotNull GradleProjectStructureHelper projectStructureHelper) {
+  public GradleProjectStructureTreeModel(@NotNull Project project, @NotNull PlatformFacade platformFacade) {
     super(null);
     myProject = project;
-    myProjectStructureHelper = projectStructureHelper;
+    myPlatformFacade = platformFacade;
     rebuild();
   }
 
@@ -68,7 +68,7 @@ public class GradleProjectStructureTreeModel extends DefaultTreeModel {
     myModules.clear();
     
     DefaultMutableTreeNode root = new DefaultMutableTreeNode(buildDescriptor(getProject()));
-    final Collection<Module> modules = myProjectStructureHelper.getModules(getProject());
+    final Collection<Module> modules = myPlatformFacade.getModules(getProject());
     RootPolicy<LibraryOrderEntry> policy = new RootPolicy<LibraryOrderEntry>() {
       @Override
       public LibraryOrderEntry visitLibraryOrderEntry(LibraryOrderEntry libraryOrderEntry, LibraryOrderEntry value) {
@@ -79,7 +79,7 @@ public class GradleProjectStructureTreeModel extends DefaultTreeModel {
       final DefaultMutableTreeNode moduleNode = new DefaultMutableTreeNode(buildDescriptor(module));
       myModules.put(module.getName(), moduleNode); // Assuming that module names are unique.
       List<LibraryOrderEntry> libraryDependencies = new ArrayList<LibraryOrderEntry>();
-      for (OrderEntry orderEntry : myProjectStructureHelper.getOrderEntries(module)) {
+      for (OrderEntry orderEntry : myPlatformFacade.getOrderEntries(module)) {
         final LibraryOrderEntry libraryDependency = orderEntry.accept(policy, null);
         if (libraryDependency != null && !StringUtil.isEmpty(libraryDependency.getLibraryName())) {
           libraryDependencies.add(libraryDependency);
@@ -111,8 +111,8 @@ public class GradleProjectStructureTreeModel extends DefaultTreeModel {
     return new GradleProjectStructureNodeDescriptor<Named>(entity, entity.getName(), icon);
   }
 
-  private static GradleProjectStructureNodeDescriptor<Project> buildDescriptor(@NotNull Project project) {
-    return new GradleProjectStructureNodeDescriptor<Project>(project, project.getName(), GradleIcons.PROJECT_ICON);
+  private GradleProjectStructureNodeDescriptor<Project> buildDescriptor(@NotNull Project project) {
+    return new GradleProjectStructureNodeDescriptor<Project>(project, project.getName(), myPlatformFacade.getProjectIcon());
   }
 
   private static GradleProjectStructureNodeDescriptor<Module> buildDescriptor(@NotNull Module module) {
index 2b096d8a4d2bcb52a86c6b72743798e0e5181d11..0dbc2256ae2bb102b0e5361eeaedc0ae0c28da68 100644 (file)
@@ -1,6 +1,5 @@
 package org.jetbrains.plugins.gradle.ui;
 
-import com.intellij.openapi.application.ex.ApplicationInfoEx;
 import com.intellij.openapi.util.IconLoader;
 
 import javax.swing.*;
@@ -13,7 +12,6 @@ public class GradleIcons {
 
   public static final Icon GRADLE_ICON       = IconLoader.getIcon("/icons/gradle.png");
   public static final Icon LIB_ICON          = IconLoader.getIcon("/nodes/ppLib.png");
-  public static final Icon PROJECT_ICON      = IconLoader.getIcon(ApplicationInfoEx.getInstanceEx().getSmallIconUrl());
   public static final Icon MODULE_ICON       = IconLoader.getIcon("/nodes/ModuleOpen.png");
   public static final Icon CONTENT_ROOT_ICON = IconLoader.getIcon("/modules/addContentEntry.png");
 
index c8ec3829baed1714214e849c936e85c6b09ce716..a1028db5d50c5be3e805ebbdbe7acb33f992affe 100644 (file)
@@ -2,10 +2,8 @@ package org.jetbrains.plugins.gradle.sync;
 
 
 import com.intellij.openapi.Disposable
-import com.intellij.openapi.application.Application
-import com.intellij.openapi.application.ApplicationManager
-import com.intellij.openapi.application.ex.ApplicationInfoEx
 import com.intellij.openapi.project.Project
+import com.intellij.openapi.util.Disposer
 import com.intellij.testFramework.SkipInHeadlessEnvironment
 import com.intellij.util.containers.ContainerUtil
 import org.jetbrains.plugins.gradle.testutil.ChangeBuilder
@@ -18,7 +16,6 @@ import org.junit.Test
 import org.picocontainer.defaults.DefaultPicoContainer
 import org.jetbrains.plugins.gradle.diff.*
 import static org.junit.Assert.assertEquals
-import com.intellij.openapi.util.Disposer
 
 /**
  * @author Denis Zhdanov
@@ -44,7 +41,7 @@ public class GradleProjectStructureChangesModelTest {
     treeChecker = new ProjectStructureChecker()
     container = new DefaultPicoContainer()
     container.registerComponentInstance(Project, intellij.project)
-    container.registerComponentInstance(GradleProjectStructureHelper, intellij.projectStructureHelper as GradleProjectStructureHelper)
+    container.registerComponentInstance(PlatformFacade, intellij.platformFacade as PlatformFacade)
     container.registerComponentImplementation(GradleProjectStructureChangesModel)
     container.registerComponentImplementation(GradleStructureChangesCalculator, GradleProjectStructureChangesCalculator)
     container.registerComponentImplementation(GradleModuleStructureChangesCalculator)
@@ -52,8 +49,6 @@ public class GradleProjectStructureChangesModelTest {
     container.registerComponentImplementation(GradleProjectStructureTreeModel)
     
     changesModel = container.getComponentInstance(GradleProjectStructureChangesModel) as GradleProjectStructureChangesModel
-    def applicationInfo = [getSmallIconUrl: {"/nodes/ideaProject.png"}] as ApplicationInfoEx
-    ApplicationManager.setApplication([getComponent: { applicationInfo } ] as Application, disposable)
   }
 
   @After
@@ -110,6 +105,7 @@ public class GradleProjectStructureChangesModelTest {
     } } } }
   }
 
+  @SuppressWarnings("GroovyAssignabilityCheck")
   private def init(gradleProjectInit, intellijProjectInit) {
     treeModel = container.getComponentInstance(GradleProjectStructureTreeModel) as GradleProjectStructureTreeModel
     changesModel.addListener({ old, current ->
index 2cea42fa39a783a6c2927daac9fe3686e514941d..4948c10dd0cb77130af42a793f990e0710357b9e 100644 (file)
@@ -2,11 +2,12 @@ package org.jetbrains.plugins.gradle.testutil
 
 import com.intellij.pom.java.LanguageLevel
 import com.intellij.openapi.module.Module
-import com.intellij.openapi.roots.RootPolicy
+
 import com.intellij.openapi.roots.libraries.Library
 import com.intellij.openapi.roots.LibraryOrderEntry
-import groovy.mock.interceptor.StubFor
+
 import com.intellij.openapi.project.Project
+import com.intellij.openapi.util.IconLoader
 
 /** 
  * @author Denis Zhdanov
@@ -16,15 +17,16 @@ class IntellijProjectBuilder extends AbstractProjectBuilder {
   
   def projectStub = [:]
   def project = projectStub as Project
-  def projectStructureHelper = [
+  def platformFacade = [
     getModules: { modules },
-    getOrderEntries: { dependencies[it] }
+    getOrderEntries: { dependencies[it] },
+    getProjectIcon: { IconLoader.getIcon("/nodes/ideaProject.png") }
   ]
 
   @Override
   protected createProject(String name, LanguageLevel languageLevel) {
     projectStub.getName = { name }
-    projectStructureHelper.getLanguageLevel = { languageLevel }
+    platformFacade.getLanguageLevel = { languageLevel }
     project
   }