About

 Recent Entries

 Tags

 Subscribe

    Subscribe in Rojo

    Add to Netvibes
    Add to Google

 Projects

 I Recommend

 Blogs I read

 Search

 Categories

 Monthly

    « January 2016
    SunMonTueWedThuFriSat
         
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
          
    Today

 Badges

It's here! Basilisk 0.0.0 has just been released! You can grab it from Bintray and JCenter immediately!

Following the steps of the first Griffon release (0.0 back in 2008) Basilisk brings high productivity and fun to mobile/desktop JavaFx application development. This release includes the following goodies:

Want to take it for a spin? Here's how you can get a Basilisk application running in no time

The recommended way to get started with a Basilisk project is to use a Lazybones project template and Gradle. You can install these tools with SDKMAN.

$ curl -s http://get.sdkman.io | bash
$ sdk install lazybones
$ sdk install gradle

Next register the basilisk-lazybones-templates repository with Lazybones' config file. Edit $USER_HOME/.lazybones/config.groovy

bintrayRepositories = [
    "basilisk/basilisk-lazybones-templates",
    "pledbrook/lazybones-templates"
]

List all available templates by invoking the following command

$ lazybones list
Available templates in basilisk/basilisk-lazybones-templates

    basilisk-javafx-ios
    basilisk-plugin

Select a starting template from the list and invoke the create command

$ lazybones create basilisk-javafx-ios sample

Compile, run and test the project with any of these commands

$ gradle build
$ gradle test
$ gradle run
$ gradle launchIPhoneSimulator

Also have a look at basilisk-samples, a repository that will contain reference and sample applications as time passes by.

If you decide to give it a try, do let us know what you think at the mailing list, issue tracker and/or @basilisk_fw.




I've been keeping an eye on JavaFXports ever since Johan announced the project. From time to time I test the latest builds to see how the project grows. A few months ago we had a breakthrough with Griffon and the jfxmobile plugin; after a few tweaks (and some API changes from Griffon's side) it was clear that running Griffon on an iOS device was no longer a wild dream, but rather a reality.

So what about those API changes? There were actually not that widespread, actually they were concentrated to a particular set of common, standard APIs that every Java SE developer knows and encounters almost ever single day: the java.beans package. For historical and practical reasons RoboVM relies on the Android SDK to enable Java (and JavaFX) to run on Android and iOS devices. This brings along some of the restrictions Android users know by heart: black listed classes such as the ones contained in the aforementioned package. The only way to make things work was to replace the black listed API with something that's functionally equivalent but with a different name, and so openbeans got into the picture. Funny thing, this package contains code from Apache Harmony, the alternate "Java" implementation that never was.

Anyway, it was clear that a breakage in compatibility was needed in order to allow Griffon applications to reach out into the mobile space with JavaFXports' help. We're over a year now since Griffon 2.0.0 was released; the 2.x line broke compatibility with the previous series, and the team thinks we still have a few more releases before we decide to break compatibility again for 3.0.0, if needed be. But we don't want to wait long in order to enjoy the benefits of Griffon on mobile, so we came up with a different plan: fork Griffon.

Basilisk is a fork of the Griffon 2 codebase (2.5.0-SNAPSHOT as we speak) that aims to bring the Griffon experience to mobile/desktop application development. Basilisk targets Java8 and JavaFX8 specifically, any Java developer will be able to pick it up quite easily.

For now, the differences between Griffon and Basilisk are minimal, besides the package renaming and the usage of openbeans almost everything else is the same. Migrating between one framework to the other can be done with a small set of steps:

  • s/org.codehaus.griffon/org.kordamp.basilik/
  • s/griffon/basilisk/i

We expect Basilisk to grow on its own, sporting features that make sense for desktop and mobile environments. It will be possible to migrate features between Griffon and Basilisk, so that porting applications will remain an easy task. While Griffon remains as the preferred solution for building all kind of desktop applications, from the very small to the full fledged, enterprise ready ones, we foresee Basilisk taking its place as the choice for developers that need to build applications that cross between desktop and mobile spaces.

There's no release yet for Basilisk; there are still some migration aspects to be taken care of, such as the guide and documentation, however you can take Basilisk for a spin right now by simply cloning https://github.com/basilisk-fw/basilisk.git and building your own version. It's as simple as

