| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.bazel; | 5 library analyzer.src.generated.bazel; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:core'; | 8 import 'dart:core'; |
| 9 | 9 |
| 10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| 11 import 'package:analyzer/src/generated/sdk.dart'; |
| 11 import 'package:analyzer/src/generated/source.dart'; | 12 import 'package:analyzer/src/generated/source.dart'; |
| 12 import 'package:analyzer/src/generated/source_io.dart'; | 13 import 'package:analyzer/src/generated/source_io.dart'; |
| 14 import 'package:analyzer/src/generated/workspace.dart'; |
| 13 import 'package:analyzer/src/util/fast_uri.dart'; | 15 import 'package:analyzer/src/util/fast_uri.dart'; |
| 14 import 'package:path/path.dart'; | 16 import 'package:path/path.dart'; |
| 15 | 17 |
| 16 /** | 18 /** |
| 17 * Instances of the class `BazelFileUriResolver` resolve `file` URI's by first | 19 * Instances of the class `BazelFileUriResolver` resolve `file` URI's by first |
| 18 * resolving file uri's in the expected way, and then by looking in the | 20 * resolving file uri's in the expected way, and then by looking in the |
| 19 * corresponding generated directories. | 21 * corresponding generated directories. |
| 20 */ | 22 */ |
| 21 class BazelFileUriResolver extends ResourceUriResolver { | 23 class BazelFileUriResolver extends ResourceUriResolver { |
| 22 final BazelWorkspace workspace; | 24 final BazelWorkspace workspace; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } | 134 } |
| 133 } | 135 } |
| 134 | 136 |
| 135 return null; | 137 return null; |
| 136 } | 138 } |
| 137 } | 139 } |
| 138 | 140 |
| 139 /** | 141 /** |
| 140 * Information about a Bazel workspace. | 142 * Information about a Bazel workspace. |
| 141 */ | 143 */ |
| 142 class BazelWorkspace { | 144 class BazelWorkspace extends Workspace { |
| 143 static const String _WORKSPACE = 'WORKSPACE'; | 145 static const String _WORKSPACE = 'WORKSPACE'; |
| 144 static const String _READONLY = 'READONLY'; | 146 static const String _READONLY = 'READONLY'; |
| 145 | 147 |
| 146 /** | 148 /** |
| 147 * Default prefix for "-genfiles" and "-bin" that will be assumed if no build | 149 * Default prefix for "-genfiles" and "-bin" that will be assumed if no build |
| 148 * output symlinks are found. | 150 * output symlinks are found. |
| 149 */ | 151 */ |
| 150 static const defaultSymlinkPrefix = 'bazel'; | 152 static const defaultSymlinkPrefix = 'bazel'; |
| 151 | 153 |
| 152 final ResourceProvider provider; | 154 final ResourceProvider provider; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 171 final String bin; | 173 final String bin; |
| 172 | 174 |
| 173 /** | 175 /** |
| 174 * The absolute path to the `bazel-genfiles` folder. | 176 * The absolute path to the `bazel-genfiles` folder. |
| 175 */ | 177 */ |
| 176 final String genfiles; | 178 final String genfiles; |
| 177 | 179 |
| 178 BazelWorkspace._( | 180 BazelWorkspace._( |
| 179 this.provider, this.root, this.readonly, this.bin, this.genfiles); | 181 this.provider, this.root, this.readonly, this.bin, this.genfiles); |
| 180 | 182 |
| 183 @override |
| 184 Map<String, List<Folder>> get packageMap => null; |
| 185 |
| 186 @override |
| 187 UriResolver get packageUriResolver => new BazelPackageUriResolver(this); |
| 188 |
| 189 @override |
| 190 SourceFactory createSourceFactory(DartSdk sdk) { |
| 191 List<UriResolver> resolvers = <UriResolver>[]; |
| 192 if (sdk != null) { |
| 193 resolvers.add(new DartUriResolver(sdk)); |
| 194 } |
| 195 resolvers.add(packageUriResolver); |
| 196 resolvers.add(new BazelFileUriResolver(this)); |
| 197 return new SourceFactory(resolvers, null, provider); |
| 198 } |
| 199 |
| 181 /** | 200 /** |
| 182 * Return the file with the given [absolutePath], looking first into | 201 * Return the file with the given [absolutePath], looking first into |
| 183 * directories for generated files: `bazel-bin` and `bazel-genfiles`, and | 202 * directories for generated files: `bazel-bin` and `bazel-genfiles`, and |
| 184 * then into the workspace root. The file in the workspace root is returned | 203 * then into the workspace root. The file in the workspace root is returned |
| 185 * even if it does not exist. Return `null` if the given [absolutePath] is | 204 * even if it does not exist. Return `null` if the given [absolutePath] is |
| 186 * not in the workspace [root]. | 205 * not in the workspace [root]. |
| 187 */ | 206 */ |
| 188 File findFile(String absolutePath) { | 207 File findFile(String absolutePath) { |
| 189 Context context = provider.pathContext; | 208 Context context = provider.pathContext; |
| 190 try { | 209 try { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 if (provider.getFolder(context.join(root, 'blaze-genfiles')).exists) { | 320 if (provider.getFolder(context.join(root, 'blaze-genfiles')).exists) { |
| 302 return 'blaze'; | 321 return 'blaze'; |
| 303 } | 322 } |
| 304 if (provider.getFolder(context.join(root, 'bazel-genfiles')).exists) { | 323 if (provider.getFolder(context.join(root, 'bazel-genfiles')).exists) { |
| 305 return 'bazel'; | 324 return 'bazel'; |
| 306 } | 325 } |
| 307 // Couldn't find it. Make a default assumption. | 326 // Couldn't find it. Make a default assumption. |
| 308 return defaultSymlinkPrefix; | 327 return defaultSymlinkPrefix; |
| 309 } | 328 } |
| 310 } | 329 } |
| OLD | NEW |