ece0ccd2ab2ae955aa3157092f7441f563c4ce18
[teamcity/dotNetPackagesSupport.git] / nuget-agent / src / jetbrains / buildServer / nuget / agent / commands / impl / LoggingNuGetActionFactoryImpl.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.BuildProcess;\r
21 import jetbrains.buildServer.agent.BuildProgressLogger;\r
22 import jetbrains.buildServer.agent.BuildRunnerContext;\r
23 import jetbrains.buildServer.nuget.agent.commands.NuGetActionFactory;\r
24 import jetbrains.buildServer.nuget.agent.parameters.NuGetFetchParameters;\r
25 import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;\r
26 import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;\r
27 import jetbrains.buildServer.nuget.agent.util.DelegatingBuildProcess;\r
28 import jetbrains.buildServer.util.FileUtil;\r
29 import org.jetbrains.annotations.NotNull;\r
30 \r
31 import java.io.File;\r
32 \r
33 /**\r
34  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
35  * Date: 18.07.11 19:57\r
36  */\r
37 public class LoggingNuGetActionFactoryImpl implements NuGetActionFactory {\r
38   private NuGetActionFactory myActionFactory;\r
39 \r
40   public LoggingNuGetActionFactoryImpl(@NotNull final NuGetActionFactory actionFactory) {\r
41     myActionFactory = actionFactory;\r
42   }\r
43 \r
44   @NotNull\r
45   public BuildProcess createUsageReport(@NotNull BuildRunnerContext context, @NotNull NuGetFetchParameters params, @NotNull File packagesConfig, @NotNull File targetFolder) throws RunBuildException {\r
46     return myActionFactory.createUsageReport(context, params, packagesConfig, targetFolder);\r
47   }\r
48 \r
49   @NotNull\r
50   public BuildProcess createInstall(@NotNull final BuildRunnerContext context,\r
51                                     @NotNull final PackagesInstallParameters params,\r
52                                     @NotNull final File config,\r
53                                     @NotNull final File targetFolder) {\r
54     return new DelegatingBuildProcess(\r
55             new DelegatingBuildProcess.Action() {\r
56               private final BuildProgressLogger logger = context.getBuild().getBuildLogger();\r
57 \r
58               @NotNull\r
59               public BuildProcess startImpl() throws RunBuildException {\r
60                 String pathToLog = FileUtil.getRelativePath(context.getBuild().getCheckoutDirectory(), config);\r
61                 if (pathToLog == null) pathToLog = config.getPath();\r
62                 logger.activityStarted("install", "Installing NuGet packages for " + pathToLog, "nuget");\r
63 \r
64 \r
65                 return myActionFactory.createInstall(\r
66                         context,\r
67                         params,\r
68                         config,\r
69                         targetFolder)\r
70                         ;\r
71               }\r
72 \r
73               public void finishedImpl() {\r
74                 logger.activityFinished("install", "nuget");\r
75               }\r
76             }\r
77     );\r
78   }\r
79 \r
80   @NotNull\r
81   public BuildProcess createUpdate(@NotNull final BuildRunnerContext context,\r
82                                    @NotNull final PackagesUpdateParameters params,\r
83                                    @NotNull final File config,\r
84                                    @NotNull final File targetFolder) {\r
85     return new DelegatingBuildProcess(\r
86             new DelegatingBuildProcess.Action() {\r
87               private final BuildProgressLogger logger = context.getBuild().getBuildLogger();\r
88 \r
89               @NotNull\r
90               public BuildProcess startImpl() throws RunBuildException {\r
91                 String pathToLog = FileUtil.getRelativePath(context.getBuild().getCheckoutDirectory(), config);\r
92                 if (pathToLog == null) pathToLog = config.getPath();\r
93                 logger.activityStarted("update", "Updating NuGet packages for " + pathToLog, "nuget");\r
94 \r
95                 return myActionFactory.createUpdate(\r
96                         context,\r
97                         params,\r
98                         config,\r
99                         targetFolder)\r
100                         ;\r
101               }\r
102 \r
103               public void finishedImpl() {\r
104                 logger.activityFinished("update", "nuget");\r
105               }\r
106             }\r
107     );\r
108   }\r
109 \r
110 }\r