add environment arguments to commandline process factory
[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 import java.util.Collections;\r
34 \r
35 /**\r
36  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
37  * Date: 07.07.11 17:49\r
38  */\r
39 public class NuGetActionFactoryImpl implements NuGetActionFactory {\r
40   private final CommandFactory myCommandFactory;\r
41   private final CommandlineBuildProcessFactory myFactory;\r
42   private final PackageUsages myPackageUsages;\r
43 \r
44   public NuGetActionFactoryImpl(@NotNull final CommandlineBuildProcessFactory factory,\r
45                                 @NotNull final PackageUsages packageUsages,\r
46                                 @NotNull final CommandFactory commandFactory) {\r
47     myFactory = factory;\r
48     myPackageUsages = packageUsages;\r
49     myCommandFactory = commandFactory;\r
50   }\r
51 \r
52   private CommandFactory.Callback<BuildProcess> getCallback(@NotNull final BuildRunnerContext context) {\r
53     return new CommandFactory.Callback<BuildProcess>() {\r
54       @NotNull\r
55       public BuildProcess createCommand(@NotNull File program,\r
56                                         @NotNull File workingDir,\r
57                                         @NotNull Collection<String> argz) throws RunBuildException {\r
58         return myFactory.executeCommandLine(\r
59                 context,\r
60                 program,\r
61                 argz,\r
62                 workingDir,\r
63                 Collections.<String, String>emptyMap()\r
64         );\r
65       }\r
66     };\r
67   }\r
68 \r
69   @NotNull\r
70   public BuildProcess createInstall(@NotNull final BuildRunnerContext context,\r
71                                     @NotNull final PackagesInstallParameters params,\r
72                                     @NotNull final File packagesConfig,\r
73                                     @NotNull final File targetFolder) throws RunBuildException {\r
74     return myCommandFactory.createInstall(params, packagesConfig, targetFolder, getCallback(context));\r
75   }\r
76 \r
77 \r
78   @NotNull\r
79   public BuildProcess createUpdate(@NotNull final BuildRunnerContext context,\r
80                                    @NotNull final PackagesUpdateParameters params,\r
81                                    @NotNull final File packagesConfig,\r
82                                    @NotNull final File targetFolder) throws RunBuildException {\r
83     return myCommandFactory.createUpdate(params, packagesConfig, targetFolder, getCallback(context));\r
84   }\r
85 \r
86   @NotNull\r
87   public BuildProcess createUsageReport(@NotNull final BuildRunnerContext context,\r
88                                         @NotNull final NuGetFetchParameters params,\r
89                                         @NotNull final File packagesConfig,\r
90                                         @NotNull final File targetFolder) throws RunBuildException {\r
91     return new BuildProcessBase() {\r
92       @NotNull\r
93       @Override\r
94       protected BuildFinishedStatus waitForImpl() throws RunBuildException {\r
95         myPackageUsages.createReport(packagesConfig);\r
96         return BuildFinishedStatus.FINISHED_SUCCESS;\r
97       }\r
98     };\r
99   }\r
100 \r
101   @NotNull\r
102   public BuildProcess createPush(@NotNull BuildRunnerContext context,\r
103                                  @NotNull NuGetPublishParameters params,\r
104                                  @NotNull File packagePath) throws RunBuildException {\r
105     return myCommandFactory.createPush(params, packagePath, getCallback(context));\r
106   }\r
107 \r
108   @NotNull\r
109   public BuildProcess createPack(@NotNull BuildRunnerContext context, @NotNull NuGetPackParameters params) throws RunBuildException {\r
110     return myCommandFactory.createPack(params, context.getBuild().getCheckoutDirectory(), getCallback(context));\r
111   }\r
112 }\r