filter installed tool versions from install tool list
authorEugene Petrenko <eugene.petrenko@gmail.com>
Tue, 16 Aug 2011 22:20:08 +0000 (02:20 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Tue, 16 Aug 2011 22:20:08 +0000 (02:20 +0400)
nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/NuGetToolManagerImpl.java

index 0361ff513d214ba0d11cf0df97e97a71ff542947..b54715e73e2e275fc677768a24d2366272cbe802 100644 (file)
@@ -27,8 +27,7 @@ import java.io.File;
 import java.lang.reflect.InvocationHandler;\r
 import java.lang.reflect.Method;\r
 import java.lang.reflect.Proxy;\r
-import java.util.Collection;\r
-import java.util.Collections;\r
+import java.util.*;\r
 \r
 /**\r
  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
@@ -61,8 +60,20 @@ public class NuGetToolManagerImpl implements NuGetToolManager {
 \r
   @NotNull\r
   public Collection<? extends NuGetTool> getAvailableTools(@NotNull ToolsPolicy policy) throws FetchException {\r
+    final Set<String> installed = new HashSet<String>();\r
+    for (NuGetInstalledTool tool : getInstalledTools()) {\r
+      installed.add(tool.getVersion());\r
+    }\r
     //This must be cached to make if work faster!\r
-    return myAvailables.getAvailable(policy);\r
+    final Collection<NuGetTool> available = new ArrayList<NuGetTool>(myAvailables.getAvailable(policy));\r
+    final Iterator<NuGetTool> it = available.iterator();\r
+    while (it.hasNext()) {\r
+      NuGetTool next = it.next();\r
+      if (installed.contains(next.getVersion())) {\r
+        it.remove();\r
+      }\r
+    }\r
+    return available;\r
   }\r
 \r
   public void installTool(@NotNull String toolId) {\r