diff options
author | Yigit Boyar <yboyar@google.com> | 2015-10-12 18:59:27 -0700 |
---|---|---|
committer | Yigit Boyar <yboyar@google.com> | 2015-10-28 14:33:53 -0700 |
commit | 9784c9aaedeb863018f5fcaa0a598e8e2f8ed2f3 (patch) | |
tree | 50d9b6a2ce235ca732e9da52026eef55e708e1ce /compilationTests | |
parent | 012f7781add1b38b28c0c68a94172715e635c00e (diff) | |
download | data-binding-9784c9aaedeb863018f5fcaa0a598e8e2f8ed2f3.tar.gz |
Data binding as studio dep + java6
This CL gets rid of the gradle plugin and instead provides
DataBindingBuilder for the gradle plugin to directly use.
Now, everything that is deployed via SDK Manager (lib and adapters)
are included as prebuilts so that we avoid accidently changing
them w/o an SDK manager release.
There is still work to do:
> re-enable proguard for externel dependencies
> release a batch to ensure everything works
Bug: 22516688
Change-Id: I83ace15bd6d3d23bf5b4ad850f36453dd23ebd43
Diffstat (limited to 'compilationTests')
7 files changed, 88 insertions, 106 deletions
diff --git a/compilationTests/build.gradle b/compilationTests/build.gradle index ae64d72b..0ca1877a 100644 --- a/compilationTests/build.gradle +++ b/compilationTests/build.gradle @@ -1,17 +1,17 @@ apply plugin: 'java' -sourceCompatibility = 1.7 +sourceCompatibility = 1.6 version = '1.0' dependencies { - testCompile group: 'junit', name: 'junit', version: '4.12' + testCompile 'junit:junit:4.12' testCompile 'org.apache.commons:commons-lang3:3.3.2' testCompile 'commons-io:commons-io:2.4' testCompile 'commons-codec:commons-codec:1.10' - testCompile project(':compilerCommon') + testCompile project(':dataBinding:compilerCommon') } afterEvaluate { - tasks['test'].systemProperties['useReleaseVersion'] = config.inReleaseBuild ? 'true' : 'false' - tasks['test'].systemProperties['addRemoteRepos'] = config.addRemoteRepos ? 'true' : 'false' + tasks['test'].systemProperties['useReleaseVersion'] = dataBindingConfig.inReleaseBuild ? 'true' : 'false' + tasks['test'].systemProperties['addRemoteRepos'] = dataBindingConfig.addRemoteRepos ? 'true' : 'false' }
\ No newline at end of file diff --git a/compilationTests/src/test/java/android/databinding/compilationTest/BaseCompilationTest.java b/compilationTests/src/test/java/android/databinding/compilationTest/BaseCompilationTest.java index 3bd05321..e008c828 100644 --- a/compilationTests/src/test/java/android/databinding/compilationTest/BaseCompilationTest.java +++ b/compilationTests/src/test/java/android/databinding/compilationTest/BaseCompilationTest.java @@ -31,9 +31,6 @@ import java.io.IOException; import java.io.InputStream; import java.net.URISyntaxException; import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.nio.file.attribute.PosixFilePermission; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -52,7 +49,7 @@ import static org.junit.Assert.assertTrue; public class BaseCompilationTest { private static final String PRINT_ENCODED_ERRORS_PROPERTY - = "android.databinding.injected.print.encoded.errors"; + = "android.injected.invoked.from.ide"; @Rule public TestName name = new TestName(); static Pattern VARIABLES = Pattern.compile("!@\\{([A-Za-z0-9_-]*)}"); @@ -147,7 +144,7 @@ public class BaseCompilationTest { protected static Map<String, String> toMap(String... keysAndValues) { assertEquals(0, keysAndValues.length % 2); - Map<String, String> map = new HashMap<>(); + Map<String, String> map = new HashMap<String, String>(); for (int i = 0; i < keysAndValues.length; i += 2) { map.put(keysAndValues[i], keysAndValues[i + 1]); } @@ -191,7 +188,7 @@ public class BaseCompilationTest { private Map<String, String> addDefaults(Map<String, String> map) { if (map == null) { - map = new HashMap<>(); + map = new HashMap<String, String>(); } if (!map.containsKey(KEY_MANIFEST_PACKAGE)) { map.put(KEY_MANIFEST_PACKAGE, DEFAULT_APP_PACKAGE); @@ -241,7 +238,7 @@ public class BaseCompilationTest { throws IOException, InterruptedException { setExecutable(); File pathToExecutable = new File(testFolder, "gradlew"); - List<String> args = new ArrayList<>(); + List<String> args = new ArrayList<String>(); args.add(pathToExecutable.getAbsolutePath()); args.add("-P" + PRINT_ENCODED_ERRORS_PROPERTY + "=true"); if ("true".equals(System.getProperties().getProperty("useReleaseVersion", "false"))) { @@ -268,17 +265,8 @@ public class BaseCompilationTest { } private void setExecutable() throws IOException { - Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>(); - //add owners permission - perms.add(PosixFilePermission.OWNER_READ); - perms.add(PosixFilePermission.OWNER_WRITE); - perms.add(PosixFilePermission.OWNER_EXECUTE); - //add group permissions - perms.add(PosixFilePermission.GROUP_READ); - //add others permissions - perms.add(PosixFilePermission.OTHERS_READ); - Files.setPosixFilePermissions(Paths.get(new File(testFolder, "gradlew").getAbsolutePath()), - perms); + File gw = new File(testFolder, "gradlew"); + gw.setExecutable(true); } diff --git a/compilationTests/src/test/java/android/databinding/compilationTest/MultiLayoutVerificationTest.java b/compilationTests/src/test/java/android/databinding/compilationTest/MultiLayoutVerificationTest.java index 0591ea9f..bbf86e7a 100644 --- a/compilationTests/src/test/java/android/databinding/compilationTest/MultiLayoutVerificationTest.java +++ b/compilationTests/src/test/java/android/databinding/compilationTest/MultiLayoutVerificationTest.java @@ -58,25 +58,24 @@ public class MultiLayoutVerificationTest extends BaseCompilationTest { assertTrue(file.exists()); assertEquals(1, report.getLocations().size()); Location location = report.getLocations().get(0); - switch (file.getParentFile().getName()) { - case "layout": - assertEquals(new File(testFolder, - "/app/src/main/res/layout/with_class_name.xml") - .getCanonicalFile(), file.getCanonicalFile()); - String extract = extract("/app/src/main/res/layout/with_class_name.xml", - location); - assertEquals(extract, "AClassName"); - assertEquals(String.format( - ErrorMessages.MULTI_CONFIG_LAYOUT_CLASS_NAME_MISMATCH, - DEFAULT_APP_PACKAGE + ".databinding.AClassName", - "layout/with_class_name"), exception.getBareMessage()); - foundNormal = true; - break; - case "layout-land": + String name = file.getParentFile().getName(); + if ("layout".equals(name)) { + assertEquals(new File(testFolder, + "/app/src/main/res/layout/with_class_name.xml") + .getCanonicalFile(), file.getCanonicalFile()); + String extract = extract("/app/src/main/res/layout/with_class_name.xml", + location); + assertEquals(extract, "AClassName"); + assertEquals(String.format( + ErrorMessages.MULTI_CONFIG_LAYOUT_CLASS_NAME_MISMATCH, + DEFAULT_APP_PACKAGE + ".databinding.AClassName", + "layout/with_class_name"), exception.getBareMessage()); + foundNormal = true; + } else if ("layout-land".equals(name)) { assertEquals(new File(testFolder, "/app/src/main/res/layout-land/with_class_name.xml") .getCanonicalFile(), file.getCanonicalFile()); - extract = extract("/app/src/main/res/layout-land/with_class_name.xml", + String extract = extract("/app/src/main/res/layout-land/with_class_name.xml", location); assertEquals("SomeOtherClassName", extract); assertEquals(String.format( @@ -84,13 +83,12 @@ public class MultiLayoutVerificationTest extends BaseCompilationTest { DEFAULT_APP_PACKAGE + ".databinding.SomeOtherClassName", "layout-land/with_class_name"), exception.getBareMessage()); foundLandscape = true; - break; - default: - fail("unexpected error file"); + } else { + fail("unexpected error file"); } } - assertTrue(result.error, foundNormal); - assertTrue(result.error, foundLandscape); + assertTrue("should find default config error\n" + result.error, foundNormal); + assertTrue("should find landscape error\n" + result.error, foundLandscape); } @Test @@ -117,19 +115,17 @@ public class MultiLayoutVerificationTest extends BaseCompilationTest { assertEquals(result.error, 1, report.getLocations().size()); Location location = report.getLocations().get(0); // validated in switch - String config = file.getParentFile().getName(); + String name = file.getParentFile().getName(); + String config = name; String type = "???"; - switch (file.getParentFile().getName()) { - case "layout": - type = "String"; - foundNormal = true; - break; - case "layout-land": - type = "CharSequence"; - foundLandscape = true; - break; - default: - fail("unexpected error file"); + if ("layout".equals(name)) { + type = "String"; + foundNormal = true; + } else if ("layout-land".equals(name)) { + type = "CharSequence"; + foundLandscape = true; + } else { + fail("unexpected error file"); } assertEquals(new File(testFolder, "/app/src/main/res/" + config + "/layout_with_variable_type.xml") @@ -172,19 +168,17 @@ public class MultiLayoutVerificationTest extends BaseCompilationTest { assertEquals(result.error, 1, report.getLocations().size()); Location location = report.getLocations().get(0); // validated in switch - String config = file.getParentFile().getName(); + String name = file.getParentFile().getName(); + String config = name; String type = "???"; - switch (file.getParentFile().getName()) { - case "layout": - type = typeNormal; - foundNormal = true; - break; - case "layout-land": - type = typeLand; - foundLandscape = true; - break; - default: - fail("unexpected error file"); + if ("layout".equals(name)) { + type = typeNormal; + foundNormal = true; + } else if ("layout-land".equals(name)) { + type = typeLand; + foundLandscape = true; + } else { + fail("unexpected error file"); } assertEquals(new File(testFolder, "/app/src/main/res/" + config + "/layout_with_import_type.xml") @@ -227,22 +221,19 @@ public class MultiLayoutVerificationTest extends BaseCompilationTest { Location location = report.getLocations().get(0); // validated in switch String config = file.getParentFile().getName(); - switch (file.getParentFile().getName()) { - case "layout": - String extract = extract("/app/src/main/res/" + config + "/foo.xml", location); - assertEquals(extract, "<include layout=\"@layout/basic_layout\" " - + "android:id=\"@+id/sharedId\" bind:myVariable=\"@{myVariable}\"/>"); - foundNormal = true; - break; - case "layout-land": - extract = extract("/app/src/main/res/" + config + "/foo.xml", location); - assertEquals(extract, "<TextView android:layout_width=\"wrap_content\" " - + "android:layout_height=\"wrap_content\" android:id=\"@+id/sharedId\" " - + "android:text=\"@{myVariable}\"/>"); - foundLandscape = true; - break; - default: - fail("unexpected error file"); + if ("layout".equals(config)) { + String extract = extract("/app/src/main/res/" + config + "/foo.xml", location); + assertEquals(extract, "<include layout=\"@layout/basic_layout\" " + + "android:id=\"@+id/sharedId\" bind:myVariable=\"@{myVariable}\"/>"); + foundNormal = true; + } else if ("layout-land".equals(config)) { + String extract = extract("/app/src/main/res/" + config + "/foo.xml", location); + assertEquals(extract, "<TextView android:layout_width=\"wrap_content\" " + + "android:layout_height=\"wrap_content\" android:id=\"@+id/sharedId\" " + + "android:text=\"@{myVariable}\"/>"); + foundLandscape = true; + } else { + fail("unexpected error file"); } assertEquals(new File(testFolder, "/app/src/main/res/" + config + "/foo.xml").getCanonicalFile(), diff --git a/compilationTests/src/test/java/android/databinding/compilationTest/SimpleCompilationTest.java b/compilationTests/src/test/java/android/databinding/compilationTest/SimpleCompilationTest.java index f86165e2..84d4459f 100644 --- a/compilationTests/src/test/java/android/databinding/compilationTest/SimpleCompilationTest.java +++ b/compilationTests/src/test/java/android/databinding/compilationTest/SimpleCompilationTest.java @@ -73,18 +73,19 @@ public class SimpleCompilationTest extends BaseCompilationTest { "/app/src/main/res/layout-sw100dp/main.xml"); CompilationResult result = runGradle("assembleDebug"); assertEquals(result.error, 0, result.resultCode); - File debugOut = new File(testFolder, "/app/build/intermediates/res/merged/debug/"); + File debugOut = new File(testFolder, + "app/build/intermediates/data-binding-layout-out/debug"); Collection<File> layoutFiles = FileUtils.listFiles(debugOut, new SuffixFileFilter(".xml"), new PrefixFileFilter("layout")); assertTrue("test sanity", layoutFiles.size() > 1); for (File layout : layoutFiles) { + final String contents = FileUtils.readFileToString(layout); if (layout.getParent().contains("sw100")) { assertTrue("File has wrong tag:" + layout.getPath(), - FileUtils.readFileToString(layout) - .indexOf("android:tag=\"layout-sw100dp/main_0\"") > 0); + contents.indexOf("android:tag=\"layout-sw100dp/main_0\"") > 0); } else { - assertTrue("File has wrong tag:" + layout.getPath(), - FileUtils.readFileToString(layout).indexOf("android:tag=\"layout/main_0\"") + assertTrue("File has wrong tag:" + layout.getPath() + "\n" + contents, + contents.indexOf("android:tag=\"layout/main_0\"") > 0); } } diff --git a/compilationTests/src/test/resources/app_build.gradle b/compilationTests/src/test/resources/app_build.gradle index d189ca14..22632c58 100644 --- a/compilationTests/src/test/resources/app_build.gradle +++ b/compilationTests/src/test/resources/app_build.gradle @@ -1,10 +1,11 @@ apply plugin: 'com.android.application' -apply plugin: 'com.android.databinding' android { - compileSdkVersion config.compileSdkVersion - buildToolsVersion config.buildToolsVersion - + compileSdkVersion dataBindingConfig.compileSdkVersion + buildToolsVersion dataBindingConfig.buildToolsVersion + dataBinding { + enabled = true + } defaultConfig { minSdkVersion 7 targetSdkVersion 21 @@ -22,8 +23,8 @@ android { exclude 'META-INF/services/javax.annotation.processing.Processor' } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_7 - targetCompatibility JavaVersion.VERSION_1_7 + sourceCompatibility JavaVersion.VERSION_1_6 + targetCompatibility JavaVersion.VERSION_1_6 } } diff --git a/compilationTests/src/test/resources/module_build.gradle b/compilationTests/src/test/resources/module_build.gradle index 2eb780a3..112b27b2 100644 --- a/compilationTests/src/test/resources/module_build.gradle +++ b/compilationTests/src/test/resources/module_build.gradle @@ -15,12 +15,13 @@ */ apply plugin: 'com.android.library' -apply plugin: 'com.android.databinding' android { - compileSdkVersion config.compileSdkVersion - buildToolsVersion config.buildToolsVersion - + compileSdkVersion dataBindingConfig.compileSdkVersion + buildToolsVersion dataBindingConfig.buildToolsVersion + dataBinding { + enabled = true + } defaultConfig { minSdkVersion 7 targetSdkVersion 21 @@ -38,8 +39,8 @@ android { exclude 'META-INF/services/javax.annotation.processing.Processor' } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_7 - targetCompatibility JavaVersion.VERSION_1_7 + sourceCompatibility JavaVersion.VERSION_1_6 + targetCompatibility JavaVersion.VERSION_1_6 } } diff --git a/compilationTests/src/test/resources/project_build.gradle b/compilationTests/src/test/resources/project_build.gradle index fcf1b754..4622a5b1 100644 --- a/compilationTests/src/test/resources/project_build.gradle +++ b/compilationTests/src/test/resources/project_build.gradle @@ -1,23 +1,23 @@ buildscript { - ext.rootFolder = new File(project.projectDir, "../../..") + ext.dataBindingRootFolder = new File(project.projectDir, "../../..") apply from: "${project.projectDir}/propLoaderClone.gradle" ext.addRepos(repositories) dependencies { - classpath "com.android.databinding:dataBinder:${config.version}" + classpath "com.android.tools.build:gradle:${dataBindingConfig.androidPluginVersion}" } } subprojects { apply plugin: 'maven' - group = config.group - version = config.version + group = dataBindingConfig.group + version = dataBindingConfig.version } allprojects { repositories { jcenter() maven { - url config.mavenRepoDir + url dataBindingConfig.mavenRepoDir } } } |