$ curl -s http://get.sdkman.io | bash
$ sdkman install gradle
$ git clone https://github.com/basilisk-fw/basilisk.git
$ cd basilisk
$ gradle publishToMavenLocal
$ gradle installAllTemplates

After this you can use the provided templates to create and test an application

$ sdkman install lazybones
$ lazybones create basilisk-javafx-ios 0.1.0-SNAPSHOT sample
$ cd sample
$ gradle launchIPhoneSimulator

Don't be fooled by the low version number, Basilisk comes from a fine codebase lineage that includes Griffon (2008) and Grails (2005), it's pretty mature as you will see.

These are exciting times to be building Java(FX) applications for desktop and mobile.

Keep on Groovying!




I clearly remember back in 2007 when Ben & Dion mentioned at DesktopMatters: "Web is becoming more desktopy, and desktop is becoming more weby". The past few years have proved them right. Webapps continue to imitate the behavior of desktop applications, while desktop tries to emulate the ease of use and better experience found in web apps.

If someone told me years ago I'll be back to "web development" but targeting the desktop instead I wouldn't had believe it, but lately I've been working a lot with JavaFX, CSS, and SASS at may day job. Yup, that's right. It's surprising how fast one can change the look of an JavaFX application by using CSS, deceptively fast ;-) You can spend more than half the time tweaking borders and colors instead of writing business logic. Still, the experience is much better than writing custom renderers and UI delegates in Swing.

With this in mind, I decided to give a try at porting Twitter's Bootstrap to JavaFX. There have been a couple of prior attempts (mixed with ScalaFX even, something that does not play well with the rest of the JavaFX ecosystem) but no concrete releases just yet. Without further ado here are some screenshots and corresponding FXML files on what can be done after a few hours of tweaking Bootstrap 3.3.5 with SASS

buttons

labels

Granted, it's not much but buttons, labels, headers and badges are already working. With a few more hours of work I'm positive I can get tables and lists ready too. I'll post the CSS after reaching that milestone.

Keep on Groovying!




Some days ago I blogged about the availability of web based font icons for Griffon applications. Adding icons to a Griffon application is quite easy as shown in that entry. Today I'm going to show how JavaFX can make it plain simple to create composite icons.

Fontawesome defines a couple of CSS classes that can be used to create stacked icons. Unfortunately those CSS classes cannot be used with JavaFX directly, however you can create stacked icons given the right container is used. It turns out JavaFX provides a node container named StackPane. It lays out its children based on the order in which they are added to the container. We can use this knowledge and the fact that any JavaFX Node that exposes a graphic property accepts a Node as its value, to our advantage. Let me show you what we want to accomplish:

Stacked Fontawesome Icons

The screenshot is an exact replica of the stacked example found at Fontawesome. So how do we make it happen? There are several options, but it all boils down to the following:

  • create a StackPane.
  • add instances of FontawesomeIcon with the right settings in the correct order.
  • set the StackPane instance as the value of the graphic property of a button.

We can do all these things with FXML alone, here's how to do it

As you can see, FXML makes it pretty straightforward to follow the steps needed to create stacked icons. You may notice there are no text-danger or fa-stack-2x CSS classes in use for this particular demonstration. Instead, icon sizes and colors are set directly on the icons. Of course someone could create an appropriate CSS stylesheet that goes along with the settings provided by fontawesome.css in order to minimize XML code.

This trick will work pretty much the same with the rest of web font based Griffon plugins listed at the bottom of the previous blog entry.

Keep on Groovying!




There are many options out there to make an application to look better. Icons are one of these options. As good looking icons may be there is a drawback if they are image based: the amount of memory used to load data and render them. This is probably the reason why modern applications, at least web ones, prefer to use font based glyphs to render icons. FontAwesome is perhaps the most well known of the bunch.

Applying FontAwesome to a desktop application is not that different from a web application. JavaFX makes it particularly easy, with the the griffon-fontawesome-plugin is even easier. Here's a short video of a simple application that can tweak some values such as color, size, and even drop shadow to a set of icons that rely on FontAwesome's webfont:

FontAwesome Icon sample application with Griffon 2.3.0 from Andres Almiray on Vimeo.

Let's see the code piece by piece. This little application makes use of FXML to define the UI, and it looks like this

