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;
}
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();
}
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();
}
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();
}
}
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);
}
Aggregations