Search in sources :

Example 1 with CeylonConfig

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

the class CeylonTool method execute.

// Warning: this method called by reflection in Launcher
public int execute() throws Exception {
    int result = SC_OK;
    try {
        setSystemCwd();
        String[] names = (toolName != null) ? getToolNames() : new String[] { null };
        for (String singleToolName : names) {
            ToolModel<Tool> model = getToolModel(singleToolName);
            Tool tool = getTool(model);
            CeylonConfig oldConfig2 = null;
            if (oldConfig == null) {
                oldConfig2 = setupConfig(tool);
            }
            try {
                run(model, tool);
                result = SC_OK;
            } finally {
                if (oldConfig2 != null) {
                    CeylonConfig.set(oldConfig2);
                }
            }
        }
    } catch (Exception e) {
        result = handleException(this, e);
    } finally {
        if (oldConfig != null) {
            CeylonConfig.set(oldConfig);
            oldConfig = null;
        }
    }
    System.out.flush();
    return result;
}
Also used : CeylonConfig(org.eclipse.ceylon.common.config.CeylonConfig) OptionArgumentException(org.eclipse.ceylon.common.tool.OptionArgumentException) IOException(java.io.IOException) NoSuchToolException(org.eclipse.ceylon.common.tool.NoSuchToolException) ModelException(org.eclipse.ceylon.common.tool.ModelException) Tool(org.eclipse.ceylon.common.tool.Tool) CeylonBaseTool(org.eclipse.ceylon.common.tool.CeylonBaseTool)

Example 2 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 either `cwd` or `config` was set for the main tool)
private CeylonConfig setupConfig() throws IOException {
    File cwd = getCwd();
    if (!getNoConfig()) {
        File cfgFile = getConfig();
        if (cfgFile != null) {
            File absCfgFile = FileUtil.applyCwd(cwd, cfgFile);
            CeylonConfig config = CeylonConfigFinder.DEFAULT.loadConfigFromFile(absCfgFile);
            return CeylonConfig.set(config);
        }
        if (cwd != null && cwd.isDirectory()) {
            CeylonConfig config = CeylonConfigFinder.loadDefaultConfig(cwd);
            return CeylonConfig.set(config);
        }
    } else {
        // We're not loading any configuration file, so we set an empty one
        return CeylonConfig.set(new CeylonConfig());
    }
    return null;
}
Also used : CeylonConfig(org.eclipse.ceylon.common.config.CeylonConfig) File(java.io.File)

Example 3 with CeylonConfig

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

the class CeylonNewTool method buildPromptedEnv.

private Environment buildPromptedEnv() {
    Environment env = new Environment();
    // TODO Tidy up how we create and what's in this initial environment
    if (project.getDirectory() != null) {
        env.put("base.dir", applyCwd(project.getDirectory()).getAbsolutePath());
    }
    env.put("ceylon.home", System.getProperty(Constants.PROP_CEYLON_HOME_DIR));
    // env.put("ceylon.system.repo", System.getProperty("ceylon.system.repo"));
    env.put("ceylon.version.number", Versions.CEYLON_VERSION_NUMBER);
    env.put("ceylon.version.major", Integer.toString(Versions.CEYLON_VERSION_MAJOR));
    env.put("ceylon.version.minor", Integer.toString(Versions.CEYLON_VERSION_MINOR));
    env.put("ceylon.version.release", Integer.toString(Versions.CEYLON_VERSION_RELEASE));
    env.put("ceylon.version.name", Versions.CEYLON_VERSION_NAME);
    Set<String> seenKeys = new HashSet<>();
    List<Variable> vars = new LinkedList<>(project.getVariables());
    while (!vars.isEmpty()) {
        Variable var = vars.remove(0);
        if (seenKeys.contains(var.getKey())) {
            throw new RuntimeException("Variables for project do not form a tree");
        }
        seenKeys.add(var.getKey());
        // TODO Use the value from rest if there is one, only prompting if
        // there is not
        // TODO The problem with this is: "How does the user figure out
        // what option they need to specify on the command line
        // in order to avoid being prompted for it interactively?"
        // Each subtool could provide their own getters and setters
        // but they requires we write a subtool for each project
        // It would be nice if we didn't have to do that, but could just
        // drive the whole thing from a script in the templates dir.
        vars.addAll(0, var.initialize(getProjectName(), env));
    }
    String sourceFolder = Constants.DEFAULT_SOURCE_DIR;
    String baseDir = env.get("base.dir");
    if (project.getDirectory() == null) {
        project.setDirectory(new File(baseDir));
    }
    try {
        CeylonConfig config = CeylonConfig.createFromLocalDir(new File(baseDir));
        List<File> srcs = DefaultToolOptions.getCompilerSourceDirs(config);
        if (!srcs.isEmpty()) {
            sourceFolder = srcs.get(0).getPath();
        } else {
            sourceFolder = Constants.DEFAULT_SOURCE_DIR;
        }
    } catch (Exception e) {
    // Ignore any errors
    }
    env.put("source.folder", sourceFolder);
    log(env);
    return env;
}
Also used : CeylonConfig(org.eclipse.ceylon.common.config.CeylonConfig) File(java.io.File) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 4 with CeylonConfig

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

the class ProxiesTest method testProxyWithUser.

@Test
public void testProxyWithUser() throws Exception {
    CeylonConfig testConfig = loadTestConfig("proxy+user.config");
    Proxies proxies = getProxies(testConfig);
    Proxy proxy = proxies.getProxy();
    Assert.assertEquals("myproxy", proxy.getHost());
    Assert.assertEquals(1234, proxy.getPort());
    Authentication auth = Authentication.fromConfig(testConfig);
    auth.installProxy();
    Assert.assertNotNull(auth.getProxyAuthenticator());
    this.mockPrompt.prompts.put("Password for HTTP proxy myproxy:1234: ", "wibble");
    PasswordAuthentication up = Authenticator.requestPasswordAuthentication(null, 80, "ceylon-lang.org", "Hello, world", "fnar");
    Assert.assertEquals("me", up.getUserName());
    Assert.assertEquals("wibble", new String(up.getPassword()));
    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());
    Assert.assertEquals("myproxy", ((InetSocketAddress) selectedProxies.get(0).address()).getHostName());
    Assert.assertEquals(1234, ((InetSocketAddress) selectedProxies.get(0).address()).getPort());
    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) PasswordAuthentication(java.net.PasswordAuthentication) Test(org.junit.Test)

Example 5 with CeylonConfig

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

the class ProxiesTest method testProxyWithPassword.

@Test
public void testProxyWithPassword() throws Exception {
    CeylonConfig testConfig = loadTestConfig("proxy+password.config");
    Proxies proxies = getProxies(testConfig);
    Proxy proxy = proxies.getProxy();
    Assert.assertEquals("myproxy", proxy.getHost());
    Assert.assertEquals(1234, proxy.getPort());
    Authentication auth = Authentication.fromConfig(testConfig);
    auth.installProxy();
    Assert.assertNotNull(auth.getProxyAuthenticator());
    PasswordAuthentication up = Authenticator.requestPasswordAuthentication(null, 80, "ceylon-lang.org", "Hello, world", "fnar");
    Assert.assertEquals("me", up.getUserName());
    Assert.assertEquals("mypassword", new String(up.getPassword()));
    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());
    Assert.assertEquals("myproxy", ((InetSocketAddress) selectedProxies.get(0).address()).getHostName());
    Assert.assertEquals(1234, ((InetSocketAddress) selectedProxies.get(0).address()).getPort());
    // Check there were no prompts
    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) PasswordAuthentication(java.net.PasswordAuthentication) 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