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