test trigger updater
[teamcity/dotNetPackagesSupport.git] / nuget-server / src / jetbrains / buildServer / nuget / server / trigger / NamedPackagesUpdateChecker.java
index 27184cd95be07616ccc412d34e246b575b718428..5ba574fe2decc71adc1f2c3a4d04f8a200ab48d4 100644 (file)
@@ -5,6 +5,7 @@ import jetbrains.buildServer.buildTriggers.BuildTriggerException;
 import jetbrains.buildServer.nuget.server.exec.ListPackagesCommand;\r
 import jetbrains.buildServer.nuget.server.exec.PackageInfo;\r
 import jetbrains.buildServer.serverSide.CustomDataStorage;\r
+import jetbrains.buildServer.util.StringUtil;\r
 import org.jetbrains.annotations.NotNull;\r
 \r
 import java.io.File;\r
@@ -23,17 +24,35 @@ public class NamedPackagesUpdateChecker implements TriggerUpdateChecker {
   }\r
 \r
   public BuildStartReason checkChanges(@NotNull BuildTriggerDescriptor descriptor,\r
-                              @NotNull CustomDataStorage storage) throws BuildTriggerException {\r
+                                       @NotNull CustomDataStorage storage) throws BuildTriggerException {\r
     final String path = descriptor.getProperties().get(TriggerConstants.NUGET_EXE);\r
     final String pkgId = descriptor.getProperties().get(TriggerConstants.PACKAGE);\r
     final String version = descriptor.getProperties().get(TriggerConstants.VERSION);\r
     final String source = descriptor.getProperties().get(TriggerConstants.SOURCE);\r
 \r
-    Collection<PackageInfo> result = myCommand.checkForChanges(new File(path), source, pkgId, version);\r
+    if (StringUtil.isEmptyOrSpaces(path)) {\r
+      throw new BuildTriggerException("Path to NuGet.exe must be specified");\r
+    }\r
+\r
+    if (StringUtil.isEmptyOrSpaces(pkgId)) {\r
+      throw new BuildTriggerException("Package Id must be specified");\r
+    }\r
+\r
+    File nugetPath = new File(path);\r
+    if (!nugetPath.isFile()) {\r
+      throw new BuildTriggerException("Failed to find NuGet.exe at: " + nugetPath);\r
+    }\r
+\r
+    Collection<PackageInfo> result;\r
+    try {\r
+      result = myCommand.checkForChanges(nugetPath, source, pkgId, version);\r
+    } catch (Throwable t) {\r
+      throw new BuildTriggerException("Failed to check for package versions. " + t.getMessage(), t);\r
+    }\r
     final String hash = serializeHashcode(result);\r
 \r
     String oldHash = storage.getValue(KEY);\r
-    if (!hash.equals(oldHash)) {\r
+    if (oldHash != null && !hash.equals(oldHash)) {\r
       storage.putValue(KEY, hash);\r
       storage.flush();\r
       return new BuildStartReason("NuGet Package " + pkgId + " updated");\r