Notice that the icon definitions make use of a new JavaFX node named FontAwesomeIcon. This little guy is in charge of resolving icon names to their corresponding icon. You can also tweak its size and color; it even accepts gradient paints as shown in the video. Notice also that all color buttons point to the same action (changeColor).

Each one of the color buttons on the controls section is rendered using a custom CSS style. We'll use this style to obtain the paint that must be applied to all icons.

Now that we have covered the resources of this application is time to dive into the code. We only need two artifacts to make it happen: a model that can keep track of common values, and the view that realizes the FXML file and creates appropriate property bindings. Let's see the model first.

There are two observable properties here: one that retains the current color to be applied to all icons, another that indicates whether a shadow should be applied to icons or not. We could have kept these properties in the view for now as the application is very small, however keeping data separate from the view helps in better structuring of an application, specially if it'll grow over time. We also keep track of these variables because we'd like to bind all icons to a single source of changes.

Let's turn to the view now

The view makes use of the @FXML annotation to grab hold of all icons and controls (except for the color buttons). It uses standard JavaFX property bindings and listeners to arrange for icon properties to be updated given the controls and the models properties. Finally it defines the changeColor action whose job is to update the models color property. Because all icons have their iconColor property bound to the models color property it's enough to modify the color in one place an have all icons react immediately. The same is true for the shadow property, which uses a ChangeListener to define a converter.

FontAwesome is great but it's not the only game in town when it comes to icon based webfonts. The following is a list of all currently supported icon based webfonts plugins in Griffon:

It's worth saying that these icons work with both Swing and JavaFX applications, as long as you use Griffon of course ;-)

Keep on Groovying!




2014 has been an incredible year for Hackergarten! To begin with, the original group in Basel had consistent meetings throughout the year, with half of the total people attending being new to the group. We were having so much fun at Basel that Anatole Tresch (@atsticks) decided to launch the Zurich Hackergarten Chapter in early March. But the fun didn't stop there, Marcus Fihlon (@mcpringle) decided that Luzern would not stay behind and kickstarted the Luzern Hackergarten Chapter in October. Not to forget that we also had a session in Bern by mid year.

So, if you're a developer living in Switzerland know that there are a few options to get your hacking fix each month. We're also considering hosting sessions in Lausanne, Geneva and Lugano; if you're interested, let us know!

Being an open group about all things open source means we can host sessions whenever and wherever a group of hackers show interest. And what better place is there to round up interested individuals for a couple of hours of hacking fun than at a software conference? We've hosted Hackergarten sessions at international conferences in the past, and 2014 was not the exception.

We began the year at JavaLand in March with a modest setup just because everything at JavaLand was brand new! Then came Devoxx FR in April where French speaking developers did an amazing job with their contributions. Next came Hackergarten month (June) as we had not one, not two but 4 meetings! one for each week. The first meeting was at Gr8conf CPH (our 5th!) with close to 70 people in attendance. I must confess that Gr8conf Hackergarten has been the most fun and the most engaging. Next came in Devoxx UK where attendees had the chance to mingle and code with JCP members and JSR spec leads thanks to the efforts of Heather Vancura (@heathervc). The second half of the month we had meetings in Bern and Basel.

The next international location was Crete in late August. The JCrete (un)conference is an incredible opportunity to turbocharge your brain. Unfortunately for the Hackergarten we couldn't agree on a time and place to get it "officially" started but it did happen in some way ;-) September came by and we saw ourselves having fun in Oslo, a day before JavaZone started. Kudos to @javabin and @kodemaker for helping in getting the place and sponsoring pizza and drinks in such a short notice!

