report used packages agent-side
authorEugene Petrenko <eugene.petrenko@gmail.com>
Mon, 18 Jul 2011 22:00:11 +0000 (02:00 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Mon, 18 Jul 2011 22:00:11 +0000 (02:00 +0400)
23 files changed:
.idea/libraries/Idea_OpenApi.xml
nuget-agent/nuget-agent.iml
nuget-agent/src/META-INF/build-agent-plugin-nuget.xml
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/NuGetActionFactory.java
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/NuGetPackagesCollector.java [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/NuGetPackagesConfigParser.java [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackageInfo.java [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackageUsages.java [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackagesInstallerRunner.java
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/InstallStages.java [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/InstallStagesImpl.java [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/LoggingNuGetActionFactoryImpl.java
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/NuGetActionFactoryImpl.java
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/NuGetPackagesCollectorEx.java [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/NuGetPackagesCollectorImpl.java [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/PackageUsagesImpl.java [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/PackagesInfoUploader.java [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/PackagesInstallerBuilder.java [moved from nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackagesInstallerBuilder.java with 78% similarity]
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/PackagesWatcher.java [new file with mode: 0644]
nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/NuGetInstallPackageActionFactoryTest.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/NuGetUpdatePackageActionFactoryTest.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/PackagesInstallerBuilderTest.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/InstallPackageIntegtatoinTest.java

index 7cdf0cd1c96f3294bcb399fca88ed901c4b3dde1..12c0ba987c6c1911cdac9b98e76bf205a1858d7f 100644 (file)
@@ -4,6 +4,7 @@
       <root url="jar://$TeamCityDistribution$/webapps/ROOT/WEB-INF/lib/util.jar!/" />\r
       <root url="jar://$TeamCityDistribution$/webapps/ROOT/WEB-INF/lib/openapi.jar!/" />\r
       <root url="jar://$TeamCityDistribution$/webapps/ROOT/WEB-INF/lib/trove4j.jar!/" />\r
+      <root url="jar://$TeamCityDistribution$/webapps/ROOT/WEB-INF/lib/jdom.jar!/" />\r
     </CLASSES>\r
     <JAVADOC />\r
     <SOURCES />\r
index 4a2a067bccadfb2d72a6cbb47132689cffb77d61..6ec8153d0949adc5f9e0c05fc78ed7103d1bafe9 100644 (file)
     <orderEntry type="sourceFolder" forTests="false" />\r
     <orderEntry type="library" name="Agent-Api" level="project" />\r
     <orderEntry type="library" name="Common-Api" level="project" />\r
-    <orderEntry type="library" name="Idea-OpenApi" level="project" />\r
     <orderEntry type="library" name="log4j" level="project" />\r
     <orderEntry type="module" module-name="nuget-common" />\r
     <orderEntry type="library" name="Agent-internal" level="project" />\r
     <orderEntry type="library" name="Common-Impl" level="project" />\r
+    <orderEntry type="library" name="Idea-OpenApi" level="project" />\r
   </component>\r
 </module>\r
 \r
index 7e157a597ceb4f38bfb7129327b9efdeef6ff675..f066b82b34b633fd2fc184922f275d62b314f773 100644 (file)
   </bean>\r
 \r
   <bean class="jetbrains.buildServer.nuget.agent.parameters.impl.PackagesParametersFactoryImpl"/>\r
+\r
+  <bean class="jetbrains.buildServer.nuget.agent.install.impl.PackageUsagesImpl"/>\r
+  <bean class="jetbrains.buildServer.nuget.agent.install.NuGetPackagesConfigParser" />\r
+  <bean class="jetbrains.buildServer.nuget.agent.install.impl.PackagesWatcher"/>\r
+  <bean class="jetbrains.buildServer.nuget.agent.install.impl.PackagesInfoUploader"/>\r
+  <bean class="jetbrains.buildServer.nuget.agent.install.impl.NuGetPackagesCollectorImpl"/>\r
 </beans>
\ No newline at end of file
index 378f3783958c12217e579b404ff946fb9db73352..94bb7dee3409f5c0a3b69582360dfd222814edf7 100644 (file)
@@ -42,4 +42,10 @@ public interface NuGetActionFactory {
                             @NotNull PackagesUpdateParameters params,\r
                             @NotNull File packagesConfig,\r
                             @NotNull File targetFolder) throws RunBuildException;\r
+\r
+  @NotNull\r
+  BuildProcess createUsageReport(@NotNull BuildRunnerContext context,\r
+                                 @NotNull NuGetParameters params,\r
+                                 @NotNull File packagesConfig,\r
+                                 @NotNull File targetFolder) throws RunBuildException;\r
 }\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/NuGetPackagesCollector.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/NuGetPackagesCollector.java
new file mode 100644 (file)
index 0000000..091344e
--- /dev/null
@@ -0,0 +1,39 @@
+/*\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.agent.install;\r
+\r
+import org.jetbrains.annotations.NotNull;\r
+import org.jetbrains.annotations.Nullable;\r
+\r
+import java.util.Collection;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 18.07.11 22:43\r
+ */\r
+public interface NuGetPackagesCollector {\r
+\r
+  void addPackage(@NotNull final String packageId,\r
+                  @NotNull final String version,\r
+                  @Nullable final String allowedVersions);\r
+\r
+  /**\r
+   * @return sorted list of packages that were registered\r
+   */\r
+  @NotNull\r
+  public Collection<PackageInfo> getPackages();\r
+}\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/NuGetPackagesConfigParser.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/NuGetPackagesConfigParser.java
new file mode 100644 (file)
index 0000000..64002cd
--- /dev/null
@@ -0,0 +1,68 @@
+/*\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.agent.install;\r
+\r
+import com.intellij.openapi.diagnostic.Logger;\r
+import jetbrains.buildServer.util.StringUtil;\r
+import jetbrains.buildServer.util.XmlXppAbstractParser;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.util.Arrays;\r
+import java.util.List;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 18.07.11 22:45\r
+ */\r
+public class NuGetPackagesConfigParser {\r
+  private static final Logger LOG = Logger.getInstance(NuGetPackagesConfigParser.class.getName());\r
+\r
+  public void parseNuGetPackages(@NotNull final File packagesConfig,\r
+                                 @NotNull final NuGetPackagesCollector callback) throws IOException {\r
+    XmlXppAbstractParser parser = new XmlXppAbstractParser() {\r
+      @Override\r
+      protected List<XmlHandler> getRootHandlers() {\r
+        return Arrays.asList(elementsPath(new Handler() {\r
+          public XmlReturn processElement(@NotNull XmlElementInfo xmlElementInfo) {\r
+            String id = xmlElementInfo.getAttribute("id");\r
+            String version = xmlElementInfo.getAttribute("version");\r
+            if (id == null || StringUtil.isEmptyOrSpaces(id))\r
+              return xmlElementInfo.noDeep();\r
+\r
+            if (version == null || StringUtil.isEmptyOrSpaces(version))\r
+              return xmlElementInfo.noDeep();\r
+\r
+\r
+            callback.addPackage(\r
+                    id,\r
+                    version,\r
+                    xmlElementInfo.getAttribute("allowedVersions"));\r
+\r
+            return xmlElementInfo.noDeep();\r
+          }\r
+        }, "packages", "package"));\r
+      }\r
+    };\r
+    try {\r
+      parser.parse(packagesConfig);\r
+    } catch (IOException e) {\r
+      LOG.warn("Failed to parse packages.config file: " + packagesConfig + ". " + e.getMessage(), e);\r
+    }\r
+  }\r
+}\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackageInfo.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackageInfo.java
new file mode 100644 (file)
index 0000000..596da40
--- /dev/null
@@ -0,0 +1,67 @@
+/*\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.agent.install;\r
+\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 18.07.11 22:55\r
+ */\r
+public class PackageInfo implements Comparable<PackageInfo> {\r
+  private final String myId;\r
+  private final String myVersion;\r
+\r
+  public PackageInfo(@NotNull final String id,\r
+                     @NotNull final String version) {\r
+    myId = id;\r
+    myVersion = version;\r
+  }\r
+\r
+  public int compareTo(PackageInfo o) {\r
+    int x;\r
+    if ((x = getId().compareTo(o.getId())) != 0) return x;\r
+    if ((x = getVersion().compareTo(o.getVersion())) != 0) return x;\r
+    return 0;\r
+  }\r
+\r
+  @NotNull\r
+  public String getId() {\r
+    return myId;\r
+  }\r
+\r
+  @NotNull\r
+  public String getVersion() {\r
+    return myVersion;\r
+  }\r
+\r
+  @Override\r
+  public boolean equals(Object o) {\r
+    if (this == o) return true;\r
+    if (o == null || getClass() != o.getClass()) return false;\r
+\r
+    PackageInfo that = (PackageInfo) o;\r
+    return myId.equals(that.myId) && myVersion.equals(that.myVersion);\r
+  }\r
+\r
+  @Override\r
+  public int hashCode() {\r
+    int result = myId.hashCode();\r
+    result = 31 * result + myVersion.hashCode();\r
+    return result;\r
+  }\r
+}\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackageUsages.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackageUsages.java
new file mode 100644 (file)
index 0000000..ba89c78
--- /dev/null
@@ -0,0 +1,31 @@
+/*\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.agent.install;\r
+\r
+import jetbrains.buildServer.agent.BuildProcess;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+import java.io.File;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 18.07.11 23:50\r
+ */\r
+public interface PackageUsages {\r
+  @NotNull\r
+  BuildProcess createReport(@NotNull File packagesConfig);\r
+}\r
index 8db97682d4116728d457632b0ae9825b402d3760..6c5c07a5d816304bbf3f60ab0effaaf944971583 100644 (file)
@@ -19,11 +19,13 @@ package jetbrains.buildServer.nuget.agent.install;
 import com.intellij.openapi.diagnostic.Logger;\r
 import jetbrains.buildServer.RunBuildException;\r
 import jetbrains.buildServer.agent.*;\r
+import jetbrains.buildServer.nuget.agent.install.impl.InstallStages;\r
+import jetbrains.buildServer.nuget.agent.install.impl.InstallStagesImpl;\r
+import jetbrains.buildServer.nuget.agent.install.impl.PackagesInstallerBuilder;\r
 import jetbrains.buildServer.nuget.agent.parameters.NuGetParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesParametersFactory;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;\r
-import jetbrains.buildServer.nuget.agent.util.CompositeBuildProcess;\r
 import jetbrains.buildServer.nuget.agent.util.impl.CompositeBuildProcessImpl;\r
 import jetbrains.buildServer.nuget.common.DotNetConstants;\r
 import jetbrains.buildServer.nuget.common.PackagesConstants;\r
@@ -49,6 +51,13 @@ public class PackagesInstallerRunner implements AgentBuildRunner, AgentBuildRunn
   public BuildProcess createBuildProcess(@NotNull AgentRunningBuild runningBuild,\r
                                          @NotNull final BuildRunnerContext context) throws RunBuildException {\r
     CompositeBuildProcessImpl process = new CompositeBuildProcessImpl();\r
+    InstallStages stages = new InstallStagesImpl(process);\r
+    createStages(context, stages);\r
+    return process;\r
+  }\r
+\r
+  private void createStages(@NotNull final BuildRunnerContext context,\r
+                            @NotNull final InstallStages stages) throws RunBuildException {\r
     final NuGetParameters parameters = myParametersFactory.loadNuGetParameters(context);\r
     final PackagesInstallParameters installParameters = myParametersFactory.loadInstallPackagesParameters(context, parameters);\r
     final PackagesUpdateParameters updateParameters = myParametersFactory.loadUpdatePackagesParameters(context, parameters);\r
@@ -57,29 +66,18 @@ public class PackagesInstallerRunner implements AgentBuildRunner, AgentBuildRunn
       throw new RunBuildException("NuGet install packages must be enabled");\r
     }\r
 \r
-    final CompositeBuildProcess install = new CompositeBuildProcessImpl();\r
-    final CompositeBuildProcess update = new CompositeBuildProcessImpl();\r
-    final CompositeBuildProcess postUpdate = new CompositeBuildProcessImpl();\r
-\r
     final LocateNuGetConfigBuildProcess locate = new LocateNuGetConfigBuildProcess(\r
             parameters,\r
             context.getBuild().getBuildLogger(),\r
             new PackagesInstallerBuilder(\r
                     myNuGetActionFactory,\r
-                    install,\r
-                    update,\r
-                    postUpdate,\r
+                    stages,\r
                     context,\r
                     installParameters,\r
                     updateParameters\r
             ));\r
 \r
-    process.pushBuildProcess(locate);\r
-    process.pushBuildProcess(install);\r
-    process.pushBuildProcess(update);\r
-    process.pushBuildProcess(postUpdate);\r
-\r
-    return process;\r
+    stages.getLocateStage().pushBuildProcess(locate);\r
   }\r
 \r
   @NotNull\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/InstallStages.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/InstallStages.java
new file mode 100644 (file)
index 0000000..f395fbf
--- /dev/null
@@ -0,0 +1,41 @@
+/*\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.agent.install.impl;\r
+\r
+import jetbrains.buildServer.nuget.agent.util.BuildProcessContinuation;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 18.07.11 23:36\r
+ */\r
+public interface InstallStages {\r
+  @NotNull\r
+  BuildProcessContinuation getLocateStage();\r
+\r
+  @NotNull\r
+  BuildProcessContinuation getInstallStage();\r
+\r
+  @NotNull\r
+  BuildProcessContinuation getUpdateStage();\r
+\r
+  @NotNull\r
+  BuildProcessContinuation getPostUpdateStart();\r
+\r
+  @NotNull\r
+  BuildProcessContinuation getReportStage();\r
+}\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/InstallStagesImpl.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/InstallStagesImpl.java
new file mode 100644 (file)
index 0000000..9f59c5c
--- /dev/null
@@ -0,0 +1,73 @@
+/*\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.agent.install.impl;\r
+\r
+import jetbrains.buildServer.nuget.agent.util.BuildProcessContinuation;\r
+import jetbrains.buildServer.nuget.agent.util.impl.CompositeBuildProcessImpl;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 18.07.11 23:40\r
+ */\r
+public class InstallStagesImpl implements InstallStages {\r
+  private final BuildProcessContinuation myLocate;\r
+  private final BuildProcessContinuation myInstall;\r
+  private final BuildProcessContinuation myUpdate;\r
+  private final BuildProcessContinuation myPostInstall;\r
+  private final BuildProcessContinuation myReport;\r
+\r
+  public InstallStagesImpl(@NotNull final BuildProcessContinuation host) {\r
+    //order is significant\r
+    myLocate = push(host);\r
+    myInstall = push(host);\r
+    myUpdate = push(host);\r
+    myPostInstall = push(host);\r
+    myReport = push(host);\r
+  }\r
+\r
+  private static BuildProcessContinuation push(@NotNull final BuildProcessContinuation proc) {\r
+    CompositeBuildProcessImpl child = new CompositeBuildProcessImpl();\r
+    proc.pushBuildProcess(child);\r
+    return child;\r
+  }\r
+\r
+  @NotNull\r
+  public BuildProcessContinuation getLocateStage() {\r
+    return myLocate;\r
+  }\r
+\r
+  @NotNull\r
+  public BuildProcessContinuation getInstallStage() {\r
+    return myInstall;\r
+  }\r
+\r
+  @NotNull\r
+  public BuildProcessContinuation getUpdateStage() {\r
+    return myUpdate;\r
+  }\r
+\r
+  @NotNull\r
+  public BuildProcessContinuation getPostUpdateStart() {\r
+    return myPostInstall;\r
+  }\r
+\r
+  @NotNull\r
+  public BuildProcessContinuation getReportStage() {\r
+    return myReport;\r
+  }\r
+}\r
index d35f855568a5c4e4784179216b03845e55603dbe..04812bb5c6bea5242fac63701355c6bc3fcadd35 100644 (file)
@@ -21,6 +21,7 @@ import jetbrains.buildServer.agent.BuildProcess;
 import jetbrains.buildServer.agent.BuildProgressLogger;\r
 import jetbrains.buildServer.agent.BuildRunnerContext;\r
 import jetbrains.buildServer.nuget.agent.install.NuGetActionFactory;\r
+import jetbrains.buildServer.nuget.agent.parameters.NuGetParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;\r
 import jetbrains.buildServer.nuget.agent.util.DelegatingBuildProcess;\r
@@ -40,6 +41,11 @@ public class LoggingNuGetActionFactoryImpl implements NuGetActionFactory {
     myActionFactory = actionFactory;\r
   }\r
 \r
+  @NotNull\r
+  public BuildProcess createUsageReport(@NotNull BuildRunnerContext context, @NotNull NuGetParameters params, @NotNull File packagesConfig, @NotNull File targetFolder) throws RunBuildException {\r
+    return myActionFactory.createUsageReport(context, params, packagesConfig, targetFolder);\r
+  }\r
+\r
   @NotNull\r
   public BuildProcess createInstall(@NotNull final BuildRunnerContext context,\r
                                     @NotNull final PackagesInstallParameters params,\r
index 1ce6cafedc2f1095073a1bccff5040d7e4d8e6e9..236d4d549cd0e1c7446eeff6bdccb0ac34633610 100644 (file)
@@ -20,6 +20,7 @@ import jetbrains.buildServer.RunBuildException;
 import jetbrains.buildServer.agent.BuildProcess;\r
 import jetbrains.buildServer.agent.BuildRunnerContext;\r
 import jetbrains.buildServer.nuget.agent.install.NuGetActionFactory;\r
+import jetbrains.buildServer.nuget.agent.install.PackageUsages;\r
 import jetbrains.buildServer.nuget.agent.parameters.NuGetParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;\r
@@ -38,9 +39,12 @@ import java.util.List;
  */\r
 public class NuGetActionFactoryImpl implements NuGetActionFactory {\r
   private final CommandlineBuildProcessFactory myFactory;\r
+  private final PackageUsages myPackageUsages;\r
 \r
-  public NuGetActionFactoryImpl(CommandlineBuildProcessFactory factory) {\r
+  public NuGetActionFactoryImpl(@NotNull final CommandlineBuildProcessFactory factory,\r
+                                @NotNull final PackageUsages packageUsages) {\r
     myFactory = factory;\r
+    myPackageUsages = packageUsages;\r
   }\r
 \r
   @NotNull\r
@@ -84,6 +88,13 @@ public class NuGetActionFactoryImpl implements NuGetActionFactory {
     return executeNuGet(context, params.getNuGetParameters(), argz, packagesConfig.getParentFile());\r
   }\r
 \r
+  @NotNull\r
+  public BuildProcess createUsageReport(@NotNull BuildRunnerContext context,\r
+                                        @NotNull NuGetParameters params,\r
+                                        @NotNull File packagesConfig,\r
+                                        @NotNull File targetFolder) throws RunBuildException {\r
+    return myPackageUsages.createReport(packagesConfig);\r
+  }\r
 \r
   @NotNull\r
   private BuildProcess executeNuGet(@NotNull final BuildRunnerContext context,\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/NuGetPackagesCollectorEx.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/NuGetPackagesCollectorEx.java
new file mode 100644 (file)
index 0000000..ab89d8e
--- /dev/null
@@ -0,0 +1,27 @@
+/*\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.agent.install.impl;\r
+\r
+import jetbrains.buildServer.nuget.agent.install.NuGetPackagesCollector;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 18.07.11 23:00\r
+ */\r
+public interface NuGetPackagesCollectorEx extends NuGetPackagesCollector {\r
+  void removeAllPackages();\r
+}\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/NuGetPackagesCollectorImpl.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/NuGetPackagesCollectorImpl.java
new file mode 100644 (file)
index 0000000..55e0141
--- /dev/null
@@ -0,0 +1,47 @@
+/*\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.agent.install.impl;\r
+\r
+import jetbrains.buildServer.nuget.agent.install.PackageInfo;\r
+import org.jetbrains.annotations.NotNull;\r
+import org.jetbrains.annotations.Nullable;\r
+\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+import java.util.TreeSet;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 18.07.11 22:52\r
+ */\r
+public class NuGetPackagesCollectorImpl implements NuGetPackagesCollectorEx {\r
+  private final TreeSet<PackageInfo> myPackages = new TreeSet<PackageInfo>();\r
+\r
+\r
+  public void addPackage(@NotNull String packageId, @NotNull String version, @Nullable String allowedVersions) {\r
+    myPackages.add(new PackageInfo(packageId, version));\r
+  }\r
+\r
+  @NotNull\r
+  public Collection<PackageInfo> getPackages() {\r
+    return Collections.unmodifiableCollection(myPackages);\r
+  }\r
+\r
+  public void removeAllPackages() {\r
+    myPackages.clear();\r
+  }\r
+}\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/PackageUsagesImpl.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/PackageUsagesImpl.java
new file mode 100644 (file)
index 0000000..e01d67e
--- /dev/null
@@ -0,0 +1,69 @@
+/*\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.agent.install.impl;\r
+\r
+import com.intellij.openapi.diagnostic.Logger;\r
+import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.agent.BuildFinishedStatus;\r
+import jetbrains.buildServer.agent.BuildProcess;\r
+import jetbrains.buildServer.nuget.agent.install.NuGetPackagesCollector;\r
+import jetbrains.buildServer.nuget.agent.install.NuGetPackagesConfigParser;\r
+import jetbrains.buildServer.nuget.agent.install.PackageUsages;\r
+import jetbrains.buildServer.nuget.agent.util.BuildProcessBase;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 18.07.11 23:17\r
+ */\r
+public class PackageUsagesImpl implements PackageUsages {\r
+  private static final Logger LOG = Logger.getInstance(PackageUsagesImpl.class.getName());\r
+\r
+  private final NuGetPackagesCollector myCollector;\r
+  private final NuGetPackagesConfigParser myParser;\r
+\r
+  public PackageUsagesImpl(@NotNull final NuGetPackagesCollector collector,\r
+                           @NotNull final NuGetPackagesConfigParser parser) {\r
+    myCollector = collector;\r
+    myParser = parser;\r
+  }\r
+\r
+  @NotNull\r
+  public BuildProcess createReport(@NotNull final File packagesConfig) {\r
+    return new BuildProcessBase() {\r
+      @NotNull\r
+      @Override\r
+      protected BuildFinishedStatus waitForImpl() throws RunBuildException {\r
+        if (!packagesConfig.exists()) {\r
+          LOG.debug("Packages file: " + packagesConfig + " does not exit");\r
+          return BuildFinishedStatus.FINISHED_SUCCESS;\r
+        }\r
+\r
+        try {\r
+          myParser.parseNuGetPackages(packagesConfig, myCollector);\r
+        } catch (IOException e) {\r
+          LOG.warn("Failed to parse " + packagesConfig + ". " + e.getMessage(), e);\r
+        }\r
+\r
+        return BuildFinishedStatus.FINISHED_SUCCESS;\r
+      }\r
+    };\r
+  }\r
+}\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/PackagesInfoUploader.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/PackagesInfoUploader.java
new file mode 100644 (file)
index 0000000..26af34d
--- /dev/null
@@ -0,0 +1,66 @@
+/*\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.agent.install.impl;\r
+\r
+import jetbrains.buildServer.agent.AgentRunningBuild;\r
+import jetbrains.buildServer.agent.artifacts.ArtifactsWatcher;\r
+import jetbrains.buildServer.nuget.agent.install.PackageInfo;\r
+import jetbrains.buildServer.util.FileUtil;\r
+import jetbrains.buildServer.util.XmlUtil;\r
+import org.jdom.Content;\r
+import org.jdom.Document;\r
+import org.jdom.Element;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+import java.io.*;\r
+import java.util.Collection;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 18.07.11 23:02\r
+ */\r
+public class PackagesInfoUploader {\r
+  private final ArtifactsWatcher myPublisher;\r
+\r
+  public PackagesInfoUploader(@NotNull final ArtifactsWatcher publisher) {\r
+    myPublisher = publisher;\r
+  }\r
+\r
+  public void uploadDepectedPackages(@NotNull final AgentRunningBuild build,\r
+                                     @NotNull final Collection<PackageInfo> infos) throws IOException {\r
+    File tmp = FileUtil.createTempDirectory("nuget", "packages", build.getBuildTempDirectory());\r
+\r
+    Element root = new Element("packages");\r
+    for (PackageInfo info : infos) {\r
+      Element pkg = new Element("package");\r
+      pkg.setAttribute("id", info.getId());\r
+      pkg.setAttribute("version", info.getVersion());\r
+      root.addContent((Content)pkg);\r
+    }\r
+    Document doc = new Document(root);\r
+\r
+    final File content = new File(tmp, "nuget-packages.xml");\r
+    OutputStream os = new BufferedOutputStream(new FileOutputStream(content));\r
+    try {\r
+      XmlUtil.saveDocument(doc, os);\r
+    } finally {\r
+      FileUtil.close(os);\r
+    }\r
+\r
+    myPublisher.addNewArtifactsPath(content.getPath() + " => .teamcity/nuget");\r
+  }\r
+}\r
similarity index 78%
rename from nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackagesInstallerBuilder.java
rename to nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/PackagesInstallerBuilder.java
index 856da9050dbfc34dffc90864ab3ea85a6fec02e4..230851c2a44b8df1e41084f647caac5e6865e4e8 100644 (file)
  * limitations under the License.\r
  */\r
 \r
-package jetbrains.buildServer.nuget.agent.install;\r
+package jetbrains.buildServer.nuget.agent.install.impl;\r
 \r
 import jetbrains.buildServer.RunBuildException;\r
 import jetbrains.buildServer.agent.BuildRunnerContext;\r
+import jetbrains.buildServer.nuget.agent.install.LocateNuGetConfigBuildProcess;\r
+import jetbrains.buildServer.nuget.agent.install.NuGetActionFactory;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;\r
-import jetbrains.buildServer.nuget.agent.util.BuildProcessContinuation;\r
 import jetbrains.buildServer.nuget.common.PackagesUpdateMode;\r
 import org.jetbrains.annotations.NotNull;\r
 import org.jetbrains.annotations.Nullable;\r
@@ -35,24 +36,18 @@ import static jetbrains.buildServer.nuget.common.PackagesUpdateMode.FOR_EACH_PAC
  */\r
 public class PackagesInstallerBuilder implements LocateNuGetConfigBuildProcess.Callback {\r
   private final NuGetActionFactory myActionFactory;\r
-  private final BuildProcessContinuation myInstall;\r
-  private final BuildProcessContinuation myUpdate;\r
-  private final BuildProcessContinuation myPostUpdate;\r
+  private final InstallStages myStages;\r
   private final BuildRunnerContext myContext;\r
 \r
   private final PackagesUpdateParameters myUpdateParameters;\r
   private final PackagesInstallParameters myInstallParameters;\r
 \r
   public PackagesInstallerBuilder(@NotNull final NuGetActionFactory actionFactory,\r
-                                  @NotNull final BuildProcessContinuation install,\r
-                                  @NotNull final BuildProcessContinuation update,\r
-                                  @NotNull final BuildProcessContinuation postUpdate,\r
+                                  @NotNull final InstallStages stages,\r
                                   @NotNull final BuildRunnerContext context,\r
                                   @NotNull final PackagesInstallParameters installParameters,\r
                                   @Nullable final PackagesUpdateParameters updateParameters) {\r
-    myInstall = install;\r
-    myUpdate = update;\r
-    myPostUpdate = postUpdate;\r
+    myStages = stages;\r
     myContext = context;\r
     myUpdateParameters = updateParameters;\r
     myInstallParameters = installParameters;\r
@@ -63,7 +58,7 @@ public class PackagesInstallerBuilder implements LocateNuGetConfigBuildProcess.C
     if (myUpdateParameters == null) return;\r
     if (myUpdateParameters.getUpdateMode() != PackagesUpdateMode.FOR_SLN) return;\r
 \r
-    myUpdate.pushBuildProcess(\r
+    myStages.getUpdateStage().pushBuildProcess(\r
             myActionFactory.createUpdate(\r
                     myContext,\r
                     myUpdateParameters,\r
@@ -74,14 +69,20 @@ public class PackagesInstallerBuilder implements LocateNuGetConfigBuildProcess.C
   }\r
 \r
   public final void onPackagesConfigFound(@NotNull final File config, @NotNull final File targetFolder) throws RunBuildException {\r
-    myInstall.pushBuildProcess(myActionFactory.createInstall(myContext,\r
+    myStages.getInstallStage().pushBuildProcess(myActionFactory.createInstall(\r
+            myContext,\r
             myInstallParameters,\r
             config,\r
             targetFolder));\r
 \r
+    myStages.getReportStage().pushBuildProcess(myActionFactory.createUsageReport(\r
+            myContext,\r
+            myInstallParameters.getNuGetParameters(),\r
+            config, targetFolder));\r
+\r
     if (myUpdateParameters == null) return;\r
     if (myUpdateParameters.getUpdateMode() == FOR_EACH_PACKAGES_CONFIG) {\r
-      myUpdate.pushBuildProcess(\r
+      myStages.getUpdateStage().pushBuildProcess(\r
               myActionFactory.createUpdate(\r
                       myContext,\r
                       myUpdateParameters,\r
@@ -91,7 +92,7 @@ public class PackagesInstallerBuilder implements LocateNuGetConfigBuildProcess.C
       );\r
     }\r
 \r
-    myPostUpdate.pushBuildProcess(\r
+    myStages.getPostUpdateStart().pushBuildProcess(\r
             myActionFactory.createInstall(\r
                     myContext,\r
                     myInstallParameters,\r
@@ -99,6 +100,8 @@ public class PackagesInstallerBuilder implements LocateNuGetConfigBuildProcess.C
                     targetFolder\r
             )\r
     );\r
+\r
+\r
   }\r
 \r
 }\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/PackagesWatcher.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/PackagesWatcher.java
new file mode 100644 (file)
index 0000000..c55f50d
--- /dev/null
@@ -0,0 +1,66 @@
+/*\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.agent.install.impl;\r
+\r
+import com.intellij.openapi.diagnostic.Logger;\r
+import jetbrains.buildServer.agent.AgentLifeCycleAdapter;\r
+import jetbrains.buildServer.agent.AgentLifeCycleListener;\r
+import jetbrains.buildServer.agent.AgentRunningBuild;\r
+import jetbrains.buildServer.agent.BuildFinishedStatus;\r
+import jetbrains.buildServer.nuget.agent.install.PackageInfo;\r
+import jetbrains.buildServer.util.EventDispatcher;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 18.07.11 22:59\r
+ */\r
+public class PackagesWatcher {\r
+  private static final Logger LOG = Logger.getInstance(PackagesWatcher.class.getName());\r
+\r
+  public PackagesWatcher(@NotNull final EventDispatcher<AgentLifeCycleListener> events,\r
+                         @NotNull final NuGetPackagesCollectorEx collector,\r
+                         @NotNull final PackagesInfoUploader uploader) {\r
+    events.addListener(new AgentLifeCycleAdapter(){\r
+      @Override\r
+      public void buildStarted(@NotNull AgentRunningBuild runningBuild) {\r
+        collector.removeAllPackages();\r
+      }\r
+\r
+      @Override\r
+      public void beforeBuildFinish(@NotNull AgentRunningBuild build, @NotNull BuildFinishedStatus buildStatus) {\r
+        Collection<PackageInfo> packages = new ArrayList<PackageInfo>(collector.getPackages());\r
+        if (packages.isEmpty()) return;\r
+\r
+        try {\r
+          uploader.uploadDepectedPackages(build, packages);\r
+        } catch (IOException e) {\r
+          LOG.warn("Failed to generate and upload list of used NuGet packages. " + e.getMessage(), e);\r
+        }\r
+      }\r
+\r
+      @Override\r
+      public void buildFinished(@NotNull AgentRunningBuild build, @NotNull BuildFinishedStatus buildStatus) {\r
+        collector.removeAllPackages();\r
+      }\r
+    });\r
+  }\r
+}\r
index 7eaf04787c83089d3fe7c21e0c34c05164fa9124..86b8c059d4dc67bf1cdc09c37521521e28e3e20d 100644 (file)
@@ -19,6 +19,7 @@ package jetbrains.buildServer.nuget.tests.agent;
 import jetbrains.buildServer.BaseTestCase;\r
 import jetbrains.buildServer.RunBuildException;\r
 import jetbrains.buildServer.agent.BuildRunnerContext;\r
+import jetbrains.buildServer.nuget.agent.install.PackageUsages;\r
 import jetbrains.buildServer.nuget.agent.parameters.NuGetParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;\r
 import jetbrains.buildServer.nuget.agent.install.impl.NuGetActionFactoryImpl;\r
@@ -53,7 +54,8 @@ public class NuGetInstallPackageActionFactoryTest extends BaseTestCase {
     super.setUp();\r
     m = new Mockery();\r
     myProcessFactory = m.mock(CommandlineBuildProcessFactory.class);\r
-    i = new NuGetActionFactoryImpl(myProcessFactory);\r
+    PackageUsages pu = m.mock(PackageUsages.class);\r
+    i = new NuGetActionFactoryImpl(myProcessFactory, pu);\r
     ctx = m.mock(BuildRunnerContext.class);\r
     ps = m.mock(PackagesInstallParameters.class);\r
     nugetParams = m.mock(NuGetParameters.class);\r
index 022d936a047281aefa648a7cb7827446ace33d56..2131a6abb4e744240eae9f547f249f8dd41e7950 100644 (file)
@@ -19,6 +19,7 @@ package jetbrains.buildServer.nuget.tests.agent;
 import jetbrains.buildServer.BaseTestCase;\r
 import jetbrains.buildServer.RunBuildException;\r
 import jetbrains.buildServer.agent.BuildRunnerContext;\r
+import jetbrains.buildServer.nuget.agent.install.PackageUsages;\r
 import jetbrains.buildServer.nuget.agent.parameters.NuGetParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;\r
 import jetbrains.buildServer.nuget.agent.install.impl.NuGetActionFactoryImpl;\r
@@ -53,7 +54,8 @@ public class NuGetUpdatePackageActionFactoryTest extends BaseTestCase {
     super.setUp();\r
     m = new Mockery();\r
     myProcessFactory = m.mock(CommandlineBuildProcessFactory.class);\r
-    i = new NuGetActionFactoryImpl(myProcessFactory);\r
+    PackageUsages pu = m.mock(PackageUsages.class);\r
+    i = new NuGetActionFactoryImpl(myProcessFactory, pu);\r
     ctx = m.mock(BuildRunnerContext.class);\r
     ps = m.mock(PackagesUpdateParameters.class);\r
     nugetParams = m.mock(NuGetParameters.class);\r
index c063287e59703bdc6ed6441495c742d5fefb0ef4..233b621d1b79fb8ca410f2a32f618082504a2b54 100644 (file)
@@ -21,7 +21,8 @@ import jetbrains.buildServer.RunBuildException;
 import jetbrains.buildServer.agent.BuildProcess;\r
 import jetbrains.buildServer.agent.BuildRunnerContext;\r
 import jetbrains.buildServer.nuget.agent.install.NuGetActionFactory;\r
-import jetbrains.buildServer.nuget.agent.install.PackagesInstallerBuilder;\r
+import jetbrains.buildServer.nuget.agent.install.impl.InstallStages;\r
+import jetbrains.buildServer.nuget.agent.install.impl.PackagesInstallerBuilder;\r
 import jetbrains.buildServer.nuget.agent.parameters.NuGetParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;\r
@@ -46,6 +47,7 @@ public class PackagesInstallerBuilderTest extends BaseTestCase {
   private BuildProcessContinuation install;\r
   private BuildProcessContinuation update;\r
   private BuildProcessContinuation postUpdate;\r
+  private BuildProcessContinuation report;\r
   private BuildRunnerContext context;\r
   private NuGetParameters nugetSettings;\r
   private PackagesInstallParameters installParameters;\r
@@ -71,25 +73,39 @@ public class PackagesInstallerBuilderTest extends BaseTestCase {
     install = m.mock(BuildProcessContinuation.class, "install");\r
     update = m.mock(BuildProcessContinuation.class, "update");\r
     postUpdate = m.mock(BuildProcessContinuation.class, "post-install");\r
+    report = m.mock(BuildProcessContinuation.class, "report");\r
     context = m.mock(BuildRunnerContext.class);\r
     installParameters = m.mock(PackagesInstallParameters.class);\r
     updateParameters = m.mock(PackagesUpdateParameters.class);\r
     nugetSettings = m.mock(NuGetParameters.class);\r
 \r
+    final InstallStages is = m.mock(InstallStages.class);\r
+    final BuildProcess reportProcess = m.mock(BuildProcess.class, "report process");\r
+    m.checking(new Expectations(){{\r
+      allowing(is).getInstallStage(); will(returnValue(install));\r
+      allowing(is).getUpdateStage(); will(returnValue(update));\r
+      allowing(is).getPostUpdateStart(); will(returnValue(postUpdate));\r
+      allowing(is).getReportStage(); will(returnValue(report));\r
+\r
+      allowing(factory).createUsageReport(context, nugetSettings, myConfig, myTaget);\r
+      will(returnValue(reportProcess));\r
+      allowing(factory).createUsageReport(context, nugetSettings, myConfig2, myTaget);\r
+      will(returnValue(reportProcess));\r
+\r
+      allowing(report).pushBuildProcess(reportProcess);\r
+    }});\r
+\r
     builderUpdate = new PackagesInstallerBuilder(\r
             factory,\r
-            install,\r
-            update,\r
-            postUpdate,\r
+            is,\r
             context,\r
             installParameters,\r
-            updateParameters);\r
+            updateParameters\r
+            );\r
 \r
     builderInstall = new PackagesInstallerBuilder(\r
             factory,\r
-            install,\r
-            update,\r
-            postUpdate,\r
+            is,\r
             context,\r
             installParameters,\r
             null);\r
@@ -102,7 +118,7 @@ public class PackagesInstallerBuilderTest extends BaseTestCase {
 \r
   @Test\r
   public void test_install() throws RunBuildException {\r
-    final BuildProcess bp = m.mock(BuildProcess.class);\r
+    final BuildProcess bp = m.mock(BuildProcess.class, "bp");\r
     m.checking(new Expectations(){{\r
       oneOf(factory).createInstall(context, installParameters, myConfig, myTaget);\r
       will(returnValue(bp));\r
index 489a5a45b65c479dd4dd4d288a25569ff5adcfcb..92039146866893d0e37976a65a41e9e06fb7af5f 100644 (file)
@@ -21,6 +21,7 @@ import jetbrains.buildServer.ExecResult;
 import jetbrains.buildServer.RunBuildException;\r
 import jetbrains.buildServer.SimpleCommandLineProcessRunner;\r
 import jetbrains.buildServer.agent.*;\r
+import jetbrains.buildServer.nuget.agent.install.PackageUsages;\r
 import jetbrains.buildServer.nuget.agent.install.PackagesInstallerRunner;\r
 import jetbrains.buildServer.nuget.agent.install.impl.NuGetActionFactoryImpl;\r
 import jetbrains.buildServer.nuget.agent.parameters.NuGetParameters;\r
@@ -222,6 +223,8 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
                              final List<String> sources,\r
                              final boolean excludeVersion,\r
                              final boolean update) throws RunBuildException {\r
+    final PackageUsages pu = m.mock(PackageUsages.class);\r
+    final BuildProcess pup = m.mock(BuildProcess.class, "report usages");\r
     m.checking(new Expectations() {{\r
       allowing(myParametersFactory).loadNuGetParameters(myContext);  will(returnValue(myNuGet));\r
       allowing(myParametersFactory).loadInstallPackagesParameters(myContext, myNuGet);  will(returnValue(myInstall));\r
@@ -232,10 +235,16 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
       allowing(myNuGet).getNuGetPackageSources(); will(returnValue(sources));\r
       allowing(myInstall).getExcludeVersion(); will(returnValue(excludeVersion));\r
       allowing(myParametersFactory).loadUpdatePackagesParameters(myContext, myNuGet);  will(returnValue(update ? myUpdate : null));\r
+\r
+      allowing(pu).createReport(with(any(File.class)));\r
+      will(returnValue(pup));\r
+\r
+      allowing(pup).start();\r
+      allowing(pup).waitFor(); will(returnValue(BuildFinishedStatus.FINISHED_SUCCESS));\r
     }});\r
 \r
     BuildProcess proc = new PackagesInstallerRunner(\r
-            new NuGetActionFactoryImpl(executingFactory()),\r
+            new NuGetActionFactoryImpl(executingFactory(), pu),\r
             myParametersFactory\r
     ).createBuildProcess(myBuild, myContext);\r
 \r