filter nuget.commandline versions
authorEugene Petrenko <eugene.petrenko@gmail.com>
Mon, 15 Aug 2011 12:57:53 +0000 (16:57 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Mon, 15 Aug 2011 12:57:53 +0000 (16:57 +0400)
nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/impl/AvailableToolsState.java

index a912e04eb764ca05c3f714c2fce5b52b2766c759..bb69a94f0c6fdce89a450b771ca3338aca1189b9 100644 (file)
@@ -22,6 +22,7 @@ import jetbrains.buildServer.nuget.server.feed.reader.NuGetFeedReader;
 import jetbrains.buildServer.nuget.server.toolRegistry.NuGetTool;\r
 import jetbrains.buildServer.util.CollectionsUtil;\r
 import jetbrains.buildServer.util.Converter;\r
+import jetbrains.buildServer.util.filters.Filter;\r
 import org.jetbrains.annotations.NotNull;\r
 \r
 import java.io.IOException;\r
@@ -42,14 +43,35 @@ public class AvailableToolsState {
   public Collection<NuGetTool> getAvailable() {\r
     try {\r
       final Collection<FeedPackage> packages = myReader.queryPackageVersions(FeedConstants.FEED_URL, FeedConstants.NUGET_COMMANDLINE);\r
-      return CollectionsUtil.convertCollection(\r
+      return CollectionsUtil.filterAndConvertCollection(\r
               packages,\r
               new Converter<NuGetTool, FeedPackage>() {\r
                 public NuGetTool createFrom(@NotNull FeedPackage source) {\r
                   return new InstallableTool(source);\r
                 }\r
+              },\r
+              new Filter<FeedPackage>() {\r
+                public boolean accept(@NotNull FeedPackage data) {\r
+                  final String[] version = data.getInfo().getVersion().split("\\.");\r
+                  if (version.length < 2) return false;\r
+                  int major = parse(version[0]);\r
+                  if (major < 1) return false;\r
+\r
+                  int minor = parse(version[1]);\r
+                  if (minor < 4) return false;\r
+\r
+                  return true;\r
+                }\r
+\r
+                private int parse(String s) {\r
+                  try {\r
+                    return Integer.parseInt(s.trim());\r
+                  } catch (Exception e) {\r
+                    return -1;\r
+                  }\r
+                }\r
               }\r
-              );\r
+      );\r
 \r
     } catch (IOException e) {\r
       e.printStackTrace();\r