Closing the year came 3 more opportunities. JavaOne, JMaghreb and Devoxx BE. This was the 2nd time we were able to host Hackergarten at JavaOne but the 1st time we were able to use the original name (last year we had to go with CodeGarten, don't ask ;-) JMaghreb hosted the first Hackergarten in Africa! We're very honored and humbled by this opportunity :D Devoxx closed the conference season, and we got again lots of people interested in JSRs thanks to Heather. But this is not all, there were Hackergarten meetings hosted by JUGs too, for example Marseille JUG and JUG Hyderabad.

Throughtout the year we hacked on many things. Just to name a few:

  • Released several updates for the gradle-asciidoctor-plugin, a project that was born at a Hackergarten (back in JFokus 2013).
  • Added better archiving support to jmh-gradle-plugin.
  • Rekindled development on Json-lib by fixing long-standing bugs.
  • Sent in patches for several gradle plugins to enable their publication to the Gradle Plugin Portal.
  • Upgraded the Hackergarten website to a static site hosted at GitHub. Another patch added Angular support for better handling of upcoming and past events.
  • Ed Burns fixed issue 1337 (yes, that number) of the JSF spec.
  • Sven Reimers and co. finished TweetwallFX for Devoxx. There's a 20min video about the details here.
  • The TCK for JSR-354 (JavaMoney) was improved.
  • Grails, Groovy, Griffon, GVM, Geb, Spock, Lazybones and other Groovy ecosystem projects benefited from many contributions made at Gr8Conf and other meetings.

As great as 2014 was we're looking forward to things to come in 2015. We already have in schedule the next 2 meetings in Switzerland: Jan 22 at Canoo HQ (Basel) and Jan 29 at CSS Versicherung (Luzern). There will be new destinations: VoxxedDays Ticino, GIDS. We'll revisit old and new favorites: Gr8conf CPH and JavaLand.

Keep and eye on Hackergarten and @hackergarten for news and updates.




It's been a few weeks since I posted the announcement regarding the New Desktop Application Framework JSR and its follow up Q & A. Some of you may be wondering: what's going on now?

Well since the time these post were made public I've been in touch with people interested in Java Desktop technologies; the same people that have built frameworks to simplify development of such applications. The feedback so far is very positive, there's indeed a need to standardize how desktop (and embedded) applications are built, much in the same way web applications have been standardized with Java EE.

Just recently I made a short presentation to the JCP EC; to let them about the plans of starting a JSR on this topic. If all goes well, that is, the proposal is accepted and the EC gives the green light then the Expert Group can be formed as early as late January 2015.

Stay tuned for more news :-D




The announcement of a new Desktop Application Framework JSR a few days ago has gathered a lot of interest. It also generated a good number of questions, which hopefully I'll be able to address in this post.

First and foremost, JSR296 is not the first attempt at creating a JSR on this subject. As Sven Reimers (@SvenNB) correctly pointed out to me, JSR193 was proposed by Adam Bien (@adambien) back in 2002. This JSR resembled JavaEE (then called J2EE) due to its container approach.

And now for the questions:

1. Should NDAF target only the desktop or could it go further into tablets and other mobile devices?

Considering the rise of tablets and mobile devices as we've seen so far it would be silly not to consider those enviroments as potential deployment targets. JavaSE8 and embedded Java have closed the gap in terms of compatibility and API convergence. This gap is very likely to shorten in future versions of the JDK. So yes, NDAF should break out of the desktop and reach out.

2. OK, so we jump into the JavaFX bandwagon and ride it like there's no tomorrow, right?

Not quite. JavaFX is poised to replace Swing as the defacto UI toolkit provided by the JDK. It's my personal opinion that JavaFX has not reached this spot just yet; Not with missing accessibility and other features found in Swing (actions everyone?). The JavaFX team has openly expressed that some of these missing features should be implemented by the community, and to that effort a set of open source projects have been created (ControlsFX, JideFX, MigLayoutFX, etc). However JavaFX will become the dominant UI toolkit in the embedded space, meanwhile we'll still have access to all other popular choices such as Swing, SWT, Qt, Lanterna (to name a few). Bottom line, NDAF APIs should be close to a particular UI toolkit where it makes sense (if at all). This is one thing that both Griffon and Eclipse4 do very well, as they can target multiple UI toolkits without compromising on performance and features.

3. How deep should the behavior be specified?

Allow me to reiterate what I believe what useful features a DAF should provide

  • dependency injection via JSR330.
  • common application structure.
  • application life-cycle.
  • localized resources.
  • resource injection.
  • localized configuration.
  • decouple state from UI (binding).
  • persistence session state (preferences).
  • action management.
  • component life-cycle.
  • light-weight event bus.
  • honor threading concerns (specific to UI toolkit).
  • application extensibility via plugins (implies modularity).
  • testing support (unit and functional).
  • deployment profiles.

In my mind that would be the minimum set of features I'll define in NDAF. Of course others may differ; and this is precisely the point to bringing the discussion into the JSR space.

4. OK, so what about a full stack framework?

I think standardazing on a full stack framework would be far too much. That would be akin to saying all JavaEE applications must use JPA one way or another, without a chance of an alternative persistence option, or no persistence at all! If you look around at the different applications you're currently running you'll notice that all of them share some common behavior but not all have persistence capabilities; some don't even have preferences! Championing a fullstack as part of the NDAF JSR would be a turn off IMHO; however what can be done is prepare the NDAF APIs so that persistence (or any other non core behavior) can be added effortlessly, that is, we need API hooks and plugin capabilities. And no, I'm not saying we should go with with the OSGi route, but any of the implementors might choose OSGi to fulfil this requirement.

5. This is great! Can you pick my framework to make it happen?

I don't think it's that easy. First the framework you proposed must comply to the minimum set of features that NDAF should provide. Secondly, what about IP and licensing? There are some rules to be followed so we can't pick just any codebase out there. On the other hand, once NDAF goes public any implementors are free to choose how they retrofit their frameworks to conform to the NDAF spec, so eventually your framework can be made NDAF compliant.

6. I get it now, you just want to rub Griffon in our faces! BOOO!

I've openly confessed Griffon to be my passion. It's true that I consider it mature enough to fulfil the set of features I've put forward, after all it almost covers them all today. But it's not the only one that partially covers them. Here's a somewhat incomplete list of (mostly JavaFX) frameworks that also cover some of the features found in the list

Any of these frameworks/platforms can become an NDAF implementation, even the RI for that matter; again I believe Griffon is closer but the open discussion will clear that subject.

I hope this clears out some of the question brought by the first announcement. No doubt other questions will rise, so please keep commenting and share. Let's make NDAF a reality, together.

PS: a name for this JSR should be decided pretty soon or NDAF will stick ;-)




