Semantic versioning with Gradle

There are lot of different approaches when it comes to application versioning. Absolute minimum for modern application is to have immutable version for each release. I would suggest to go a step further and use semantic versioning and Git tags as a source of version information.
In this post I will show you how easy it is to use proper semantic versioning for your application with Gradle and axion-release-plugin.

GitOps with Flux

Kubernetes has now become de facto standard for container orchestration and cloud native operations. It solves a lot of problems with service discovery, load balancing, horizontal scaling, rolling updates and many more. Kubernetes manifest YAML files allow to describe desirable state of your applications in the cluster with configuration and secrets.
When that is not enough - you can use Helm for packaging and templating of your application resources. This is all great, but you still need a way to apply all of these elements to the cluster. Running kubectl apply or helm upgrade from your machine or CI quickly become cumbersome.

This is where GitOps will help.

Building Docker image with Gradle

In the world of cloud-native applications - Docker and containerization is a must. Jar (or war) file as a final artifact is no longer an option. What you need to provide to easily deploy an application is Docker image in Docker registry. In short - you need to build Docker image and push it to registry. Fortunately, well known tools like Gradle can significantly help with this task.

There are a few tools you can use to achieve that with Gradle:

I will show how to prepare Gradle configuration with each of the tools above and compare them.

Why multi-stage Docker build does not work

Building inside container sounds very appealing for multiple reasons. Using multi-stage Docker suppose to help you with:

  • having smaller production Docker image
  • avoiding additional Docker file for building
  • avoiding intermediate images (comparing to Docker builder pattern)
  • no need to extract artifacts to local system (comparing to Docker builder pattern)
  • eliminating build differences between developers machines and continuous integration agent
  • common way for describing build process, independent of used continuous integration solution

Unfortunately, I believe this approach has some major flaws in common building scenarios.

Hosting with free HTTPS in 5 minutes

Aim of this post is to create hosting for your web application (or blog or webpage or anything-what-hosting-is-for) with free SSL certificate, so your page can be accessed securely with HTTPS. Certificate creation and renewal is going to be fully automated and adding new website is as simple as adding another Docker container.

This solution uses Let’s Encrypt certificates and is based on Docker containers.

Spring Boot Admin inside Docker

Spring Boot Admin is great tool to manage and monitor your Spring Boot Applications. As the famous idiom says, a picture is worth a thousand words.

It offers really cool features and it is very easy to install, but… it gets bit more complicated when you have all your applications in Docker and want to run Spring Boot Admin in Docker as well.

If you use Spring Cloud supported service discovery solution like Netflix Eureka, Zookeeper or Consul you can probably run Spring Boot Admin within this service discovery and you are good to go. Find more about it in documentation.

In this post I will describe what you need to do if you are not using any of these service discovery tools and want to run Spring Boot Admin as Docker container along with you other Spring Boot applications.

Why to use Spock

From Spock documentation:

Spock is a testing and specification framework for Java and Groovy applications. What makes it stand out from the crowd is its beautiful and highly expressive specification language.

Spock in an amazing testing framework, which I believe is a better replacement for JUnit library. Using Spock will make your tests not only easier to write, but what is more important, it will make them easier to read and understand their results.

What could be the biggest challenges to switch from JUnit to Spock:

  1. Spock is using Groovy (not Java) so you need to learn new language.
  2. Spock is not JUnit so it is not compatible with other software (i.e. IDE, build tools, continuous integration tools).

Fortunatelly, the above statements are false!

Definition of Done

It is not always clear what are the requirements for the task to be considered „done”. Each team member might have slightly different understanding of „done” which is build gradually with gaining experience in the team. This can sometimes cause miscommunication and misleading perception of functionality as being production ready. From the team member perspective (especially someone new in the team) it is hard to tell if all the work required for the task, has been completed.

There is a solution for this issue called „Definition of Done” which is well known Agile methodology tool.

Date and time in Java – java.util.Date and java.time.Instant

I have lately discovered, I wasn’t fully aware how date and time works in Java. In my current project we are using date and time quite heavily, but until recently we were on Java 7 and we have used java.util.Date and Joda-Time library.

Recently things have changed when we’ve started a new project using Java 8 with brand new and shining Date and Time API (JSR 310). Because we are integrating our application with external system which API library was using old java.util.Date, we had to convert data between old java.util.Date and new date and time Java API.

Editable HTML element with AngularJS and HTML5 contentEditable attribute

There is a new attribute in HTML5 „contentEditable”. It allows user to edit content of the website elements like „span” or „div”. It might be very useful when you need to make some element editable only in the specific circumstances.

In my TaskRoo project I am using „contentEditable” with AngularJS to make tasks names editable in-place with the double-click.

In this post I will describe how to implement and use AngularJS directive to make HTML element editable in-place. In case you are just looking for solution, you can find complete implementation on plunker:

http://plnkr.co/edit/Yt4bFd9mF9iwZirtWvYg?p=preview

Null sucks

I know there are already many articles in this topic, but sometimes looking into the codebase, I feel it is still not emphasised enough. This post purpose is to explain why null reference is undesired in clean code. I would like this post to clearly answer why „null” should be avoided if you care about quality of your code.

