diff --git a/.gitignore b/.gitignore index 09ab494393..5267dfa417 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Mac +.DS_Store + # Intellij *.iml *.ipr diff --git a/.travis.yml b/.travis.yml index 43f616aa7b..3ba1dbfa39 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,6 +34,9 @@ matrix: env: SKIP_RELEASE=true - jdk: openjdk11 env: SKIP_RELEASE=true MOCK_MAKER=mock-maker-inline + - jdk: openjdk8 + script: ./check_reproducibility.sh + after_success: true branches: #Don't build tags @@ -50,9 +53,9 @@ script: # We are using && below on purpose # ciPerformRelease must run only when the entire build has completed # This guarantees that no release steps are executed when the build or tests fail - - ./gradlew spotlessCheck && ./gradlew build idea -s && ./gradlew checkReproducibility && ./gradlew ciPerformRelease + - ./gradlew spotlessCheck && ./gradlew build idea -s && ./gradlew ciPerformRelease after_success: #Generates coverage report: - - ./gradlew coverageReport -Pjacoco -s --scan && cp build/reports/jacoco/mockitoCoverage/mockitoCoverage.xml jacoco.xml || echo "Code coverage failed" + - ./gradlew coverageReport -s --scan && cp build/reports/jacoco/mockitoCoverage/mockitoCoverage.xml jacoco.xml || echo "Code coverage failed" - bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports" diff --git a/build.gradle b/build.gradle index 5009dc14bd..beafbf2693 100644 --- a/build.gradle +++ b/build.gradle @@ -15,10 +15,10 @@ buildscript { } plugins { - id 'com.gradle.build-scan' version '2.2.1' id "com.diffplug.gradle.spotless" version "3.24.3" id 'eclipse' id 'com.github.ben-manes.versions' version '0.28.0' + id 'biz.aQute.bnd.builder' version '5.1.0' } description = 'Mockito mock objects library core API and implementation' @@ -43,7 +43,6 @@ apply from: 'gradle/root/coverage.gradle' apply from: 'gradle/mockito-core/inline-mock.gradle' apply from: 'gradle/mockito-core/osgi.gradle' apply from: 'gradle/mockito-core/javadoc.gradle' -apply from: 'gradle/mockito-core/reproducible-build.gradle' apply from: 'gradle/mockito-core/testing.gradle' apply from: 'gradle/dependencies.gradle' @@ -104,12 +103,6 @@ wrapper { distributionSha256Sum = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' } -//Posting Build scans to https://scans.gradle.com -buildScan { - termsOfServiceUrl = 'https://gradle.com/terms-of-service' - termsOfServiceAgree = 'yes' -} - spotless { java { licenseHeaderFile rootProject.file('config/spotless/spotless.header') diff --git a/check_reproducibility.sh b/check_reproducibility.sh new file mode 100755 index 0000000000..9352def942 --- /dev/null +++ b/check_reproducibility.sh @@ -0,0 +1,26 @@ +#!/bin/bash -e + +# This script is taken from https://github.com/junit-team/junit5/pull/2217 + +rm -rf checksums/ +mkdir checksums/ + +export SOURCE_DATE_EPOCH=$(date +%s) + +function calculate_checksums() { + OUTPUT=checksums/$1 + + ./gradlew --no-build-cache clean assemble --parallel + + find ./build -name '*.jar' \ + | grep '/build/libs/' \ + | grep --invert-match 'javadoc' \ + | sort \ + | xargs sha256sum > ${OUTPUT} +} + + +calculate_checksums checksums-1.txt +calculate_checksums checksums-2.txt + +diff checksums/checksums-1.txt checksums/checksums-2.txt \ No newline at end of file diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 6f57f1f41c..8fc97e4c92 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -34,15 +34,10 @@ libraries.osgi = 'org.osgi:osgi.core:7.0.0' libraries.equinox = 'org.eclipse.platform:org.eclipse.osgi:3.15.0' libraries.bndGradle = 'biz.aQute.bnd:biz.aQute.bnd.gradle:4.3.1' -def kotlinVersion = '1.2.10' -def kotlinVersion_1_3 = '1.3.0-rc-57' +def kotlinVersion = '1.3.72' libraries.kotlin = [ version: kotlinVersion, - version_1_3: kotlinVersion_1_3, stdlib: "org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}", - coroutines: 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.19.3', - - stdlib_1_3: "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion_1_3", - releaseCoroutines: "org.jetbrains.kotlinx:kotlinx-coroutines-core:0.26.1-eap13" + coroutines: 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7', ] diff --git a/gradle/mockito-core/osgi.gradle b/gradle/mockito-core/osgi.gradle index 9ed59f8363..41f1902b45 100644 --- a/gradle/mockito-core/osgi.gradle +++ b/gradle/mockito-core/osgi.gradle @@ -7,49 +7,36 @@ import java.util.jar.Manifest import static java.util.Calendar.FEBRUARY -apply plugin: 'osgi' - -afterEvaluate { - tasks.matching { it.name == 'jar' }.all { jar -> - jar.manifest { - classpath = project.configurations.runtime - - instruction '-versionpolicy', '[${version;==;${@}},${version;+;${@}})' - - name = 'Mockito Mock Library for Java. Core bundle requires Byte Buddy and Objenesis.' - symbolicName = 'org.mockito.mockito-core' - version = project.version.replace('-', '.') - - instruction 'Export-Package', - '!org.mockito.internal.*', - "org.mockito.*;version=${version}" - - instruction 'Import-Package', - 'net.bytebuddy.*;version="[1.6.0,2.0)"', - 'junit.*;resolution:=optional', - 'org.junit.*;resolution:=optional', - 'org.hamcrest;resolution:=optional', - 'org.objenesis;version="[2.5,3.0)"', - 'org.opentest4j.*;resolution:=optional', - 'org.mockito.*' - - instruction 'Private-Package', - 'org.mockito.*' - - instruction '-removeheaders', 'Private-Package' - - attributes 'Automatic-Module-Name': 'org.mockito' - } - - jar.doLast { - JarFile originalJar = new JarFile(jar.archivePath) +apply plugin: 'biz.aQute.bnd.builder' + +jar { + classpath = project.configurations.runtime + bnd( + 'Bundle-Name': 'Mockito Mock Library for Java. Core bundle requires Byte Buddy and Objenesis.', + 'Bundle-SymbolicName': 'org.mockito.mockito-core', + 'Bundl-version': project.version.replace('-', '.'), + '-versionpolicy': '[${version;==;${@}},${version;+;${@}})', + 'Export-Package': "!org.mockito.internal.*,org.mockito.*;version=${version}", + 'Import-Package': [ + 'net.bytebuddy.*;version="[1.6.0,2.0)"', + 'junit.*;resolution:=optional', + 'org.junit.*;resolution:=optional', + 'org.hamcrest;resolution:=optional', + 'org.objenesis;version="[2.5,3.0)"', + 'org.opentest4j.*;resolution:=optional', + 'org.mockito.*' + ].join(','), + '-removeheaders': 'Private-Package', + 'Automatic-Module-Name': 'org.mockito' + ) +} - new RemoveOsgiLastModifiedHeader(originalJar) - .transform() - .renameTo jar.archivePath - } +jar.doLast { + JarFile originalJar = new JarFile(jar.archivePath) - } + new RemoveOsgiLastModifiedHeader(originalJar) + .transform() + .renameTo jar.archivePath } diff --git a/gradle/mockito-core/reproducible-build.gradle b/gradle/mockito-core/reproducible-build.gradle deleted file mode 100644 index bb513706ab..0000000000 --- a/gradle/mockito-core/reproducible-build.gradle +++ /dev/null @@ -1,69 +0,0 @@ -import java.security.DigestInputStream -import java.security.MessageDigest - -/* - * The `checkReproducibility` task compares two sets of checksums, generated - * in two independent builds, from non-javadoc output archives. - * - * This task ensures that a change has not regressed the reproducibility of - * the Mockito project and its subprojects. - */ - -task checkReproducibility { - doLast { - def first = new File("checksums", "checksums-1.txt").text.split('\n') - def second = new File("checksums", "checksums-2.txt").text.split('\n') - - assert first.sort() == second.sort() - } -} - -task getChecksums1(type: GradleBuild) { - tasks = ['clean', 'assemble'] - startParameter.projectProperties = ['build-id': "1"] -} - -task getChecksums2(type: GradleBuild) { - tasks = ['clean', 'assemble'] - startParameter.projectProperties = ['build-id': "2"] -} - -getChecksums2.dependsOn(getChecksums1) -checkReproducibility.dependsOn(getChecksums2) - -if (project.hasProperty('build-id')) { - - String id = project.getProperty('build-id') - - mkdir "checksums" - - File checksums = new File("checksums", "checksums-${id}.txt") - checksums.delete() - - afterEvaluate { - - ([project] + subprojects).each { p -> - - p.tasks.withType(AbstractArchiveTask) { task -> - - if (!task.name.contains('javadoc')) { - task.doLast { - File output = task.archiveFile.get().getAsFile() - - checksums << "${output.name},${calculateHash(output)}\n" - } - } - } - } - - } -} - -static def calculateHash(File file) { - file.withInputStream { - new DigestInputStream(it, MessageDigest.getInstance("SHA-256")).withStream { - it.eachByte {} - it.messageDigest.digest().encodeHex() as String - } - } -} diff --git a/gradle/root/coverage.gradle b/gradle/root/coverage.gradle index 03ec3883e6..5e973c0db8 100644 --- a/gradle/root/coverage.gradle +++ b/gradle/root/coverage.gradle @@ -1,16 +1,18 @@ -if (!project.hasProperty("jacoco")) { - //JaCoCo plugin prevents using Build Cache. We will enable jacoco configuration only when specific property is supplied - //TODO remove this workaround when we migrate to Gradle 5.0 (https://github.com/gradle/gradle/issues/5269) - logger.info "JaCoCo code coverage will not be configured because 'jacoco' project property is not present." - return //don't evaluate this Gradle file any further -} else { - logger.lifecycle "Configuring JaCoCo code coverage because 'jacoco' project property is present." -} - -//TODO: Standard JaCoCo coverage doesn't work in Android module task mockitoCoverage(type: JacocoReport) { allprojects { currentProject -> + // These tests do not have a `test` task. + if (currentProject.name in ['android']) { + return + } + // We only run these tests on Java 9+ + if (currentProject.name in ['module-test'] && !JavaVersion.current().isJava9Compatible()) { + return + } + // We only run these tests on Java 8 + if (currentProject.name in ['errorprone'] && JavaVersion.current().isJava9Compatible()) { + return + } plugins.withId("java") { mockitoCoverage.sourceSets currentProject.sourceSets.main diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 0d4a951687..5c2d1cf016 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ea13fdfd19..9fe9d37d43 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.3.1-bin.zip +distributionSha256Sum=e58cdff0cee6d9b422dcd08ebeb3177bc44eaa09bd9a2e838ff74c408fe1cbcd +distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index cccdd3d517..b0d6d0ab5d 100755 --- a/gradlew +++ b/gradlew @@ -1,5 +1,21 @@ #!/usr/bin/env sh +# +# Copyright 2015 the original author or authors. +# +# 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, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + ############################################################################## ## ## Gradle start up script for UN*X @@ -28,7 +44,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" diff --git a/gradlew.bat b/gradlew.bat index f9553162f1..9991c50326 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem http://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome diff --git a/settings.gradle.kts b/settings.gradle.kts index fdd9f374fb..be0e981f7f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -34,6 +34,18 @@ rootProject.children.forEach { project -> } } +plugins { + id("com.gradle.enterprise").version("3.3.4") +} + +//Posting Build scans to https://scans.gradle.com +gradleEnterprise { + buildScan { + termsOfServiceUrl = "https://gradle.com/terms-of-service" + termsOfServiceAgree = "yes" + } +} + buildCache { local { isEnabled = !System.getenv().containsKey("CI") diff --git a/subprojects/kotlinReleaseCoroutinesTest/kotlinReleaseCoroutinesTest.gradle b/subprojects/kotlinReleaseCoroutinesTest/kotlinReleaseCoroutinesTest.gradle index 0812f26b35..d3c809ff5e 100644 --- a/subprojects/kotlinReleaseCoroutinesTest/kotlinReleaseCoroutinesTest.gradle +++ b/subprojects/kotlinReleaseCoroutinesTest/kotlinReleaseCoroutinesTest.gradle @@ -4,7 +4,7 @@ buildscript { maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } } dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${libraries.kotlin.version_1_3}" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${libraries.kotlin.version}" } } @@ -21,6 +21,6 @@ dependencies { testCompile project(":") testCompile libraries.junit4 - testCompile libraries.kotlin.stdlib_1_3 - testCompile libraries.kotlin.releaseCoroutines + testCompile libraries.kotlin.stdlib + testCompile libraries.kotlin.coroutines } diff --git a/subprojects/kotlinTest/kotlinTest.gradle b/subprojects/kotlinTest/kotlinTest.gradle index 38eb74b166..9e40101a52 100644 --- a/subprojects/kotlinTest/kotlinTest.gradle +++ b/subprojects/kotlinTest/kotlinTest.gradle @@ -1,17 +1,11 @@ plugins { // Can not use libraries.kotlin.version here per https://stackoverflow.com/questions/37555196/in-gradle-how-to-use-a-variable-for-a-plugin-version - id 'org.jetbrains.kotlin.jvm' version '1.2.31' + id 'org.jetbrains.kotlin.jvm' version '1.3.72' id 'java' } description = "Kotlin tests for Mockito." -kotlin { - experimental { - coroutines "enable" - } -} - apply from: "$rootDir/gradle/dependencies.gradle" dependencies { diff --git a/subprojects/kotlinTest/src/test/kotlin/org/mockito/kotlin/SuspendTest.kt b/subprojects/kotlinTest/src/test/kotlin/org/mockito/kotlin/SuspendTest.kt index bfef4071e4..85131ac6f8 100644 --- a/subprojects/kotlinTest/src/test/kotlin/org/mockito/kotlin/SuspendTest.kt +++ b/subprojects/kotlinTest/src/test/kotlin/org/mockito/kotlin/SuspendTest.kt @@ -4,7 +4,7 @@ */ package org.mockito.kotlin -import kotlinx.coroutines.experimental.runBlocking +import kotlinx.coroutines.runBlocking import org.hamcrest.core.IsEqual import org.junit.Assert.assertThat import org.junit.Test