/**
 * Copyright 2018 BlazeMeter Inc.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package hudson.plugins.blazemeter;

import hudson.ProxyConfiguration;

public class ProxyConfigurator {
    static String PROXY_HOST = "http.proxyHost";
    static String PROXY_PORT = "http.proxyPort";
    static String PROXY_USER = "http.proxyUser";
    static String PROXY_PASS = "http.proxyPass";

    public static void updateProxySettings(boolean updateProxySettings) throws Exception {
        if (updateProxySettings) {
            ProxyConfiguration proxyConfiguration = ProxyConfiguration.load();
            if (proxyConfiguration != null) {
                System.setProperty(PROXY_HOST, proxyConfiguration.name);
                System.setProperty(PROXY_PORT, String.valueOf(proxyConfiguration.port));
                System.setProperty(PROXY_USER, proxyConfiguration.getUserName());
                System.setProperty(PROXY_PASS, proxyConfiguration.getPassword());
            } else {
                System.clearProperty(PROXY_HOST);
                System.clearProperty(PROXY_PORT);
                System.clearProperty(PROXY_USER);
                System.clearProperty(PROXY_PASS);
            }
        }
    }
}
@@ -657,16 +657,60 @@
 uration;
+%0Aimport org.apache.commons.lang.StringUtils;
 %0A%0Apublic
@@ -1180,24 +1180,99 @@
  != null) %7B%0A
+                if (StringUtils.isNotBlank(proxyConfiguration.name)) %7B%0A    
             
@@ -1352,163 +1352,476 @@
     
-System.setProperty(PROXY_PORT, String.valueOf(proxyConfiguration.port));%0A                System.setProperty(PROXY_USER, proxyConfiguration.getUserName());%0A
+%7D%0A                if (StringUtils.isNotBlank(String.valueOf(proxyConfiguration.port))) %7B%0A                    System.setProperty(PROXY_PORT, String.valueOf(proxyConfiguration.port));%0A                %7D%0A                if (StringUtils.isNotBlank(proxyConfiguration.getUserName())) %7B%0A                    System.setProperty(PROXY_USER, proxyConfiguration.getUserName());%0A                %7D%0A                if (StringUtils.isNotBlank(proxyConfiguration.getPassword())) %7B%0A    
     
@@ -1894,24 +1894,42 @@
 assword());%0A
+                %7D%0A
             

fix require proxy username & password (#54)