How to add Groovy and Spock to your Hybris extension.

My goal is to develop new features for our eCommerce solution with TDD methodology. To achieve that I want to use fancy technologies: Groovy and Spock.

Hybris uses ant, and don’t have direct support for Spock, but has for Groovy. To introduce this framework to your Hybris 5.4, please fallow those steps:

General advice, read my comments in code listing.


Make sure, you configure groovy extensions in your hybris instance. To check this, please go to hybris\config\localextensions.xml and look for two entries:

<hybrisconfig (...)>
		<extension dir="${HYBRIS_BIN_DIR}/ext-platform-optional/ygroovy" />
		<extension dir="${HYBRIS_BIN_DIR}/ext-platform-optional/groovynature" />

Step 1

Configure your extension to use maven and add groovy (EXTENSION_PATH/extensioninfo.xml):

    <extension (...) usemaven="true">
        <requires-extension name="groovynature"/>

Step 2

This step is needed if you didn’t create extension with groovy nature.

Add missing ant macrodef, for your extension (EXTENSION_PATH/buildcallbacks.xml):

<project name="EXTENSION_NAME_buildcallbacks">    
	<macrodef name="EXTENSION_NAME_before_build">
            <!-- defines native file extension used by the nature of the extension -->
            <property name="ext.EXTENSION_NAME.native.file.extension" value="groovy"/>
            <!-- defines source folder for groovy files -->
            <property name="ext.EXTENSION_NAME.additional.src.dir" value="groovysrc"/>
            <!-- defines test source folder for groovy tests -->
            <property name="ext.EXTENSION_NAME.additional.testsrc.dir" value="groovytestsrc"/>
                    <fileset dir="${ext.EXTENSION_NAME.path}">
                        <include name="${ext.EXTENSION_NAME.additional.src.dir}/**"/>
                <targetfiles path="${HYBRIS_TEMP_DIR}/touch/EXTENSION_NAME_srctouch"/>
                    <touch mkdirs="true">
                    <fileset dir="${ext.EXTENSION_NAME.path}">
                        <include name="${ext.EXTENSION_NAME.additional.testsrc.dir}/**"/>
                <targetfiles path="${HYBRIS_TEMP_DIR}/touch/EXTENSION_NAME_testsrctouch"/>
                    <touch mkdirs="true">

    <macrodef name="EXTENSION_NAME_after_compile_core">
            <groovynature_compile_core extname="EXTENSION_NAME"/>

Step 3

Add required dependencies to your extension (EXTENSION_PATH/external-dependencies.xml):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
		<!-- TESTING -->
			<version>1.0-groovy-2.3</version><!-- Hybris 5.4 depends on Groovy 2.3, so we are obligated to use this version -->
		<!-- Optional dependencies for using Spock -->
		<!-- use a specific Groovy version rather than the one specified by spock-core -->
		<!-- already in hybris
		<dependency> <!-- enables mocking of classes (in addition to interfaces) -->
		<dependency> <!-- enables mocking of classes without default constructor (together with CGLIB) -->
		<dependency> <!-- only required if Hamcrest matchers are used -->
			<version>5.0.3</version><!-- watch out for this one! -->

Run maven to update your new dependencies:

hybris\bin\platform> ant updateMavenDependencies

Maven should download all your new dependencies into EXTENSION_PATH/lib folder.

Step 4

Replace old ASM library with newer. Spock requires this change.

Replace: hybris/bin/platform/ext/core/lib/asm-3.3.1.jar with asm-5.0.3.jar.

You can find this JAR in your EXTENSION_PATH/lib folder.

Step 5

Create your firs Spock Specification in folder EXTENSION_PATH/groovytestsrc.

package pl.com.bernas.hybris.groovy

import de.hybris.bootstrap.annotations.UnitTest
import org.junit.Test
import spock.lang.Specification

 * @UnitTest is really important for Hybris to know when this test should be executed.
 * Without any of de.hybris.bootstrap.annotations.* annotation, test mechanism will not pick up this specification.
 * Created by kirkor on 7/25/2016.
class SimpleStringComparatorSpec extends Specification {

     * If a test class don't have at least one test annotation,
     * TestClassesUtil will ommit this test and it will not be executed.
    def "should concatenate two strings into one"() {
            String test = "I have a dog"
            test += " and two cats."
            test == "I have a dog and two cats."


hybris\bin\platform> setantenv.bat
hybris\bin\platform> cd ..\custom\EXTENSION
hybris\bin\custom\EXTENSION> ant build
 [echo] preparing...
 [echo] building extension 'EXTENSION'...
  [groovyc] Compiling 1 source files to hybris\bin\custom\EXTENSION\classes
[testClassesScanner] Found 1 EXTENSION testclasses in 14.25 ms
Total time: 10 seconds
hybris\bin\custom\EXTENSION> ant unittests -Dtestclasses.packages=pl.com.bernas.*
 [echo] preparing...
 [echo] Annotations : unittests
 [echo] Extensions  : EXTENSION
 [echo] Packages(+) : pl.com.bernas.*
 [echo] Packages(-) :
 [echo] JUnit Split :
 [echo] Web         : false
|-- Adding Filter for package pl.com.bernas.*
|-- Adding Filter for UnitTests
|-- Adding Filter for extension EXTENSION
 [yunitint] Using TestClassesUtil...
 [yunitint] Found 1 filtered classes...
 [yunitint] Scanning finished in : 337ms, found 1 testclasse(s)!
 [yunitint] --> found 1 testclasses!
 [yunitint] Running pl.com.bernas.hybris.groovy.SimpleStringComparatorSpec
 [yunitint] INFO  [main] (junit) [SimpleLog4jPerformanceMeasurement] Test method pl.com.bernas.hybris.groovy.SimpleStringComparatorSpec.should concatenate two strings into one succeeded. Time taken: 181.5 ms
 [yunitint] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.636 sec
     [echo] Report generated to src/hybris/log/junit/index.html

What we just achieve is the possibility of running together, the old JUnit tests and Spock Specification. This is because Spock is build on top of JUnit, as a Runner.

This is extremely useful if we already have some test in JUnit, but we want to add new with Spock, and run them from command line on Jenkins or Bamboo – to have one big report about our tests.

Yesterday I faced one problem, how to insert new row to SQLite database with newline char.

First I’ve try to use CHAR(13) function (witch is ASCI newline char), but the Android version of SQLite does not have char function (Exception).

Finally I found the way how to do it:

insert into TABLE ('column') values ('First line, ' || x'0A' || 'Second line.');

Special characters || are responsible for concatenation, tells that his is a HEX value, and 0A is hex representation of Line Feed.


Few weeks ago I watch one video on YouTube by Tomasz Dziurko: Jinkubator #28 – 1011 błędów w rekrutacji, które pokazują jaki będzie twój kod. It’s in polish, but some of you may enjoy. I really fall in love with this sentence: I write and read faily well ;-)

I write about this because yesterday I faced one English grammar problem. During implementation of one feature I’ve add an method to our interface:


It’s about returning list of codes for different categories. One of my code reviewer told me that this against English grammar – I couldn’t believe ;-)

First because other similar methods looks the same eg:


Second it was against my logic, but after all it occurs that my logic throws there RuntimeException ;-)