Game of Life on Global Day of Coderetreat 2014

Last Saturday I took part in the Global Day of Coderetreat 2014 (GDCR2014) in Aspect Capital, London. GDCR is an amazing event organised every year since last 6 years. This year it was organised in 44 countries, 141 cities with about 2500 developers participating. Long story short – on GDCR there is a simple programming problem to solve: Conway’s Game of Life. The aim is to learn as much as possible and not necessarily solve the problem.

Groovy coding conventions

At work we are using Groovy language to write the Cucumber acceptance tests. Groovy turns out to be very nice language with flat learning curve for Java developer. There are many interesting features in the language, but I believe some of them have to be used with caution.

As we work more with Groovy and learn more of its features we found there are many ways of doing the same thing. It is useful, because it makes code more expressive, but it can also be an issue when there are multiple developers working on the same code base. This problem most probably exists in every programming language and it can be partially solved by agreeing on the coding conventions. Unfortunately there is no established code convention for Groovy yet as there are for other languages like Java.

In this post I list some features of the Groovy language and try to choose a convention to use. Of course this is not the only correct approach. This is more a try to orginise the conventions and keep it for future reference.

Save and restore session of the Gnome Terminal

INFO: Unfortunately „–save-config” option is no longer supported in the new versions of gnome-terminal so this script will not work.

I use terminal quite often in my work. I have a specific way how I work with terminal. I usually have about 10 tabs open in different directories so I can quickly switch between them. I felt quite frustrated when I was in the middle of something, but I had to reboot the PC for some reason. It is because it means I would need to set-up my perfect multi-tab terminal from scratch.

Fortunately I found very easy solution for this issue. This article describes easy way to save and restore the terminal session.

A bit about Java code conventions

Most commonly used set of Java coding conventions comes from Sun Microsystems and it is still available on Oracle website. The document describes many important aspects of formatting, naming conventions etc for Java.

However, for most of the teams it is not enough for two major reasons. First of all, the document has become quite outdated in some cases as it is has been created back in 1999. Things like maximum of 80 characters per line, when most of us use full HD monitors, does not seem right. The other reason is that Sun’s code conventions still leaves a lot of freedom and it is easier to maintain and read the code written in the similar fashion. This is why many teams decide to create additional code conventions on top of the Sun’s document adding more specific things.

In this post I am discussing two of the Java code conventions which are not part of the mentioned official Java code convention, but which are often added on top of it. These two are: keep all variables in the code as „final” and using „this” for every field and method access in class.

ScalaTest with Maven

With multiple languages working on the same JVM now, it is possible (and easy) to use different languages for your production and test code.

Why not to take this opportunity when it can be easier and faster to write test code. This can be also a good way to learn a new language. You can keep your production code using the language you are the most comfortable with and write your tests in Scala or Groovy.

This post describes how to configure Maven project to use Java as a production code language and Scala with a ScalaTest framework for unit tests.

Eclipse Juno toolbar problems

I have moved lately with my IDE to the newest Juno Eclipse. I do not want to write much about the whole default UI appearance in new Eclipse because enough has been written already probably. The first thing to do on new Eclipse is to change theme of Eclipse to Classic one and restart it. Then it starts to be usable and look quite good. However I still had one problem because of using Eclipse on a small notebook display.

Owncloud – instalacja i aktualizacja

Owncloud to aplikacja, która umożliwia utrzymywanie swoich plików, kontaktów i kalendarzy w prywatnej chmurze. Owncloud do działania potrzebuje tylko PHP i MySQL (lub SQLite). Większość osób najprawdopodobniej kojarzy Dropbox, który ma bardzo podobny sposób działania. Owncloud wyróżnia się tym, że możemy go zainstalować na własnym serwerze dzięki czemu nie musimy polegać na firmie, która będzie zarządzać naszymi danymi. Instalacja z konsoli, na serwerze, na którym jest zainstalowany Apache wraz PHP i MySQL jest banalnie prosta i opiera się na pobraniu odpowiednich plików z repozytorium GIT.

EasyMock dla nieznanych parametrów – matchers

W poprzednim poście pokrótce opisałem sposób działania EasyMock. W tym poście chciałbym skupić się na jednej z możliwości tej biblioteki. Podczas testowania zdarzają się przypadki kiedy wiemy, że dana metoda obiektu zostanie wywołana i jaki wynik powinna zwrócić dla naszych testów, ale nie chcemy (albo nie jesteśmy w stanie) dokładnie analizować jakie parametry wywołania otrzyma. W takim właśnie przypadku możemy użyć matcher’ów EasyMock’a. Wiedząc, że na mock’owanym obiekcie zostanie wywołana metoda xyz(String,int,long), równocześnie nie znając dokładnych wartości parametrów możemy przygotować mock na przyjęcie różnych parametrów.

EasyMock – łatwy sposób na testy jednostkowe