A few days ago an innocent tweet appeared

That's right, I'm thinking it's time to discuss and formalize what a Desktop Application Framework JSR should be. It's said that one who forgets the past is condemned to repeat it, yup, I'm referring to JSR296, dead and buried since 2009. According to Wikipedia JSR296 had the following goals

  • management of application life-cycle, startup and shutdown.
  • support for loading localized resources.
  • persistent session state.
  • support for loosely coupling actions to their presentation.

Not bad but also not ambitious enough. It targeted a single UI toolkit (Swing). It's main goal was to define runtime concerns, leaving out other important app development aspects such as testing and deployment. And it was proposed before other helpful JSRs (such as JSR330 and the upcoming Java Config JSR) came up. So why now? Why not revive JSR296 instead of proposing a new one?

I believe the following features to be of great advantage when developing an application that targets the desktop:

  • dependency injection via JSR330.
  • common application structure.
  • application life-cycle.
  • localized resources.
  • resource injection.
  • localized configuration.
  • decouple state from UI (binding).
  • persistence session state (preferences).
  • action management.
  • component life-cycle.
  • light-weight event bus.
  • honor threading concerns (specific to UI toolkit).
  • application extensibility via plugins (implies modularity).
  • testing support (unit and functional).
  • deployment profiles.

Some of these features are quite straight forward to understand, others might lead to a rabbit hole that may be too deep (should OSGi support be included for example?). This is why discussing in the open is a Good Thing(tm). Many of these features can be found in Griffon (my natural choice for an RI of this JSR at this point) but it you look at the Eclipse 4 Platform you'll find out that it too provides many of them too. Coincidence? I. Think. Not.

There's a new UI toolkit found in the JDK since Java8: JavaFX. Both Swing and JavaFX can coexist, even within the same application. But these two are not the only toolkits you can choose from, there's also SWT, Qt, Pivot, GTK and Lanterna (to name a few). The New Desktop Application Framework (NDAF (should come up with a better name)) should be flexible enough to accomodate any of these toolkits, not just a single one (Swing) like SAF did.

JSR330 did not exist when JSR296 was proposed. It's now pretty much everywhere. Java developers have found it to be a very useful item in ther development toolbox. JSR205 includes additional annotations that can further simplify component life-cycle management (@PostConstruct and @PreDestroy).

The JavaConfig JSR can help with configuration and preferences. I urge everybody to have a look at what Anatole is proposing for this JSR and state your support if it makes sense to you too.

Finally, with the push of Java8 running on smaller devices thru embedded Java, such as Raspberrie Pi, it also makes sense to target these devices with NDAF; after all Griffon 2.0 runs on Raspberrie Pi already ;-)

