Search in sources :

Example 21 with CeylonConfig

use of org.eclipse.ceylon.common.config.CeylonConfig in project ceylon by eclipse.

the class CeylonTool method setupConfig.

// Here we set up the global configuration for this thread
// if (and only if) the setup deviates from the default
// (meaning `cwd` was set for the given tool)
private CeylonConfig setupConfig(Tool tool) throws IOException {
    if (tool instanceof CeylonBaseTool) {
        CeylonBaseTool cbt = (CeylonBaseTool) tool;
        File cwd = cbt.getCwd();
        if (cwd != null && cwd.isDirectory()) {
            CeylonConfig config = CeylonConfigFinder.loadDefaultConfig(cwd);
            return CeylonConfig.set(config);
        }
        if (getCwd() != null) {
            // If the main tool's `cwd` options is set it
            // always overrides the one in the given tool
            cbt.setCwd(getCwd());
        }
    }
    return null;
}
Also used : CeylonBaseTool(org.eclipse.ceylon.common.tool.CeylonBaseTool) CeylonConfig(org.eclipse.ceylon.common.config.CeylonConfig) File(java.io.File)

Example 22 with CeylonConfig

use of org.eclipse.ceylon.common.config.CeylonConfig in project ceylon by eclipse.

the class ProxiesTest method testProxy.

@Test
public void testProxy() throws Exception {
    CeylonConfig testConfig = loadTestConfig("proxy.config");
    Proxies proxies = getProxies(testConfig);
    Proxy proxy = proxies.getProxy();
    Assert.assertEquals("myproxy", proxy.getHost());
    Assert.assertEquals(1234, proxy.getPort());
    Authentication auth = Authentication.fromConfig(testConfig);
    Assert.assertNull(auth.getProxyAuthenticator());
    auth.installProxy();
    Assert.assertEquals(null, auth.getProxyAuthenticator());
    InetSocketAddress address = (InetSocketAddress) auth.getProxy().address();
    Assert.assertEquals("myproxy", address.getHostName());
    Assert.assertEquals(1234, address.getPort());
    List<java.net.Proxy> selectedProxies = auth.getProxySelector().select(URI.create("anything"));
    Assert.assertEquals(1, selectedProxies.size());
    Assert.assertEquals(java.net.Proxy.Type.HTTP, selectedProxies.get(0).type());
    mockPrompt.assertSeenOnlyGivenPrompts();
}
Also used : Proxy(org.eclipse.ceylon.common.config.Proxies.Proxy) Proxies(org.eclipse.ceylon.common.config.Proxies) CeylonConfig(org.eclipse.ceylon.common.config.CeylonConfig) Authentication(org.eclipse.ceylon.common.config.Authentication) PasswordAuthentication(java.net.PasswordAuthentication) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Example 23 with CeylonConfig

use of org.eclipse.ceylon.common.config.CeylonConfig in project ceylon by eclipse.

the class ProxiesTest method testProxyWithNonProxyHosts.

@Test
public void testProxyWithNonProxyHosts() throws Exception {
    CeylonConfig testConfig = loadTestConfig("proxy+non-proxy-hosts.config");
    Proxies proxies = getProxies(testConfig);
    Proxy proxy = proxies.getProxy();
    Assert.assertEquals("myproxy", proxy.getHost());
    Assert.assertEquals(1234, proxy.getPort());
    Authentication auth = Authentication.fromConfig(testConfig);
    Assert.assertNull(auth.getProxyAuthenticator());
    auth.installProxy();
    Assert.assertEquals(null, auth.getProxyAuthenticator());
    InetSocketAddress address = (InetSocketAddress) auth.getProxy().address();
    Assert.assertEquals("myproxy", address.getHostName());
    Assert.assertEquals(1234, address.getPort());
    List<java.net.Proxy> selectedProxies = auth.getProxySelector().select(URI.create("http://anything"));
    Assert.assertEquals(1, selectedProxies.size());
    Assert.assertEquals(java.net.Proxy.Type.HTTP, selectedProxies.get(0).type());
    Assert.assertEquals("myproxy", ((InetSocketAddress) selectedProxies.get(0).address()).getHostName());
    Assert.assertEquals(1234, ((InetSocketAddress) selectedProxies.get(0).address()).getPort());
    selectedProxies = auth.getProxySelector().select(URI.create("http://foo"));
    Assert.assertEquals(1, selectedProxies.size());
    Assert.assertEquals(java.net.Proxy.Type.DIRECT, selectedProxies.get(0).type());
    Assert.assertNull(selectedProxies.get(0).address());
    mockPrompt.assertSeenOnlyGivenPrompts();
}
Also used : Proxy(org.eclipse.ceylon.common.config.Proxies.Proxy) Proxies(org.eclipse.ceylon.common.config.Proxies) CeylonConfig(org.eclipse.ceylon.common.config.CeylonConfig) Authentication(org.eclipse.ceylon.common.config.Authentication) PasswordAuthentication(java.net.PasswordAuthentication) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Example 24 with CeylonConfig