I even ask question about it on StackOverflow and the conclusion was:

As both a native English speaker and a Java programmer: getCategoryCodes() is preferable. getCategoriesCodes() implies to me that I am getting multiple codes for each category, or that the codes relate to the collection of categories, rather than a code for each category.

As an example from “real” English: a car has one driver; you would refer to the drivers of many cars as “car drivers”, not “cars drivers”.

If you are interested in more detailed discussion please read my post: Java naming conventions versus English language correctness

Today I faced small confusion how to configure my Eclipse to use JRebel with Grails 3 framework. This is step by step configuration.

  1. Get ready with your eclipse on fedora 22 and gnome shell (I’m using sts-3.7.0.RELEASE);
  2. Install Gradle IDE Plugin;
    Screenshot from 2015-09-30 10-25-49
  3. Install JRebel – it’s just a tool to autoreloading classes and spring beans ;-);
    Screenshot from 2015-10-02 10-49-40
  4. Install Groovy 2.4 support from GitHub, (eclipse 4.5 Mars);
    Screenshot from 2015-10-02 10-43-57
  5. Create your Grails 3 application
    grails create-app hello-world --profile=web
    cd hello-world
    grails> create-controller homePage
  6. Import project into eclipse;
  7. Edit gradle.build file (to add JRebel compatibility), documentation at GitHub:
    buildscript {
      repositories {
      dependencies {
         classpath group: 'org.zeroturnaround', name: 'gradle-jrebel-plugin', version: '1.1.2'
    apply plugin: 'rebel'
  8. Run “gradle generateRebel” -> generate rebel.xml file
    1. In eclipse, Window -> Show view -> Other -> Select Gradle -> Gradle Tasks
      Screenshot from 2015-10-02 15-06-47
    2. The file is generated under this location: build/classes/main/rebel.xml

During the next few days I will publish how to run Grails 3 with JRebel:

  1. From command line without JRebel
  2. From command line with JRebel
  3. From eclipse as a Spring Boot Application without JRebel
  4. From eclipse as a Spring Boot Application with JRebel

When I run the default eclipse STS-3.7.0 on the linux fedora 22 the look and feel is not what I’m expecting. Especially margin of tabs, button, text is too big. I’m loosing a lot of screen space because of this “nice GTK3 look”. The problem is with current GTK3 theme that is used by fedora on Gnome Shell 3.16.2. I’ve tried many different approaches to change this (editing css styles for eclipse, editing current GTK3 theme), but the simplest and the best is just to use GTK2 to run eclipse.

To achieve this, create simple bash script (like STS_GTK2.sh) in  your eclipse directory:

export SWT_GTK3=0

Remember to make this file “runnable”:

chmod +x STS_GTK2.sh

This is how the eclipse looks before:

Screenshot from 2015-10-02 09-31-39


Screenshot from 2015-10-02 09-43-05

Troszkę mi się nudzi w pracy (nie robię nic specjalnie wciągającego), praca inżynierska trochę już mnie zmęczyła więc trzeba w wolnych chwilach zrobić coś interesującego. Dobrze będzie się czegoś przy okazji nauczyć. Potrzebuję programu, który będzie pamiętał o naprawach okresowych mojego samochodu oraz będzie wiedział kiedy należy wymienić rozrząd dla mojego modelu. Fajnie jeżeli na podstawie innych napraw tego samego modelu określi, że np. 90% Opli Vectra C (1.9 Diesel) po przejechaniu 130 tyś wymaga wymiany tylnich amortyzatorów.

Więcej na temat kiedy wmienić klocki hamulcowe, olej i mojego pomysłu przeczytasz klikając na link TUTAJ

Continue reading

Ostatnio popełniłem okropną gafę… Do niedawna byłem szczęśliwym użytkownikiem Ubuntu 11.04, jednak zostało wydane o wiele lepsze Ubuntu 12.04 i postanowiłem przeinstalować system na najnowszą wersję. Niestety postanowiłem to zrobić o 23:00 przy piwku… oczywiście przygotowałem się – zrobiłem mini procedurę na kartce papieru jakie kroki poczynić aby wszystko skopiować.
Miałem 3 punkty:

  1. Kopia /home/kirkor
  2. Kopia baz danych MySQL
  3. Kopia /etc/apach2/sites-available

Continue reading