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

Side by Side Diff: pkg/fasta/lib/src/environment_variable.dart

Issue 2634453004: Fasta infrastructure. (Closed)
Patch Set: Created 3 years, 11 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) 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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library fasta.environment_variable;
6
7 import 'dart:async' show
8 Future;
9
10 import 'dart:io' show
11 Directory,
12 File,
13 Platform;
14
15 import 'errors.dart' show
16 inputError;
17
18 class EnvironmentVariable {
19 final String name;
20
21 final String what;
22
23 const EnvironmentVariable(this.name, this.what);
24
25 Future<String> get value async {
26 String value = Platform.environment[name];
27 if (value == null) return variableNotDefined();
28 await validate(value);
29 return value;
30 }
31
32 Future<Null> validate(String value) => new Future<Null>.value();
33
34 variableNotDefined() {
35 inputError(null, null,
36 "The environment variable '$name' isn't defined. $what");
37 }
38 }
39
40 class EnvironmentVariableFile extends EnvironmentVariable {
41 const EnvironmentVariableFile(String name, String what)
42 : super(name, what);
43
44 Future<Null> validate(String value) async {
45 if (!await new File(value).exists()) notFound(value);
46 return null;
47 }
48
49 notFound(String value) {
50 inputError(null, null,"The environment variable '$name' has the value "
51 "'$value', that isn't a file. $what");
52 }
53 }
54
55 class EnvironmentVariableDirectory extends EnvironmentVariable {
56 const EnvironmentVariableDirectory(String name, String what)
57 : super(name, what);
58
59 Future<Null> validate(String value) async {
60 if (!await new Directory(value).exists()) notFound(value);
61 return null;
62 }
63
64 notFound(String value) {
65 inputError(null, null, "The environment variable '$name' has the value "
66 "'$value', that isn't a directory. $what");
67 }
68 }
69
70 Future<bool> fileExists(Uri base, String path) async {
71 return await new File.fromUri(base.resolve(path)).exists();
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698