Archive: February 2017

Grails Goodness: Using Domain Classes Without Persistence

Posted on by  
Hubert Klein Ikkink

Normally when we create a domain class in Grails we rely on GORM for all the persistence logic. But we can use the static property mapWith with the value none to instruct Grails the domain class is not persisted. This can be useful for example if we want to use a RestfulController for a resource and use the default data binding support in the RestfulController. The resource must be a domain class to make it work, but we might have a custom persistence implementation that is not GORM. By using the mapWith property we can still have benefits from the RestfulController and implement our own persistence mechanism.

In the following example we have a simple Book resource. We define it as a domain class, but tell Grails the persistence should not be handled by GORM:

Continue reading →

Release NPM package with git-flow

Posted on by  
Willem Cheizoo

Having an NPM package in an enterprise environment and wanting to release that package using the git-flow model? Then using the [node-generate-release](https://ift.tt/28QYo7d) can be very helpful. This blog shows how to execute an integrated git flow release from your NPM package, even if your master and develop branches are protected.

Let’s assume we have all changes in the develop branch and we would like to create a release with all the current changes in develop. With the git-flow release the result will be that all changes will be merged into master and a tag for the release version is created with correct version. Before we can finish the release the correct version in NPM package.json needs to be set. This can all be nicely done with node-generate-release plugin.

Continue reading →

Groovy Goodness: Using The Call Operator ()

Posted on by  
Hubert Klein Ikkink

In Groovy we can add a method named call to a class and then invoke the method without using the name call. We would simply just type the parentheses and optional arguments on an object instance. Groovy calls this the call operator: (). This can be especially useful in for example a DSL written with Groovy. We can add multiple call methods to our class each with different arguments. The correct method is invoked at runtime based on the arguments.

In the following example we have User class with three call method implementations. Next we see how we invoke the call methods, but without typing the method name and just use the parenthesis and arguments:

Continue reading →

Groovy Goodness: Creating Root JSON Array With JsonBuilder

Posted on by  
Hubert Klein Ikkink

To create JSON output with Groovy is easy using JsonBuilder and StreamingJsonBuilder. In the samples mentioned in the links we create a JSON object with a key and values. But what if we want to create JSON with a root JSON array using JsonBuilder or StreamingJsonBuilder? It turns out to be very simple by passing a list of values using the constructor or using the implicit method call.

In the following example we use JsonBuilder to create a root JSON array:

Continue reading →

Gradle Goodness: Check Operating System In Build Scripts

Posted on by  
Hubert Klein Ikkink

Sometimes we want to check which operating system is used in our build script. For example we have tasks that need to run if the operating system is Windows and not for other operating systems. Gradle has an internal class org.gradle.nativeplatform.platform.internal.DefaultOperatingSystem, but we should not use this class in our build scripts. The class is used internally by Gradle and can change without warning. If we would depend on this class and it changes we break our build scripts. But we can use a class from Ant that is already in Gradle’s class path: org.apache.tools.ant.taskdefs.condition.Os. The class has several methods and constants to check the operating system name, version and architecture. The values are based on the Java system properties os.name, os.version and os.arch.

In the following example build script we use import static to include the Os class, so we can directly invoke the methods and refer to the constants in the Os class. We add some tasks that have a condition check with onlyIf so the task only runs when the condition in the closure is true. The task osInfo simply shows values from the Os class:

Continue reading →

shadow-left