diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index ae4dba19..3aa66807 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -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" diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 87b738cb..5c2d1cf0 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 44e7c4d1..5f1b1201 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/plugin/android-junit5/src/main/groovy/de/mannodermaus/gradle/plugins/junit5/GroovyInterop.groovy b/plugin/android-junit5/src/main/groovy/de/mannodermaus/gradle/plugins/junit5/GroovyInterop.groovy index 867559a6..4777f721 100644 --- a/plugin/android-junit5/src/main/groovy/de/mannodermaus/gradle/plugins/junit5/GroovyInterop.groovy +++ b/plugin/android-junit5/src/main/groovy/de/mannodermaus/gradle/plugins/junit5/GroovyInterop.groovy @@ -2,16 +2,14 @@ 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, @@ -19,30 +17,9 @@ import javax.annotation.Nullable * 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 reflectiveClass(String fqcn) { - try { - return Optional.of(Class.forName(fqcn)) - } catch (ignored) { - return Optional.empty() - } - } - /** * Obtains the VariantData of the provided Variant. * @@ -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 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 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 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 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 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 } /** diff --git a/plugin/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Constants.kt b/plugin/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Constants.kt index 095433c2..8cf9cf52 100644 --- a/plugin/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Constants.kt +++ b/plugin/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Constants.kt @@ -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" diff --git a/plugin/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Interop.kt b/plugin/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Interop.kt index af1ba57a..a6bc0dfb 100644 --- a/plugin/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Interop.kt +++ b/plugin/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Interop.kt @@ -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 @@ -18,17 +17,8 @@ import java.io.File val BaseVariant.variantData: BaseVariantData get() = GroovyInterop.baseVariant_variantData(this) -val VariantScope.safeJavaOutputDirs: Set - get() = GroovyInterop.variantScope_javaOutputDirs(this) - -val AndroidUnitTest.safeResCollection: Set? - get() = GroovyInterop.androidUnitTest_resCollection(this) - -val AndroidUnitTest.safeAssetsCollection: Set? - get() = GroovyInterop.androidUnitTest_assetsCollection(this) - -val AndroidUnitTest.safeMergedManifest: Set? - get() = GroovyInterop.androidUnitTest_mergedManifest(this) +val VariantScope.safeJavacArtifactFiles: Set + get() = GroovyInterop.variantScope_getJavacArtifactFiles(this) /* * Compatibility methods for multiple Gradle versions. diff --git a/plugin/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/providers/Java.kt b/plugin/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/providers/Java.kt index 1382970b..9828a786 100644 --- a/plugin/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/providers/Java.kt +++ b/plugin/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/providers/Java.kt @@ -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 /** @@ -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 } diff --git a/plugin/android-junit5/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/PluginSpec.kt b/plugin/android-junit5/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/PluginSpec.kt index a4a1addb..42eca729 100644 --- a/plugin/android-junit5/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/PluginSpec.kt +++ b/plugin/android-junit5/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/PluginSpec.kt @@ -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() @@ -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() diff --git a/plugin/android-junit5/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/VersionCheckerSpec.kt b/plugin/android-junit5/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/VersionCheckerSpec.kt index 6dcfef8a..056b0088 100644 --- a/plugin/android-junit5/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/VersionCheckerSpec.kt +++ b/plugin/android-junit5/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/VersionCheckerSpec.kt @@ -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) -> diff --git a/plugin/android-junit5/src/test/projects/agp32x/build.gradle b/plugin/android-junit5/src/test/projects/agp32x/build.gradle index da5a5e90..d64d00b2 100644 --- a/plugin/android-junit5/src/test/projects/agp32x/build.gradle +++ b/plugin/android-junit5/src/test/projects/agp32x/build.gradle @@ -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 diff --git a/plugin/android-junit5/src/test/projects/agp33x/build.gradle b/plugin/android-junit5/src/test/projects/agp33x/build.gradle index 6e297b5c..3062fc7f 100644 --- a/plugin/android-junit5/src/test/projects/agp33x/build.gradle +++ b/plugin/android-junit5/src/test/projects/agp33x/build.gradle @@ -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 diff --git a/plugin/android-junit5/src/test/projects/agp34x/build.gradle b/plugin/android-junit5/src/test/projects/agp34x/build.gradle index 71c39358..9101a670 100644 --- a/plugin/android-junit5/src/test/projects/agp34x/build.gradle +++ b/plugin/android-junit5/src/test/projects/agp34x/build.gradle @@ -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 diff --git a/plugin/android-junit5/src/test/projects/agp35x/build.gradle b/plugin/android-junit5/src/test/projects/agp35x/build.gradle index e888965a..dcd14659 100644 --- a/plugin/android-junit5/src/test/projects/agp35x/build.gradle +++ b/plugin/android-junit5/src/test/projects/agp35x/build.gradle @@ -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 diff --git a/plugin/gradlew b/plugin/gradlew index af6708ff..b0d6d0ab 100755 --- a/plugin/gradlew +++ b/plugin/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='"-Xmx64m"' +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" diff --git a/plugin/gradlew.bat b/plugin/gradlew.bat index 0f8d5937..15e1ee37 100644 --- a/plugin/gradlew.bat +++ b/plugin/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="-Xmx64m" +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome