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: pkg/barback/lib/src/asset_id.dart

Issue 16854005: First pass at build dependency graph for barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 7 years, 6 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
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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 barback.asset_id;
6
7 import 'dart:async';
8 import 'dart:io';
9
10 import 'package:pathos/path.dart' as pathos;
11
12 /// AssetIDs always use POSIX style paths regardless of the host platform.
13 final _posix = new pathos.Builder(style: pathos.Style.posix);
14
15 /// Identifies an asset within a package.
16 class AssetId {
17 /// The name of the package containing this asset.
18 final String package;
19
20 /// The path to the asset relative to the root directory of [package].
21 ///
22 /// Source (i.e. read from disk) and generated (i.e. the output of a
23 /// [Transformer]) assets all have paths. Even intermediate assets that are
24 /// generated and then consumed by later transformations will still have
25 /// a path used to identify it.
26 ///
27 /// Asset paths always use forward slashes as path separators, regardless of
28 /// the host platform.
29 final String path;
30
31 /// Gets the file extension of the asset, if it has one, including the ".".
32 String get extension => pathos.extension(path);
33
34 /// Creates a new AssetId at [path] within [package].
35 AssetId(this.package, String path)
36 : path = _posix.normalize(path);
37
38 /// Parses an [AssetId] string of the form "package|path/to/asset.txt".
39 factory AssetId.parse(String description) {
40 var parts = description.split("|");
41 if (parts.length != 2) {
42 throw new FormatException('Could not parse "$description".');
43 }
44
45 return new AssetId(parts[0], parts[1]);
46 }
47
48 /// Deserializes an [AssetId] from [data], which must be the result of
49 /// calling [serialize] on an existing [AssetId].
50 ///
51 /// Note that this is intended for communicating ids across isolates and not
52 /// for persistent storage of asset identifiers. There is no guarantee of
53 /// backwards compatibility in serialization form across versions.
54 AssetId.deserialize(data)
55 : package = data[0],
56 path = data[1];
57
58 /// Returns `true` of [other] is an [AssetId] with the same package and path.
59 operator ==(other) =>
60 other is AssetId &&
61 package == other.package &&
62 path == other.path;
63
64 int get hashCode => package.hashCode ^ path.hashCode;
65
66 /// Returns a new [AssetId] with the same [package] as this one and with the
67 /// [path] extended to include [extension].
68 AssetId addExtension(String extension) =>
69 new AssetId(package, "$path$extension");
70
71 /// Returns a new [AssetId] with the same [package] and [path] as this one
72 /// but with file extension [newExtension].
73 AssetId changeExtension(String newExtension) =>
74 new AssetId(package, pathos.withoutExtension(path) + newExtension);
75
76 String toString() => "$package|$path";
77
78 /// Serializes this [AssetId] to an object that can be sent across isolates
79 /// and passed to [deserialize].
80 serialize() => [package, path];
81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698