What's next? For now I'm collecting feedback from interested parties. So far input has been very positive with a few words of caution. Please comment and share the pros and cons of such initiative.




This installment of Gradle Glam is not about a particular plugin or Gradle trick. Rather it discusses some features that I think will benefit the overall Gradle community. Some of these features might be already in the works by the fine folks at Gradleware, some others are ... up for grabs I guess ;-)

In no particular order these are:

  • The maven-publish plugin should honor the compile/runtime configuration when setting the value of <scope> for each dependency added to the generated pom. Test dependencies should be discarded/hidden. Currently all dependencies have runtime as their scope.
  • Centralized metadata that can be consumed by several plugins, for example project URL, contributors, developers, etc. This information can be consumed b maven-publish, bintray and other plugins. Netflix already provides a set of plugins that deal with this problem up to some extent.
  • Integrate reporting plugins with reporting capabilities provided by the build-dashboard plugin. For example stats, license and versions plugins.
  • A plugin that generates prettified HTML source with links, much like Maven's JXR.
  • Aggregated documentation and reports, much like Maven's site feature. Bonus: use Asciidoc as the defacto format.
  • Environment aware build file variations via a DSL. Think applying ConfigSlurper's environments feature to a build file, but more open (not just environments but platforms or other constrained vars).

Keep on Grooving!




Today I'd like to bring your attention to asciidoctor-gradle-plugin. This plugin process Asciidoc sources and creates beautiful documentation. It began life on a cold morning back in February of 2013 during the first JFokus Hackergarten, and has taken a life of its own ever since.

The team just pushed the 1.5.0 release, opening the door for many features, one of which is the topic of today's post: the ability to write custom extensions inside a Gradle build.

So, what exactly do we mean by custom extensions? Recall that Asciidoc has built-in "tags" (or macros) such as include, image, source and more. Well know you can write your own tags :-D Say for example you'd like to write some content in Pig Latin (a very popular pseudo language in some circles). The rules are simple but given that you have to shuffle letters around it can be tricky to get all the sentences right. It would probably be better if there was an automatic way to convert plain text into its Pig Latin counterpart, wouldn't it? And that's precisely what we'll do. We're aiming to render something similar to the following screenshot

screenshot

While keeping the source sentence in plain English. The source asciidoc document looks like this

Notice the [pig-latin] tag applied to the second example sentence. We'll begin with a small Gradle build that follows this structure

The bulk of the project is found in the extension itself. We'll begin by defining the build file for the extension

This extension is so simple it only needs the base asciidoctorj dependency to work. Next comes the main course: PigLatinBlock. This is the code that's capable of handling the pig-latin block in the asciidoc sources. The implementation is trivial though I can't claim is bug free nor is it capable of dealing with all corner cases.

Basically it breaks an annotated paragraph into lines, then further breaks each line into words and process each one of them. Now comes the part of registering the extension. First we create the handler for the extension

Finally we make sure the extension is registered by writing a metadata file in META-INF/services

We could have used gipsy to keep that file up to date and have it be generated automatically at compile time ;-)

And that's al the setup that's needed. Running gradle asciidoctor on the project results in the asciidoc sources being processed. If for some reason the extension was not correctly registered you'd see a warning on the command line, something along the lines of "WARNING: index.adoc: line 16: invalid style for paragraph: pig-latin".

Keep on Groovying!




This is a quick one. A few days ago I posted how you can configure JaCoCo and Coveralls to work in tandem. However there's a problem with the setup shown in that post, basically coveralls will fail to find the aggregated report file because it's place in a non-standard location #sadpanda

But there's a way to fix it. First we must instruct the jacocoRootReport task to generate an XML report at the expected location. Secondly we must tell coveralls where it can find all the source files, because it will attempt to load source files from the root project (which is empty). The fixed build file is here

I supposed we could also configure the report location in the coveralls configuration as there is a property named jacocoReportPath as appreciated at https://github.com/kt3k/coveralls-gradle-plugin/blob/master/src/main/groovy/org/kt3k/gradle/plugin/CoverallsPluginExtension.groovy.

Keep on Groovying!




UPDATE: turns out the JUnitParam tests are broken due to Issue #47, however there's an alternative for parameterized tests: Spock. Continue reading at the bottom to see the updated tests

