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