move nuget anction/commands classes
[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 com.intellij.openapi.diagnostic.Logger;\r
20 import jetbrains.buildServer.RunBuildException;\r
21 import jetbrains.buildServer.agent.BuildFinishedStatus;\r
22 import jetbrains.buildServer.agent.BuildProcess;\r
23 import jetbrains.buildServer.agent.BuildRunnerContext;\r
24 import jetbrains.buildServer.nuget.agent.commands.CommandFactory;\r
25 import jetbrains.buildServer.nuget.agent.commands.NuGetActionFactory;\r
26 import jetbrains.buildServer.nuget.agent.install.PackageUsages;\r
27 import jetbrains.buildServer.nuget.agent.parameters.NuGetFetchParameters;\r
28 import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;\r
29 import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;\r
30 import jetbrains.buildServer.nuget.agent.util.BuildProcessBase;\r
31 import jetbrains.buildServer.nuget.agent.util.CommandlineBuildProcessFactory;\r
32 import org.jetbrains.annotations.NotNull;\r
33 \r
34 import java.io.File;\r
35 import java.util.Collection;\r
36 \r
37 /**\r
38  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
39  * Date: 07.07.11 17:49\r
40  */\r
41 public class NuGetActionFactoryImpl implements NuGetActionFactory {\r
42   private final CommandFactory myCommandFactory;\r
43   private final CommandlineBuildProcessFactory myFactory;\r
44   private final PackageUsages myPackageUsages;\r
45 \r
46   public NuGetActionFactoryImpl(@NotNull final CommandlineBuildProcessFactory factory,\r
47                                 @NotNull final PackageUsages packageUsages,\r
48                                 @NotNull final CommandFactory commandFactory) {\r
49     myFactory = factory;\r
50     myPackageUsages = packageUsages;\r
51     myCommandFactory = commandFactory;\r
52   }\r
53 \r
54   private CommandFactory.Callback<BuildProcess> getCallback(@NotNull final BuildRunnerContext context) {\r
55     return new CommandFactory.Callback<BuildProcess>() {\r
56       @NotNull\r
57       public BuildProcess createCommand(@NotNull File program,\r
58                                         @NotNull File workingDir,\r
59                                         @NotNull Collection<String> argz) throws RunBuildException {\r
60         return myFactory.executeCommandLine(\r
61                 context,\r
62                 program,\r
63                 argz,\r
64                 workingDir\r
65         );\r
66       }\r
67     };\r
68   }\r
69 \r
70   @NotNull\r
71   public BuildProcess createInstall(@NotNull final BuildRunnerContext context,\r
72                                     @NotNull final PackagesInstallParameters params,\r
73                                     @NotNull final File packagesConfig,\r
74                                     @NotNull final File targetFolder) throws RunBuildException {\r
75     return myCommandFactory.createInstall(params, packagesConfig, targetFolder, getCallback(context));\r
76   }\r
77 \r
78 \r
79   @NotNull\r
80   public BuildProcess createUpdate(@NotNull final BuildRunnerContext context,\r
81                                    @NotNull final PackagesUpdateParameters params,\r
82                                    @NotNull final File packagesConfig,\r
83                                    @NotNull final File targetFolder) throws RunBuildException {\r
84     return myCommandFactory.createUpdate(params, packagesConfig, targetFolder, getCallback(context));\r
85   }\r
86 \r
87   @NotNull\r
88   public BuildProcess createUsageReport(@NotNull final BuildRunnerContext context,\r
89                                         @NotNull final NuGetFetchParameters params,\r
90                                         @NotNull final File packagesConfig,\r
91                                         @NotNull final File targetFolder) throws RunBuildException {\r
92     return new BuildProcessBase() {\r
93       @NotNull\r
94       @Override\r
95       protected BuildFinishedStatus waitForImpl() throws RunBuildException {\r
96         myPackageUsages.createReport(packagesConfig);\r
97         return BuildFinishedStatus.FINISHED_SUCCESS;\r
98       }\r
99     };\r
100   }\r
101 }\r