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

Unified Diff: pkg/fasta/lib/src/environment_variable.dart

Issue 2634453004: Fasta infrastructure. (Closed)
Patch Set: Address review comments. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/fasta/lib/src/compiler_command_line.dart ('k') | pkg/fasta/lib/src/errors.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/fasta/lib/src/environment_variable.dart
diff --git a/pkg/fasta/lib/src/environment_variable.dart b/pkg/fasta/lib/src/environment_variable.dart
new file mode 100644
index 0000000000000000000000000000000000000000..c58ab1771ebcb3abb30052fd238106cde485bbce
--- /dev/null
+++ b/pkg/fasta/lib/src/environment_variable.dart
@@ -0,0 +1,72 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library fasta.environment_variable;
+
+import 'dart:async' show
+ Future;
+
+import 'dart:io' show
+ Directory,
+ File,
+ Platform;
+
+import 'errors.dart' show
+ inputError;
+
+class EnvironmentVariable {
+ final String name;
+
+ final String what;
+
+ const EnvironmentVariable(this.name, this.what);
+
+ Future<String> get value async {
+ String value = Platform.environment[name];
+ if (value == null) return variableNotDefined();
+ await validate(value);
+ return value;
+ }
+
+ Future<Null> validate(String value) => new Future<Null>.value();
+
+ variableNotDefined() {
+ inputError(null, null,
+ "The environment variable '$name' isn't defined. $what");
+ }
+}
+
+class EnvironmentVariableFile extends EnvironmentVariable {
+ const EnvironmentVariableFile(String name, String what)
+ : super(name, what);
+
+ Future<Null> validate(String value) async {
+ if (!await new File(value).exists()) notFound(value);
+ return null;
+ }
+
+ notFound(String value) {
+ inputError(null, null,"The environment variable '$name' has the value "
+ "'$value', that isn't a file. $what");
+ }
+}
+
+class EnvironmentVariableDirectory extends EnvironmentVariable {
+ const EnvironmentVariableDirectory(String name, String what)
+ : super(name, what);
+
+ Future<Null> validate(String value) async {
+ if (!await new Directory(value).exists()) notFound(value);
+ return null;
+ }
+
+ notFound(String value) {
+ inputError(null, null, "The environment variable '$name' has the value "
+ "'$value', that isn't a directory. $what");
+ }
+}
+
+Future<bool> fileExists(Uri base, String path) async {
+ return await new File.fromUri(base.resolve(path)).exists();
+}
« no previous file with comments | « pkg/fasta/lib/src/compiler_command_line.dart ('k') | pkg/fasta/lib/src/errors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698