Friday, June 13, 2014

Cloud9 and Ceylon

Cloud9

I recently stumbled across a really impressive online full fledged coding IDE called Cloud9. By signing up for a free account you get as many public workspaces as you want, plus, a quite complete Linux environment including a really outstanding terminal. This is all made in javascript and HTML5, so this is 100% portable. A recent browser is all you need.

Cloud9 proposes workspace templates, which includes node.js, ruby on rails, php, pyhon and some others. Me being on the Java side, I initially thought it was missing this behemoth, but found out that the JDK comes pre-installed, along with a few tools like Ant.

I find there is no better environment for prototyping some stuff. Nothing to install.

I might write a complete article on Cloud9 in the near future.

Ceylon

I'm a big fan of Gavin King, all the way since the beginning of Hibernate a long time ago. I was quite curious when I heard he was on a special project at Red Hat which was about creating a new language for the JVM. Now that version 1.0.0 is out, it's time to put our hands dirty and check this out. 

Installing Ceylon on Cloud9


From here I assume you already have your Cloud9 account and you created a custom workspace.

Prerequisites for Ceylon are a JDK plus Ant, and they come preinstalled in Cloud9. So lets download the package and install it at convenient place (don't forget to add Ceylon binaries to the $PATH variable in ~/.bashrc):

mkdir ~/packages
wget http://downloads.ceylon-lang.org/cli/ceylon-1.0.0.zip
mkdir ~/apps
unzip ~/packages/ceylon-1.0.0.zip -d ~/apps
view raw gistfile1.sh hosted with ❤ by GitHub
We now have a working Ceylon installation.

Creating the Hello World project



# Optional, but I like to create a symbolic name so the worspace is more readable
cd ~
ln -s 885674 ceylon-demo
cd ceylon-demo
ceylon new helloworld .
Enter module name [com.example.helloworld]: com.example.helloworld
Enter module version [1.0.0]:
Would you like to generate Eclipse project files? (y/n): n
Would you like to generate an ant build.xml? (y/n): y

Executing the project

First execution will provoke the following exception:
mathieufortin01@ceylon-demo:~/ceylon-demo $ ant run
Buildfile: build.xml
ceylon-ant-taskdefs:
compile:
BUILD FAILED
...
Caused by: java.lang.IllegalArgumentException: Cannot create Ceylon cache repository directory: /var/lib/openshift/5398cc545004464a170006ee/.ceylon/cache
at com.redhat.ceylon.cmr.impl.RootRepositoryManager.<init>(RootRepositoryManager.java:56)
at com.redhat.ceylon.cmr.impl.RootRepositoryManager.<init>(RootRepositoryManager.java:50)
at com.redhat.ceylon.cmr.impl.RepositoryManagerBuilderImpl.<init>(RepositoryManagerBuilderImpl.java:45)
... 33 more
This is a common error on Cloud9 when installing/running custom binaries. Access controls restrict write operations in core folders.
We need to override where the cache folder will reside:
# create cache folder
mkdir ~/.ceylon
mkdir ~/.ceylon/cache
# create configuration file
vi ~/ceylon/config
# set cache folder in newly create cache folder in home directory. To find home, use echo $HOME.
# and save the file
view raw gistfile1.sh hosted with ❤ by GitHub
A new execution will give us a new error:
mathieufortin01@ceylon-demo:~/ceylon-demo $ ant compile
Buildfile: build.xml
ceylon-ant-taskdefs:
compile:
[ceylon-compile] /var/lib/stickshift/5398cc545004464a170006ee/app-root/data/886846/source/com/example/helloworld/run.ceylon:1: error: compiler message file broken: key=compiler.err.ceylon.parser arguments=incorrect syntax: no viable alternative at token '"The classic Hello World program"', {1}, {2}, {3}, {4}, {5}, {6}, {7}
[ceylon-compile] doc "The classic Hello World program"
[ceylon-compile] ^
[ceylon-compile] /var/lib/stickshift/5398cc545004464a170006ee/app-root/data/886846/source/com/example/helloworld/run.ceylon:6: error: compiler message file broken: key=compiler.err.ceylon.parser arguments=incorrect syntax: no viable alternative at token '"Run the module `com.example.helloworld`."', {1}, {2}, {3}, {4}, {5}, {6}, {7}
[ceylon-compile] doc "Run the module `com.example.helloworld`."
[ceylon-compile] ^
[ceylon-compile] ceylon compile: There were 2 errors
BUILD FAILED
/var/lib/stickshift/5398cc545004464a170006ee/app-root/data/886846/build.xml:22: Error running Ceylon compile tool (an exception was thrown, run ant with -v parameter to see the exception)
view raw gistfile1.sh hosted with ❤ by GitHub
It appears that commenting out the documentation lines in run.ceylon fixes the problem.
mathieufortin01@ceylon-demo:~/886846 $ ant run
Buildfile: build.xml
ceylon-ant-taskdefs:
compile:
[ceylon-compile] No need to compile com.example.helloworld/1.0.0, it is up to date
[ceylon-compile] Everything is up to date
run:
[ceylon-run] Hello, World!
BUILD SUCCESSFUL
Total time: 14 seconds
view raw gistfile1.sh hosted with ❤ by GitHub

Next steps

This is just the beginning. Full Ceylon applications can probably be build this way. By natively linking to GitHub, Cloud9 makes a wonderful environment to prototype and test ideas.

No comments:

Post a Comment