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

Side by Side Diff: utils/pub/io.dart

Issue 12090093: Reapply "Rename mappedBy to map." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed bug in previous commit. Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « utils/pub/hosted_source.dart ('k') | utils/pub/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /// Helper functionality to make working with IO easier. 5 /// Helper functionality to make working with IO easier.
6 library io; 6 library io;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:io'; 9 import 'dart:io';
10 import 'dart:isolate'; 10 import 'dart:isolate';
11 import 'dart:json'; 11 import 'dart:json';
12 import 'dart:uri'; 12 import 'dart:uri';
13 13
14 import '../../pkg/path/lib/path.dart' as path; 14 import '../../pkg/path/lib/path.dart' as path;
15 import 'log.dart' as log; 15 import 'log.dart' as log;
16 import 'utils.dart'; 16 import 'utils.dart';
17 17
18 final NEWLINE_PATTERN = new RegExp("\r\n?|\n\r?"); 18 final NEWLINE_PATTERN = new RegExp("\r\n?|\n\r?");
19 19
20 /// Joins a number of path string parts into a single path. Handles 20 /// Joins a number of path string parts into a single path. Handles
21 /// platform-specific path separators. Parts can be [String], [Directory], or 21 /// platform-specific path separators. Parts can be [String], [Directory], or
22 /// [File] objects. 22 /// [File] objects.
23 String join(part1, [part2, part3, part4, part5, part6, part7, part8]) { 23 String join(part1, [part2, part3, part4, part5, part6, part7, part8]) {
24 var parts = [part1, part2, part3, part4, part5, part6, part7, part8] 24 var parts = [part1, part2, part3, part4, part5, part6, part7, part8]
25 .mappedBy((part) => part == null ? null : _getPath(part)).toList(); 25 .map((part) => part == null ? null : _getPath(part)).toList();
26 26
27 return path.join(parts[0], parts[1], parts[2], parts[3], parts[4], parts[5], 27 return path.join(parts[0], parts[1], parts[2], parts[3], parts[4], parts[5],
28 parts[6], parts[7]); 28 parts[6], parts[7]);
29 } 29 }
30 30
31 /// Gets the basename, the file name without any leading directory path, for 31 /// Gets the basename, the file name without any leading directory path, for
32 /// [file], which can either be a [String], [File], or [Directory]. 32 /// [file], which can either be a [String], [File], or [Directory].
33 String basename(file) => path.basename(_getPath(file)); 33 String basename(file) => path.basename(_getPath(file));
34 34
35 /// Gets the the leading directory path for [file], which can either be a 35 /// Gets the the leading directory path for [file], which can either be a
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 buffer.add('Creating .tag.gz stream containing:\n'); 866 buffer.add('Creating .tag.gz stream containing:\n');
867 contents.forEach((file) => buffer.add('$file\n')); 867 contents.forEach((file) => buffer.add('$file\n'));
868 log.fine(buffer.toString()); 868 log.fine(buffer.toString());
869 869
870 // TODO(nweiz): Propagate errors to the returned stream (including non-zero 870 // TODO(nweiz): Propagate errors to the returned stream (including non-zero
871 // exit codes). See issue 3657. 871 // exit codes). See issue 3657.
872 var stream = new ListInputStream(); 872 var stream = new ListInputStream();
873 873
874 if (baseDir == null) baseDir = path.current; 874 if (baseDir == null) baseDir = path.current;
875 baseDir = getFullPath(baseDir); 875 baseDir = getFullPath(baseDir);
876 contents = contents.mappedBy((entry) { 876 contents = contents.map((entry) {
877 entry = getFullPath(entry); 877 entry = getFullPath(entry);
878 if (!isBeneath(entry, baseDir)) { 878 if (!isBeneath(entry, baseDir)) {
879 throw 'Entry $entry is not inside $baseDir.'; 879 throw 'Entry $entry is not inside $baseDir.';
880 } 880 }
881 return relativeTo(entry, baseDir); 881 return relativeTo(entry, baseDir);
882 }).toList(); 882 }).toList();
883 883
884 if (Platform.operatingSystem != "windows") { 884 if (Platform.operatingSystem != "windows") {
885 var args = ["--create", "--gzip", "--directory", baseDir]; 885 var args = ["--create", "--gzip", "--directory", baseDir];
886 args.addAll(contents.mappedBy(_getPath)); 886 args.addAll(contents.map(_getPath));
887 // TODO(nweiz): It's possible that enough command-line arguments will make 887 // TODO(nweiz): It's possible that enough command-line arguments will make
888 // the process choke, so at some point we should save the arguments to a 888 // the process choke, so at some point we should save the arguments to a
889 // file and pass them in via --files-from for tar and -i@filename for 7zip. 889 // file and pass them in via --files-from for tar and -i@filename for 7zip.
890 startProcess("tar", args).then((process) { 890 startProcess("tar", args).then((process) {
891 pipeInputToInput(process.stdout, stream); 891 pipeInputToInput(process.stdout, stream);
892 892
893 // Drain and discard 7zip's stderr. 7zip writes its normal output to 893 // Drain and discard 7zip's stderr. 7zip writes its normal output to
894 // stderr. We don't want to show that since it's meaningless. 894 // stderr. We don't want to show that since it's meaningless.
895 // TODO(rnystrom): Should log this and display it if an actual error 895 // TODO(rnystrom): Should log this and display it if an actual error
896 // occurs. 896 // occurs.
897 consumeInputStream(process.stderr); 897 consumeInputStream(process.stderr);
898 }); 898 });
899 return stream; 899 return stream;
900 } 900 }
901 901
902 withTempDir((tempDir) { 902 withTempDir((tempDir) {
903 // Create the tar file. 903 // Create the tar file.
904 var tarFile = join(tempDir, "intermediate.tar"); 904 var tarFile = join(tempDir, "intermediate.tar");
905 var args = ["a", "-w$baseDir", tarFile]; 905 var args = ["a", "-w$baseDir", tarFile];
906 args.addAll(contents.mappedBy((entry) => '-i!"$entry"')); 906 args.addAll(contents.map((entry) => '-i!"$entry"'));
907 907
908 // Note: This line of code gets munged by create_sdk.py to be the correct 908 // Note: This line of code gets munged by create_sdk.py to be the correct
909 // relative path to 7zip in the SDK. 909 // relative path to 7zip in the SDK.
910 var pathTo7zip = '../../third_party/7zip/7za.exe'; 910 var pathTo7zip = '../../third_party/7zip/7za.exe';
911 var command = relativeToPub(pathTo7zip); 911 var command = relativeToPub(pathTo7zip);
912 912
913 // We're passing 'baseDir' both as '-w' and setting it as the working 913 // We're passing 'baseDir' both as '-w' and setting it as the working
914 // directory explicitly here intentionally. The former ensures that the 914 // directory explicitly here intentionally. The former ensures that the
915 // files added to the archive have the correct relative path in the archive. 915 // files added to the archive have the correct relative path in the archive.
916 // The latter enables relative paths in the "-i" args to be resolved. 916 // The latter enables relative paths in the "-i" args to be resolved.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 Directory _getDirectory(entry) { 966 Directory _getDirectory(entry) {
967 if (entry is Directory) return entry; 967 if (entry is Directory) return entry;
968 return new Directory(entry); 968 return new Directory(entry);
969 } 969 }
970 970
971 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. 971 /// Gets a [Uri] for [uri], which can either already be one, or be a [String].
972 Uri _getUri(uri) { 972 Uri _getUri(uri) {
973 if (uri is Uri) return uri; 973 if (uri is Uri) return uri;
974 return Uri.parse(uri); 974 return Uri.parse(uri);
975 } 975 }
OLDNEW
« no previous file with comments | « utils/pub/hosted_source.dart ('k') | utils/pub/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698