IDEA-250243 Gradle project windows displays incorrect project dependencies
authorVladislav.Soroka <Vladislav.Soroka@jetbrains.com>
Wed, 9 Sep 2020 10:09:32 +0000 (13:09 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Wed, 9 Sep 2020 10:10:10 +0000 (10:10 +0000)
GitOrigin-RevId: a277816858bd27a47316e5319abd34542f0f9b3a

platform/external-system-rt/src/com/intellij/openapi/externalSystem/model/project/dependencies/AbstractDependencyNode.java
platform/external-system-rt/src/com/intellij/openapi/externalSystem/model/project/dependencies/ArtifactDependencyNodeImpl.java
platform/external-system-rt/src/com/intellij/openapi/externalSystem/model/project/dependencies/DependencyScopeNode.java
platform/external-system-rt/src/com/intellij/openapi/externalSystem/model/project/dependencies/FileCollectionDependencyNodeImpl.java
platform/external-system-rt/src/com/intellij/openapi/externalSystem/model/project/dependencies/ProjectDependencyNodeImpl.java
platform/external-system-rt/src/com/intellij/openapi/externalSystem/model/project/dependencies/UnknownDependencyNode.java
plugins/gradle/tooling-extension-impl/testSources/org/jetbrains/plugins/gradle/tooling/serialization/ToolingSerializerTest.kt

index 79266944a606a746a2cc8aef84a6687aca57117e..dcaee9131ce6adb5a10cbef3c1823bf5da8f3a7e 100644 (file)
@@ -11,8 +11,6 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
-import static com.intellij.openapi.externalSystem.util.IteratorUtils.match;
-
 public abstract class AbstractDependencyNode implements DependencyNode, Serializable {
   private final long id;
   private final List<DependencyNode> dependencies;
@@ -45,14 +43,14 @@ public abstract class AbstractDependencyNode implements DependencyNode, Serializ
   }
 
   @Override
-  public boolean equals(Object o) {
+  public final boolean equals(Object o) {
     if (this == o) return true;
     if (o == null || getClass() != o.getClass()) return false;
 
     AbstractDependencyNode node = (AbstractDependencyNode)o;
     if (id != node.id) return false;
     if (resolutionState != null ? !resolutionState.equals(node.resolutionState) : node.resolutionState != null) return false;
-    if (!equal(dependencies, node.dependencies)) return false;
+    if (!match(dependencies, node.dependencies)) return false;
     return true;
   }
 
@@ -64,26 +62,29 @@ public abstract class AbstractDependencyNode implements DependencyNode, Serializ
     return result;
   }
 
-  private static boolean equal(@NotNull Collection<DependencyNode> dependencies1,
+  protected abstract boolean match(AbstractDependencyNode o);
+
+  private static boolean match(@NotNull Collection<DependencyNode> dependencies1,
                                @NotNull Collection<DependencyNode> dependencies2) {
-    return match(new DependenciesIterator(dependencies1), new DependenciesIterator(dependencies2),
-                 new BooleanBiFunction<DependencyNode, DependencyNode>() {
-                   @Override
-                   public Boolean fun(DependencyNode o1, DependencyNode o2) {
-                     if (o1 instanceof AbstractDependencyNode && o2 instanceof AbstractDependencyNode) {
-                       AbstractDependencyNode o11 = (AbstractDependencyNode)o1;
-                       AbstractDependencyNode o21 = (AbstractDependencyNode)o2;
-                       if (o11.id != o21.id) return false;
-                       if (o11.resolutionState != null ? !o11.resolutionState.equals(o21.resolutionState) : o21.resolutionState != null) {
-                         return false;
-                       }
-                       return true;
-                     }
-                     else {
-                       return o1 == null ? o2 == null : o1.equals(o2);
-                     }
-                   }
-                 });
+    return IteratorUtils.match(
+      new DependenciesIterator(dependencies1), new DependenciesIterator(dependencies2),
+      new BooleanBiFunction<DependencyNode, DependencyNode>() {
+        @Override
+        public Boolean fun(DependencyNode o1, DependencyNode o2) {
+          if (o1 instanceof AbstractDependencyNode && o2 instanceof AbstractDependencyNode) {
+            AbstractDependencyNode o11 = (AbstractDependencyNode)o1;
+            AbstractDependencyNode o21 = (AbstractDependencyNode)o2;
+            if (o11.id != o21.id) return false;
+            if (o11.resolutionState != null ? !o11.resolutionState.equals(o21.resolutionState) : o21.resolutionState != null) {
+              return false;
+            }
+            return o11.match(o21);
+          }
+          else {
+            return o1 == null ? o2 == null : o1.equals(o2);
+          }
+        }
+      });
   }
 
   private static final class DependenciesIterator extends IteratorUtils.AbstractObjectGraphIterator<DependencyNode> {
index 847c15c8db48834170c941b9d06e5288f890e41d..cd8e13e1385f2068e60391916e3fc1a07a6c4018 100644 (file)
@@ -43,12 +43,9 @@ public class ArtifactDependencyNodeImpl extends AbstractDependencyNode implement
   }
 
   @Override
-  public boolean equals(Object o) {
-    if (this == o) return true;
-    if (o == null || getClass() != o.getClass()) return false;
-    if (!super.equals(o)) return false;
-
-    ArtifactDependencyNodeImpl node = (ArtifactDependencyNodeImpl)o;
+  public boolean match(AbstractDependencyNode dependencyNode) {
+    if (dependencyNode == null || getClass() != dependencyNode.getClass()) return false;
+    ArtifactDependencyNodeImpl node = (ArtifactDependencyNodeImpl)dependencyNode;
     if (!group.equals(node.group)) return false;
     if (!module.equals(node.module)) return false;
     if (!version.equals(node.version)) return false;
index d3b452f8657f832dabbd6d79fa87980560541fc2..3d7b299dc356c91eadd3916f678ba36575e5aa03 100644 (file)
@@ -35,12 +35,9 @@ public class DependencyScopeNode extends AbstractDependencyNode {
   }
 
   @Override
-  public boolean equals(Object o) {
-    if (this == o) return true;
-    if (o == null || getClass() != o.getClass()) return false;
-    if (!super.equals(o)) return false;
-
-    DependencyScopeNode node = (DependencyScopeNode)o;
+  public boolean match(AbstractDependencyNode dependencyNode) {
+    if (dependencyNode == null || getClass() != dependencyNode.getClass()) return false;
+    DependencyScopeNode node = (DependencyScopeNode)dependencyNode;
     if (!scope.equals(node.scope)) return false;
     if (!displayName.equals(node.displayName)) return false;
     if (description != null ? !description.equals(node.description) : node.description != null) return false;
index 7d69290798ab70ca319e25d54bbe2e78a5b5ffb6..c9b10c76b5704e977b6749ab397ebf0624f055c3 100644 (file)
@@ -29,12 +29,9 @@ public class FileCollectionDependencyNodeImpl extends AbstractDependencyNode imp
   }
 
   @Override
-  public boolean equals(Object o) {
-    if (this == o) return true;
-    if (o == null || getClass() != o.getClass()) return false;
-    if (!super.equals(o)) return false;
-
-    FileCollectionDependencyNodeImpl node = (FileCollectionDependencyNodeImpl)o;
+  public boolean match(AbstractDependencyNode dependencyNode) {
+    if (dependencyNode == null || getClass() != dependencyNode.getClass()) return false;
+    FileCollectionDependencyNodeImpl node = (FileCollectionDependencyNodeImpl)dependencyNode;
     if (!displayName.equals(node.displayName)) return false;
     if (!path.equals(node.path)) return false;
     return true;
index 54b374594ced5165bf5e56ac9138f2f184c570e6..f34c5aa14cc70ac624b065de37748db3f8df0d7a 100644 (file)
@@ -29,11 +29,9 @@ public class ProjectDependencyNodeImpl extends AbstractDependencyNode implements
   }
 
   @Override
-  public boolean equals(Object o) {
-    if (this == o) return true;
-    if (o == null || getClass() != o.getClass()) return false;
-    if (!super.equals(o)) return false;
-    ProjectDependencyNodeImpl node = (ProjectDependencyNodeImpl)o;
+  public boolean match(AbstractDependencyNode dependencyNode) {
+    if (dependencyNode == null || getClass() != dependencyNode.getClass()) return false;
+    ProjectDependencyNodeImpl node = (ProjectDependencyNodeImpl)dependencyNode;
     if (!projectName.equals(node.projectName)) return false;
     return true;
   }
index d86cea888cea202d18d6d16682f1b079b4936ba6..860970cb45e26a3fcc2d404adb3f06d87294c0b1 100644 (file)
@@ -21,11 +21,9 @@ public class UnknownDependencyNode extends AbstractDependencyNode {
   }
 
   @Override
-  public boolean equals(Object o) {
-    if (this == o) return true;
-    if (o == null || getClass() != o.getClass()) return false;
-    if (!super.equals(o)) return false;
-    UnknownDependencyNode node = (UnknownDependencyNode)o;
+  public boolean match(AbstractDependencyNode dependencyNode) {
+    if (dependencyNode == null || getClass() != dependencyNode.getClass()) return false;
+    UnknownDependencyNode node = (UnknownDependencyNode)dependencyNode;
     if (name != null ? !name.equals(node.name) : node.name != null) return false;
     return true;
   }
index cbe2b250ac497fc3d2e68824c68da1b8561f5a2f..2e30775cf6e6cfdc35d4edac75dd7a28b191f042 100644 (file)
@@ -1,7 +1,7 @@
 // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
 package org.jetbrains.plugins.gradle.tooling.serialization
 
-import com.intellij.openapi.externalSystem.model.project.dependencies.ProjectDependenciesImpl
+import com.intellij.openapi.externalSystem.model.project.dependencies.*
 import io.github.classgraph.ClassGraph
 import io.github.classgraph.ClassInfo
 import org.assertj.core.api.Assertions.assertThat
@@ -145,6 +145,36 @@ class ToolingSerializerTest {
   @Throws(Exception::class)
   fun `project dependencies serialization test`() {
     doTest(ProjectDependenciesImpl::class.java)
+
+    val projectDependencies = ProjectDependenciesImpl()
+    val mainCompileDependencies = DependencyScopeNode(1, "compileClasspath", "project : (compileClasspath)", "")
+    val mainRuntimeDependencies = DependencyScopeNode(1, "runtimeClasspath", "project : (runtimeClasspath)", "")
+    val mainDependency = ArtifactDependencyNodeImpl(2, "dep", "dep", "1.0")
+    val mainNestedDependency = ArtifactDependencyNodeImpl(3, "nestedDep", "nestedDep", "1.1")
+    mainDependency.dependencies.add(mainNestedDependency)
+    mainRuntimeDependencies.dependencies.add(mainDependency)
+    mainRuntimeDependencies.dependencies.add(ReferenceNode(3))
+    val mainComponentDependencies = ComponentDependenciesImpl("main", mainCompileDependencies, mainRuntimeDependencies)
+    projectDependencies.add(mainComponentDependencies)
+
+    val testCompileDependencies = DependencyScopeNode(1, "testCompileClasspath", "project : (testCompileClasspath)", "")
+    val testRuntimeDependencies = DependencyScopeNode(1, "testRuntimeClasspath", "project : (testRuntimeClasspath)", "")
+    val testDependency = ArtifactDependencyNodeImpl(2, "dep", "dep", "1.0")
+    val testNestedDependency = ArtifactDependencyNodeImpl(3, "nestedDep", "nestedDep", "1.0")
+    testDependency.dependencies.add(testNestedDependency)
+    testRuntimeDependencies.dependencies.add(testDependency)
+    testRuntimeDependencies.dependencies.add(ReferenceNode(3))
+    val testComponentDependencies = ComponentDependenciesImpl("test", testCompileDependencies, testRuntimeDependencies)
+    projectDependencies.add(testComponentDependencies)
+
+    val bytes = ToolingSerializer().write(projectDependencies, ProjectDependenciesImpl::class.java)
+    val deserializedObject = ToolingSerializer().read(bytes, ProjectDependenciesImpl::class.java)
+
+    val deserializedMainNestedDependency = deserializedObject!!.componentsDependencies[0].runtimeDependenciesGraph.dependencies[0].dependencies[0]
+    assertThat(deserializedMainNestedDependency).isEqualToComparingFieldByField(mainNestedDependency)
+
+    val deserializedTestNestedDependency = deserializedObject.componentsDependencies[1].runtimeDependenciesGraph.dependencies[0].dependencies[0]
+    assertThat(deserializedTestNestedDependency).isEqualToComparingFieldByField(testNestedDependency)
   }
 
   @Throws(IOException::class)