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

create henson plugin #185

Merged
Merged
Show file tree
Hide file tree
Changes from 10 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
33 changes: 28 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
language: java
language: android

android:
components:
# Update tools and then platform-tools explicitly so lint gets an updated database. Can be removed once 3.0 is out.
- tools
- platform-tools

jdk:
- oraclejdk8

after_success:
- .buildscript/deploy_snapshot.sh

env:
global:
- secure: "S2ANsF5glMuPrjilyE6+JqVp/t9bEQgkLXNHN1quLebTaJcveNFgyCPCvcevKJLiHCb4USY0cteZYj1U0QOvVR3zi/chr6Pxuo1kwgrfKpdBCWa1oxzLt0ipkVgH60VwxQNWjoUQCleOhu3F16X7IvCx32Wu7OqpmenJ6FJZYUw="
- secure: "ZetM/udS7DJMVdsFlSTCf88D6J4zQPS6hY3qc/f0BfYJP6qpOkHMBuxfIJMxkyQ9Rwi45RAX5kFFHJg/4wYiCQhlCSKy1gZaf4PORbhxTQR+rJCRtUi5dfHz2S2og/qWZm8KgaCalKW1s+f6/shFIBLcHvw8gnQmKvcIv7BHNaQ="

before_install:
# Install SDK license so Android Gradle plugin can install deps.
- mkdir "$ANDROID_HOME/licenses" || true
- echo "d56f5187479451eabf01fb78af6dfcb131a6481e" > "$ANDROID_HOME/licenses/android-sdk-license"
# Install the rest of tools (e.g., avdmanager)
#- sdkmanager tools
# Install the system image
#- sdkmanager "android-26"

script:
- ./gradlew check -s


after_success:
- .buildscript/deploy_snapshot.sh

after_failure:
- cat /home/travis/build/f2prateek/dart/henson-plugin/build/reports/tests/functionalTest/classes/dart.henson.plugin.HensonPluginFunctionalTest.html

branches:
except:
- gh-pages
Expand All @@ -23,4 +44,6 @@ sudo: false

cache:
directories:
- $HOME/.m2
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- $HOME/.android/build-cache
65 changes: 65 additions & 0 deletions henson-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
apply plugin: 'groovy'
apply plugin: 'java-gradle-plugin'


sourceSets {
functionalTest {
groovy.srcDir file('src/functTest/groovy')
resources.srcDir file('src/functTest/resources')
compileClasspath += sourceSets.main.output + configurations.testRuntime
runtimeClasspath += output + compileClasspath
}
}

gradlePlugin {
plugins {
hensonPlugin {
id = 'dart.henson-plugin'
implementationClass = 'dart.henson.plugin.HensonPlugin'
}
}
testSourceSets sourceSets.functionalTest
}

task functionalTest(type: Test) {
description = 'Runs the functional tests.'
group = 'verification'
testClassesDirs = sourceSets.functionalTest.output.classesDirs
classpath = sourceSets.functionalTest.runtimeClasspath
mustRunAfter test
}

check.dependsOn functionalTest

project.afterEvaluate {
tasks.getByName('compileGroovy').doFirst {
//we create a file in the plugin project containing the current project version
//it will be used later by the plugin to add the proper version of
//dependencies to the project that uses the plugin
def prop = new Properties()
def propFile = new File("${project.rootDir}/henson-plugin/src/main/resources/build.properties")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the D&H version go here? If so, would be nice to use it for the composite builds needed for D&H sample.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if there is no better way to do it.

propFile.parentFile.mkdirs()
prop.setProperty("dart.version", "$version")
propFile.createNewFile()
prop.store(propFile.newWriter(), null)
}
}

repositories {
jcenter()
google()
mavenLocal()
}

dependencies {
compile localGroovy()
implementation 'com.android.tools.build:gradle:3.0.0'

functionalTestCompile('org.spockframework:spock-core:1.1-groovy-2.4') {
exclude group: 'org.codehaus.groovy'
}
functionalTestCompile gradleTestKit()
}

//TODO : Does the release work ?
apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
3 changes: 3 additions & 0 deletions henson-plugin/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POM_ARTIFACT_ID=henson-plugin
POM_NAME=Henson Gradle Plugin
POM_PACKAGING=jar
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
package dart.henson.plugin

import org.gradle.testkit.runner.GradleRunner
import org.junit.Rule
import org.junit.rules.TemporaryFolder

import spock.lang.Specification

import java.util.zip.ZipFile

import static org.gradle.testkit.runner.TaskOutcome.FAILED
import static groovy.io.FileType.FILES