UPDATE 2: JUnitParams 1.0.3 fixes the problem reported by Issue #47.

Today I read a post by Alexander Casall (@sialcasa) about How to test JavaFX Services and thought "maybe I can come up with an alternative using Griffon". So this post is the Griffon version to test out services and controllers in a JavaFX application.

The first thing I'd like to state is that's my conviction that services should be completely separate from UI aspects. In Alexander's example, the LoginService creates an instanced of javafx.concurrent.Task in the body of the login() method. This asserts that the execution always happens inside the UI thread. Hmmm. I agree that updating an observable model property (which appears to be the case for the updateMessage() method) must happen inside the UI thread, however the service could be simpler and just be responsible for plain inputs and outputs.

Here's my (full) version for a LoginService that performs the login operation according to the new design:

In Alexander's example, the service calls out to another component (clientApi) to perform the actual login procedure. This API call may throw an exception if there's a network problem or because of another unforeseen condition. I decided to keep the example simpler and make a trivial username/password check in the service method itself.

Now, because the service is so simple you can test it out in the following manner

A few things of note

  • GriffonUnitRule instantiates a dummy GriffonApplication and performs dependency injection (similarly to a GuiceBerry enabled test).
  • an instance of LoginService is injected to the service field.
  • JUnitParams is used to parameterize the test. John Ferguson Smart (@wakaleo) just posted a great article title "Data-driven unit testing in Java" on this very topic.

Alright, the service is done. But we still have to build a functioning application, isn't it? Somehow, a component must make a call to LoginService and update model properties inside the right thread. This is a job for a controller, like the following one

for those new to Griffon there's a special feature regarding controller actions that you must be aware of, mainly, that they will be executed outside of the UI thread automatically. This behavior is configurable of course. In our case the login() action is executed outside of the UI thread because it relies on the default configuration. This action performs the following tasks

  • disable the login action (of type JavaFXAction). This action is bound to the login button. You can think of JavaFXAction as a similar abstraction as javafx.action.Action. A missing class in the JavaFX 8 API if you ask me.
  • notice that disabling the action happens inside the UI thread. The code makes use of the lambda expression syntax (which is nice!).
  • invoke the loginService.login() with values coming from the model. How those values are placed in the model is of no concern to the controller, but we can assume they come from bindings made to UI components.
  • update another model property with the output of the login procedure. This update happens inside the UI thread too because we assume the property is bound to an UI component.
  • finally re-enabled the login action.

Testing this controller will require that we're able to handle asynchronous validations, precisely the problem that Alexander addresses in his post. But instead of using a custom JUnitRunner and CompletableFuture we'll leverage Griffon's test support coupled with an amazing testing utility called Awaitility. Here's how the test looks

This is another parameterized test using JUnitParams, another reason why we can't use a custom JUnitRunner like the one shown by Alexander. Instead we go with the simplest route in order to initialize the JavaFX toolkit: create an instance of javafx.embed.swing.JFXPanel during class initialization. Waiting for a condition to be reached in an asynchronous way is quite trivial with Awaitility, as seen in line 48. I'd say the code is quite readable, woudln't you agree? The IsBlank matchers is not provided by the Hamcrest, but it's simple to create

In order to be able to use both JunitParams and Awaitility we must define dependencies in the build file. Griffon uses Gradle by default (although you can use Maven too), so the build.gradle file contains the following dependency entries

You may be wondering about the rest of the code, Model and View. Here's the model that shows usage of plain JavaFX properties

Definitely verbose. Here's hoping a Lombok extension is built in the future that can create such boiler-plate code for JavaFX properties. Next is the view, where we see the linking between model properties and UI components

The important bits happen inside the init() method. This is where model properties are bound to their respective UI components. Controller actions are also connected to their intended targets. Notice that the view uses the @FXML annotations to mark the injection points for UI components. This means it's SampleView and not the SampleController the one that receives the injections. This switch is automatically handled by the loadFromFXML() method. Finally we see the FXML loaded by the view

This is a run-of-the-mill, SceneBuilder generated FXML file. The only thing that make look suspicious is the button's id. Griffon follows a naming convention to be able to connect controller actions to control targets. The following screenshots show the application as it appears after some login attempts

no login blank entries
successful login invalid entries

And there you have it. And alternate way to write and test controller and services in JavaFX.

Keep on Groovying!

