db156a597e7101350f60daf1aa53db0252cb80cf
[teamcity/dotNetPackagesSupport.git] / nuget-agent / src / jetbrains / buildServer / nuget / agent / commands / impl / NuGetActionFactoryImpl.java
1 /*\r
2  * Copyright 2000-2011 JetBrains s.r.o.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  * http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 package jetbrains.buildServer.nuget.agent.commands.impl;\r
18 \r
19 import jetbrains.buildServer.RunBuildException;\r
20 import jetbrains.buildServer.agent.BuildFinishedStatus;\r
21 import jetbrains.buildServer.agent.BuildProcess;\r
22 import jetbrains.buildServer.agent.BuildRunnerContext;\r
23 import jetbrains.buildServer.nuget.agent.commands.CommandFactory;\r
24 import jetbrains.buildServer.nuget.agent.commands.NuGetActionFactory;\r
25 import jetbrains.buildServer.nuget.agent.dependencies.PackageUsages;\r
26 import jetbrains.buildServer.nuget.agent.parameters.*;\r
27 import jetbrains.buildServer.nuget.agent.util.BuildProcessBase;\r
28 import jetbrains.buildServer.nuget.agent.util.CommandlineBuildProcessFactory;\r
29 import org.jetbrains.annotations.NotNull;\r
30 \r
31 import java.io.File;\r
32 import java.util.Collection;\r
33 \r
34 /**\r
35  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
36  * Date: 07.07.11 17:49\r
37  */\r
38 public class NuGetActionFactoryImpl implements NuGetActionFactory {\r
39   private final CommandFactory myCommandFactory;\r
40   private final CommandlineBuildProcessFactory myFactory;\r
41   private final PackageUsages myPackageUsages;\r
42 \r
43   public NuGetActionFactoryImpl(@NotNull final CommandlineBuildProcessFactory factory,\r
44                                 @NotNull final PackageUsages packageUsages,\r
45                                 @NotNull final CommandFactory commandFactory) {\r
46     myFactory = factory;\r
47     myPackageUsages = packageUsages;\r
48     myCommandFactory = commandFactory;\r
49   }\r
50 \r
51   private CommandFactory.Callback<BuildProcess> getCallback(@NotNull final BuildRunnerContext context) {\r
52     return new CommandFactory.Callback<BuildProcess>() {\r
53       @NotNull\r
54       public BuildProcess createCommand(@NotNull File program,\r
55                                         @NotNull File workingDir,\r
56                                         @NotNull Collection<String> argz) throws RunBuildException {\r
57         return myFactory.executeCommandLine(\r
58                 context,\r
59                 program,\r
60                 argz,\r
61                 workingDir\r
62         );\r
63       }\r
64     };\r
65   }\r
66 \r
67   @NotNull\r
68   public BuildProcess createInstall(@NotNull final BuildRunnerContext context,\r
69                                     @NotNull final PackagesInstallParameters params,\r
70                                     @NotNull final File packagesConfig,\r
71                                     @NotNull final File targetFolder) throws RunBuildException {\r
72     return myCommandFactory.createInstall(params, packagesConfig, targetFolder, getCallback(context));\r
73   }\r
74 \r
75 \r
76   @NotNull\r
77   public BuildProcess createUpdate(@NotNull final BuildRunnerContext context,\r
78                                    @NotNull final PackagesUpdateParameters params,\r
79                                    @NotNull final File packagesConfig,\r
80                                    @NotNull final File targetFolder) throws RunBuildException {\r
81     return myCommandFactory.createUpdate(params, packagesConfig, targetFolder, getCallback(context));\r
82   }\r
83 \r
84   @NotNull\r
85   public BuildProcess createUsageReport(@NotNull final BuildRunnerContext context,\r
86                                         @NotNull final NuGetFetchParameters params,\r
87                                         @NotNull final File packagesConfig,\r
88                                         @NotNull final File targetFolder) throws RunBuildException {\r
89     return new BuildProcessBase() {\r
90       @NotNull\r
91       @Override\r
92       protected BuildFinishedStatus waitForImpl() throws RunBuildException {\r
93         myPackageUsages.createReport(packagesConfig);\r
94         return BuildFinishedStatus.FINISHED_SUCCESS;\r
95       }\r
96     };\r
97   }\r
98 \r
99   @NotNull\r
100   public BuildProcess createPush(@NotNull BuildRunnerContext context,\r
101                                  @NotNull NuGetPublishParameters params,\r
102                                  @NotNull File packagePath) throws RunBuildException {\r
103     return myCommandFactory.createPush(params, packagePath, getCallback(context));\r
104   }\r
105 \r
106   @NotNull\r
107   public BuildProcess createPack(@NotNull BuildRunnerContext context, @NotNull NuGetPackParameters params) throws RunBuildException {\r
108     return myCommandFactory.createPack(params, context.getBuild().getCheckoutDirectory(), getCallback(context));\r
109   }\r
110 }\r