| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 library barback.asset_id; | 5 library barback.asset_id; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:path/path.dart' as pathos; | 10 import 'package:path/path.dart' as pathos; |
| 11 | 11 |
| 12 /// AssetIDs always use POSIX style paths regardless of the host platform. | 12 /// AssetIDs always use POSIX style paths regardless of the host platform. |
| 13 final _posix = new pathos.Builder(style: pathos.Style.posix); | 13 final _posix = new pathos.Builder(style: pathos.Style.posix); |
| 14 | 14 |
| 15 /// Identifies an asset within a package. | 15 /// Identifies an asset within a package. |
| 16 class AssetId { | 16 class AssetId implements Comparable<AssetId> { |
| 17 /// The name of the package containing this asset. | 17 /// The name of the package containing this asset. |
| 18 final String package; | 18 final String package; |
| 19 | 19 |
| 20 /// The path to the asset relative to the root directory of [package]. | 20 /// The path to the asset relative to the root directory of [package]. |
| 21 /// | 21 /// |
| 22 /// Source (i.e. read from disk) and generated (i.e. the output of a | 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 | 23 /// [Transformer]) assets all have paths. Even intermediate assets that are |
| 24 /// generated and then consumed by later transformations will still have | 24 /// generated and then consumed by later transformations will still have |
| 25 /// a path used to identify it. | 25 /// a path used to identify it. |
| 26 /// | 26 /// |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 path = data[1]; | 66 path = data[1]; |
| 67 | 67 |
| 68 /// Returns `true` of [other] is an [AssetId] with the same package and path. | 68 /// Returns `true` of [other] is an [AssetId] with the same package and path. |
| 69 operator ==(other) => | 69 operator ==(other) => |
| 70 other is AssetId && | 70 other is AssetId && |
| 71 package == other.package && | 71 package == other.package && |
| 72 path == other.path; | 72 path == other.path; |
| 73 | 73 |
| 74 int get hashCode => package.hashCode ^ path.hashCode; | 74 int get hashCode => package.hashCode ^ path.hashCode; |
| 75 | 75 |
| 76 int compareTo(AssetId other) { |
| 77 var packageComp = package.compareTo(other.package); |
| 78 if (packageComp != 0) return packageComp; |
| 79 return path.compareTo(other.path); |
| 80 } |
| 81 |
| 76 /// Returns a new [AssetId] with the same [package] as this one and with the | 82 /// Returns a new [AssetId] with the same [package] as this one and with the |
| 77 /// [path] extended to include [extension]. | 83 /// [path] extended to include [extension]. |
| 78 AssetId addExtension(String extension) => | 84 AssetId addExtension(String extension) => |
| 79 new AssetId(package, "$path$extension"); | 85 new AssetId(package, "$path$extension"); |
| 80 | 86 |
| 81 /// Returns a new [AssetId] with the same [package] and [path] as this one | 87 /// Returns a new [AssetId] with the same [package] and [path] as this one |
| 82 /// but with file extension [newExtension]. | 88 /// but with file extension [newExtension]. |
| 83 AssetId changeExtension(String newExtension) => | 89 AssetId changeExtension(String newExtension) => |
| 84 new AssetId(package, pathos.withoutExtension(path) + newExtension); | 90 new AssetId(package, pathos.withoutExtension(path) + newExtension); |
| 85 | 91 |
| 86 String toString() => "$package|$path"; | 92 String toString() => "$package|$path"; |
| 87 | 93 |
| 88 /// Serializes this [AssetId] to an object that can be sent across isolates | 94 /// Serializes this [AssetId] to an object that can be sent across isolates |
| 89 /// and passed to [deserialize]. | 95 /// and passed to [deserialize]. |
| 90 serialize() => [package, path]; | 96 serialize() => [package, path]; |
| 91 } | 97 } |
| OLD | NEW |