diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6a9c8b3..bb0ebd3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,11 @@ name: build -on: [push, pull_request] +on: + push: + branches: + - master + pull_request: + types: [ opened, labeled, unlabeled, synchronize ] env: GRADLE_OPTS: "-Dorg.gradle.jvmargs=-Xmx4g -Dorg.gradle.daemon=false -Dkotlin.incremental=false" @@ -15,47 +20,47 @@ jobs: api-level: - 23 java-version: - - 1.8 - 11 steps: + - name: Checkout Project + uses: actions/checkout@v3 + + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@v1.0.4 + - name: Cache Gradle dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | ~/.gradle/caches ~/.gradle/wrapper/ ~/.android/build-cache - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} - restore-keys: ${{ runner.os }}-gradle - - - name: Checkout Project - uses: actions/checkout@v2 - - - name: Validate Gradle Wrapper - uses: gradle/wrapper-validation-action@v1 + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: ${{ runner.os }}-gradle- - name: Configure JDK - uses: actions/setup-java@v1 + uses: actions/setup-java@v3.1.0 with: + distribution: temurin java-version: ${{ matrix.java-version }} - name: Build the Plugin - run: ./gradlew clean ktlintCheck build jar docsJar sourcesJar testsJar reportsZip generatePomFileForMavenPublication -s --scan + run: ./gradlew clean ktlintCheck build -s - name: Run Unit Tests - run: rm -rf ~/.m2/repository/com/jaredsburrows/gradle-spoon-plugin/ && ./gradlew publishMavenPublicationToMavenLocal -x test -s --scan + run: rm -rf ~/.m2/repository/com/jaredsburrows/gradle-spoon-plugin/ && ./gradlew publishToMavenLocal -x test -s - name: Run Instrumentation Tests uses: reactivecircus/android-emulator-runner@v2 with: api-level: ${{ matrix.api-level }} - script: cd test-app && ../gradlew clean spoonDebugAndroidTest checkReports -s --scan && cd .. + script: cd test-app && ../gradlew clean spoonDebugAndroidTest checkReports -s && cd .. env: API_LEVEL: ${{ matrix.api-level }} - name: Upload Artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3.0.0 if: always() with: name: gradle-spoon-plugin-${{ github.workflow }}-${{ github.run_id }} @@ -76,20 +81,19 @@ jobs: steps: - name: Checkout Project - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Validate Gradle Wrapper - uses: gradle/wrapper-validation-action@v1 + uses: gradle/wrapper-validation-action@v1.0.4 - name: Configure JDK - uses: actions/setup-java@v1 + uses: actions/setup-java@v3.0.0 with: - java-version: 1.8 + distribution: 'adopt' + java-version: 11 - name: Publish - run: ./gradlew clean artifactoryPublish -s --scan + run: ./gradlew clean publish -s env: - BINTRAY_API_KEY: ${{ secrets.BINTRAY_API_KEY }} - BINTRAY_USERNAME: ${{ secrets.BINTRAY_USERNAME }} - GRADLE_KEY: ${{ secrets.GRADLE_KEY }} - GRADLE_SECRET: ${{ secrets.GRADLE_SECRET }} + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_PASSWORD }} diff --git a/README.md b/README.md index 72ce874..28c8376 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Gradle Spoon Plugin [![License](https://img.shields.io/badge/license-apache%202.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0) -[![Build](https://github.com/jaredsburrows/gradle-spoon-plugin/workflows/build/badge.svg)](https://github.com/jaredsburrows/gradle-spoon-plugin/actions) +[![Build](https://github.com/jaredsburrows/gradle-spoon-plugin/actions/workflows/build.yml/badge.svg)](https://github.com/jaredsburrows/gradle-spoon-plugin/actions/workflows/build.yml) [![Twitter Follow](https://img.shields.io/twitter/follow/jaredsburrows.svg?style=social)](https://twitter.com/jaredsburrows) Gradle plugin for [Spoon](https://github.com/square/spoon) 2+ and [Android Gradle Plugin](https://developer.android.com/studio/releases/gradle-plugin.html) 3+. @@ -12,12 +12,12 @@ Gradle plugin for [Spoon](https://github.com/square/spoon) 2+ and [Android Gradl ```groovy buildscript { repositories { - jcenter() + mavenCentral() maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } // For Spoon snapshot, until 2.0.0 is released } dependencies { - classpath 'com.jaredsburrows:gradle-spoon-plugin:1.5.1' + classpath 'com.jaredsburrows:gradle-spoon-plugin:1.5.0' } } @@ -32,7 +32,7 @@ dependencies { androidTestCompile 'com.squareup.spoon:spoon-client:2.0.0-SNAPSHOT' // For Spoon snapshot, until 2.0.0 is released } ``` -Release versions are available in the [JFrog Bintray repository](https://jcenter.bintray.com/com/jaredsburrows/gradle-spoon-plugin/). +Release versions are available in the [Sonatype's release repository](https://repo1.maven.org/maven2/com/jaredsburrows/gradle-spoon-plugin/). **Snapshot:** ```groovy @@ -43,7 +43,7 @@ buildscript { } dependencies { - classpath 'com.jaredsburrows:gradle-spoon-plugin:1.5.2-SNAPSHOT' + classpath 'com.jaredsburrows:gradle-spoon-plugin:1.6.0-SNAPSHOT' } } @@ -58,13 +58,13 @@ dependencies { androidTestCompile 'com.squareup.spoon:spoon-client:2.0.0-SNAPSHOT' // For Spoon snapshot, until 2.0.0 is released } ``` -Snapshot versions are available in the [JFrog Artifactory repository](https://oss.jfrog.org/artifactory/libs-snapshot/com/jaredsburrows/gradle-spoon-plugin/). +Snapshot versions are available in the [Sonatype's snapshots repository](https://oss.sonatype.org/content/repositories/snapshots/com/jaredsburrows/gradle-spoon-plugin/). **Library modules:** This plugin allows Spoon to be run on library modules too! -``` +```groovy apply plugin: 'com.android.library' apply plugin: 'com.jaredsburrows.spoon' @@ -153,17 +153,18 @@ spoon { ``` ## License +``` +Copyright (C) 2017 Jared Burrows - Copyright (C) 2017 Jared Burrows - - 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 +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 + 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. +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. +``` diff --git a/build.gradle b/build.gradle index cb297e9..6802ed7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,44 +1,33 @@ +import java.time.ZonedDateTime +import java.time.format.DateTimeFormatter + plugins { - id 'com.jfrog.artifactory' version '4.18.3' - id 'com.jfrog.bintray' version '1.8.5' - id 'com.github.ben-manes.versions' version '0.36.0' - id 'com.gradle.plugin-publish' version '0.12.0' - id 'org.jetbrains.kotlin.jvm' version '1.4.10' - id 'org.jetbrains.dokka' version '0.10.0' - id 'org.jlleitschuh.gradle.ktlint' version '9.4.1' + id 'org.jetbrains.kotlin.jvm' version '1.6.20' + id 'org.jetbrains.dokka' version '1.6.10' + id 'org.jlleitschuh.gradle.ktlint' version '10.2.1' + id 'com.vanniktech.maven.publish' version '0.18.0' + id 'com.gradle.plugin-publish' version '0.21.0' + id 'com.github.ben-manes.versions' version '0.42.0' id 'java-gradle-plugin' + id 'java-library' id 'groovy' - id 'maven-publish' } repositories { gradlePluginPortal() google() + mavenCentral() maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } // For Spoon snapshot, until 2.0.0 is released } apply from: 'gradle/dependencies.gradle' -apply from: 'gradle/compile.gradle' -apply from: 'gradle/publish.gradle' group = GROUP version = VERSION_NAME description = POM_DESCRIPTION -sourceCompatibility = versions.java -targetCompatibility = versions.java - -jar { - manifest { - attributes( - 'Implementation-Title': POM_NAME, - 'Implementation-Version': archiveVersion, - 'Built-By': System.getProperty('user.name'), - 'Built-Date': new Date(), - 'Built-JDK': System.getProperty('java.version'), - 'Built-Gradle': gradle.gradleVersion) - } -} +sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_8 configurations.all { resolutionStrategy.cacheDynamicVersionsFor 0, 'seconds' @@ -58,12 +47,76 @@ dependencies { implementation deps.android.tools.build.gradle implementation deps.android.tools.ddmlib + testImplementation deps.junit testImplementation localGroovy() testImplementation deps.spock, { exclude module: 'groovy-all' } // Use localGroovy() } -tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) { +gradlePlugin { + plugins { + spoonPlugin { + id = PLUGIN_NAME + implementationClass = PLUGIN_NAME_CLASS + } + } +} + +tasks.withType(Jar).configureEach { + def dateFile = new File(buildDir, 'jar-manifest-date.txt') + if (!dateFile.exists()) { + def date = DateTimeFormatter.ofPattern('EEE MMM dd HH:mm:ss zzz yyyy'). + format(ZonedDateTime.now()) + dateFile.parentFile.mkdirs() + dateFile.text = date.trim() + } + + manifest { + attributes( + 'Created-By': POM_DEVELOPER_NAME, + 'Implementation-Title': POM_NAME, + 'Implementation-Version': VERSION_NAME, + 'Implementation-Vendor': POM_DEVELOPER_NAME, + 'Built-By': System.getProperty('user.name'), + 'Built-Date': dateFile.text.trim(), + 'Built-JDK': System.getProperty('java.version'), + 'Built-Gradle': gradle.gradleVersion) + } +} + +tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { kotlinOptions { - jvmTarget = rootProject.versions.java + jvmTarget = JavaVersion.VERSION_1_8.toString() + } +} + +tasks.withType(JavaCompile).configureEach { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + + configure(options) { + compilerArgs << '-Xlint:all' + compilerArgs << '-Xlint:-options' + encoding = 'utf-8' + } +} + +tasks.withType(GroovyCompile).configureEach { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + + configure(options) { + compilerArgs << '-Xlint:all' + compilerArgs << '-Xlint:-options' + encoding = 'utf-8' + } +} + +tasks.withType(Test).configureEach { + testLogging { + exceptionFormat 'full' + showCauses true + showExceptions true + showStackTraces true + events 'failed', 'skipped' } } diff --git a/gradle.properties b/gradle.properties index 96a96a6..bc6d2e7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,10 @@ GROUP=com.jaredsburrows -VERSION_NAME=1.5.2-SNAPSHOT +POM_ARTIFACT_ID=gradle-spoon-plugin +VERSION_NAME=1.6.0-SNAPSHOT POM_NAME=Gradle Spoon Plugin -POM_ARTIFACT_ID=gradle-spoon-plugin POM_DESCRIPTION=Gradle plugin that provides a task to run Android instrumentation tests via Spoon. +POM_INCEPTION_YEAR=2017 POM_PACKAGING=jar POM_URL=https://github.com/jaredsburrows/gradle-spoon-plugin @@ -14,14 +15,13 @@ POM_SCM_URL=https://github.com/jaredsburrows/gradle-spoon-plugin POM_SCM_CONNECTION=scm:git:git://github.com/jaredsburrows/gradle-spoon-plugin.git POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/jaredsburrows/gradle-spoon-plugin.git -POM_LICENCE_NAME=The Apache Software License, Version 2.0 -POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt -POM_LICENCE_DIST=repo +POM_LICENSE_NAME=The Apache Software License, Version 2.0 +POM_LICENSE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt +POM_LICENSE_DIST=repo POM_DEVELOPER_ID=jaredsburrows POM_DEVELOPER_NAME=Jared Burrows POM_DEVELOPER_EMAIL=jaredsburrows@gmail.com -BINTRAY_GITHUB_REPO=jaredsburrows/gradle-spoon-plugin PLUGIN_NAME=com.jaredsburrows.spoon PLUGIN_NAME_CLASS=com.jaredsburrows.spoon.SpoonPlugin diff --git a/gradle/compile.gradle b/gradle/compile.gradle deleted file mode 100644 index 6bb6c35..0000000 --- a/gradle/compile.gradle +++ /dev/null @@ -1,34 +0,0 @@ -tasks.withType(JavaCompile) { - sourceCompatibility = rootProject.versions.java - targetCompatibility = rootProject.versions.java - - // Show all warnings except boot classpath - configure(options) { - compilerArgs << '-Xlint:all' // Turn on all warnings - compilerArgs << '-Werror' // Turn warnings into errors - encoding = 'utf-8' - } -} - -tasks.withType(GroovyCompile) { - sourceCompatibility = rootProject.versions.java - targetCompatibility = rootProject.versions.java - - // Show all warnings except boot classpath - configure(options) { - compilerArgs << '-Xlint:all' // Turn on all warnings - compilerArgs << '-Werror' // Turn warnings into errors - encoding = 'utf-8' - } -} - -tasks.withType(Test) { - // Turn on logging for all tests, filter to show failures/skips only - testLogging { - exceptionFormat 'full' - showCauses true - showExceptions true - showStackTraces true - events 'failed', 'skipped' - } -} diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index a5c1150..a8f112f 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -1,7 +1,7 @@ ext.buildConfig = [ - 'compileSdk': 29, + 'compileSdk': 30, 'minSdk' : 21, - 'targetSdk' : 29, + 'targetSdk' : 30, 'signing' : [ 'alias' : "androiddebugkey", 'password': "android" @@ -9,9 +9,8 @@ ext.buildConfig = [ ] ext.versions = [ - 'agp' : '4.1.1', - 'java' : '1.8', - 'kotlin' : '1.4.10', + 'agp' : '4.2.2', // 7.1.3, ddms issue + 'kotlin' : '1.6.20', 'spoon' : '2.0.0-SNAPSHOT', 'jacoco' : '0.7.9', 'espresso': '3.3.0' @@ -32,10 +31,11 @@ ext.deps = [ ], 'android' : [ 'tools': [ - 'build' : [ + 'build' : [ 'gradle': "com.android.tools.build:gradle:$versions.agp", ], - 'ddmlib': 'com.android.tools.ddms:ddmlib:27.1.1', + 'desugar': 'com.android.tools:desugar_jdk_libs:1.1.5', + 'ddmlib' : 'com.android.tools.ddms:ddmlib:27.1.1', // 30.1.3 ], ], 'androidx': [ @@ -51,9 +51,9 @@ ext.deps = [ 'contrib': "androidx.test.espresso:espresso-contrib:$versions.espresso" ] ], - 'spock' : 'org.spockframework:spock-core:1.3-groovy-2.5', - 'junit' : 'junit:junit:4.13.1', - 'truth' : 'com.google.truth:truth:1.1', + 'spock' : 'org.spockframework:spock-core:2.1-M2-groovy-3.0', // error on upgrading 2.2-M1-groovy-4.0 + 'junit' : 'junit:junit:4.13.2', + 'truth' : 'com.google.truth:truth:1.1.3', 'jaococ' : [ 'agent': "org.jacoco:org.jacoco.agent:$versions.jacoco", 'ant' : "org.jacoco:org.jacoco.ant:$versions.jacoco", diff --git a/gradle/publish.gradle b/gradle/publish.gradle deleted file mode 100644 index 74da0b9..0000000 --- a/gradle/publish.gradle +++ /dev/null @@ -1,180 +0,0 @@ -def pomConfig = { - resolveStrategy = Closure.DELEGATE_FIRST - name POM_ARTIFACT_ID - description POM_DESCRIPTION - url POM_URL - - issueManagement { - system POM_ISSUE_SYSTEM - url POM_ISSUE_URL - } - - scm { - url POM_SCM_URL - connection POM_SCM_CONNECTION - developerConnection POM_SCM_DEV_CONNECTION - } - - licenses { - license { - name POM_LICENCE_NAME - url POM_LICENCE_URL - distribution POM_LICENCE_DIST - } - } - - developers { - developer { - id POM_DEVELOPER_ID - name POM_DEVELOPER_NAME - email POM_DEVELOPER_EMAIL - } - } -} - -task docsJar(type: Jar, dependsOn: dokka) { - group = 'Publications' - description = 'Create jar of documentation.' - archiveClassifier = 'docs' - from dokka.outputDirectory -} - -task sourcesJar(type: Jar, dependsOn: classes) { - group = 'Publications' - description = 'Create jar of sources.' - archiveClassifier = 'sources' - from sourceSets.main.allSource -} - -task testsJar(type: Jar) { - group = 'Publications' - description = 'Create jar of tests.' - archiveClassifier = 'tests' - from sourceSets.test.output -} - -task reportsZip(type: Zip, dependsOn: check) { - group = 'Publications' - description = 'Create a zip of all reports.' - classifier = 'reports' - from reporting.baseDir -} - -// Local published to ~/.m2 - mavenLocal() -publishing { - repositories { - mavenLocal() - } - - publications { - maven(MavenPublication) { - from components.java // includes main 'artifact jar' - artifact docsJar - artifact sourcesJar - artifact testsJar - artifact reportsZip - - groupId GROUP - artifactId POM_ARTIFACT_ID - version VERSION_NAME - - pom.withXml { - // Add parent POM information - asNode().children().first() + pomConfig - } - } - } -} -publish.dependsOn jar, docsJar, sourcesJar, testsJar, reportsZip -publish.dependsOn 'generatePomFileForMavenPublication' - -// Snapshots published to JFrog Artifactory repository -artifactory { - contextUrl = 'https://oss.jfrog.org' - - publish { - repository { - repoKey = 'oss-snapshot-local' - username = project.properties['BINTRAY_USERNAME'] ?: System.getenv('BINTRAY_USERNAME') - password = project.properties['BINTRAY_API_KEY'] ?: System.getenv('BINTRAY_API_KEY') - } - - defaults { - publications 'maven' - } - } - - resolve { - repository { - repoKey = 'libs-release' - } - } -} -artifactoryPublish.dependsOn jar, docsJar, sourcesJar, testsJar, reportsZip -artifactoryPublish.dependsOn 'generatePomFileForMavenPublication' - -// Publishes to JFrog Bintray's JCenter repository -bintray { - user = project.properties['BINTRAY_USERNAME'] ?: System.getenv('BINTRAY_USERNAME') - key = project.properties['BINTRAY_API_KEY'] ?: System.getenv('BINTRAY_API_KEY') - publications = ['maven'] - publish = true - - pkg { - repo = 'maven' - name = POM_ARTIFACT_ID - desc = POM_DESCRIPTION - websiteUrl = POM_URL - issueTrackerUrl = POM_ISSUE_URL - vcsUrl = POM_URL - labels = ['gradle', 'plugin', 'spoon'] - githubRepo = BINTRAY_GITHUB_REPO - githubReleaseNotesFile = 'README.md' - - version { - name = VERSION_NAME - desc = POM_DESCRIPTION - released = new Date() - vcsTag = VERSION_NAME - - mavenCentralSync { - sync = false - user = project.properties['SONATYPE_USERNAME'] ?: System.getenv('SONATYPE_USERNAME') - password = project.properties['SONATYPE_PASSWORD'] ?: System.getenv('SONATYPE_PASSWORD') - close = '1' - } - } - } -} -bintrayUpload.dependsOn jar, docsJar, sourcesJar, testsJar, reportsZip -bintrayUpload.dependsOn 'generatePomFileForMavenPublication' - -// Publishes to Gradle plugins repository -gradlePlugin { - plugins { - spoonPlugin { - id = PLUGIN_NAME - implementationClass = PLUGIN_NAME_CLASS - } - } -} -pluginBundle { - website = POM_URL - vcsUrl = POM_URL - description = POM_DESCRIPTION - tags = bintray.pkg.labels - - plugins { - spoonPlugin { - displayName = POM_NAME - } - } -} -publishPlugins.dependsOn jar, docsJar, sourcesJar, testsJar, reportsZip -publishPlugins.dependsOn 'generatePomFileForMavenPublication' - -// Publish to both Bintray and Gradle repositories -task release(dependsOn: [bintrayUpload, publishPlugins]) { - group = 'Publishing' - description = 'Publish to JFrog Jcenter\'s Brintray and Gradle Plugins Repositories.' -} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c..41d9927 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 4d9ca16..aa991fc 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-6.7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 4f906e0..1b6c787 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,67 +17,101 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=${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" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +121,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -106,80 +140,95 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/settings.gradle b/settings.gradle index 087cec6..efdd519 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,12 +1,13 @@ plugins { - id "com.gradle.enterprise" version "3.4.1" + id 'com.gradle.enterprise' version '3.6.4' } -rootProject.name = 'gradle-spoon-plugin' - gradleEnterprise { buildScan { - termsOfServiceUrl = "https://gradle.com/terms-of-service" - termsOfServiceAgree = "yes" + termsOfServiceUrl = 'https://gradle.com/terms-of-service' + termsOfServiceAgree = 'yes' + publishAlways() } } + +rootProject.name = 'gradle-spoon-plugin' diff --git a/src/main/kotlin/com/jaredsburrows/spoon/SpoonPlugin.kt b/src/main/kotlin/com/jaredsburrows/spoon/SpoonPlugin.kt index d940fcb..b3104b2 100644 --- a/src/main/kotlin/com/jaredsburrows/spoon/SpoonPlugin.kt +++ b/src/main/kotlin/com/jaredsburrows/spoon/SpoonPlugin.kt @@ -8,6 +8,7 @@ import org.gradle.api.DomainObjectSet import org.gradle.api.Plugin import org.gradle.api.Project import java.io.File +import java.util.Locale /** A [Plugin] which wraps the Spoon test runner. */ class SpoonPlugin : Plugin { @@ -29,8 +30,15 @@ class SpoonPlugin : Plugin { variants?.all { variant -> variant.outputs.all { + val taskVariant = variant.name.replaceFirstChar { + if (it.isLowerCase()) { + it.titlecase(Locale.getDefault()) + } else { + it.toString() + } + } // Create tasks based on variant - project.tasks.create("spoon${variant.name.capitalize()}", SpoonTask::class.java).apply { + project.tasks.create("spoon$taskVariant", SpoonTask::class.java).apply { description = "Run instrumentation tests for '${variant.name}' variant." group = "Verification" dependsOn(variant.testedVariant.assembleProvider, variant.assembleProvider) diff --git a/src/main/resources/META-INF/gradle-plugins/com.jaredsburrows.spoon.properties b/src/main/resources/META-INF/gradle-plugins/com.jaredsburrows.spoon.properties deleted file mode 100644 index 21b520c..0000000 --- a/src/main/resources/META-INF/gradle-plugins/com.jaredsburrows.spoon.properties +++ /dev/null @@ -1 +0,0 @@ -implementation-class=com.jaredsburrows.spoon.SpoonPlugin diff --git a/src/main/resources/META-INF/gradle-plugins/spoon.properties b/src/main/resources/META-INF/gradle-plugins/spoon.properties deleted file mode 100644 index 21b520c..0000000 --- a/src/main/resources/META-INF/gradle-plugins/spoon.properties +++ /dev/null @@ -1 +0,0 @@ -implementation-class=com.jaredsburrows.spoon.SpoonPlugin diff --git a/test-app/build.gradle b/test-app/build.gradle index 2bbce53..e853291 100644 --- a/test-app/build.gradle +++ b/test-app/build.gradle @@ -4,6 +4,7 @@ buildscript { repositories { mavenLocal() google() + mavenCentral() maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } // For Spoon snapshot, until 2.0.0 is released gradlePluginPortal() } @@ -11,13 +12,14 @@ buildscript { dependencies { classpath deps.android.tools.build.gradle classpath deps.kotlin.gradle.plugin - classpath 'com.github.ben-manes:gradle-versions-plugin:0.36.0' + classpath 'com.github.ben-manes:gradle-versions-plugin:0.42.0' classpath 'com.jaredsburrows:gradle-spoon-plugin:latest.integration' } } repositories { google() + mavenCentral() maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } // For Spoon snapshot, until 2.0.0 is released gradlePluginPortal() } @@ -41,6 +43,12 @@ android { testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } + compileOptions { +// coreLibraryDesugaringEnabled = true + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + buildTypes { debug { testCoverageEnabled = true @@ -84,6 +92,8 @@ configurations.all { } dependencies { +// coreLibraryDesugaring deps.android.tools.desugar + implementation deps.kotlin.stdlib.jdk androidTestImplementation deps.truth @@ -99,8 +109,6 @@ dependencies { androidTestUtil deps.androidx.test.orchestrator } -apply from: rootProject.file('../gradle/compile.gradle') - tasks.register("checkReports") { dependsOn(tasks.named("spoonDebugAndroidTest")) doLast { diff --git a/test-app/gradle.properties b/test-app/gradle.properties index 44f1e4b..e9ed87a 100644 --- a/test-app/gradle.properties +++ b/test-app/gradle.properties @@ -1,25 +1,22 @@ -################################################################################################### -# Gradle -################################################################################################### -org.gradle.caching=true -org.gradle.parallel=true +android.useAndroidX=true +android.enableR8.fullMode=true +android.nonTransitiveRClass=true +android.enableResourceOptimizations=true +android.uniquePackageNames=true +android.injected.studio.version.check=false + +android.defaults.buildfeatures.aidl=false +android.defaults.buildfeatures.buildconfig=false +android.defaults.buildfeatures.databinding=false +android.defaults.buildfeatures.compose=false +android.defaults.buildfeatures.prefab=false +android.defaults.buildfeatures.renderscript=false +android.defaults.buildfeatures.resvalues=false +android.defaults.buildfeatures.shaders=false +android.defaults.buildfeatures.viewbinding=true -################################################################################################### -# Kotlin -################################################################################################### -# Kotlin Gradle Plugin kapt.use.worker.api=true kapt.incremental.apt=true kapt.include.compile.classpath=false -################################################################################################### -# Android -################################################################################################### -# Use R8 instead of ProGuard for code shrinking. -android.enableR8.fullMode=true -android.nonTransitiveRClass=true - -# Android X -android.useAndroidX=true -#android.enableJetifier=true -android.jetifier.blacklist=.*bcprov.* +kotlin.code.style=official diff --git a/test-app/settings.gradle b/test-app/settings.gradle index 46391a3..efdd519 100644 --- a/test-app/settings.gradle +++ b/test-app/settings.gradle @@ -1,12 +1,13 @@ plugins { - id "com.gradle.enterprise" version "3.4.1" + id 'com.gradle.enterprise' version '3.6.4' } -rootProject.name = 'test-app' - gradleEnterprise { buildScan { - termsOfServiceUrl = "https://gradle.com/terms-of-service" - termsOfServiceAgree = "yes" + termsOfServiceUrl = 'https://gradle.com/terms-of-service' + termsOfServiceAgree = 'yes' + publishAlways() } } + +rootProject.name = 'gradle-spoon-plugin' diff --git a/test-app/src/main/AndroidManifest.xml b/test-app/src/main/AndroidManifest.xml index dcc6db3..9a887ec 100644 --- a/test-app/src/main/AndroidManifest.xml +++ b/test-app/src/main/AndroidManifest.xml @@ -1,18 +1,20 @@ - - + + android:name=".MainActivity" + android:exported="true"> - - + +