EasyMock to biblioteka języka Java, która umożliwia tworzenie obiektów w locie i wykorzystywanie ich jako mock’ów (imitacji prawdziwych obiektów). Dzięki tej możliwości testowanie jednostkowe może być o wiele prostsze, ponieważ możemy zastąpić prawdziwe, często ciężkie obiekty przez mock’i. Dodatkowo pozwala nam się to skupić na testowaniu jednej klasy podczas gdy zachowanie obiektów innych klas możemy dokładnie zaplanować. Przykładowo mając klasę: `Chcąc przetestować działanie metody start() trzeba zapewnić silnik i komputer pokładowy dla samochodu.

Zasady zdawania egzaminu na Sun Certified Java Programmer

Egzamin certyfikujący Sun Certified Java Programmer to potwierdzenie wysokich umiejętności i profesjonalizmu w programowaniu w języku Java. Egzamin można zdać w jednym z centrów certyfikacyjnych, których lista jest dostępna na stronie firmy Prometric. Aby zdać egzamin należy odpowiedzieć prawidłowo na przynajmniej 35 z 60 pytań wielokrotnego wyboru. Na rozwiązanie testu mamy 180 minut. Zakres materiału egzaminacyjnego został podzielony na 7 części: Deklaracje Kontrola sterowania API Wątki Obiektowość Kolekcje i typy generyczne Podstawy

Web developement – alternatywa dla PHP

Jeśli chodzi o programowanie aplikacji internetowych to nie jest tajemnicą, że niepodzielnie żądzi tu nieśmiertelny język PHP obecny aktualnie w wersji 5. Niestety prawdą jest też, że w wielu aspektach jest to język przestarzały i nieprofesjonalny. Taki stan rzeczy zmieniają nieco frameworki takie jak Symfony, CodeIgniter czy wreszcie Zend Framework tworzony przez tą samą firmę która zajmuje sie rozwojem samego PHP. Mimo wszystko, po dłuższym używaniu PHP i spróbowaniu nieco (Symfony, CodeIgniter), lub nieco bardziej (ZF) frameworków do niego oceniam, że jest to język któremu daleko do uporządkowania i profesjonalizmu znanego z języków wysokiego poziomu używanych do pisania aplikacji desktopowych (Java, C++).

I'm Linux!

Linux Foundation startuje z kampanią reklamową, a właściwie konkursem, mającym promować systemy Linux. Kampania „I’m Linux” ma być odpowiedzią linuksowego świata na wcześniejsze akcje promocyjne „I’m Mac” oraz „I’m PC”. Linux Fundation zachęca wszystkich do nadsyłania filmików związanych z zaletami systemów Linux. W zamian, na twórcę najlepszego filmu czeka wylot i konferencja Linux Foundation Japan Symposium w grudniu 2009. Tutaj można umieszczać filmy, a także zdobyć więcej informacji na temat konkursu.

Opera 10 Alpha (Peregrino)

Trzeciego grudnia światło ujrzała pierwsza wersja alpha przeglądarki Opera 10 o nazwie kodowej – Peregrino. Nowa Opera wprowadza kilka nowych udogodnień przeglądarki, nowe funkcjonalności klienta pocztowego, a co ważniejsze – będzie posiadać uaktualniony silnik Presto w wersji 2.2. Nowy silnik ma znacząco przyspieszyć renderowanie stron i już teraz przechodzi w 100% test ACID3. Umożliwia to tworzenie świetnych efektów na stronach bez użycia obrazów, przy użyciu czcionek True Type oraz kaskadowych styli CSS.

Odczytywanie informacji o pamięci operacyjnej w systemach Linux

Informację na temat zainstalowanej w naszym sprzęcie pamięci można otrzymać z systemu na kilka sposobów.

Pierwszy to odczytanie informacji z pliku meminfo znajdującego się w kartotece /proc/

$ cat /proc/meminfo

MemTotal: 1025648 kB

MemFree: 26272 kB

Buffers: 48304 kB

Cached: 321696 kB

SwapCached: 56 kB

Active: 633540 kB

Inactive: 178652 kB

HighTotal: 121728 kB

HighFree: 252 kB

LowTotal: 903920 kB

LowFree: 26020 kB

SwapTotal: 1052216 kB

SwapFree: 1052124 kB

Dirty: 80 kB

Writeback: 0 kB

AnonPages: 440256 kB

Mapped: 129824 kB

Slab: 34584 kB

SReclaimable: 21204 kB

SUnreclaim: 13380 kB

PageTables: 7004 kB

NFS_Unstable: 0 kB

Bounce: 0 kB

CommitLimit: 1565040 kB

Committed_AS: 1008220 kB

VmallocTotal: 110584 kB

VmallocUsed: 12668 kB

VmallocChunk: 97268 kB

HugePages_Total: 0

HugePages_Free: 0

HugePages_Rsvd: 0

HugePages_Surp: 0

Hugepagesize: 2048 kB

Odczytanie informacji o procesorze w systemach Linux

Doszło do tego że potrzebowałem uzyskać jak najwięcej informacji o swoim procesorze. Przy tym musiałem szczególnie skupić się na częstotliwości procesora oraz jego wielkości jego pamięci cache.

Najprostszym sposobem uzyskania informacji na temat procesora w systemach linux jest odczytanie informacji z pliku /proc/cpuinfo . Plik ten dotarcza całkiem sporo informacji na temat procesora: