OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library analyzer.src.generated.java_io; | 5 library analyzer.src.generated.java_io; |
6 | 6 |
7 import "dart:io"; | 7 import "dart:io"; |
8 | 8 |
9 import 'package:path/path.dart' as path; | 9 import 'package:path/path.dart' as path; |
10 | 10 |
11 class JavaFile { | 11 class JavaFile { |
| 12 @deprecated |
12 static path.Context pathContext = path.context; | 13 static path.Context pathContext = path.context; |
13 static final String separator = Platform.pathSeparator; | 14 static final String separator = Platform.pathSeparator; |
14 static final int separatorChar = Platform.pathSeparator.codeUnitAt(0); | 15 static final int separatorChar = Platform.pathSeparator.codeUnitAt(0); |
15 String _path; | 16 String _path; |
16 JavaFile(String path) { | 17 JavaFile(String path) { |
17 _path = path; | 18 _path = path; |
18 } | 19 } |
19 JavaFile.fromUri(Uri uri) : this(pathContext.fromUri(uri)); | 20 JavaFile.fromUri(Uri uri) : this(path.context.fromUri(uri)); |
20 JavaFile.relative(JavaFile base, String child) { | 21 JavaFile.relative(JavaFile base, String child) { |
21 if (child.isEmpty) { | 22 if (child.isEmpty) { |
22 this._path = base._path; | 23 this._path = base._path; |
23 } else { | 24 } else { |
24 this._path = pathContext.join(base._path, child); | 25 this._path = path.context.join(base._path, child); |
25 } | 26 } |
26 } | 27 } |
27 @override | 28 @override |
28 int get hashCode => _path.hashCode; | 29 int get hashCode => _path.hashCode; |
29 @override | 30 @override |
30 bool operator ==(other) { | 31 bool operator ==(other) { |
31 return other is JavaFile && other._path == _path; | 32 return other is JavaFile && other._path == _path; |
32 } | 33 } |
33 | 34 |
34 bool exists() { | 35 bool exists() { |
35 if (_newFile().existsSync()) { | 36 if (_newFile().existsSync()) { |
36 return true; | 37 return true; |
37 } | 38 } |
38 if (_newDirectory().existsSync()) { | 39 if (_newDirectory().existsSync()) { |
39 return true; | 40 return true; |
40 } | 41 } |
41 return false; | 42 return false; |
42 } | 43 } |
43 | 44 |
44 JavaFile getAbsoluteFile() => new JavaFile(getAbsolutePath()); | 45 JavaFile getAbsoluteFile() => new JavaFile(getAbsolutePath()); |
45 String getAbsolutePath() { | 46 String getAbsolutePath() { |
46 String path = pathContext.absolute(_path); | 47 String abolutePath = path.context.absolute(_path); |
47 path = pathContext.normalize(path); | 48 abolutePath = path.context.normalize(abolutePath); |
48 return path; | 49 return abolutePath; |
49 } | 50 } |
50 | 51 |
51 JavaFile getCanonicalFile() => new JavaFile(getCanonicalPath()); | 52 JavaFile getCanonicalFile() => new JavaFile(getCanonicalPath()); |
52 String getCanonicalPath() { | 53 String getCanonicalPath() { |
53 return _newFile().resolveSymbolicLinksSync(); | 54 return _newFile().resolveSymbolicLinksSync(); |
54 } | 55 } |
55 | 56 |
56 String getName() => pathContext.basename(_path); | 57 String getName() => path.context.basename(_path); |
57 String getParent() { | 58 String getParent() { |
58 var result = pathContext.dirname(_path); | 59 var result = path.context.dirname(_path); |
59 // "." or "/" or "C:\" | 60 // "." or "/" or "C:\" |
60 if (result.length < 4) return null; | 61 if (result.length < 4) return null; |
61 return result; | 62 return result; |
62 } | 63 } |
63 | 64 |
64 JavaFile getParentFile() { | 65 JavaFile getParentFile() { |
65 var parent = getParent(); | 66 var parent = getParent(); |
66 if (parent == null) return null; | 67 if (parent == null) return null; |
67 return new JavaFile(parent); | 68 return new JavaFile(parent); |
68 } | 69 } |
(...skipping 25 matching lines...) Expand all Loading... |
94 for (FileSystemEntity entity in entities) { | 95 for (FileSystemEntity entity in entities) { |
95 files.add(new JavaFile(entity.path)); | 96 files.add(new JavaFile(entity.path)); |
96 } | 97 } |
97 return files; | 98 return files; |
98 } | 99 } |
99 | 100 |
100 String readAsStringSync() => _newFile().readAsStringSync(); | 101 String readAsStringSync() => _newFile().readAsStringSync(); |
101 @override | 102 @override |
102 String toString() => _path.toString(); | 103 String toString() => _path.toString(); |
103 Uri toURI() { | 104 Uri toURI() { |
104 String path = getAbsolutePath(); | 105 String absolutePath = getAbsolutePath(); |
105 return pathContext.toUri(path); | 106 return path.context.toUri(absolutePath); |
106 } | 107 } |
107 | 108 |
108 Directory _newDirectory() => new Directory(_path); | 109 Directory _newDirectory() => new Directory(_path); |
109 File _newFile() => new File(_path); | 110 File _newFile() => new File(_path); |
110 } | 111 } |
111 | 112 |
112 class JavaSystemIO { | 113 class JavaSystemIO { |
113 static Map<String, String> _properties = new Map(); | 114 static Map<String, String> _properties = new Map(); |
114 static String getenv(String name) => Platform.environment[name]; | 115 static String getenv(String name) => Platform.environment[name]; |
115 static String getProperty(String name) { | 116 static String getProperty(String name) { |
(...skipping 11 matching lines...) Expand all Loading... |
127 return '\r\n'; | 128 return '\r\n'; |
128 } | 129 } |
129 return '\n'; | 130 return '\n'; |
130 } | 131 } |
131 if (name == 'com.google.dart.sdk') { | 132 if (name == 'com.google.dart.sdk') { |
132 String exec = Platform.executable; | 133 String exec = Platform.executable; |
133 if (exec.length != 0) { | 134 if (exec.length != 0) { |
134 String sdkPath; | 135 String sdkPath; |
135 // may be "xcodebuild/ReleaseIA32/dart" with "sdk" sibling | 136 // may be "xcodebuild/ReleaseIA32/dart" with "sdk" sibling |
136 { | 137 { |
137 var outDir = | 138 var outDir = path.context.dirname(path.context.dirname(exec)); |
138 JavaFile.pathContext.dirname(JavaFile.pathContext.dirname(exec)); | 139 sdkPath = path.context.join(path.context.dirname(outDir), "sdk"); |
139 sdkPath = JavaFile.pathContext | |
140 .join(JavaFile.pathContext.dirname(outDir), "sdk"); | |
141 if (new Directory(sdkPath).existsSync()) { | 140 if (new Directory(sdkPath).existsSync()) { |
142 _properties[name] = sdkPath; | 141 _properties[name] = sdkPath; |
143 return sdkPath; | 142 return sdkPath; |
144 } | 143 } |
145 } | 144 } |
146 // probably be "dart-sdk/bin/dart" | 145 // probably be "dart-sdk/bin/dart" |
147 sdkPath = | 146 sdkPath = path.context.dirname(path.context.dirname(exec)); |
148 JavaFile.pathContext.dirname(JavaFile.pathContext.dirname(exec)); | |
149 _properties[name] = sdkPath; | 147 _properties[name] = sdkPath; |
150 return sdkPath; | 148 return sdkPath; |
151 } | 149 } |
152 } | 150 } |
153 return null; | 151 return null; |
154 } | 152 } |
155 | 153 |
156 static String setProperty(String name, String value) { | 154 static String setProperty(String name, String value) { |
157 String oldValue = _properties[name]; | 155 String oldValue = _properties[name]; |
158 _properties[name] = value; | 156 _properties[name] = value; |
159 return oldValue; | 157 return oldValue; |
160 } | 158 } |
161 } | 159 } |
OLD | NEW |