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

Support Android Gradle Plugin 3.5.3, 3.6.3, 4.0.0 #252

Merged
merged 7 commits into from
Jun 6, 2020
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
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
gradle: ['5.6', '6.0', '6.3', '6.4']
gradle: ['5.6.4', '6.0', '6.3', '6.4']
steps:
- uses: actions/checkout@722adc6
with:
Expand Down
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ local.properties
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/misc.xml
.idea/**/compiler.xml
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
Expand All @@ -103,9 +105,9 @@ local.properties
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
.idea/modules.xml
.idea/*.iml
.idea/modules
# *.iml
# *.ipr

Expand Down
37 changes: 0 additions & 37 deletions .idea/compiler.xml

This file was deleted.

5 changes: 0 additions & 5 deletions .idea/misc.xml

This file was deleted.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ext {
errorproneVersion = '2.3.4'
spotBugsVersion = '4.0.2'
slf4jVersion = '1.8.0-beta4'
androidGradlePluginVersion = '3.5.3'
androidGradlePluginVersion = '4.0.0'
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,143 @@ import org.gradle.internal.impldep.com.google.common.io.Files
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.util.GradleVersion
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import spock.lang.Ignore
import spock.lang.Requires
import spock.lang.Specification

import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
import static org.junit.Assume.assumeTrue
import static org.junit.jupiter.api.Assertions.assertEquals

class AndroidFunctionalTest extends Specification {
File rootDir
File buildFile
String version = System.getProperty('snom.test.functional.gradle', GradleVersion.current().version)

@BeforeEach
def setup() {
rootDir = Files.createTempDir()
buildFile = new File(rootDir, 'build.gradle')
}

@Ignore("need to install Android SDK")
def "can generate spotbugsMain depending on classes task"() {
@AfterEach
void cleanup() {
rootDir.deleteDir()
}

@Requires({env['ANDROID_SDK_ROOT']})
def "can generate spotbugsRelease depending on app variant compilation task with AGP 3.5.3"() {
given: "a Gradle project to build an Android app"
GradleRunner runner = getGradleRunner()
writeAppBuildFile(runner, '3.5.3')
writeSourceFile()
writeManifestFile()

when: "the spotbugsRelease task is executed"
BuildResult result = build(runner)

then: "gradle runs spotbugsRelease successfully"
assertEquals(SUCCESS, result.task(":spotbugsRelease").outcome)
}

@Requires({env['ANDROID_SDK_ROOT']})
def "can generate spotbugsRelease depending on library variant compilation task with AGP 3.5.3"() {
given: "a Gradle project to build an Android library"
GradleRunner runner = getGradleRunner()
writeLibraryBuildFile(runner, '3.5.3')
writeSourceFile()
writeManifestFile()

when: "the spotbugsRelease task is executed"
BuildResult result = build(runner)

then: "gradle runs spotbugsRelease successfully"
assertEquals(SUCCESS, result.task(":spotbugsRelease").outcome)
}

@Requires({env['ANDROID_SDK_ROOT']})
def "can generate spotbugsRelease depending on app variant compilation task with AGP 3.6.3"() {
given: "a Gradle project to build an Android app"
GradleRunner runner = getGradleRunner()
writeAppBuildFile(runner, '3.6.3')
writeSourceFile()
writeManifestFile()

when: "the spotbugsRelease task is executed"
BuildResult result = build(runner)

then: "gradle runs spotbugsRelease successfully"
assertEquals(SUCCESS, result.task(":spotbugsRelease").outcome)
}

@Requires({env['ANDROID_SDK_ROOT']})
def "can generate spotbugsRelease depending on library variant compilation task with AGP 3.6.3"() {
given: "a Gradle project to build an Android library"
GradleRunner runner = getGradleRunner()
writeLibraryBuildFile(runner, '3.6.3')
writeSourceFile()
writeManifestFile()

when: "the spotbugsRelease task is executed"
BuildResult result = build(runner)

then: "gradle runs spotbugsRelease successfully"
assertEquals(SUCCESS, result.task(":spotbugsRelease").outcome)
}

@Requires({env['ANDROID_SDK_ROOT']})
def "can generate spotbugsRelease depending on app variant compilation task with AGP 4.0.0"() {
assumeTrue("AGP 4.0.0 is only supported by Gradle 6.1.1 and up",
GradleVersion.version(version) >= GradleVersion.version("6.1.1"))

given: "a Gradle project to build an Android app"
GradleRunner runner = getGradleRunner()
writeAppBuildFile(runner, '4.0.0')
writeSourceFile()
writeManifestFile()

when: "the spotbugsRelease task is executed"
BuildResult result = build(runner)

then: "gradle runs spotbugsRelease successfully"
assertEquals(SUCCESS, result.task(":spotbugsRelease").outcome)
}

@Requires({env['ANDROID_SDK_ROOT']})
def "can generate spotbugsRelease depending on library variant compilation task with AGP 4.0.0"() {
assumeTrue("AGP 4.0.0 is only supported by Gradle 6.1.1 and up",
GradleVersion.version(version) >= GradleVersion.version("6.1.1"))

given: "a Gradle project to build an Android library"
GradleRunner runner = getGradleRunner()
writeLibraryBuildFile(runner, '4.0.0')
writeSourceFile()
writeManifestFile()

when: "the spotbugsRelease task is executed"
BuildResult result = build(runner)

then: "gradle runs spotbugsRelease successfully"
assertEquals(SUCCESS, result.task(":spotbugsRelease").outcome)
}

private BuildResult build(GradleRunner runner) {
runner.withArguments(":spotbugsRelease", '-s')
.withGradleVersion(version)
.build()
}

private GradleRunner getGradleRunner() {
GradleRunner runner =
GradleRunner.create()
.withProjectDir(rootDir)
.withPluginClasspath()
.forwardOutput()
.withGradleVersion(version)
runner
}

def writeAppBuildFile(runner, agpVersion) {
File buildFile = new File(rootDir, 'build.gradle')
buildFile << """
buildscript {
repositories {
Expand All @@ -53,11 +162,11 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:$agpVersion'
"""
runner.pluginClasspath.forEach({ file ->
buildFile << """
classpath '${file.absolutePath}'
classpath files('${file.absolutePath}')
"""
})
buildFile << """
Expand All @@ -82,25 +191,61 @@ android {
}
}
"""
}

def writeLibraryBuildFile(runner, agpVersion) {
File buildFile = new File(rootDir, 'build.gradle')
buildFile << """
buildscript {
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:$agpVersion'
"""
runner.pluginClasspath.forEach({ file ->
buildFile << """
classpath files('${file.absolutePath}')
"""
})
buildFile << """
}
}

apply plugin: 'com.android.library'
apply plugin: 'com.github.spotbugs'

repositories {
google()
jcenter()
}

android {
compileSdkVersion 29
buildToolsVersion '29.0.2'
}
"""
}

File sourceDir = rootDir.toPath().resolve("src").resolve("main").resolve("java").toFile()
sourceDir.mkdirs()
File sourceFile = new File(sourceDir, "Foo.java")
void writeSourceFile() {
File sourceFile = new File(rootDir, "src/main/java/Foo.java")
sourceFile.parentFile.mkdirs()
sourceFile << """
public class Foo {
public static void main(String... args) {
System.out.println("Hello, SpotBugs!");
}
}
"""
}

when: "the spotbugsMain task is executed"
BuildResult result = runner
.withArguments(":spotbugsMain")
.withGradleVersion(version)
.build()

then: "gradle runs spotbugsMain successfully"
assertEquals(SUCCESS, result.task(":spotbugsMain").outcome)
void writeManifestFile() {
File manifestFile = new File(rootDir, "src/main/AndroidManifest.xml")
manifestFile.parentFile.mkdirs()
manifestFile << """
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="test.spotbugs" />
"""
}
}
Loading