nuget tool install sketch
[teamcity/dotNetPackagesSupport.git] / nuget-server / src / jetbrains / buildServer / nuget / server / toolRegistry / impl / NuGetToolManagerImpl.java
index 57914fa007a6a82022c99eb3d9f04199f1451166..cbca2719d3c58e452c09d8f7416be71283d0ba57 100644 (file)
 \r
 package jetbrains.buildServer.nuget.server.toolRegistry.impl;\r
 \r
+import com.intellij.openapi.diagnostic.Logger;\r
 import jetbrains.buildServer.nuget.server.toolRegistry.*;\r
 import org.jetbrains.annotations.NotNull;\r
 \r
-import java.io.File;\r
+import java.lang.reflect.InvocationHandler;\r
+import java.lang.reflect.Method;\r
+import java.lang.reflect.Proxy;\r
 import java.util.Arrays;\r
 import java.util.Collection;\r
 import java.util.List;\r
@@ -29,15 +32,23 @@ import java.util.List;
  * Date: 11.08.11 1:07\r
  */\r
 public class NuGetToolManagerImpl implements NuGetToolManager {\r
+  private static final Logger LOG = Logger.getInstance(NuGetToolManagerImpl.class.getName());\r
+\r
   private final AvailableToolsState myAvailables;\r
+  private final NuGetToolsInstaller myInstaller;\r
+  private final ToolsRegistry myInstalled;\r
 \r
-  public NuGetToolManagerImpl(AvailableToolsState availables) {\r
+  public NuGetToolManagerImpl(@NotNull final AvailableToolsState availables,\r
+                              @NotNull final NuGetToolsInstaller installer,\r
+                              @NotNull final ToolsRegistry installed) {\r
     myAvailables = availables;\r
+    myInstaller = installer;\r
+    myInstalled = installed;\r
   }\r
 \r
   @NotNull\r
   public Collection<NuGetInstalledTool> getInstalledTools() {\r
-    return mockInstalledTools();\r
+    return myInstalled.getTools();\r
   }\r
 \r
   @NotNull\r
@@ -46,13 +57,27 @@ public class NuGetToolManagerImpl implements NuGetToolManager {
   }\r
 \r
   @NotNull\r
-  public Collection<NuGetTool> getAvailableTools(@NotNull ToolsPolicy policy) throws FetchException {\r
+  public Collection<? extends NuGetTool> getAvailableTools(@NotNull ToolsPolicy policy) throws FetchException {\r
     //This must be cached to make if work faster!\r
     return myAvailables.getAvailable(policy);\r
   }\r
 \r
   public void installTool(@NotNull String toolId) {\r
-\r
+    myInstaller.installNuGet(\r
+            toolId,\r
+            (InstallLogger) Proxy.newProxyInstance(getClass().getClassLoader(),\r
+                    new Class<?>[]{InstallLogger.class},\r
+                    new InvocationHandler() {\r
+                      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {\r
+                        StringBuilder sb = new StringBuilder();\r
+                        sb.append(method.getName());\r
+                        for (Object arg : args) {\r
+                          sb.append(" ").append(arg);\r
+                        }\r
+                        LOG.debug(sb.toString());\r
+                        return null;\r
+                      }\r
+                    }));\r
   }\r
 \r
   private List<NuGetInstallingTool> mockInstallingTools() {\r
@@ -75,41 +100,4 @@ public class NuGetToolManagerImpl implements NuGetToolManager {
             }\r
     );\r
   }\r
-\r
-  private List<NuGetInstalledTool> mockInstalledTools() {\r
-    return Arrays.<NuGetInstalledTool>asList(\r
-            new NuGetInstalledTool() {\r
-              @NotNull\r
-              public File getPath() {\r
-                return new File(".");\r
-              }\r
-\r
-              @NotNull\r
-              public String getId() {\r
-                return "i1";\r
-              }\r
-\r
-              @NotNull\r
-              public String getVersion() {\r
-                return "i1.2.3.5";\r
-              }\r
-            },\r
-            new NuGetInstalledTool() {\r
-              @NotNull\r
-              public File getPath() {\r
-                return new File(".");\r
-              }\r
-\r
-              @NotNull\r
-              public String getId() {\r
-                return "i2";\r
-              }\r
-\r
-              @NotNull\r
-              public String getVersion() {\r
-                return "i2.4.5.7";\r
-              }\r
-            }\r
-    );\r
-  }\r
 }\r