| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Read the contents of a file [fileName] into a [List] of [String]s. | 6 * Read the contents of a file [fileName] into a [List] of [String]s. |
| 7 * If the file does not exist and [errorIfNoFile] is true, throw an | 7 * If the file does not exist and [errorIfNoFile] is true, throw an |
| 8 * exception, else return an empty list. | 8 * exception, else return an empty list. |
| 9 */ | 9 */ |
| 10 List<String> getFileContents(String filename, bool errorIfNoFile) { | 10 List<String> getFileContents(String filename, bool errorIfNoFile) { |
| 11 File f = new File(filename); | 11 File f = new File(filename); |
| 12 if (!f.existsSync()) { | 12 if (!f.existsSync()) { |
| 13 if (errorIfNoFile) { | 13 if (errorIfNoFile) { |
| 14 throw new Exception('Config file $filename not found.'); | 14 throw new Exception('Config file $filename not found.'); |
| 15 } else { | 15 } else { |
| 16 return new List(); | 16 return new List(); |
| 17 } | 17 } |
| 18 } | 18 } |
| 19 return f.readAsLinesSync(); | 19 return f.readAsLinesSync(); |
| 20 } | 20 } |
| 21 | 21 |
| 22 /** Copy a file with path [sourceName] to destination [destName]. */ | |
| 23 void copyFile(String sourceName, String destName) { | |
| 24 var sourceFile = new File(sourceName); | |
| 25 var destFile = new File(destName); | |
| 26 var istream = sourceFile.openInputStream(); | |
| 27 var ostream = destFile.openOutputStream(FileMode.WRITE); | |
| 28 istream.pipe(ostream); | |
| 29 // TODO(gram) - make sure both streams are closed. | |
| 30 // I think they are but the docs are not clear on this point. | |
| 31 } | |
| 32 | |
| 33 /** Create a file [fileName] and populate it with [contents]. */ | |
| 34 void createFile(String fileName, String contents) { | |
| 35 var file = new File(fileName); | |
| 36 var ostream = file.openOutputStream(FileMode.WRITE); | |
| 37 ostream.writeString(contents); | |
| 38 ostream.close(); | |
| 39 } | |
| 40 | |
| 41 /** | 22 /** |
| 42 * Given a file path [path], make it absolute if it is relative, | 23 * Given a file path [path], make it absolute if it is relative, |
| 43 * and return the result. | 24 * and return the result. |
| 44 */ | 25 */ |
| 45 String makePathAbsolute(String path) { | 26 String makePathAbsolute(String path) { |
| 46 var p = new Path(path).canonicalize(); | 27 var p = new Path(path).canonicalize(); |
| 47 if (p.isAbsolute) { | 28 if (p.isAbsolute) { |
| 48 return p.toString(); | 29 return p.toString(); |
| 49 } else { | 30 } else { |
| 50 var cwd = new Path((new Directory.current()).path); | 31 var cwd = new Path((new Directory.current()).path); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } else { // Does not exist. | 69 } else { // Does not exist. |
| 89 print('$path does not exist.'); | 70 print('$path does not exist.'); |
| 90 } | 71 } |
| 91 } | 72 } |
| 92 } | 73 } |
| 93 if (--dirCount == 0) { | 74 if (--dirCount == 0) { |
| 94 onComplete(files); | 75 onComplete(files); |
| 95 } | 76 } |
| 96 } | 77 } |
| 97 | 78 |
| 98 /** Delete a file. */ | |
| 99 bool deleteFile(String fname) { | |
| 100 var f = new File(fname); | |
| 101 try { | |
| 102 f.deleteSync(); | |
| 103 } catch (e) { | |
| 104 return false; | |
| 105 } | |
| 106 return true; | |
| 107 } | |
| 108 | |
| 109 /** | 79 /** |
| 110 * Get the directory that testrunner lives in; we need it to import | 80 * Get the directory that testrunner lives in; we need it to import |
| 111 * support files into the generated scripts. | 81 * support files into the generated scripts. |
| 112 */ | 82 */ |
| 113 | 83 |
| 114 String get runnerDirectory() { | 84 String get runnerDirectory() { |
| 115 var libDirectory = makePathAbsolute(new Options().script); | 85 var libDirectory = makePathAbsolute(new Options().script); |
| 116 return libDirectory.substring(0, | 86 return libDirectory.substring(0, |
| 117 libDirectory.lastIndexOf(Platform.pathSeparator)); | 87 libDirectory.lastIndexOf(Platform.pathSeparator)); |
| 118 } | 88 } |
| 119 | 89 |
| OLD | NEW |