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

Better support for testing multiple variants on the Emulator #7561

Open
wants to merge 4 commits into
base: releases
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## 10.8.1 (YYYY-MM-DD)

### Enhancements
* None.
* The Realm transformer now supports the Gradle Configuration Cache. (Isse [#7299](https://github.com/realm/realm-java/issues/7299))

### Fixed
* [RealmApp] Failing to refresh the access token due to a 401/403 error will now correctly emit an error with `ErrorCode.BAD_AUTHENTICATION` rather than `ErrorCode.PERMISSION_DENIED`. (Realm Core [#4881](https://github.com/realm/realm-core/issues/4881), since 10.6.1)
Expand Down
26 changes: 16 additions & 10 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mongoDbRealmCommandServerContainer = null
emulatorContainer = null
dockerNetworkId = UUID.randomUUID().toString()
currentBranch = (env.CHANGE_BRANCH == null) ? env.BRANCH_NAME : env.CHANGE_BRANCH
isReleaseBranch = releaseBranches.contains(currentBranch)
isReleaseBranch = true // FIXME After testing releaseBranches.contains(currentBranch)
// FIXME: Always used the emulator until we can enable more reliable devices
// 'android' nodes have android devices attached and 'brix' are physical machines in Copenhagen.
// nodeSelector = (releaseBranches.contains(currentBranch)) ? 'android' : 'docker-cph-03' // Switch to `brix` when all CPH nodes work: https://jira.mongodb.org/browse/RCI-14
Expand Down Expand Up @@ -82,7 +82,7 @@ try {
def useEmulator = false
def emulatorImage = ""
def buildFlags = ""
def instrumentationTestTarget = "connectedAndroidTest"
def instrumentationTestTarget = ['connectedBaseDebugAndroidTest', 'connectedObjectServerDebugAndroidTest']
def deviceSerial = ""

if (!isReleaseBranch) {
Expand All @@ -91,7 +91,7 @@ try {
emulatorImage = "system-images;android-29;default;x86"
// Build core from source instead of doing it from binary
buildFlags = "-PbuildTargetABIs=x86 -PenableLTO=false -PbuildCore=true"
instrumentationTestTarget = "connectedObjectServerDebugAndroidTest"
instrumentationTestTargets = ['connectedObjectServerDebugAndroidTest']
deviceSerial = "emulator-5554"
} else {
// Build main/release branch
Expand All @@ -100,7 +100,7 @@ try {
useEmulator = true
emulatorImage = "system-images;android-29;default;x86"
buildFlags = "-PenableLTO=true -PbuildCore=true"
instrumentationTestTarget = "connectedAndroidTest"
instrumentationTestTargets = ['connectedBaseDebugAndroidTest', 'connectedObjectServerDebugAndroidTest']
deviceSerial = "emulator-5554"
}

Expand Down Expand Up @@ -157,16 +157,18 @@ try {
// TODO: We should wait until the emulator is online. For now assume it starts fast enough
// before the tests will run, since the library needs to build first.
sh """yes '\n' | avdmanager create avd -n CIEmulator -k '${emulatorImage}' --force"""
sh "adb kill-server" // https://stackoverflow.com/questions/56198290/problems-with-adb-exe
sh "adb start-server" // https://stackoverflow.com/questions/56198290/problems-with-adb-exe
sh "adb root"
// Need to go to ANDROID_HOME due to https://askubuntu.com/questions/1005944/emulator-avd-does-not-launch-the-virtual-device
sh "cd \$ANDROID_HOME/tools && emulator -avd CIEmulator -no-boot-anim -no-window -wipe-data -noaudio -partition-size 4098 &"
try {
runBuild(buildFlags, instrumentationTestTarget)
runBuild(buildFlags, instrumentationTestTargets)
} finally {
sh "adb emu kill"
}
} else {
runBuild(buildFlags, instrumentationTestTarget)
runBuild(buildFlags, instrumentationTestTargets)
}

// Release the library if needed
Expand Down Expand Up @@ -224,7 +226,7 @@ try {
}

// Runs all build steps
def runBuild(buildFlags, instrumentationTestTarget) {
def runBuild(buildFlags, instrumentationTestTargets) {

stage('Build') {
withCredentials([
Expand Down Expand Up @@ -321,7 +323,12 @@ def runBuild(buildFlags, instrumentationTestTarget) {
try {
backgroundPid = startLogCatCollector()
forwardAdbPorts()
gradle('realm', "${instrumentationTestTarget} ${buildFlags}")
instrumentationTestTargets.each { target ->
// Attempt to work around com.android.ddmlib.InstallException, which installing
// multiple variants for tests.
sh "adb uninstall io.realm.test || true"
gradle('realm', "${target} ${buildFlags}")
}
} finally {
stopLogCatCollector(backgroundPid)
storeJunitResults 'realm/realm-library/build/outputs/androidTest-results/connected/**/TEST-*.xml'
Expand Down Expand Up @@ -390,8 +397,7 @@ String startLogCatCollector() {
timeout(time: 1, unit: 'MINUTES') {
// Need ADB as root to clear all buffers: https://stackoverflow.com/a/47686978/1389357
sh 'adb devices'
sh """adb root
adb logcat -b all -c
sh """adb logcat -b all -c
adb logcat -v time > 'logcat.txt' &
echo \$! > pid
"""
Expand Down
19 changes: 19 additions & 0 deletions gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import org.gradle.api.internal.classpath.ModuleRegistry

buildscript {
def properties = new Properties()
properties.load(new FileInputStream("${rootDir}/../dependencies.list"))
ext.kotlin_version = properties.get('KOTLIN')

repositories {
jcenter()
Expand All @@ -11,9 +14,11 @@ buildscript {
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:${properties.get('BUILD_INFO_EXTRACTOR_GRADLE')}"
classpath "io.github.gradle-nexus:publish-plugin:${properties.get("GRADLE_NEXUS_PLUGIN")}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

apply plugin: 'kotlin'
apply plugin: 'groovy'
apply plugin: 'maven'

Expand Down Expand Up @@ -64,10 +69,24 @@ dependencies {
testCompile gradleTestKit()
testCompile 'junit:junit:4.12'
testCompile "com.android.tools.build:gradle:${props.get("GRADLE_BUILD_TOOLS")}"

// See https://github.com/gradle/gradle/issues/16774#issuecomment-893493869
def toolingApiBuildersJar = (project as ProjectInternal).services.get(ModuleRegistry.class)
.getModule("gradle-tooling-api-builders")
.classpath
.asFiles
.first()
testRuntimeOnly(files(toolingApiBuildersJar))
}

compileGroovy {
dependsOn tasks.getByPath('compileKotlin')
classpath += files(compileKotlin.destinationDir)
}

//for Ant filter
import org.apache.tools.ant.filters.ReplaceTokens
import org.gradle.api.internal.project.ProjectInternal

task generateVersionClass(type: Copy) {
from 'src/main/templates/Version.java'
Expand Down
5 changes: 4 additions & 1 deletion gradle-plugin/src/main/groovy/io/realm/gradle/Realm.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package io.realm.gradle
import com.android.build.gradle.AppPlugin
import com.android.build.gradle.LibraryPlugin
import com.neenbedankt.gradle.androidapt.AndroidAptPlugin
import io.realm.gradle.RealmPluginExtension
import io.realm.transformer.RealmTransformer
import org.gradle.api.GradleException
import org.gradle.api.Plugin
Expand Down Expand Up @@ -70,6 +69,10 @@ class Realm implements Plugin<Project> {
usesAptPlugin = true
}

// Register transformer during the evaluations phase, so the Android Plugin
// is able to pick it up. The project is passed in in order to gather various
// metadata in `project.afterEvaluate { }`, but the transformer is not allowed
// to store a reference to it if we want to support the Gradle Configuration Cache.
project.android.registerTransform(new RealmTransformer(project))

project.dependencies.add(dependencyConfigurationName, "io.realm:realm-annotations:${Version.VERSION}")
Expand Down
9 changes: 7 additions & 2 deletions realm-transformer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ dependencies {
compile gradleApi()
compile "io.realm:realm-annotations:${version}"
compileOnly "com.android.tools.build:gradle:${properties.get("GRADLE_BUILD_TOOLS")}"
compileOnly 'com.android.tools.build:gradle:3.1.1'
compile 'org.javassist:javassist:3.25.0-GA'
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlin_version}"

Expand All @@ -70,7 +69,7 @@ task generateVersionClass(type: Copy) {
outputs.upToDateWhen { false }
}

compileJava.dependsOn generateVersionClass
compileKotlin.dependsOn generateVersionClass

apply from: "${rootDir}/../mavencentral-publications.gradle"
apply from: "${rootDir}/../mavencentral-publish.gradle"
Expand All @@ -94,3 +93,9 @@ java {
withSourcesJar()
withJavadocJar()
}

compileKotlin {
kotlinOptions {
freeCompilerArgs = ["-Xinline-classes"]
}
}

This file was deleted.

Loading