-
Notifications
You must be signed in to change notification settings - Fork 88
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
stephanenicolas
merged 16 commits into
f2prateek:master
from
stephanenicolas:sni/create-henson-plugin
Dec 2, 2017
Merged
create henson plugin #185
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
249062d
introduce gradle plugin for henson
stephanenicolas 95144d1
first tests almost passing using spock.
stephanenicolas db1b327
test pass. I can test an android project's plugin application
stephanenicolas fda7e63
Create source sets for main, build types, flavors and variants
stephanenicolas f7250f7
the plugin should work
stephanenicolas 9140b46
plugin seems to work. We got 'some kind of tests'
stephanenicolas 1a6e656
all works. We can now define navigation sources per build type, flavo…
stephanenicolas ac145a2
better tests. We know test the content of all jars created by the plugin
stephanenicolas c6a0f36
test task creation
stephanenicolas 8123766
fix travis
stephanenicolas 84e869a
the principle woks. I can detect the navigation api dependencies and …
stephanenicolas 27f875d
good polish of extension usage, remove allAfterEvaluate blocks. Much …
stephanenicolas 83eb6f5
Merge pull request #1 from stephanenicolas/sni/plugin-detect-intent-b…
stephanenicolas 7a6860b
fix navigation source set path for variants
stephanenicolas 3d8d9fa
Merge branch 'sni/create-henson-plugin' of github.com:stephanenicolas…
stephanenicolas bac32a6
add trailing lines
stephanenicolas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
229 changes: 229 additions & 0 deletions
229
henson-plugin/src/functTest/groovy/dart/henson/plugin/HensonPluginFunctionalTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.