Skip to content
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
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ object Versions {

const val aapt2: String = "3.2.1-4818971"

const val com_android_tools_build_gradle: String = "3.4.0-rc03"
const val com_android_tools_build_gradle: String = "3.4.0"
const val com_android_tools_build_gradle_32x: String = "3.2.1"
const val com_android_tools_build_gradle_33x: String = "3.3.2"
const val com_android_tools_build_gradle_34x: String = "3.4.0-rc03"
const val com_android_tools_build_gradle_35x: String = "3.5.0-alpha07"
const val com_android_tools_build_gradle_34x: String = "3.4.0"
const val com_android_tools_build_gradle_35x: String = "3.5.0-alpha13"

const val lint_gradle: String = "26.2.1"

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,24 @@ package de.mannodermaus.gradle.plugins.junit5

import com.android.annotations.NonNull
import com.android.build.gradle.api.BaseVariant
import com.android.build.gradle.internal.scope.InternalArtifactType
import com.android.build.gradle.internal.scope.VariantScope
import com.android.build.gradle.internal.variant.BaseVariantData
import com.android.build.gradle.tasks.factory.AndroidUnitTest
import com.annimon.stream.Optional
import com.android.builder.core.VariantTypeImpl
import org.gradle.api.Project
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.testing.jacoco.tasks.JacocoReportBase

import javax.annotation.Nullable

/**
* Utility functions exposed to Kotlin consumers
* that can't safely access Groovy members otherwise,
* or require reflection to access in a compatible manner
* across all supported versions of the Android Gradle Plugin.*/
class GroovyInterop {

// Access to UNIT_TEST was moved from VariantType to VariantTypeImpl in AGP 3.2.0-alpha06
private static final def VariantType =
reflectiveClass("com.android.builder.core.VariantTypeImpl")
.or { reflectiveClass("com.android.builder.core.VariantType") }
// Java outputs are accessed through this enum in AGP 3.2.0-alpha02
private static final def InternalArtifactType =
reflectiveClass("com.android.build.gradle.internal.scope.InternalArtifactType")

// No instances
private GroovyInterop() { throw new AssertionError() }

/**
* Attempts to look up a Class based on its FQCN, returns an empty Optional if this fails
* @param fqcn Fully qualified class name
* @return The class, or an empty Optional
*/
private static Optional<Class> reflectiveClass(String fqcn) {
try {
return Optional.of(Class.forName(fqcn))
} catch (ignored) {
return Optional.empty()
}
}

/**
* Obtains the VariantData of the provided Variant.
*
Expand All @@ -56,102 +33,42 @@ class GroovyInterop {
}

/**
* Obtains the Java output directory of the provided VariantScope in a safe manner.
* TODO Clean this mess up once the Android Gradle Plugin 3.2.0 finally decides on something. :|
* Obtains the Java artifact files of the provided VariantScope in a safe manner.
*
* @because In Android Gradle Plugin 3.2.0-alpha02, the original method was removed
* @param variant VariantScope to retrieve the Java output directory from
* @because Some scopes, especially for Jacoco, don't have the files at hand through this API
* @param variant VariantScope to retrieve the Java artifact files from
* @return That file
*/
@NonNull
static Set<File> variantScope_javaOutputDirs(VariantScope scope) {
if (scope.hasProperty("buildArtifactsHolder") && InternalArtifactType.isPresent()) {
def artifactType = InternalArtifactType
.map { it.getDeclaredField("JAVAC").get(null) }
.get()
if (scope.buildArtifactsHolder.hasArtifact(artifactType)) {
// 3.2.0-alpha04 and above:
// Java outputs are moved into a subdirectory exposed by the compilation BuildArtifact
return scope.buildArtifactsHolder.getArtifactFiles(artifactType).files
} else {
// 3.2.0-alpha02 and above:
// Java outputs are still inside the "intermediates/classes" directory,
// but there is no public API for that, so construct the path yourself
return [new File(scope.globalScope.intermediatesDir,
"/classes/" + scope.variantConfiguration.dirName)]
}
static Set<File> variantScope_getJavacArtifactFiles(VariantScope scope) {
if (scope.artifacts.hasArtifact(InternalArtifactType.JAVAC)) {
return scope.artifacts.getArtifactFiles(InternalArtifactType.JAVAC).files
} else {
// Below 3.2.0-alpha02:
// Java outputs are expressed through the javaOutputDir property
return [scope.javaOutputDir]
return [new File(scope.globalScope.intermediatesDir,
"/classes/" + scope.variantConfiguration.dirName)]
}
}

/**
* Obtains the Assets Collection of the given AndroidUnitTest.
*
* @because 'assetsCollection' type changed from FileCollection to BuildArtifact in Android Gradle Plugin 3.2.0-alpha07
* @param test The Android JUnit 4 test to access
* @return Its assets collection
*/
@Nullable
static Set<File> androidUnitTest_assetsCollection(AndroidUnitTest test) {
def collection = test.assetsCollection
return collection == null ? null : collection.files
}

/**
* Obtains the Res Collection of the given AndroidUnitTest.
*
* @because 'resCollection' type changed from FileCollection to BuildArtifact in Android Gradle Plugin 3.2.0-alpha11
* @param test The Android JUnit 4 test to access
* @return Its assets collection
*/
@Nullable
static Set<File> androidUnitTest_resCollection(AndroidUnitTest test) {
def collection = test.resCollection
return collection == null ? null : collection.files
}

/**
* Obtains the Merged Manifest of the given AndroidUnitTest.
*
* @because 'mergedManifest' type changed from FileCollection to BuildArtifact in Android Gradle Plugin 3.2.0-alpha07
* @param test The Android JUnit 4 test to access
* @return Its merged manifest
*/
@Nullable
static Set<File> androidUnitTest_mergedManifest(AndroidUnitTest test) {
def collection = test.mergedManifest
return collection == null ? null : collection.files
}

/**
* Obtains the task name prefix for Unit Test variants.
*
* @because In Android Gradle Plugin 3.2.0-alpha06, the underlying constants on VariantType were renamed
* @return The unit test prefix
* @because Kotlin cannot see the VariantTypeImpl class
* @return The unit test task prefix
*/
@NonNull
static String variantType_unitTestPrefix() {
return VariantType
.map { it.getDeclaredField("UNIT_TEST").get(null) }
.map { it.prefix }
.orElseThrow { new IllegalArgumentException("can't get VariantType.UNIT_TEST.prefix") }
return VariantTypeImpl.UNIT_TEST.prefix
}

/**
* Obtains the task name suffix for Unit Test variants.
*
* @because In Android Gradle Plugin 3.2.0-alpha06, the underlying constants on VariantType were renamed
* @return The unit test prefix
* @because Kotlin cannot see the VariantTypeImpl class
* @return The unit test task prefix
*/
@NonNull
static String variantType_unitTestSuffix() {
return VariantType
.map { it.getDeclaredField("UNIT_TEST").get(null) }
.map { it.suffix }
.orElseThrow { new IllegalArgumentException("can't get VariantType.UNIT_TEST.suffix") }
return VariantTypeImpl.UNIT_TEST.suffix
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.mannodermaus.gradle.plugins.junit5

const val MIN_REQUIRED_GRADLE_VERSION = "4.7"
const val MIN_REQUIRED_AGP_VERSION = "3.2.0-alpha18"
const val MIN_REQUIRED_AGP_VERSION = "3.2.0"

const val EXTENSION_NAME = "junitPlatform"
const val FILTERS_EXTENSION_NAME = "filters"
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package de.mannodermaus.gradle.plugins.junit5
import com.android.build.gradle.api.BaseVariant
import com.android.build.gradle.internal.scope.VariantScope
import com.android.build.gradle.internal.variant.BaseVariantData
import com.android.build.gradle.tasks.factory.AndroidUnitTest
import org.gradle.api.Project
import org.gradle.testing.jacoco.tasks.JacocoReportBase
import java.io.File
Expand All @@ -18,17 +17,8 @@ import java.io.File
val BaseVariant.variantData: BaseVariantData
get() = GroovyInterop.baseVariant_variantData(this)

val VariantScope.safeJavaOutputDirs: Set<File>
get() = GroovyInterop.variantScope_javaOutputDirs(this)

val AndroidUnitTest.safeResCollection: Set<File>?
get() = GroovyInterop.androidUnitTest_resCollection(this)

val AndroidUnitTest.safeAssetsCollection: Set<File>?
get() = GroovyInterop.androidUnitTest_assetsCollection(this)

val AndroidUnitTest.safeMergedManifest: Set<File>?
get() = GroovyInterop.androidUnitTest_mergedManifest(this)
val VariantScope.safeJavacArtifactFiles: Set<File>
get() = GroovyInterop.variantScope_getJavacArtifactFiles(this)

/*
* Compatibility methods for multiple Gradle versions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package de.mannodermaus.gradle.plugins.junit5.providers

import com.android.build.gradle.api.BaseVariant
import de.mannodermaus.gradle.plugins.junit5.internal.unitTestVariant
import de.mannodermaus.gradle.plugins.junit5.safeJavaOutputDirs
import de.mannodermaus.gradle.plugins.junit5.safeJavacArtifactFiles
import de.mannodermaus.gradle.plugins.junit5.variantData

/**
Expand All @@ -25,5 +25,5 @@ class JavaDirectoryProvider(private val variant: BaseVariant) : DirectoryProvide
.toSet()

private fun classFoldersOf(variant: BaseVariant) =
variant.variantData.scope.safeJavaOutputDirs
variant.variantData.scope.safeJavacArtifactFiles
}
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,7 @@ class PluginSpec : Spek({
// create each class file in multiple directories to remain compatible with all approaches
// TODO Clean this mess up once the Android Gradle Plugin 3.2.0 finally decides on something. :|
listOf(
// AGP 3.2.0-alpha07 and above
"build/intermediates/javac/debug/compileDebugJavaWithJavac/classes",
// AGP 3.2.0-alpha06
"build/intermediates/artifact_transform/compileDebugJavaWithJavac/classes",
// AGP 3.2.0-alpha04 and above
"build/intermediates/artifact_transform/javac/debug/classes",
// Everything below
"build/intermediates/classes/debug").forEach { folder ->
project.file(folder).mkdirs()
project.file("$folder/R.class").createNewFile()
Expand All @@ -353,13 +347,7 @@ class PluginSpec : Spek({
}

listOf(
// AGP 3.2.0-alpha07 and above
"build/intermediates/javac/release/compileReleaseJavaWithJavac/classes",
// AGP 3.2.0-alpha06
"build/intermediates/artifact_transform/compileReleaseJavaWithJavac/classes",
// AGP 3.2.0-alpha04 and above
"build/intermediates/artifact_transform/javac/release/classes",
// Everything below
"build/intermediates/classes/release").forEach { folder ->
project.file(folder).mkdirs()
project.file("$folder/R.class").createNewFile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class VersionCheckerSpec : Spek({
"3.2.0-alpha01" to false,
"3.2.0-alpha14" to false,
MIN_REQUIRED_AGP_VERSION to true,
"3.2.0-beta01" to true,
"3.2.0" to true,
"3.3.0" to true,
"3.4.0" to true,
"3.5.0-alpha13" to true,
"3.3.0" to true,
"4.0.0-alpha01" to true
).forEach { (actual, expected) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
id "com.android.application"
id "org.jetbrains.kotlin.android"
id "de.mannodermaus.android-junit5"
id "jacoco"
}

def version = com.android.builder.model.Version.ANDROID_GRADLE_PLUGIN_VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ buildscript {
plugins {
id "com.android.application"
id "de.mannodermaus.android-junit5"
id "jacoco"
}

def version = com.android.builder.model.Version.ANDROID_GRADLE_PLUGIN_VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
id "com.android.application"
id "org.jetbrains.kotlin.android"
id "de.mannodermaus.android-junit5"
id "jacoco"
}

def version = com.android.builder.model.Version.ANDROID_GRADLE_PLUGIN_VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
id "com.android.application"
id "org.jetbrains.kotlin.android"
id "de.mannodermaus.android-junit5"
id "jacoco"
}

def version = com.android.builder.model.Version.ANDROID_GRADLE_PLUGIN_VERSION
Expand Down
18 changes: 17 additions & 1 deletion plugin/gradlew
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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='"-Xmx64m"'
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down
18 changes: 17 additions & 1 deletion plugin/gradlew.bat
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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="-Xmx64m"
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down