Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build Code for Java 6 and test it against all JAVA_HOME* environments #123

Merged
merged 17 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
def branchPattern = /v\d+\.\d+\.\d+.*/
def targetCompatibilities = [6, 7, 8]
def currentVersion = readVersion('version.properties')
def buildVersion = currentVersion + "-b" + env.BUILD_NUMBER
def jvmsToTest = ["JAVA_HOME","JAVA_HOME_6","JAVA_HOME_7","JAVA_HOME_8"]

properties([
buildDiscarder(logRotator(numToKeepStr: '10'))
Expand All @@ -11,14 +12,11 @@ timeout(time: 15, unit: 'MINUTES') {
stage('Checkout') {
checkout scm

def currentVersion = sh script: printVersion(), returnStdout: true
currentBuild.displayName += " - ${currentVersion}"
currentBuild.displayName += " - ${buildVersion}"
}

stage('Build') {
parallel (targetCompatibilities.collectEntries {[
'Java ' + it, createBuildTask(it)
]})
parallel (['Java': createBuildTask(jvmsToTest.join(","),currentVersion)])
}

echo "Branch: ${env.BRANCH_NAME}"
Expand All @@ -36,18 +34,16 @@ timeout(time: 15, unit: 'MINUTES') {
}
}

def createBuildTask(label) {
def createBuildTask(jvmsToTest,currentVersion) {
return {
node('default') {
withEnv(["TARGET_COMPATIBILITY=${label}"]) {
echo "Build for Java ${label}"

withEnv(["JVMS_TO_TEST=${jvmsToTest}"]) {
checkout scm

gradlew "clean assemble compileTestJava --parallel"
gradlew "-Pversion=${currentVersion} clean assemble compileTestJava --parallel"

try {
gradlew "check --continue --parallel"
gradlew "-Pversion=${currentVersion} check --continue --parallel"
} finally {
junit testResults: '**/build/test-results/test/TEST-*.xml', keepLongStdio: false
archiveArtifacts artifacts: '**/build/reports/**'
Expand All @@ -64,11 +60,3 @@ def copy(String source, String destination) {
bat "copy ${source} ${destination}"
}
}

def printVersion() {
if (isUnix()) {
return "./gradlew -q printVersion"
} else {
return "gradlew.bat -q printVersion"
}
}
38 changes: 21 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ buildscript {
}
dependencies {
classpath 'nl.javadude.gradle.plugins:license-gradle-plugin:0.11.0'
classpath 'ru.vyarus:gradle-animalsniffer-plugin:1.3.0'
classpath 'ru.vyarus:gradle-animalsniffer-plugin:1.4.6'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2'
}
}

group 'com.dynatrace.openkit'
version '1.3.0-SNAPSHOT'
version '${version}'

def groupString = group
def title = 'Dynatrace OpenKit SDK for Java'
Expand All @@ -30,10 +30,11 @@ repositories {
mavenCentral()
}

def target = System.getenv("TARGET_COMPATIBILITY") ?: "6"
def sourceTarget = "6"
def jvmsToTest = System.getenv("JVMS_TO_TEST") ?: "JAVA_HOME"

sourceCompatibility = 1.6
targetCompatibility = "1." + target
sourceCompatibility = "1." + sourceTarget
targetCompatibility = "1." + sourceTarget

dependencies {
signature 'org.codehaus.mojo.signature:java16:1.1@signature'
Expand All @@ -42,14 +43,10 @@ dependencies {
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
}

test {
exclude '**/local/*.class'
}

jar {
baseName = 'openkit'
if (System.getenv('TRAVIS') != null) {
classifier = 'java' + target
classifier = 'java' + sourceTarget
}

// split version into specification & implementation version
Expand Down Expand Up @@ -145,13 +142,20 @@ publishing {
}
}

task printVersion {
doLast {
def buildNumber = System.getenv()['BUILD_NUMBER']
if (buildNumber != null) {
logger.quiet "${version}-b${buildNumber}"
} else {
logger.quiet version
// run each test for every JAVA_HOME_* environment which is specified and set as environment
[[sourceTarget], jvmsToTest.split(",")].combinations { targetJVM, envJVM ->
if(System.getenv(envJVM) != null) {
def configName = "${targetJVM}-${envJVM}"
task "test-${configName}"(type: Test) {
exclude '**/local/*.class'
executable = System.getenv(envJVM) + "/bin/java"
}
tasks.test.dependsOn tasks."test-${configName}"
} else {
logger.quiet("Can't find " + envJVM + ". Test ignored!")
}
}

test {
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Tue Nov 14 10:24:51 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-rc-2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-bin.zip
6 changes: 3 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
Expand Down Expand Up @@ -155,7 +155,7 @@ if $cygwin ; then
fi

# Escape application args
save ( ) {
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
Expand Down
1 change: 1 addition & 0 deletions version.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version=1.3.0-SNAPSHOT