UPDATE: So JUnitParams has trouble due to Issue #47. Fortunately there's an alternative for parameterizing tests in the form of Spock. We can uses Spock's data driven feature methods to parameterize the tests for both LoginService and SampleController. I also took the liberty of updating LoginService to use a delegate ClientApi component to perform the actual login procedure. Here's how the LoginServiceSpec looks like

Notice the usage of Spock's interactions. They're like regular mocks, but groovier ;-) This also shows one of the many ways to override a JSR-330 biding in a testcase, in this case the specification requires a mock of the ClientApi type.

Next is the SampleControllerSpec, containing an almost identical setup as SampleControllerTest, the main difference being how the parameterization is setup.

So there you go. If you're willing to branch out and try out other testing tools, such as Spock, your testing experience should be a more gratifying one.




Welcome to another installment of Gradle Glam! This time I'd like to say a few words about the jacoco in combination with coveralls. JaCoCo is a well-known code coverage tool; many prefer it over Cobertura because JaCoCo delivers a much more detailed code coverage.

coveralls.io is a cloud based service that keeps track of code coverage produced by continues integration services, such as Travis-CI. What's great about this service is that it keeps historical records of all coverage sessions. Integrating both jacoco and coveralls in a gradle build is quite simple; you just need to make sure the jacocoTestReport task has the XML report enabled. This configuration works out of the box when your build defines a single project, but it breaks down the moment you try it on a multi-project build. Why? Simply put, coveralls expect an aggregated coverage report and jacoco will not do it for you out of the box.

Here's how you can make it happen.

First, make sure that the jacoco plugin is applied to all projects, including the root project (even if it's just an umbrella project, i.e, one that does not produce artifacts by itself). Next, enable the XML report on the jacocoTestReport task of each subproject. Finally, back on the root project, create a new task of type org.gradle.testing.jacoco.tasks.JacocoReport that's aware of the configuration of the jacocoTestReport tasks found in each subproject. You'll end up with something looking like this

The trick is for the jacocoRootReport to declare a dependency on the test task from all subprojects. It also adjusts the values of sourceDirectories, classDirectories and executionData properties in such a way that they depend on each subproject too.

Assuming the following project structure is in place

Running the jacocoRootReport task at the root project level yields the following

full coverage

As you can appreciate all sources have been covered and aggregated. This approach has one drawback, chiefly that every subproject must produce a coverage execution data file. This only happens when tests are run. What if a project does not have tests? The root report will be skipped altogether <sad-panda-face/>. The quick workaround is to make sure there's at least one test that can be run, even if it's ignored, like the following one

Rerunning the jacocoRootReport task now yields the following report

partial coverage

Now we're back in business :-D The final piece of the puzzle is activating coveralls when running on the CI environment. Here's an example for Travis-CI:

And that's how it's done.

Keep on Groovying!




Welcome to Gradle Glam, a series on useful Gradle plugins and how to make the most out of them in your build. Hopefully I'll be able to post at least one entry per week :-D

Let's begin with a tiny but quite resourceful plugin: gradle-versions-plugin. Seasoned Grails and Griffon developers know they can keep track of their plugin dependencies by invoking list-plugin-updates command. While useful this command does not list updates for regular JAR dependencies, only framework plugins. Bummer. Grails and Griffon resolve their dependencies using a DSL inspired by Gradle. So what if there were a plugin for Gradle that would display dependency updates? Well, this is precisely what the gradle-versions-plugin does.

Inspired by the versions-maven-plugin this little plugin will calculate the delta in your current dependency graph, given the latest artifacts available on the repositories configured for your build.

Here's how you apply the plugin to your build

Say we apply this plugin to a basic Griffon 2.0.0.BETA2 project; running the gradle dependencyUpdates command yields the following information

The gradle-versions-plugin finds out that all Griffon dependencies are out of date, as by the time of writing this entry, the latest Griffon release is 2.0.0.BETA3. Interestingly enough, the plugin can also figure out if a gradle plugin is out of date, as witnessed by the shadow and macappbundle plugins for example.

See what happens when the project switches all Griffon dependencies to their latest released version

Pretty nifty, wouldn't you say?

I'd like to close this inaugural entry of Gradle Glam with my feature wish-list for this plugin

  • generate XML and HTML reports than can be hooked into the build-dashboard plugin.

Keep on Groovying!