| 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:core'; | 7 import 'dart:core'; |
| 8 | 8 |
| 9 import 'package:analyzer/file_system/file_system.dart'; | 9 import 'package:analyzer/file_system/file_system.dart'; |
| 10 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 if (!context.isAbsolute(path)) { | 84 if (!context.isAbsolute(path)) { |
| 85 throw new ArgumentError('not absolute: $path'); | 85 throw new ArgumentError('not absolute: $path'); |
| 86 } | 86 } |
| 87 path = context.normalize(path); | 87 path = context.normalize(path); |
| 88 | 88 |
| 89 Folder folder = provider.getFolder(path); | 89 Folder folder = provider.getFolder(path); |
| 90 while (true) { | 90 while (true) { |
| 91 Folder parent = folder.parent; | 91 Folder parent = folder.parent; |
| 92 | 92 |
| 93 // Found the READONLY folder, must be a git-based workspace. | 93 // Found the READONLY folder, must be a git-based workspace. |
| 94 if (readonlySuffix != null) { | 94 if (readonlySuffix != null && parent != null) { |
| 95 Folder readonlyFolder = parent.getChildAssumingFolder(_READONLY); | 95 Folder readonlyFolder = parent.getChildAssumingFolder(_READONLY); |
| 96 if (parent != null && readonlyFolder.exists) { | 96 if (readonlyFolder.exists) { |
| 97 String root = folder.path; | 97 String root = folder.path; |
| 98 String readonly = readonlyFolder.path; | 98 String readonly = readonlyFolder.path; |
| 99 return new BazelWorkspace._( | 99 return new BazelWorkspace._( |
| 100 provider, | 100 provider, |
| 101 root, | 101 root, |
| 102 context.join(readonly, readonlySuffix), | 102 context.join(readonly, readonlySuffix), |
| 103 context.join(root, '$symlinkPrefix-bin'), | 103 context.join(root, '$symlinkPrefix-bin'), |
| 104 context.join(root, '$symlinkPrefix-genfiles')); | 104 context.join(root, '$symlinkPrefix-genfiles')); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 // Found the WORKSPACE file, must be a non-git workspace. | 108 // Found the WORKSPACE file, must be a non-git workspace. |
| 109 if (folder.getChildAssumingFile(_WORKSPACE).exists) { | 109 if (folder.getChildAssumingFile(_WORKSPACE).exists) { |
| 110 String root = folder.path; | 110 String root = folder.path; |
| 111 return new BazelWorkspace._( | 111 return new BazelWorkspace._( |
| 112 provider, | 112 provider, |
| 113 root, | 113 root, |
| 114 null, | 114 null, |
| 115 context.join(root, '$symlinkPrefix-bin'), | 115 context.join(root, '$symlinkPrefix-bin'), |
| 116 context.join(root, '$symlinkPrefix-genfiles')); | 116 context.join(root, '$symlinkPrefix-genfiles')); |
| 117 } | 117 } |
| 118 | 118 |
| 119 // Go up the folder. | 119 // Go up the folder. |
| 120 folder = parent; | 120 folder = parent; |
| 121 if (folder == null) { | 121 if (folder == null) { |
| 122 return null; | 122 return new BazelWorkspace._(provider, path, null, null, null); |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 BazelWorkspace._( | 127 BazelWorkspace._( |
| 128 this.provider, this.root, this.readonly, this.bin, this.genfiles); | 128 this.provider, this.root, this.readonly, this.bin, this.genfiles); |
| 129 | 129 |
| 130 /** | 130 /** |
| 131 * Return the file with the given [absolutePath], looking first into | 131 * Return the file with the given [absolutePath], looking first into |
| 132 * directories for generated files: `bazel-bin` and `bazel-genfiles`, and | 132 * directories for generated files: `bazel-bin` and `bazel-genfiles`, and |
| 133 * then into the workspace root. The file in the workspace root is returned | 133 * then into the workspace root. The file in the workspace root is returned |
| 134 * even if it does not exist. Return `null` if the given [absolutePath] is | 134 * even if it does not exist. Return `null` if the given [absolutePath] is |
| 135 * not in the workspace [root]. | 135 * not in the workspace [root]. |
| 136 */ | 136 */ |
| 137 File findFile(String absolutePath) { | 137 File findFile(String absolutePath) { |
| 138 Context context = provider.pathContext; | 138 Context context = provider.pathContext; |
| 139 try { | 139 try { |
| 140 String relative = context.relative(absolutePath, from: root); | 140 String relative = context.relative(absolutePath, from: root); |
| 141 // genfiles | 141 // genfiles |
| 142 { | 142 if (genfiles != null) { |
| 143 File file = provider.getFile(context.join(genfiles, relative)); | 143 File file = provider.getFile(context.join(genfiles, relative)); |
| 144 if (file.exists) { | 144 if (file.exists) { |
| 145 return file; | 145 return file; |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 // bin | 148 // bin |
| 149 { | 149 if (bin != null) { |
| 150 File file = provider.getFile(context.join(bin, relative)); | 150 File file = provider.getFile(context.join(bin, relative)); |
| 151 if (file.exists) { | 151 if (file.exists) { |
| 152 return file; | 152 return file; |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 // READONLY | 155 // READONLY |
| 156 if (readonly != null) { | 156 if (readonly != null) { |
| 157 File file = provider.getFile(context.join(readonly, relative)); | 157 File file = provider.getFile(context.join(readonly, relative)); |
| 158 if (file.exists) { | 158 if (file.exists) { |
| 159 return file; | 159 return file; |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 // Not generated, return the default one. | 162 // Not generated, return the default one. |
| 163 return provider.getFile(absolutePath); | 163 return provider.getFile(absolutePath); |
| 164 } catch (_) { | 164 } catch (_) { |
| 165 return null; | 165 return null; |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 } | 168 } |
| OLD | NEW |