Using Ceylon Bootstrap
Using Ceylon Bootstrap
The most recent came out months ago, but one of its more useful tools didn't make waves. Check out the bootstrap, which will help keep users up to date.
Join the DZone community and get the full member experience.Join For Free
A true open source, API-first CMS — giving you the power to think outside the webpage. Try it for free.
Ceylon 1.2.2 was released back in March, and at the time it shipped with a new feature that did not make a lot of noise, but I think it's worth explaining it a bit more in this blog.
In general Ceylon developers have to download the Ceylon distribution in order to compile Ceylon code, and so do Ceylon users. When you check out a Ceylon project you have to make sure you're using the right version of the Ceylon distribution to compile it, and switching Ceylon distribution can be a bit too involved on some Operating Systems.
To solve that issue, Tako has implemented the
ceylon bootstrap tool, very heavily inspired by the Gradle Wrapper, which allows you to generate a small script in your Ceylon project which your users and developpers can use to automatically download the right Ceylon distribution and cache it for future use.
Let's try it out by generating a new Ceylon project (on a machine with a Ceylon 1.2.2 distribution, this is a chicken and egg problem and we have to start somewhere):
$ ceylon new hello-world --ant=no --eclipse=no myproject Enter module name [com.example.helloworld]: Enter module version [1.0.0]:
Now let's check that it compiles and runs:
$ cd myproject $ ceylon compile,run com.example.helloworld Note: Created module com.example.helloworld/1.0.0 Hello, World!
Excellent! Now let's add the Ceylon bootstrap tool:
$ ceylon bootstrap $ ls ceylonb* ceylonb ceylonb.bat $ ls .ceylon/bootstrap/ ceylon-bootstrap.jar ceylon-bootstrap.properties
As you can see, we've created two
ceylonb scripts (one for Unix, one for Windows), and a new configuration folder for those scripts containing a tiny jar (24k) and a settings file which points to the distribution to use:
$ cat .ceylon/bootstrap/ceylon-bootstrap.properties #Generated by 'ceylon bootstrap' #Tue Aug 02 17:29:39 CEST 2016 distribution=https\://downloads.ceylon-lang.org/cli/ceylon-1.2.2.zip
These scripts and folders should be committed to your project code, so they can be used by others.
Now, whenever someone checks your project out, they can just use the provided
ceylonb script to work rather than pre-install the Ceylon distribution:
$ ./ceylonb compile,run com.example.helloworld Downloading Ceylon... 100% Note: Created module com.example.helloworld/1.0.0 Hello, World!
The first time you run this, it will download the desired Ceylon distribution to
~/.ceylon/dists, but from then on, whenever you invoke
ceylonb, it will reuse that distribution without downloading anything. Even other projects using the same distribution will be able to use it.
As I said, Gradle Wrapper users are used to this, but still, it's a really good idea and there's no reason why programming languages couldn't do the same!
Published at DZone with permission of Stephane Epardaud , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.