diff options
author | Yigit Boyar <yboyar@google.com> | 2015-07-07 21:24:03 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-07-07 21:24:04 +0000 |
commit | fb595334b2f1cfe69823335b6a239c75ad87c103 (patch) | |
tree | 002929a0e5af0ff48c193f0bfe7102278b74f93f /compilationTests | |
parent | aafbe5a2394ff9826201cca97d3298a9f355e311 (diff) | |
parent | 08119ea342cb47910ca80ff646d746f00e4663ce (diff) | |
download | data-binding-fb595334b2f1cfe69823335b6a239c75ad87c103.tar.gz |
Merge "Print encoded errors only if data binding is invoked from the IDE" into mnc-dev
Diffstat (limited to 'compilationTests')
-rw-r--r-- | compilationTests/src/test/java/android/databinding/compilationTest/BaseCompilationTest.java | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/compilationTests/src/test/java/android/databinding/compilationTest/BaseCompilationTest.java b/compilationTests/src/test/java/android/databinding/compilationTest/BaseCompilationTest.java index 41aa12e2..c9cf2a08 100644 --- a/compilationTests/src/test/java/android/databinding/compilationTest/BaseCompilationTest.java +++ b/compilationTests/src/test/java/android/databinding/compilationTest/BaseCompilationTest.java @@ -50,6 +50,9 @@ import static org.junit.Assert.assertTrue; public class BaseCompilationTest { + + private static final String PRINT_ENCODED_ERRORS_PROPERTY + = "android.databinding.injected.print.encoded.errors"; @Rule public TestName name = new TestName(); static Pattern VARIABLES = Pattern.compile("!@\\{([A-Za-z0-9_-]*)}"); @@ -103,8 +106,9 @@ public class BaseCompilationTest { /** * Extracts the text in the given location from the the at the given application path. + * * @param pathInApp The path, relative to the root of the application under test - * @param location The location to extract + * @param location The location to extract * @return The string that is contained in the given location * @throws IOException If file is invalid. */ @@ -113,7 +117,7 @@ public class BaseCompilationTest { assertTrue(file.exists()); StringBuilder result = new StringBuilder(); List<String> lines = FileUtils.readLines(file); - for (int i = location.startLine; i <= location.endLine; i ++) { + for (int i = location.startLine; i <= location.endLine; i++) { if (i > location.startLine) { result.append("\n"); } @@ -144,7 +148,7 @@ public class BaseCompilationTest { protected static Map<String, String> toMap(String... keysAndValues) { assertEquals(0, keysAndValues.length % 2); Map<String, String> map = new HashMap<>(); - for (int i = 0; i < keysAndValues.length; i+=2) { + for (int i = 0; i < keysAndValues.length; i += 2) { map.put(keysAndValues[i], keysAndValues[i + 1]); } return map; @@ -203,7 +207,8 @@ public class BaseCompilationTest { replacements = addDefaults(replacements); // how to get build folder, pass from gradle somehow ? FileUtils.forceMkdir(testFolder); - copyResourceTo("/AndroidManifest.xml", new File(testFolder, "app/src/main/AndroidManifest.xml"), replacements); + copyResourceTo("/AndroidManifest.xml", + new File(testFolder, "app/src/main/AndroidManifest.xml"), replacements); copyResourceTo("/project_build.gradle", new File(testFolder, "build.gradle"), replacements); copyResourceTo("/app_build.gradle", new File(testFolder, "app/build.gradle"), replacements); copyResourceTo("/settings.gradle", new File(testFolder, "settings.gradle"), replacements); @@ -226,14 +231,17 @@ public class BaseCompilationTest { FileUtils.forceMkdir(moduleFolder); copyResourceTo("/AndroidManifest.xml", new File(moduleFolder, "src/main/AndroidManifest.xml"), replacements); - copyResourceTo("/module_build.gradle", new File(moduleFolder, "build.gradle"), replacements); + copyResourceTo("/module_build.gradle", new File(moduleFolder, "build.gradle"), + replacements); } - protected CompilationResult runGradle(String... params) throws IOException, InterruptedException { + protected CompilationResult runGradle(String... params) + throws IOException, InterruptedException { setExecutable(); File pathToExecutable = new File(testFolder, "gradlew"); List<String> args = new ArrayList<>(); args.add(pathToExecutable.getAbsolutePath()); + args.add("-P" + PRINT_ENCODED_ERRORS_PROPERTY + "=true"); args.add("--project-cache-dir"); args.add(new File("../.caches/", name.getMethodName()).getAbsolutePath()); Collections.addAll(args, params); @@ -244,7 +252,7 @@ public class BaseCompilationTest { builder.environment().put("JAVA_HOME", javaHome); } builder.directory(testFolder); - Process process = builder.start(); + Process process = builder.start(); String output = IOUtils.toString(process.getInputStream()); String error = IOUtils.toString(process.getErrorStream()); int result = process.waitFor(); @@ -261,7 +269,8 @@ public class BaseCompilationTest { perms.add(PosixFilePermission.GROUP_READ); //add others permissions perms.add(PosixFilePermission.OTHERS_READ); - Files.setPosixFilePermissions(Paths.get(new File(testFolder, "gradlew").getAbsolutePath()), perms); + Files.setPosixFilePermissions(Paths.get(new File(testFolder, "gradlew").getAbsolutePath()), + perms); } |