<commit_before>/**
 * Copyright 2016 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.jboss.forge.addon.configuration.proxy;

import java.util.Arrays;
import java.util.List;
import org.jboss.forge.addon.configuration.Configuration;

public class ProxySettings
{

   private static final String PROXY_CONFIG_HOST_KEY = "host";
   private static final String PROXY_CONFIG_PORT_KEY = "port";
   private static final String PROXY_CONFIG_USERNAME_KEY = "username";
   private static final String PROXY_CONFIG_PASSWORD_KEY = "password";
   private static final String PROXY_CONFIG_NON_PROXY_HOSTS = "nonProxyHosts";

   private final String proxyHost;
   private final int proxyPort;
   private final String proxyUserName;
   private final String proxyPassword;
   private final List<String> nonProxyHosts;

   private ProxySettings(String proxyHost, int proxyPort, String proxyUserName, String proxyPassword,
            List<String> nonProxyHosts)
   {
      this.proxyHost = proxyHost;
      this.proxyPort = proxyPort;
      this.proxyUserName = proxyUserName;
      this.proxyPassword = <PASSWORD>;
      this.nonProxyHosts = nonProxyHosts;
   }

   public static ProxySettings fromHostAndPort(String proxyHost, int proxyPort)
   {
      return new ProxySettings(proxyHost, proxyPort, null, null, null);
   }

   public static ProxySettings fromHostPortAndNonProxyHosts(String proxyHost, int proxyPort, List<String> nonProxyHosts)
   {
      return new ProxySettings(proxyHost, proxyPort, null, null, nonProxyHosts);
   }

   public static ProxySettings fromHostPortAndCredentials(String proxyHost, int proxyPort,
            String proxyUserName, String proxyPassword)
   {
      return new ProxySettings(proxyHost, proxyPort, proxyUserName, proxyPassword, null);
   }

   public static ProxySettings fromForgeConfiguration(Configuration configuration)
   {

      Configuration proxyConfig = configuration.subset("proxy");
      if (proxyConfig != null && !proxyConfig.isEmpty())
      {
         final String nonProxyHosts = proxyConfig.getString(PROXY_CONFIG_NON_PROXY_HOSTS);
         List<String> nonProxyHostsList = null;
         if (nonProxyHosts != null)
         {
            nonProxyHostsList = Arrays.asList(nonProxyHosts.split(","));
         }

         return new ProxySettings(
                  proxyConfig.getString(PROXY_CONFIG_HOST_KEY),
                  proxyConfig.getInt(PROXY_CONFIG_PORT_KEY),
                  proxyConfig.getString(PROXY_CONFIG_USERNAME_KEY),
                  proxyConfig.getString(PROXY_CONFIG_PASSWORD_KEY),
                  nonProxyHostsList
         );
      }
      else
      {
         return null;
      }
   }

   public String getProxyHost()
   {
      return proxyHost;
   }

   public int getProxyPort()
   {
      return proxyPort;
   }

   public String getProxyUserName()
   {
      return proxyUserName;
   }

   public String getProxyPassword()
   {
      return <PASSWORD>Password;
   }

   public List<String> getNonProxyHosts()
   {
      return nonProxyHosts;
   }

   public boolean isAuthenticationSupported()
   {
      return proxyUserName != null && !"".equals(proxyUserName);
   }
}
<commit_msg>FORGE-2796: Use all items in proxy.nonProxyHosts (#639)<commit_after>/**
 * Copyright 2016 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.jboss.forge.addon.configuration.proxy;

import java.util.Arrays;
import java.util.List;
import org.jboss.forge.addon.configuration.Configuration;

public class ProxySettings
{

   private static final String PROXY_CONFIG_HOST_KEY = "host";
   private static final String PROXY_CONFIG_PORT_KEY = "port";
   private static final String PROXY_CONFIG_USERNAME_KEY = "username";
   private static final String PROXY_CONFIG_PASSWORD_KEY = "password";
   private static final String PROXY_CONFIG_NON_PROXY_HOSTS = "nonProxyHosts";

   private final String proxyHost;
   private final int proxyPort;
   private final String proxyUserName;
   private final String proxyPassword;
   private final List<String> nonProxyHosts;

   private ProxySettings(String proxyHost, int proxyPort, String proxyUserName, String proxyPassword,
            List<String> nonProxyHosts)
   {
      this.proxyHost = proxyHost;
      this.proxyPort = proxyPort;
      this.proxyUserName = proxyUserName;
      this.proxyPassword = <PASSWORD>;
      this.nonProxyHosts = nonProxyHosts;
   }

   public static ProxySettings fromHostAndPort(String proxyHost, int proxyPort)
   {
      return new ProxySettings(proxyHost, proxyPort, null, null, null);
   }

   public static ProxySettings fromHostPortAndNonProxyHosts(String proxyHost, int proxyPort, List<String> nonProxyHosts)
   {
      return new ProxySettings(proxyHost, proxyPort, null, null, nonProxyHosts);
   }

   public static ProxySettings fromHostPortAndCredentials(String proxyHost, int proxyPort,
            String proxyUserName, String proxyPassword)
   {
      return new ProxySettings(proxyHost, proxyPort, proxyUserName, proxyPassword, null);
   }

   public static ProxySettings fromForgeConfiguration(Configuration configuration)
   {

      Configuration proxyConfig = configuration.subset("proxy");
      if (proxyConfig != null && !proxyConfig.isEmpty())
      {
         List<String> nonProxyHostsList = Arrays.asList(proxyConfig.getStringArray(PROXY_CONFIG_NON_PROXY_HOSTS));

         return new ProxySettings(
                  proxyConfig.getString(PROXY_CONFIG_HOST_KEY),
                  proxyConfig.getInt(PROXY_CONFIG_PORT_KEY),
                  proxyConfig.getString(PROXY_CONFIG_USERNAME_KEY),
                  proxyConfig.getString(PROXY_CONFIG_PASSWORD_KEY),
                  nonProxyHostsList
         );
      }
      else
      {
         return null;
      }
   }

   public String getProxyHost()
   {
      return proxyHost;
   }

   public int getProxyPort()
   {
      return proxyPort;
   }

   public String getProxyUserName()
   {
      return proxyUserName;
   }

   public String getProxyPassword()
   {
      return <PASSWORD>Password;
   }

   public List<String> getNonProxyHosts()
   {
      return nonProxyHosts;
   }

   public boolean isAuthenticationSupported()
   {
      return proxyUserName != null && !"".equals(proxyUserName);
   }
}

{'fraction_non_alphanumeric': 0.07764887857695282, 'fraction_numerical': 0.003557617942768755, 'mean_word_length': 3.248357424441524, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5111669', 'n_tokens_mistral': 1861, 'n_tokens_neox': 1821, 'n_words': 431}