Skip to content

Blog

Java Sealed Classes

What is Sealed Classes?

A sealed class or interface can be extended or implemented only by those classes and interfaces permitted to do so.

A class is sealed by applying the sealed modifier to its declaration. Then, after any extends and implements clauses, the permits clause specifies the classes that are permitted to extend the sealed class.

The classes specified by permits must be located near the superclass: either in the same module (if the superclass is in a named module) or in the same package (if the superclass is in the unnamed module).

Sonarqube Integration with GitHub

After installed the sonarqube community plugin, we can analyze pull request now.

To allow sonarqube to decorate the pull request with analysis result, complete following steps,

  1. Create a github app and configure the github app in sonarqube global setting following guide github-integration
  2. Install the created github app to your repositories that need to integrate with sonarqube following guide installing-github-apps

Using Sonarqube Community Branch plugin

The Sonarqube community edition, doesn't support analyzing branch or pull request.

However, there is a plugin to support branch analysis for Sonarqube community version.

To install this plugin, you need to download the compatiablity version plugin for the Sonarqube you installed, take Docker version 8.9.10 as example.

For docker version installation please refer to this guide.

Run Sonarqube In Docker

  1. Start a Postgres Docker

    It needs to set the hostname for the Postgres Docker, so that the Sonarqube docker can connect it via hostname.

    Bash
    docker run --name postgres --hostname postgres -e POSTGRES_USER=<pg user> -e POSTGRES_PASSWORD=<pg password> \
      -e PGDATA=/var/lib/postgresql/data/pgdata  -e POSTGRES_HOST_AUTH_METHOD=scram-sha-256  \
      -v "$(pwd)/data":/var/lib/postgresql/data -p 5432:5432 -d --restart always postgres:alpine
    

Calculate the Fingerprint for a Certificate

We can run the following command to calculate the fingerprint for a certificate public key.

Bash
openssl x509 -fingerprint -sha256 -in /path/to/certifiacte/pem

It will show the fingerprint like,

Bash
root@Debian-11:~# openssl x509 -fingerprint -sha256 -in /etc/ssl/domain/pub.pem
SHA256 Fingerprint=7C:28:F2:79:D5:65:67:B0:A8:BC:AF:8A:DC:ED:63:9D:7F:D9:63:06:6E:B4:FD:05:4F:F1:1E:F9:7D:7F:1D:BD
...

Generate a self-signed Certificate for a Domain

We can use openssl to generate a self-signed certificate for a domain for testing puspose, and use it for Nginx or any other tools.

The following command are used to generate.

Bash
sudo mkdir /etc/ssl/domain

sudo openssl req -x509 -nodes -days 3650 -newkey rsa:4096 -keyout /etc/ssl/domain/private.pem -out /etc/ssl/domain/public.pem
It will ask several questions, you should be carefull with the common name, usually, input the domain name.

Dynamic Set Jenkins Plugin Start Parameters

Context

Recently, one of our Jenkins job which running inside docker got exception regarding to the durable task plugin.

Bash
20:07:29  process apparently never started in /path/workspace/durable-181c4c30
20:07:29  (running Jenkins temporarily with -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS=true might make the problem clearer)
20:07:29  Cannot contact Nodexxx: java.io.FileNotFoundException: /path/workspace/durable-181c4c30/output.txt (No such file or directory)