use of org.eclipse.ceylon.common.config.CeylonConfig in project ceylon by eclipse.

the class ProxyTool method main.

public static void main(String[] args) throws Exception {
    if (args.length != 3) {
        usage("Wrong number of arguments");
    }
    String mode = args[0];
    File configFile = new File(args[1]);
    if (!configFile.exists()) {
        usage("Config file doesn't exist");
        return;
    }
    final URL url;
    try {
        url = new URL(args[2]);
    } catch (MalformedURLException e) {
        usage("Malformed URL");
        return;
    }
    CeylonConfig config = CeylonConfigFinder.loadConfigFromFile(configFile);
    Authentication auth = Authentication.fromConfig(config);
    Proxy proxy = Proxies.withConfig(config).getProxy();
    final URLConnection conn;
    switch(mode) {
        case "proxy":
            java.net.Proxy netProxy = auth.getProxy();
            if (netProxy != null) {
                conn = url.openConnection(netProxy);
            } else {
                conn = url.openConnection();
            }
            break;
        case "install":
            auth.installProxy();
            conn = url.openConnection();
            break;
        default:
            throw new RuntimeException("Unsupported mode");
    }
    InputStream in = conn.getInputStream();
    try {
        int ch = in.read();
        while (ch != -1) {
            System.out.append((char) ch);
            ch = in.read();
        }
    } finally {
        in.close();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) InputStream(java.io.InputStream) URL(java.net.URL) URLConnection(java.net.URLConnection) Proxy(org.eclipse.ceylon.common.config.Proxies.Proxy) CeylonConfig(org.eclipse.ceylon.common.config.CeylonConfig) Authentication(org.eclipse.ceylon.common.config.Authentication) File(java.io.File)

Example 25 with CeylonConfig

use of org.eclipse.ceylon.common.config.CeylonConfig in project ceylon by eclipse.

the class RepositoriesTest method testSetRepositoriesByType.

@Test
public void testSetRepositoriesByType() {
    CeylonConfig configCopy = testConfig.copy();
    Repositories testRepos = Repositories.withConfig(configCopy);
    Repository[] reps = testRepos.getRepositoriesByType(Repositories.REPO_TYPE_LOCAL_LOOKUP);
    reps = new Repositories.SimpleRepository[] { new Repositories.SimpleRepository("", "./mods", null) };
    testRepos.setRepositoriesByType(Repositories.REPO_TYPE_LOCAL_LOOKUP, reps);
    Repository[] lookup = testRepos.getLocalLookupRepositories();
    Assert.assertTrue(lookup.length == 1);
    assertRepository(lookup[0], "%lookup-1", "./mods", null, null);
}
Also used : Repositories(org.eclipse.ceylon.common.config.Repositories) Repository(org.eclipse.ceylon.common.config.Repositories.Repository) CeylonConfig(org.eclipse.ceylon.common.config.CeylonConfig) Test(org.junit.Test)

Aggregations

CeylonConfig (org.eclipse.ceylon.common.config.CeylonConfig)28 Test (org.junit.Test)16 File (java.io.File)12 Authentication (org.eclipse.ceylon.common.config.Authentication)7 Proxy (org.eclipse.ceylon.common.config.Proxies.Proxy)7 PasswordAuthentication (java.net.PasswordAuthentication)6 Proxies (org.eclipse.ceylon.common.config.Proxies)6 InetSocketAddress (java.net.InetSocketAddress)5 Repositories (org.eclipse.ceylon.common.config.Repositories)3 Repository (org.eclipse.ceylon.common.config.Repositories.Repository)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 BuildException (org.apache.tools.ant.BuildException)2 CeylonBaseTool (org.eclipse.ceylon.common.tool.CeylonBaseTool)2 Before (org.junit.Before)2 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 HashSet (java.util.HashSet)1