class HensonPluginFunctionalTest extends Specification {
@Rule TemporaryFolder testProjectDir = new TemporaryFolder()
File settingsFile
File buildFile
File manifestFile
File srcMain
File srcNavigationMain

def setup() {
settingsFile = testProjectDir.newFile('settings.gradle')
buildFile = testProjectDir.newFile('build.gradle')
testProjectDir.newFolder('src','main')
manifestFile = testProjectDir.newFile('src/main/AndroidManifest.xml')
testProjectDir.newFolder('src','main', 'java', 'test')
srcMain = testProjectDir.newFile('src/main/java/test/FooActivity.java')
testProjectDir.newFolder('src','navigation', 'main', 'java', 'test')
srcNavigationMain = testProjectDir.newFile('src/navigation/main/java/test/Foo.java')
}

def "fails on non android projects"() {
buildFile << """
plugins {
id 'java-library'
id 'dart.henson-plugin'
}
"""

when:
def result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('build')
.withPluginClasspath()
.build()

then:
org.gradle.testkit.runner.UnexpectedBuildFailure ex = thrown()
ex.message.contains("'android' or 'android-library' plugin required.")
}

def "applies to android projects"() {
manifestFile << """
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test">

<application
android:label="Test"
android:name=".Test"/>
</manifest>
"""
srcMain << """
package test;

import android.app.Activity;
import android.os.Bundle;

class FooActivity extends Activity {

@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
Foo foo = new Foo();
}
}
"""
srcNavigationMain << """
package test;

import dart.BindExtra;
import dart.DartModel;

@DartModel("test.TestActivity")
class Foo {
@BindExtra String s;
}
"""

settingsFile << """
rootProject.name = "test-project"
"""

buildFile << """
buildscript {
repositories {
google()
jcenter()
mavenLocal()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
}

dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}

plugins {
//the order matters here
id 'com.android.application'
id 'dart.henson-plugin'
}

android {
compileSdkVersion 26
defaultConfig {
applicationId 'test'
minSdkVersion 26
targetSdkVersion 26
versionCode 1
versionName '1.0.0'
}
flavorDimensions "color"

productFlavors {
red {
applicationId "com.blue"
dimension "color"
}
blue {
applicationId "com.red"
dimension "color"
}
}
}

repositories {
google()
jcenter()
mavenLocal()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
"""

when:
def result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('--no-build-cache', 'tasks', '--all', '-d', '-s')
.withPluginClasspath()
.build()

then:
result.output.contains("navigationApiCompileJava")
result.output.contains("navigationApiCompileJavaRed")
result.output.contains("navigationApiCompileJavaBlue")
result.output.contains("navigationApiCompileJavaRelease")
result.output.contains("navigationApiCompileJavaDebug")
result.output.contains("navigationApiCompileJavaBlueRelease")
result.output.contains("navigationApiCompileJavaBlueDebug")
result.output.contains("navigationApiCompileJavaRedRelease")
result.output.contains("navigationApiCompileJavaRedDebug")

result.output.contains("navigationApiJar")
result.output.contains("navigationApiJarRed")
result.output.contains("navigationApiJarBlue")
result.output.contains("navigationApiJarRelease")
result.output.contains("navigationApiJarDebug")
result.output.contains("navigationApiJarBlueRelease")
result.output.contains("navigationApiJarBlueDebug")
result.output.contains("navigationApiJarRedRelease")
result.output.contains("navigationApiJarRedDebug")

when:
def runner = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('--no-build-cache', 'clean', 'assemble', 'navigationApiJar', 'navigationApiJarRed', 'navigationApiJarRelease', 'navigationApiJarBlueDebug', '-d', '-s')
.withPluginClasspath()

def projectDir = runner.projectDir
result = runner.build()

then:
println result.output
result.task(":assemble").outcome != FAILED
//result.task(":tasks").outcome == SUCCESS
result.task(":navigationApiJar").outcome != FAILED
result.task(":navigationApiJarRed").outcome != FAILED
result.task(":navigationApiJarRelease").outcome != FAILED
result.task(":navigationApiJarBlueDebug").outcome != FAILED

testJarsContent(projectDir)
}

boolean testJarsContent(projectDir) {
new File(projectDir, "/build/libs").eachFileRecurse(FILES) { file ->
if (file.name.endsWith('.jar')) {
println "Testing jar: ${file.name}"
def content = getJarContent(file)
assert content.contains("META-INF/")
assert content.contains("META-INF/MANIFEST.MF")
assert content.contains("test/")
assert content.contains("test/Foo.class")
assert content.contains("test/Foo__ExtraBinder.class")
assert content.contains("test/Henson\$1.class")
assert content.contains("test/Henson\$WithContextSetState.class")
assert content.contains("test/Henson.class")
assert content.contains("test/TestActivity__IntentBuilder\$AllSet.class")
assert content.contains("test/TestActivity__IntentBuilder.class")
}
}
true
}

List<String> getJarContent(file) {
def List<String> result
if(file.name.endsWith('.jar')) {
result = new ArrayList<>()
def zip = new ZipFile(file)
zip.entries().each { entry ->
result.add(entry.name)
}
}
result
}
}
Loading