diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..aa0c1fe --- /dev/null +++ b/.travis.yml @@ -0,0 +1,26 @@ +language: android +sudo: false +jdk: oraclejdk8 + +android: + components: + - tools + - tools # Include again to work around travis not using the latest. + # https://github.com/travis-ci/travis-ci/issues/6193 + # Required to get the newest platform-tools. + - platform-tools + - build-tools-26.0.1 + - android-26 + licenses: + - '.+' +before_script: + - chmod +x gradlew +script: + - ./gradlew build +after_failure: + - cat build/reports/lint-results.xml + - cat build/outputs/lint-results-debug.xml + - cd ../.. + - pwd + - ls -la $HOME + - ls -la $HOME/android-sdk \ No newline at end of file diff --git a/build.gradle b/build.gradle index a671902..172ff19 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ plugins { id 'com.gradle.plugin-publish' version '0.9.8' + id 'java-gradle-plugin' } repositories { @@ -7,12 +8,20 @@ repositories { } apply plugin: 'groovy' +apply plugin: 'java-gradle-plugin' dependencies { compile gradleApi() compile localGroovy() + + testCompile gradleTestKit() + testCompile 'junit:junit:4.12' + testCompile('org.spockframework:spock-core:1.0-groovy-2.4') { + exclude module: 'groovy-all' + } } + group = 'com.onesignal' version = '0.5.0' description 'OneSignal Gradle Plugin' @@ -30,6 +39,17 @@ pluginBundle { } } +gradlePlugin { + pluginSourceSet project.sourceSets.main + testSourceSets project.sourceSets.test + plugins { + plugin { + id = 'com.onesignal.androidsdk.onesignal-gradle-plugin' + implementationClass = 'com.onesignal.androidsdk.GradleProjectPlugin' + } + } +} + // Build for Local Testing apply plugin: 'maven' diff --git a/src/test/groovy/com/onesignal/androidsdk/MainTest.groovy b/src/test/groovy/com/onesignal/androidsdk/MainTest.groovy new file mode 100644 index 0000000..396a993 --- /dev/null +++ b/src/test/groovy/com/onesignal/androidsdk/MainTest.groovy @@ -0,0 +1,130 @@ +import spock.lang.Specification +import org.junit.Rule +import org.junit.rules.TemporaryFolder + +import org.gradle.testkit.runner.GradleRunner + +class MainTest extends Specification { + + @Rule final TemporaryFolder testProjectDir = new TemporaryFolder() + File buildFile + List pluginClasspath + + def setup() { + buildFile = testProjectDir.newFile('build.gradle') + } + + def createBuildFile(compileVersion, compileLines) { + def gradleProps = testProjectDir.newFile('gradle.properties') + gradleProps <<'''\ + android.enableAapt2=false + '''.stripIndent() + + testProjectDir.newFolder("src", "main") + def androidManifest = testProjectDir.newFile('src/main/AndroidManifest.xml') + androidManifest << '''\ + + + + '''.stripIndent() + + buildFile << """\ + buildscript { + repositories { + jcenter() + maven { url 'https://maven.google.com' } + } + dependencies { + classpath 'com.android.tools.build:gradle:3.0.0-beta6' + } + } + + plugins { + id 'com.onesignal.androidsdk.onesignal-gradle-plugin' + } + + allprojects { + repositories { + jcenter() + maven { url 'https://maven.google.com' } + } + } + + apply plugin: 'com.android.application' + + android { + compileSdkVersion ${compileVersion} + buildToolsVersion '26.0.1' + defaultConfig { + applicationId 'com.app.example' + + minSdkVersion 15 + targetSdkVersion 26 + versionCode 1 + versionName "1.0" + } + } + + dependencies { + ${compileLines} + } + """\ + } + + def runGradleProject() { + return GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('dependencies', '--configuration', 'compile') + .withPluginClasspath() + .build() + } + + def "Aligns support library"() { + def compileLines = """\ + compile 'com.android.support:appcompat-v7:25.0.0' + compile 'com.android.support:support-v4:26.0.0' + """ + + createBuildFile(26, compileLines) + + when: + def result = runGradleProject() + + then: + result.output.contains('+--- com.android.support:appcompat-v7:25.0.0 -> 26.1.0') + } + + def "Uses support library 25 when compileSdkVersion is 25"() { + def compileLines = """\ + compile 'com.android.support:support-v4:26.0.0' + """ + + createBuildFile(25, compileLines) + + when: + def result = runGradleProject() + + then: + result.output.contains('\\--- com.android.support:support-v4:26.0.0 -> 25.4.0') + } + + def "Aligns gms and firebase"() { + def compileLines = """\ + compile 'com.google.firebase:firebase-core:11.0.0' + compile 'com.google.android.gms:play-services-gcm:11.2.0' + compile 'com.google.android.gms:play-services-location:11.4.0' + """ + + createBuildFile(26, compileLines) + + when: + def result = runGradleProject() + + then: + result.output.contains('+--- com.google.firebase:firebase-core:11.0.0 -> 11.4.2') + result.output.contains('+--- com.google.android.gms:play-services-gcm:11.2.0 -> 11.4.2') + result.output.contains('+--- com.google.android.gms:play-services-gcm:11.2.0 -> 11.4.2') + } + +} \ No newline at end of file