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

Side by Side Diff: mojo/public/dart/third_party/analyzer/lib/source/analysis_options_provider.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
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.
4
5 library source.analysis_options_provider;
6
7 import 'package:analyzer/file_system/file_system.dart';
8 import 'package:yaml/yaml.dart';
9
10 /// Provide the options found in the `.analysis_options` file.
11 class AnalysisOptionsProvider {
12 /// The name of the analysis options source file.
13 static const String ANALYSIS_OPTIONS_NAME = '.analysis_options';
14
15 /// Provide the options found in [root]/[ANALYSIS_OPTIONS_NAME].
16 /// Return an empty options map if the file does not exist.
17 Map<String, YamlNode> getOptions(Folder root) {
18 var optionsSource =
19 _readAnalysisOptionsFile(root.getChild(ANALYSIS_OPTIONS_NAME));
20 return getOptionsFromString(optionsSource);
21 }
22
23 /// Provide the options found in [file].
24 /// Return an empty options map if the file does not exist.
25 Map<String, YamlNode> getOptionsFromFile(File file) {
26 var optionsSource = _readAnalysisOptionsFile(file);
27 return getOptionsFromString(optionsSource);
28 }
29
30 /// Provide the options found in [optionsSource].
31 /// Return an empty options map if the source is null.
32 Map<String, YamlNode> getOptionsFromString(String optionsSource) {
33 var options = <String, YamlNode>{};
34 if (optionsSource == null) {
35 return options;
36 }
37 var doc = loadYaml(optionsSource);
38 if (doc is! YamlMap) {
39 throw new Exception(
40 'Bad options file format (expected map, got ${doc.runtimeType})');
41 }
42 if (doc is YamlMap) {
43 doc.forEach((k, v) {
44 if (k is! String) {
45 throw new Exception(
46 'Bad options file format (expected String scope key, '
47 'got ${k.runtimeType})');
48 }
49 options[k] = v;
50 });
51 }
52 return options;
53 }
54
55 /// Read the contents of [file] as a string.
56 /// Returns null if file does not exist.
57 String _readAnalysisOptionsFile(File file) {
58 try {
59 return file.readAsStringSync();
60 } on FileSystemException {
61 // File can't be read.
62 return null;
63 }
64 }
65 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698