package com.francetelecom.clara.cloud.mvn.consumer.aether;

import org.eclipse.aether.repository.Proxy;
import org.eclipse.aether.repository.ProxySelector;
import org.eclipse.aether.util.repository.DefaultProxySelector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ProxyManager {
    private static Logger logger = LoggerFactory.getLogger(ProxyManager.class);

    public ProxyManager() {
    }

    public ProxySelector selectProxies() {
        DefaultProxySelector proxySelector = new DefaultProxySelector();
        String httpProxyHost = System.getProperty("http.proxyHost");
        if (httpProxyHost != null) {
            logger.debug("Setting same proxy for http and https");
            int proxyPort = -1;
            try {
                proxyPort = Integer.parseInt(System.getProperty("http.proxyPort"));
            } catch (NumberFormatException nfe) {
                throw new RuntimeException("Invalid (or null) http.proxyPort specified into system.properties");
            }
            String nonProxyHosts = System.getProperty("http.nonProxyHosts");
            nonProxyHosts = (nonProxyHosts != null ? nonProxyHosts : "");
            Proxy httpProxy = new Proxy("http", httpProxyHost, proxyPort, null);
            Proxy httpsProxy = new Proxy("https", httpProxyHost, proxyPort, null);

            proxySelector.add(httpProxy, nonProxyHosts);
            proxySelector.add(httpsProxy, nonProxyHosts);
            logger.debug("MvnRepo proxy set to {}:{}" + (nonProxyHosts != null ? " (nonProxyHosts:" + nonProxyHosts + ")" : ""), httpProxyHost, proxyPort);
        } else {
            logger.debug("No proxy set (http.proxyHost not defined).");

        }
        return proxySelector;
    }
}

@@ -1,8 +1,590 @@
+/**%0A * Copyright (C) 2015 Orange%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A * http://www.apache.org/licenses/LICENSE-2.0%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A
 package 

fix ProxyManager license hearder...