IDEA-134622 Gradle projects and symbolic links
authorVladislav.Soroka <Vladislav.Soroka@jetbrains.com>
Tue, 23 Dec 2014 11:52:45 +0000 (14:52 +0300)
committerVladislav.Soroka <Vladislav.Soroka@jetbrains.com>
Tue, 23 Dec 2014 11:53:33 +0000 (14:53 +0300)
plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/data/ExternalProjectDataService.java

index d286050be7494ecca200695c67782dbf12706d20..06e3790de334d4c530be44c4fff9c8e6b95d1dd0 100644 (file)
@@ -25,11 +25,15 @@ import com.intellij.openapi.externalSystem.util.Order;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Pair;
+import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.util.containers.ConcurrentFactoryMap;
+import com.intellij.util.containers.ContainerUtil;
+import gnu.trove.TObjectHashingStrategy;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.Collection;
 import java.util.Map;
 
@@ -47,9 +51,41 @@ public class ExternalProjectDataService implements ProjectDataService<ExternalPr
 
   @NotNull private ProjectDataManager myProjectDataManager;
 
+  private static final TObjectHashingStrategy<Pair<ProjectSystemId, File>> HASHING_STRATEGY =
+    new TObjectHashingStrategy<Pair<ProjectSystemId, File>>() {
+      @Override
+      public int computeHashCode(Pair<ProjectSystemId, File> object) {
+        try {
+          return object.first.hashCode() + FileUtil.pathHashCode(object.second.getCanonicalPath());
+        }
+        catch (IOException e) {
+          LOG.warn("unable to get canonical file path", e);
+          return object.first.hashCode() + FileUtil.fileHashCode(object.second);
+        }
+      }
+
+      @Override
+      public boolean equals(Pair<ProjectSystemId, File> o1, Pair<ProjectSystemId, File> o2) {
+        try {
+          return o1.first.equals(o2.first) && FileUtil.pathsEqual(o1.second.getCanonicalPath(), o2.second.getCanonicalPath());
+        }
+        catch (IOException e) {
+          LOG.warn("unable to get canonical file path", e);
+          return o1.first.equals(o2.first) && FileUtil.filesEqual(o1.second, o2.second);
+        }
+      }
+    };
+
+
   public ExternalProjectDataService(@NotNull ProjectDataManager projectDataManager) {
     myProjectDataManager = projectDataManager;
     myExternalRootProjects = new ConcurrentFactoryMap<Pair<ProjectSystemId, File>, ExternalProject>() {
+
+      @Override
+      protected Map<Pair<ProjectSystemId, File>, ExternalProject> createMap() {
+        return ContainerUtil.newConcurrentMap(HASHING_STRATEGY);
+      }
+
       @Nullable
       @Override
       protected ExternalProject create(Pair<ProjectSystemId, File> key) {