View Javadoc

1   /**
2    * Copyright (C) 2012 White Source Ltd.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.whitesource.teamcity.server;
17  
18  import jetbrains.buildServer.serverSide.BuildStartContext;
19  import jetbrains.buildServer.serverSide.BuildStartContextProcessor;
20  import jetbrains.buildServer.serverSide.SRunnerContext;
21  import jetbrains.buildServer.serverSide.TeamCityProperties;
22  import org.jetbrains.annotations.NotNull;
23  import org.whitesource.teamcity.common.Constants;
24  
25  /**
26   * Implementation of the interface for loading plugin settings into new builds.
27   *
28   * @author Edo.Shor
29   */
30  public class WhitesourceBuildStartContextProcessor implements BuildStartContextProcessor {
31  
32      /* --- Members -- */
33  
34      private GlobalSettingsManager settingsManager;
35  
36      /* --- Constructors -- */
37  
38      /**
39       * Constructor
40       *
41       * @param settingsManager
42       */
43      public WhitesourceBuildStartContextProcessor(@NotNull final GlobalSettingsManager settingsManager) {
44          this.settingsManager = settingsManager;
45      }
46  
47      @Override
48      public void updateParameters(@NotNull BuildStartContext context) {
49  
50          GlobalSettings globalSettings = settingsManager.getGlobalSettings();
51          if (globalSettings == null) {
52              return;
53          }
54  
55          String orgToken = globalSettings.getOrgToken();
56          boolean checkPolicies = globalSettings.isCheckPolicies();
57          ProxySettings proxy = globalSettings.getProxy();
58  
59          for (SRunnerContext runnerContext : context.getRunnerContexts()) {
60              // system envrionment
61              runnerContext.addRunnerParameter(Constants.RUNNER_SERVICE_URL,
62                      TeamCityProperties.getProperty(Constants.RUNNER_SERVICE_URL));
63  
64              // global settings
65              runnerContext.addRunnerParameter(Constants.RUNNER_ORGANIZATION_TOKEN, orgToken);
66              runnerContext.addRunnerParameter(Constants.RUNNER_CHECK_POLICIES, Boolean.toString(checkPolicies));
67  
68              if (proxy != null) {
69                  runnerContext.addRunnerParameter(Constants.RUNNER_PROXY_HOST, proxy.getHost());
70                  runnerContext.addRunnerParameter(Constants.RUNNER_PROXY_PORT, Integer.valueOf(proxy.getPort()).toString());
71                  runnerContext.addRunnerParameter(Constants.RUNNER_PROXY_USERNAME, proxy.getUsername());
72                  runnerContext.addRunnerParameter(Constants.RUNNER_PROXY_PASSWORD, proxy.getPassword());
73              }
74          }
75  
76      }
77  
78  }