show available nuget versions
authorEugene Petrenko <eugene.petrenko@gmail.com>
Mon, 15 Aug 2011 12:52:21 +0000 (16:52 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Mon, 15 Aug 2011 12:52:21 +0000 (16:52 +0400)
nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/NuGetToolManager.java
nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/AvailableToolsState.java [new file with mode: 0644]
nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/NuGetToolManagerImpl.java

index f9b1634eb361801dc83e205d93369abb3880aca4..b211f77cb993de2898779d72af447da9c12a7569 100644 (file)
@@ -49,11 +49,4 @@ public interface NuGetToolManager {
    * @param progress callback for showing messages\r
    */\r
   void installTool(@NotNull NuGetTool tool, @NotNull ActionProgress progress);\r
-\r
-  /**\r
-   * Registers user-provided NuGet tool from given NuGetInstalledTool i\r
-   * @param tool tool description to install\r
-   * @param progress action progress callback\r
-   */\r
-  void registerCustomTool(@NotNull NuGetUserTool tool, @NotNull ActionProgress progress);\r
 }\r
diff --git a/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/AvailableToolsState.java b/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/AvailableToolsState.java
new file mode 100644 (file)
index 0000000..a912e04
--- /dev/null
@@ -0,0 +1,83 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.server.toolRegistry.impl;\r
+\r
+import jetbrains.buildServer.nuget.server.feed.reader.FeedConstants;\r
+import jetbrains.buildServer.nuget.server.feed.reader.FeedPackage;\r
+import jetbrains.buildServer.nuget.server.feed.reader.NuGetFeedReader;\r
+import jetbrains.buildServer.nuget.server.toolRegistry.NuGetTool;\r
+import jetbrains.buildServer.util.CollectionsUtil;\r
+import jetbrains.buildServer.util.Converter;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+import java.io.IOException;\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 15.08.11 16:33\r
+ */\r
+public class AvailableToolsState {\r
+  private final NuGetFeedReader myReader;\r
+\r
+  public AvailableToolsState(@NotNull final NuGetFeedReader reader) {\r
+    myReader = reader;\r
+  }\r
+\r
+  public Collection<NuGetTool> getAvailable() {\r
+    try {\r
+      final Collection<FeedPackage> packages = myReader.queryPackageVersions(FeedConstants.FEED_URL, FeedConstants.NUGET_COMMANDLINE);\r
+      return CollectionsUtil.convertCollection(\r
+              packages,\r
+              new Converter<NuGetTool, FeedPackage>() {\r
+                public NuGetTool createFrom(@NotNull FeedPackage source) {\r
+                  return new InstallableTool(source);\r
+                }\r
+              }\r
+              );\r
+\r
+    } catch (IOException e) {\r
+      e.printStackTrace();\r
+      //TODO: handle exception\r
+      return Collections.emptyList();\r
+    }\r
+  }\r
+\r
+  private static class InstallableTool implements NuGetTool {\r
+    private final FeedPackage myPackage;\r
+\r
+    private InstallableTool(@NotNull final FeedPackage aPackage) {\r
+      myPackage = aPackage;\r
+    }\r
+\r
+    @NotNull\r
+    public String getId() {\r
+      return myPackage.getAtomId();\r
+    }\r
+\r
+    @NotNull\r
+    public String getVersion() {\r
+      return myPackage.getInfo().getVersion();\r
+    }\r
+\r
+    @NotNull\r
+    public FeedPackage getPackage() {\r
+      return myPackage;\r
+    }\r
+  }\r
+}\r
index 481818b85f3aeb0ffcf25b7f680b4bd477d02aee..145d58bfa397793117e9d50d2e220b84020efa24 100644 (file)
@@ -22,52 +22,42 @@ import org.jetbrains.annotations.NotNull;
 import java.io.File;\r
 import java.util.Arrays;\r
 import java.util.Collection;\r
+import java.util.List;\r
 \r
 /**\r
  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
  * Date: 11.08.11 1:07\r
  */\r
 public class NuGetToolManagerImpl implements NuGetToolManager {\r
+  private final AvailableToolsState myAvailables;\r
+\r
+  public NuGetToolManagerImpl(AvailableToolsState availables) {\r
+    myAvailables = availables;\r
+  }\r
+\r
   @NotNull\r
   public Collection<NuGetInstalledTool> getInstalledTools() {\r
-    return Arrays.<NuGetInstalledTool>asList(\r
-            new NuGetInstalledTool() {\r
-              @NotNull\r
-              public File getPath() {\r
-                return new File(".");\r
-              }\r
+    return mockInstalledTools();\r
+  }\r
 \r
-              @NotNull\r
-              public String getId() {\r
-                return "i1";\r
-              }\r
+  @NotNull\r
+  public Collection<NuGetInstallingTool> getInstallingTool() {\r
+    return mockInstallingTools();\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
+  @NotNull\r
+  public Collection<NuGetTool> getAvailableTools() {\r
+    //This must be cached to make if work faster!\r
+    return myAvailables.getAvailable();\r
+  }\r
+\r
+\r
+  public void installTool(@NotNull NuGetTool tool, @NotNull ActionProgress progress) {\r
 \r
-              @NotNull\r
-              public String getVersion() {\r
-                return "i2.4.5.7";\r
-              }\r
-            }\r
-    );\r
   }\r
 \r
-  @NotNull\r
-  public Collection<NuGetInstallingTool> getInstallingTool() {\r
+  private List<NuGetInstallingTool> mockInstallingTools() {\r
     return Arrays.<NuGetInstallingTool>asList(\r
             new NuGetInstallingTool() {\r
               @NotNull\r
@@ -88,39 +78,40 @@ public class NuGetToolManagerImpl implements NuGetToolManager {
     );\r
   }\r
 \r
-  @NotNull\r
-  public Collection<NuGetTool> getAvailableTools() {\r
-    return Arrays.<NuGetTool>asList(\r
-            new NuGetTool() {\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 "a-1";\r
+                return "i1";\r
               }\r
 \r
               @NotNull\r
               public String getVersion() {\r
-                return "a.3.5.6";\r
+                return "i1.2.3.5";\r
               }\r
             },\r
-            new NuGetTool() {\r
+            new NuGetInstalledTool() {\r
+              @NotNull\r
+              public File getPath() {\r
+                return new File(".");\r
+              }\r
+\r
               @NotNull\r
               public String getId() {\r
-                return "a-2";\r
+                return "i2";\r
               }\r
 \r
               @NotNull\r
               public String getVersion() {\r
-                return "a2.5.6.6";\r
+                return "i2.4.5.7";\r
               }\r
             }\r
     );\r
   }\r
-\r
-  public void installTool(@NotNull NuGetTool tool, @NotNull ActionProgress progress) {\r
-\r
-  }\r
-\r
-  public void registerCustomTool(@NotNull NuGetUserTool tool, @NotNull ActionProgress progress) {\r
-\r
-  }\r
 }\r