JDriven Blog

Kotlin Kandy: Padding Strings

Posted on by  
Hubert Klein Ikkink

Kotlin extends the String class with a couple of padding methods. These methods allows us to define a fixed width a string value must occupy. If the string itself is less than the fixed width then the space is padded with spaces or any other character we define. We can pad to the left or the right of the string using the padStart and padEnd methods. When we don’t define an argument a space character is used for padding, but we can also add our own custom character as argument that will be used as padding character.

Continue reading →

Kotlin Kandy: Strip Leading Spaces From Multiline Strings

Posted on by  
Hubert Klein Ikkink

Multiline strings are very useful. But sometimes we want use the multiline string without the leading spaces that are added because of code formatting. To remove leading spaces we can use the trimIndent method. This method will find the least amount of leading spaces and removes that amount of spaces from each line. Also a first and last empty line are removed.

If we want a bit more control we can also add a character to the start of each line to show where the line starts. And then we use the method trimMargin and all spaces before that character are removed. The default character is the pipe symbol, |, but we can also define our own and pass it as argument to the trimMargin method.

Continue reading →

Kotlin Kandy: Transforming Collection Items With Index

Posted on by  
Hubert Klein Ikkink

If we want to transform items in a collection we can use the map method. If we also want to use the index of the element in the collection in the transformation we must use the mapIndexed method. We must provide a lambda function with 2 arguments, where the first argument is the index of the element in the collection and the second argument is the element in the collection.

Continue reading →

Gradle Goodness: Configure Test Task With JVM Test Suite

Posted on by  
Hubert Klein Ikkink

The JVM Test Suite plugin is part of the Java plugin and provides a nice way to configure multiple test types in our build file. Even if we don’t have multiple test types we have a default test type, which is used when we run the Gradle test task. Using the test suite DSL we can configure the task of type Test that belongs to a test suite type. The current release of the JVM Test Suite plugin provides a single target for a test suite type with a single Test task. This will probably change in future releases of the plugin so more task of type Test can be created and configured.

Continue reading →

How to change your C# class template in Visual Studio 2022 to use the new file scoped namespaces

Posted on by  
Alexander Chatzizacharias

In C# version 10, support for file scoped namespaces was added. This allows us to eliminate more boilerplate from our classes and also get rid of some extra unneeded identation. Unfortunately, when you create a new C# class in Visual Studio 2022, the template still uses the old namespace declaration style. I don’t like that, and if you found this blogpost, neither do you!

Thankfully, changing this is not hard.

Continue reading →

Gradle Goodness: Set Project Version In Version Catalog

Posted on by  
Hubert Klein Ikkink

The version catalog in Gradle is very useful to have one place in our project to define our project and plugin dependencies with their versions. But we can also use it to define our project version and then refer to that version from the version catalog in our build script file. That way the version catalog is our one place to look for everything related to a version. In the version catalog we have a versions section and there we can define a key with a version value. The name of the key could be our project or application name for example. We can use type safe accessors generated by Gradle in our build script to refer to that version.

Continue reading →

Gradle Goodness: Add Extra Dependencies For Running Tests Using JVM Test Suite Plugin

Posted on by  
Hubert Klein Ikkink

The JVM Test Suite plugin adds an extension to our build that allows us to configure test tasks. We always can access the default test task and for example specify the test framework we want to use. Gradle will then automatically add the dependencies of that test framework to the testImplementation configuration. If we want to add more dependencies to the testImplementation configuration we don’t have to do that by explicitly mentioning the testImplementation configuration. Instead we can also use a dependencies block from within the JvmTestSuite extension. Any extra dependencies we need to run our tests can be added using the configuration names without a test prefix. Gradle will automatically add them to the correct test configuration for us so the dependencies are available when we compile and run our tests. This will also work for any other new test type we add to the test suites, e.g. for integration tests.

Continue reading →

DataWeave Delight: Turn String Into Snake Case With underscore

Posted on by  
Hubert Klein Ikkink

In a previous post we learned we can turn a string into a string with kebab casing using dasherize from the dw::core::Strings module. If we want to turn a string into a string with camel casing we can use the underscore function. The underscore function will replace spaces, dashes and camel-casing with underscores, which makes the result snake-casing. Any uppercase characters are transformed to lowercase characters.

Continue reading →

Change Log Level For Events In Keycloak

Posted on by  
Hubert Klein Ikkink

When running Keycloak it can be useful to log events like a login or logout event using the jboss-logging event listener. This is a built-in event listener that will use JBoss logging to log events. For example we can configure our JBoss logging to log to the standard output streams and when we run Keycloak we can see in the console output details about events when they happen. The event listener jboss-logging is enabled by default for a realm. We can check it from the Events Config page where it is listed in the Event Listeners field.

Continue reading →

shadow-left