move classes to .impl package, implement packages fetcher
authorEugene Petrenko <eugene.petrenko@gmail.com>
Fri, 12 Aug 2011 10:52:20 +0000 (14:52 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Fri, 12 Aug 2011 10:52:20 +0000 (14:52 +0400)
12 files changed:
nuget-server/src/META-INF/build-server-plugin-nuget.xml
nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/NuGetFeedReader.java
nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/impl/FeedClient.java [moved from nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/FeedClient.java with 93% similarity]
nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/impl/FeedConstants.java [moved from nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/FeedConstants.java with 90% similarity]
nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/impl/FeedGetMethodFactory.java [moved from nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/FeedGetMethodFactory.java with 93% similarity]
nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/impl/NuGetFeedReaderImpl.java [new file with mode: 0644]
nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/impl/PackagesFeedParser.java [moved from nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/PackagesFeedParser.java with 94% similarity]
nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/impl/Param.java [moved from nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/Param.java with 91% similarity]
nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/impl/UrlResolver.java [moved from nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/UrlResolver.java with 94% similarity]
nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/FeedReaderTest.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/server/FeedPackagesParserTest.java
nuget-tests/src/testng-nuget-integration.xml

index 8ed0da09af346bff2bb333b1c9d4ff8d9625fd97..10e5f16fd738fa83963f2295a33e46886bbb611d 100644 (file)
@@ -32,9 +32,9 @@
   <bean class="jetbrains.buildServer.nuget.server.publish.PublishRunType"/>\r
 \r
 \r
-  <bean class="jetbrains.buildServer.nuget.server.feed.reader.FeedClient" destroy-method="dispose"/>\r
-  <bean class="jetbrains.buildServer.nuget.server.feed.reader.NuGetFeedReader"/>\r
-  <bean class="jetbrains.buildServer.nuget.server.feed.reader.FeedGetMethodFactory"/>\r
-  <bean class="jetbrains.buildServer.nuget.server.feed.reader.UrlResolver"/>\r
+  <bean class="jetbrains.buildServer.nuget.server.feed.reader.impl.FeedClient" destroy-method="dispose"/>\r
+  <bean class="jetbrains.buildServer.nuget.server.feed.reader.impl.NuGetFeedReaderImpl"/>\r
+  <bean class="jetbrains.buildServer.nuget.server.feed.reader.impl.FeedGetMethodFactory"/>\r
+  <bean class="jetbrains.buildServer.nuget.server.feed.reader.impl.UrlResolver"/>\r
 \r
 </beans>
\ No newline at end of file
index b8a10094675cc3bf388f46afee0a1c12e1124fb5..35901b3c99871fd17f5bc02d672a61fdfaf0dd66 100644 (file)
 \r
 package jetbrains.buildServer.nuget.server.feed.reader;\r
 \r
-import com.intellij.openapi.diagnostic.Logger;\r
-import com.intellij.openapi.util.Pair;\r
-import jetbrains.buildServer.util.FileUtil;\r
-import jetbrains.buildServer.util.XmlUtil;\r
-import org.apache.http.HttpHeaders;\r
-import org.apache.http.HttpResponse;\r
-import org.apache.http.client.methods.HttpGet;\r
-import org.jdom.Element;\r
-import org.jdom.JDOMException;\r
 import org.jetbrains.annotations.NotNull;\r
 \r
 import java.io.IOException;\r
+import java.util.Collection;\r
 \r
 /**\r
  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
- * Date: 11.08.11 15:42\r
+ * Date: 12.08.11 14:46\r
  */\r
-public class NuGetFeedReader {\r
-  private static final Logger LOG = Logger.getInstance(NuGetFeedReader.class.getName());\r
-  private final FeedClient myClient;\r
-  private final UrlResolver myResolver;\r
-  private final FeedGetMethodFactory myMethodFactory;\r
-\r
-  public NuGetFeedReader(FeedClient client, UrlResolver resolver, FeedGetMethodFactory methodFactory) {\r
-    myClient = client;\r
-    myResolver = resolver;\r
-    myMethodFactory = methodFactory;\r
-  }\r
-\r
-  public void queryPackage(@NotNull String feedUrl,\r
-                           @NotNull String packageId) throws IOException {\r
-    LOG.debug("Connecting to NuGet feed url: " + feedUrl);\r
-    final Pair<String, HttpResponse> pair = myResolver.resolvePath(feedUrl);\r
-    feedUrl = pair.first;\r
-    LOG.debug("Resolved NuGet feed URL to " + feedUrl);\r
-    final Element element = toDocument(pair.second);\r
-    LOG.debug("Recieved xml: " + XmlUtil.to_s(element));\r
-\r
-    final HttpGet get = myMethodFactory.createGet(feedUrl + "/Packages()",\r
-            new Param("$filter", "Id eq '" + packageId + "'")\r
-            );\r
-    get.setHeader(HttpHeaders.ACCEPT_ENCODING, "application/atom+xml");\r
-\r
-    LOG.debug("Query for packages: " + get.getURI());\r
-\r
-    final HttpResponse execute = myClient.getClient().execute(get);\r
-    System.out.println(execute);\r
-    execute.getEntity().writeTo(System.out);\r
-  }\r
-\r
-  private Element toDocument(HttpResponse response) throws IOException {\r
-    try {\r
-      return FileUtil.parseDocument(response.getEntity().getContent(), false);\r
-    } catch (final JDOMException e) {\r
-      throw new IOException("Failed to parse xml document. " + e.getMessage()) {{\r
-        initCause(e);\r
-      }};\r
-    }\r
-  }\r
+public interface NuGetFeedReader {\r
+  @NotNull\r
+  Collection<FeedPackage> queryPackageVersions(@NotNull String feedUrl,\r
+                                               @NotNull String packageId) throws IOException;\r
 }\r
similarity index 93%
rename from nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/FeedClient.java
rename to nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/impl/FeedClient.java
index d10632afba13b202b5a7325785af75d1aa35dc3c..e426130619a7f7a1cfc924b86105be8ff9eb915b 100644 (file)
@@ -14,7 +14,7 @@
  * limitations under the License.\r
  */\r
 \r
-package jetbrains.buildServer.nuget.server.feed.reader;\r
+package jetbrains.buildServer.nuget.server.feed.reader.impl;\r
 \r
 import jetbrains.buildServer.version.ServerVersionHolder;\r
 import org.apache.http.client.HttpClient;\r
similarity index 90%
rename from nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/FeedConstants.java
rename to nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/impl/FeedConstants.java
index 8b3b7db1bc80375cfef07b226ae9d17e3f15cc68..103d36dd76cc0abc06bf7939121b6a751fb5bfb3 100644 (file)
@@ -14,7 +14,7 @@
  * limitations under the License.\r
  */\r
 \r
-package jetbrains.buildServer.nuget.server.feed.reader;\r
+package jetbrains.buildServer.nuget.server.feed.reader.impl;\r
 \r
 /**\r
  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
similarity index 93%
rename from nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/FeedGetMethodFactory.java
rename to nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/impl/FeedGetMethodFactory.java
index 9683c5ae213113a9daefd55e850499c17525a5c6..2e0a77d678cece1e08fc1b7c4c5e45f52eebd008 100644 (file)
@@ -14,7 +14,7 @@
  * limitations under the License.\r
  */\r
 \r
-package jetbrains.buildServer.nuget.server.feed.reader;\r
+package jetbrains.buildServer.nuget.server.feed.reader.impl;\r
 \r
 import org.apache.http.HttpVersion;\r
 import org.apache.http.NameValuePair;\r
diff --git a/nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/impl/NuGetFeedReaderImpl.java b/nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/impl/NuGetFeedReaderImpl.java
new file mode 100644 (file)
index 0000000..bec0ffa
--- /dev/null
@@ -0,0 +1,82 @@
+/*\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.feed.reader.impl;\r
+\r
+import com.intellij.openapi.diagnostic.Logger;\r
+import com.intellij.openapi.util.Pair;\r
+import jetbrains.buildServer.nuget.server.feed.reader.*;\r
+import jetbrains.buildServer.util.FileUtil;\r
+import jetbrains.buildServer.util.XmlUtil;\r
+import org.apache.http.HttpHeaders;\r
+import org.apache.http.HttpResponse;\r
+import org.apache.http.client.methods.HttpGet;\r
+import org.jdom.Element;\r
+import org.jdom.JDOMException;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+import java.io.IOException;\r
+import java.util.Collection;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 11.08.11 15:42\r
+ */\r
+public class NuGetFeedReaderImpl implements NuGetFeedReader {\r
+  private static final Logger LOG = Logger.getInstance(NuGetFeedReader.class.getName());\r
+  private final FeedClient myClient;\r
+  private final UrlResolver myResolver;\r
+  private final FeedGetMethodFactory myMethodFactory;\r
+  private final PackagesFeedParser myParser;\r
+\r
+  public NuGetFeedReaderImpl(FeedClient client, UrlResolver resolver, FeedGetMethodFactory methodFactory, PackagesFeedParser parser) {\r
+    myClient = client;\r
+    myResolver = resolver;\r
+    myMethodFactory = methodFactory;\r
+    myParser = parser;\r
+  }\r
+\r
+  @NotNull\r
+  public Collection<FeedPackage> queryPackageVersions(@NotNull String feedUrl,\r
+                           @NotNull String packageId) throws IOException {\r
+    LOG.debug("Connecting to NuGet feed url: " + feedUrl);\r
+    final Pair<String, HttpResponse> pair = myResolver.resolvePath(feedUrl);\r
+    feedUrl = pair.first;\r
+    LOG.debug("Resolved NuGet feed URL to " + feedUrl);\r
+    final Element element = toDocument(pair.second);\r
+    LOG.debug("Recieved xml: " + XmlUtil.to_s(element));\r
+\r
+    final HttpGet get = myMethodFactory.createGet(feedUrl + "/Packages()",\r
+            new Param("$filter", "Id eq '" + packageId + "'")\r
+            );\r
+    get.setHeader(HttpHeaders.ACCEPT_ENCODING, "application/atom+xml");\r
+\r
+    LOG.debug("Query for packages: " + get.getURI());\r
+\r
+    final HttpResponse execute = myClient.getClient().execute(get);\r
+    return myParser.readPackages(toDocument(execute));\r
+  }\r
+\r
+  private Element toDocument(HttpResponse response) throws IOException {\r
+    try {\r
+      return FileUtil.parseDocument(response.getEntity().getContent(), false);\r
+    } catch (final JDOMException e) {\r
+      throw new IOException("Failed to parse xml document. " + e.getMessage()) {{\r
+        initCause(e);\r
+      }};\r
+    }\r
+  }\r
+}\r
similarity index 94%
rename from nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/PackagesFeedParser.java
rename to nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/impl/PackagesFeedParser.java
index d6aee0fe895ada6505aa1773ac8f73adbc90f34b..750bb6d8e7e31a803a204358c83f5c94b712a823 100644 (file)
  * limitations under the License.\r
  */\r
 \r
-package jetbrains.buildServer.nuget.server.feed.reader;\r
+package jetbrains.buildServer.nuget.server.feed.reader.impl;\r
 \r
 import com.intellij.openapi.diagnostic.Logger;\r
 import jetbrains.buildServer.nuget.common.PackageInfo;\r
+import jetbrains.buildServer.nuget.server.feed.reader.FeedPackage;\r
 import jetbrains.buildServer.util.StringUtil;\r
 import org.jdom.Element;\r
 import org.jdom.Namespace;\r
similarity index 91%
rename from nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/Param.java
rename to nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/impl/Param.java
index 1378413d2b869e8dbc6bbc8e29962d2adbe507ec..1e49539bb395a710e7d330c751f69aa3f0f0aa27 100644 (file)
@@ -14,7 +14,7 @@
  * limitations under the License.\r
  */\r
 \r
-package jetbrains.buildServer.nuget.server.feed.reader;\r
+package jetbrains.buildServer.nuget.server.feed.reader.impl;\r
 \r
 import org.apache.http.NameValuePair;\r
 import org.jetbrains.annotations.NotNull;\r
similarity index 94%
rename from nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/UrlResolver.java
rename to nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/impl/UrlResolver.java
index 4d1b3c4a0186ac7dfe6ab37bfdfb5abf21d639c8..597676767b5ea044afe109a609b976ef7e6e6cfe 100644 (file)
@@ -14,7 +14,7 @@
  * limitations under the License.\r
  */\r
 \r
-package jetbrains.buildServer.nuget.server.feed.reader;\r
+package jetbrains.buildServer.nuget.server.feed.reader.impl;\r
 \r
 import com.intellij.openapi.util.Pair;\r
 import org.apache.http.Header;\r
index f9e43b79cefd7e5083fe04735983ed833651379f..6ab0cd8d8a198dc7fa3552588c5330c02f20ead7 100644 (file)
 package jetbrains.buildServer.nuget.tests.integration;\r
 \r
 import jetbrains.buildServer.BaseTestCase;\r
-import jetbrains.buildServer.nuget.server.feed.reader.*;\r
-import org.apache.log4j.ConsoleAppender;\r
-import org.apache.log4j.Level;\r
-import org.apache.log4j.Logger;\r
-import org.apache.log4j.SimpleLayout;\r
+import jetbrains.buildServer.nuget.server.feed.reader.FeedPackage;\r
+import jetbrains.buildServer.nuget.server.feed.reader.NuGetFeedReader;\r
+import jetbrains.buildServer.nuget.server.feed.reader.impl.*;\r
+import org.testng.Assert;\r
 import org.testng.annotations.AfterMethod;\r
 import org.testng.annotations.BeforeMethod;\r
 import org.testng.annotations.Test;\r
 \r
 import java.io.IOException;\r
+import java.util.Collection;\r
 \r
 /**\r
  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
@@ -42,7 +42,7 @@ public class FeedReaderTest extends BaseTestCase {
     super.setUp();\r
     myClient = new FeedClient();\r
     final FeedGetMethodFactory methods = new FeedGetMethodFactory();\r
-    myReader = new NuGetFeedReader(myClient, new UrlResolver(myClient, methods), methods);\r
+    myReader = new NuGetFeedReaderImpl(myClient, new UrlResolver(myClient, methods), methods, new PackagesFeedParser());\r
   }\r
 \r
   @AfterMethod\r
@@ -54,12 +54,14 @@ public class FeedReaderTest extends BaseTestCase {
 \r
   @Test\r
   public void testRead() throws IOException {\r
-    enableDebug();\r
+    final Collection<FeedPackage> feedPackages = myReader.queryPackageVersions(FeedConstants.FEED_URL, "NuGet.CommandLine");\r
+    Assert.assertTrue(feedPackages.size() > 0);\r
 \r
-    final Logger logger = Logger.getLogger("org.apache.commons");\r
-    logger.setLevel(Level.DEBUG);\r
-    logger.addAppender(new ConsoleAppender(new SimpleLayout()));\r
-\r
-    myReader.queryPackage(FeedConstants.FEED_URL, "NuGet.CommandLine");\r
+    boolean hasLatest = false;\r
+    for (FeedPackage feedPackage : feedPackages) {\r
+      Assert.assertFalse(hasLatest && feedPackage.isLatestVersion(), "There could be only one latest");\r
+      hasLatest |= feedPackage.isLatestVersion();\r
+      System.out.println("feedPackage = " + feedPackage);\r
+    }\r
   }\r
 }\r
index 0827c90156943c76696a1345e2f673b86b12d259..e6c16e3bd8f94579ff7cd56c63219f0a4a7ce866 100644 (file)
@@ -18,7 +18,7 @@ package jetbrains.buildServer.nuget.tests.server;
 \r
 import jetbrains.buildServer.BaseTestCase;\r
 import jetbrains.buildServer.nuget.server.feed.reader.FeedPackage;\r
-import jetbrains.buildServer.nuget.server.feed.reader.PackagesFeedParser;\r
+import jetbrains.buildServer.nuget.server.feed.reader.impl.PackagesFeedParser;\r
 import jetbrains.buildServer.nuget.tests.integration.Paths;\r
 import jetbrains.buildServer.util.FileUtil;\r
 import org.jdom.Element;\r
index 0d42ca6c54d20f8a9b051cf0a3ee67ffdf4de3f1..4112e5236b6d651a4fde8f075b374367521c4ea9 100644 (file)
@@ -5,6 +5,7 @@
       <class name="jetbrains.buildServer.nuget.tests.integration.InstallPackageIntegtatoinTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.integration.NuGetExecutorTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.integration.PackagesPublishIntegrationTest"/>\r
+      <class name="jetbrains.buildServer.nuget.tests.integration.FeedReaderTest"/>\r
     </classes>\r
   </test>\r
 </suite>\r