Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 library java.io; | 1 library java.io; |
| 2 | 2 |
| 3 import "dart:io"; | 3 import "dart:io"; |
| 4 import 'package:path/path.dart' as pathos; | |
| 4 | 5 |
| 5 class JavaSystemIO { | 6 class JavaSystemIO { |
| 6 static Map<String, String> _properties = new Map(); | 7 static Map<String, String> _properties = new Map(); |
| 7 static String getProperty(String name) { | 8 static String getProperty(String name) { |
| 8 { | 9 { |
| 9 String value = _properties[name]; | 10 String value = _properties[name]; |
| 10 if (value != null) { | 11 if (value != null) { |
| 11 return value; | 12 return value; |
| 12 } | 13 } |
| 13 } | 14 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 26 _properties[name] = value; | 27 _properties[name] = value; |
| 27 return value; | 28 return value; |
| 28 } | 29 } |
| 29 } | 30 } |
| 30 if (name == 'com.google.dart.sdk') { | 31 if (name == 'com.google.dart.sdk') { |
| 31 String exec = Platform.executable; | 32 String exec = Platform.executable; |
| 32 if (exec.length != 0) { | 33 if (exec.length != 0) { |
| 33 String sdkPath; | 34 String sdkPath; |
| 34 // may be "xcodebuild/ReleaseIA32/dart" with "dart-sdk" sibling | 35 // may be "xcodebuild/ReleaseIA32/dart" with "dart-sdk" sibling |
| 35 { | 36 { |
| 36 sdkPath = new Path(exec).directoryPath.append("dart-sdk").toNativePath (); | 37 sdkPath = pathos.join(pathos.dirname(exec), "dart-sdk"); |
| 37 if (new Directory(sdkPath).existsSync()) { | 38 if (new Directory(sdkPath).existsSync()) { |
| 38 _properties[name] = sdkPath; | 39 _properties[name] = sdkPath; |
| 39 return sdkPath; | 40 return sdkPath; |
| 40 } | 41 } |
| 41 } | 42 } |
| 42 // probably be "dart-sdk/bin/dart" | 43 // probably be "dart-sdk/bin/dart" |
| 43 sdkPath = new Path(exec).directoryPath.directoryPath.toString(); | 44 sdkPath = pathos.dirname(pathos.dirname(exec)); |
| 44 _properties[name] = sdkPath; | 45 _properties[name] = sdkPath; |
| 45 return sdkPath; | 46 return sdkPath; |
| 46 } | 47 } |
| 47 } | 48 } |
| 48 return null; | 49 return null; |
| 49 } | 50 } |
| 50 static String setProperty(String name, String value) { | 51 static String setProperty(String name, String value) { |
| 51 String oldValue = _properties[name]; | 52 String oldValue = _properties[name]; |
| 52 _properties[name] = value; | 53 _properties[name] = value; |
| 53 return oldValue; | 54 return oldValue; |
| 54 } | 55 } |
| 55 static String getenv(String name) => Platform.environment[name]; | 56 static String getenv(String name) => Platform.environment[name]; |
| 56 } | 57 } |
| 57 | 58 |
| 58 class JavaFile { | 59 class JavaFile { |
| 59 static final String separator = Platform.pathSeparator; | 60 static final String separator = Platform.pathSeparator; |
| 60 static final int separatorChar = Platform.pathSeparator.codeUnitAt(0); | 61 static final int separatorChar = Platform.pathSeparator.codeUnitAt(0); |
| 61 Path _path; | 62 String _path; |
| 62 JavaFile(String path) { | 63 JavaFile(this._path); |
| 63 this._path = new Path(path); | |
| 64 } | |
| 65 JavaFile.relative(JavaFile base, String child) { | 64 JavaFile.relative(JavaFile base, String child) { |
| 66 if (child.isEmpty) { | 65 if (child.isEmpty) { |
| 67 this._path = base._path; | 66 this._path = base._path; |
| 68 } else { | 67 } else { |
| 69 this._path = base._path.join(new Path(child)); | 68 this._path = pathos.join(base._path, child); |
| 70 } | 69 } |
| 71 } | 70 } |
| 72 JavaFile.fromUri(Uri uri) : this(uri.path); | 71 JavaFile.fromUri(Uri uri) : this(uri.path); |
| 72 String toString() => _path.toString(); | |
| 73 int get hashCode => _path.hashCode; | 73 int get hashCode => _path.hashCode; |
| 74 bool operator ==(other) { | 74 bool operator ==(other) { |
| 75 return other is JavaFile && other._path.toNativePath() == _path.toNativePath (); | 75 return other is JavaFile && other._path == _path; |
| 76 } | 76 } |
| 77 String getPath() => _path.toNativePath(); | 77 String getPath() => _path; |
| 78 String getName() => _path.filename; | 78 String getName() => pathos.basename(_path); |
| 79 String getParent() { | 79 String getParent() { |
| 80 var result = _path.directoryPath.toNativePath(); | 80 var result = pathos.dirname(_path); |
| 81 // "." or "/" or "C:\" | 81 // "." or "/" or "C:\" |
| 82 if (result.length < 4) return null; | 82 if (result.length < 4) return null; |
| 83 return result; | 83 return result; |
| 84 } | 84 } |
| 85 JavaFile getParentFile() { | 85 JavaFile getParentFile() { |
| 86 var parent = getParent(); | 86 var parent = getParent(); |
| 87 if (parent == null) return null; | 87 if (parent == null) return null; |
| 88 return new JavaFile(parent); | 88 return new JavaFile(parent); |
| 89 } | 89 } |
| 90 String getAbsolutePath() => _path.canonicalize().toNativePath(); | 90 String getAbsolutePath() => pathos.absolute(_path); |
| 91 String getCanonicalPath() => _path.canonicalize().toNativePath(); | 91 String getCanonicalPath() => _newFile().fullPathSync(); |
|
Brian Wilkerson
2013/07/15 18:38:42
While the comment for this method reads "Synchrono
| |
| 92 JavaFile getAbsoluteFile() => new JavaFile(getAbsolutePath()); | 92 JavaFile getAbsoluteFile() => new JavaFile(getAbsolutePath()); |
| 93 JavaFile getCanonicalFile() => new JavaFile(getCanonicalPath()); | 93 JavaFile getCanonicalFile() => new JavaFile(getCanonicalPath()); |
| 94 bool exists() { | 94 bool exists() { |
| 95 if (_newFile().existsSync()) { | 95 if (_newFile().existsSync()) { |
| 96 return true; | 96 return true; |
| 97 } | 97 } |
| 98 if (_newDirectory().existsSync()) { | 98 if (_newDirectory().existsSync()) { |
| 99 return true; | 99 return true; |
| 100 } | 100 } |
| 101 return false; | 101 return false; |
| 102 } | 102 } |
| 103 bool isDirectory() { | 103 bool isDirectory() { |
| 104 return _newDirectory().existsSync(); | 104 return _newDirectory().existsSync(); |
| 105 } | 105 } |
| 106 Uri toURI() => new Uri(path: _path.toString()); | 106 Uri toURI() => new Uri(path: _path.toString()); |
| 107 String readAsStringSync() => _newFile().readAsStringSync(); | 107 String readAsStringSync() => _newFile().readAsStringSync(); |
| 108 int lastModified() { | 108 int lastModified() { |
| 109 if (!_newFile().existsSync()) return 0; | 109 if (!_newFile().existsSync()) return 0; |
| 110 return _newFile().lastModifiedSync().millisecondsSinceEpoch; | 110 return _newFile().lastModifiedSync().millisecondsSinceEpoch; |
| 111 | 111 |
| 112 } | 112 } |
| 113 List<JavaFile> listFiles() { | 113 List<JavaFile> listFiles() { |
| 114 List<JavaFile> files = []; | 114 List<JavaFile> files = []; |
| 115 List<FileSystemEntity> entities = _newDirectory().listSync(); | 115 List<FileSystemEntity> entities = _newDirectory().listSync(); |
| 116 for (FileSystemEntity entity in entities) { | 116 for (FileSystemEntity entity in entities) { |
| 117 files.add(new JavaFile(entity.path)); | 117 files.add(new JavaFile(entity.path)); |
| 118 } | 118 } |
| 119 return files; | 119 return files; |
| 120 } | 120 } |
| 121 File _newFile() => new File.fromPath(_path); | 121 File _newFile() => new File(_path); |
| 122 Directory _newDirectory() => new Directory.fromPath(_path); | 122 Directory _newDirectory() => new Directory(_path); |
| 123 } | 123 } |
| OLD | NEW |