Skip to content

Instantly share code, notes, and snippets.

@aslakknutsen
aslakknutsen / start_testing_java8_today.asciidoc
Last active October 11, 2023 20:07
Example of how to use both JDK 7 and JDK 8 in one build.

JDK 8 Released

Most of us won’t be able to use/deploy JDK 8 in production for a looong time. But that shouldn’t stop us from using it, right?

It should be possible to sneak in JDK 8 in the back way, the same way we snuck in Groovy and other libraries we wanted to use.

The Test Suite to the rescue

The Maven compiler plugin run in two separate lifecycles, compile and testCompile. Those can be configured separately.

@aslakknutsen
aslakknutsen / blog.md
Created April 19, 2012 16:25
Import your project's history in Sonar

When you do your first Sonar run on your project, you get a lot of new quality numbers to play with, but no trends. You only have one data set for comparison, the now picture.

Wouldn't it be nice if you could see the current trend of the project without waiting a couple of month for the 'daily/weekly' Sonar runs to fill up the data? Well, you're in luck! And if you're using git as a version system as well, this is your day. :)

In the Sonar Advanced Parameter documentation you will find a System Property called sonar.projectDate. The property let you tell Sonar when in time the running analysis was ran.

By combining this property and what your version system does best, track changes to source, we can now play back the history of the project as far as Sonar is concerned.

This little Bash script illustrates the concept. To spell out what it does in human readable form:

# Copyright 2018 Datawire. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,

Keybase proof

I hereby claim:

  • I am aslakknutsen on github.
  • I am aslakknutsen (https://keybase.io/aslakknutsen) on keybase.
  • I have a public key ASA0usfakObuP-k6yxY1STXfA80Ais1oIALzlZ_d27Z7AQo

To claim this, I am signing this object:

@aslakknutsen
aslakknutsen / console.log
Last active November 8, 2019 19:25
Configure Surefire to scan specific Dependencies for Test classes to include in the test run. Allows us to create reusable test jars without having to unpacking the jar content to disk and setting up testClassesDirectory configuration http://jira.codehaus.org/browse/SUREFIRE-569
[INFO]
[INFO] --- maven-surefire-plugin:2.14-SNAPSHOT:test (tck-tests) @ arquillian-jbossas-remote-6 ---
[INFO] Surefire report directory: /home/aslak/dev/source/testing/arquillian-container-jbossas/jbossas-remote-6/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.arquillian.tck.container.cdi_1_0.CDIBeanLookupWarTestCase
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.866 sec
Running org.arquillian.tck.container.servlet_2_5.MultipleWebContextLookupMultiWarTestCase
@aslakknutsen
aslakknutsen / SUREFIRE-762_AbstractSurefireMojo.patch
Created August 18, 2011 21:28
Arquillian / Surefire - Using Profiles as separation between TestCompile and TestRuntime. Binding Maven Surefire to operate on different TestRuntimes within the same Maven run
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
index f9a8db4..ea6f97c 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
@@ -34,7 +34,10 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
@aslakknutsen
aslakknutsen / template_test.go
Last active July 19, 2019 15:06
Template based json patch
func TestX(t *testing.T) {
patchs := []Patch{
Patch{
Name: "telepresence",
Template: []byte(`[
{{ if .Data.Has "/spec/template/metadata/labels/version" }}
{"op": "copy", "from": "/spec/template/metadata/labels/version", "path": "/spec/template/metadata/labels/version-source"},
{{ end }}
{"op": "replace", "path": "/metadata/name", "value": "{{.Data.Value "/metadata/name"}}-{{.NewVersion}}"},
{"op": "replace", "path": "/spec/template/spec/replicas", "value": "1"},
@aslakknutsen
aslakknutsen / vs_test.go
Last active March 6, 2019 16:15
istio API duplication on DeepCopy
import (
"testing"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
v1alpha3 "istio.io/api/networking/v1alpha3"
istionetwork "istio.io/api/pkg/kube/apis/networking/v1alpha3"
)
var objects []runtime.Object
var ctx model.SessionContext
BeforeEach(func() {
ctx = model.SessionContext{
Context: context.TODO(),
Name: "test",
Namespace: "test",
Log: logf.Log.WithName("test"),
Client: fake.NewFakeClient(objects...),
}
var objects []runtime.Object
var ctx model.SessionContext
BeforeEach(func() {
ctx = model.SessionContext{
Context: context.TODO(),
Name: "test",
Namespace: "test",
Log: logf.Log.WithName("test"),
Client: fake.NewFakeClient(objects...),
}