Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(771)

Side by Side Diff: editor/util/plugins/com.google.dart.java2dart/resources/java_io.dart

Issue 19266005: Use pathos.fromUri() to make it work on Windows. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analyzer_experimental/lib/src/generated/java_io.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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(String path) {
63 this._path = new Path(path); 64 _path = pathos.normalize(path);
64 } 65 }
65 JavaFile.relative(JavaFile base, String child) { 66 JavaFile.relative(JavaFile base, String child) {
66 if (child.isEmpty) { 67 if (child.isEmpty) {
67 this._path = base._path; 68 this._path = base._path;
68 } else { 69 } else {
69 this._path = base._path.join(new Path(child)); 70 this._path = pathos.join(base._path, child);
70 } 71 }
71 } 72 }
72 JavaFile.fromUri(Uri uri) : this(uri.path); 73 JavaFile.fromUri(Uri uri) : this(pathos.fromUri(uri));
74 String toString() => _path.toString();
73 int get hashCode => _path.hashCode; 75 int get hashCode => _path.hashCode;
74 bool operator ==(other) { 76 bool operator ==(other) {
75 return other is JavaFile && other._path.toNativePath() == _path.toNativePath (); 77 return other is JavaFile && other._path == _path;
76 } 78 }
77 String getPath() => _path.toNativePath(); 79 String getPath() => _path;
78 String getName() => _path.filename; 80 String getName() => pathos.basename(_path);
79 String getParent() { 81 String getParent() {
80 var result = _path.directoryPath.toNativePath(); 82 var result = pathos.dirname(_path);
81 // "." or "/" or "C:\" 83 // "." or "/" or "C:\"
82 if (result.length < 4) return null; 84 if (result.length < 4) return null;
83 return result; 85 return result;
84 } 86 }
85 JavaFile getParentFile() { 87 JavaFile getParentFile() {
86 var parent = getParent(); 88 var parent = getParent();
87 if (parent == null) return null; 89 if (parent == null) return null;
88 return new JavaFile(parent); 90 return new JavaFile(parent);
89 } 91 }
90 String getAbsolutePath() => _path.canonicalize().toNativePath(); 92 String getAbsolutePath() => pathos.absolute(_path);
91 String getCanonicalPath() => _path.canonicalize().toNativePath(); 93 String getCanonicalPath() => _newFile().fullPathSync();
92 JavaFile getAbsoluteFile() => new JavaFile(getAbsolutePath()); 94 JavaFile getAbsoluteFile() => new JavaFile(getAbsolutePath());
93 JavaFile getCanonicalFile() => new JavaFile(getCanonicalPath()); 95 JavaFile getCanonicalFile() => new JavaFile(getCanonicalPath());
94 bool exists() { 96 bool exists() {
95 if (_newFile().existsSync()) { 97 if (_newFile().existsSync()) {
96 return true; 98 return true;
97 } 99 }
98 if (_newDirectory().existsSync()) { 100 if (_newDirectory().existsSync()) {
99 return true; 101 return true;
100 } 102 }
101 return false; 103 return false;
102 } 104 }
103 bool isDirectory() { 105 bool isDirectory() {
104 return _newDirectory().existsSync(); 106 return _newDirectory().existsSync();
105 } 107 }
106 Uri toURI() => new Uri(path: _path.toString()); 108 Uri toURI() => pathos.toUri(_path);
107 String readAsStringSync() => _newFile().readAsStringSync(); 109 String readAsStringSync() => _newFile().readAsStringSync();
108 int lastModified() { 110 int lastModified() {
109 if (!_newFile().existsSync()) return 0; 111 if (!_newFile().existsSync()) return 0;
110 return _newFile().lastModifiedSync().millisecondsSinceEpoch; 112 return _newFile().lastModifiedSync().millisecondsSinceEpoch;
111 113
112 } 114 }
113 List<JavaFile> listFiles() { 115 List<JavaFile> listFiles() {
114 List<JavaFile> files = []; 116 var files = <JavaFile>[];
115 List<FileSystemEntity> entities = _newDirectory().listSync(); 117 var entities = _newDirectory().listSync();
116 for (FileSystemEntity entity in entities) { 118 for (FileSystemEntity entity in entities) {
117 files.add(new JavaFile(entity.path)); 119 files.add(new JavaFile(entity.path));
118 } 120 }
119 return files; 121 return files;
120 } 122 }
121 File _newFile() => new File.fromPath(_path); 123 File _newFile() => new File(_path);
122 Directory _newDirectory() => new Directory.fromPath(_path); 124 Directory _newDirectory() => new Directory(_path);
123 } 125 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer_experimental/lib/src/generated/java_io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698