| OLD | NEW |
| 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 library pub.package; | 5 library pub.package; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
| 10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 if (isMagic) return name; | 333 if (isMagic) return name; |
| 334 return "$name from $source"; | 334 return "$name from $source"; |
| 335 } | 335 } |
| 336 | 336 |
| 337 /// Returns a [PackageRef] with this one's [name], [source], and | 337 /// Returns a [PackageRef] with this one's [name], [source], and |
| 338 /// [description]. | 338 /// [description]. |
| 339 PackageRef toRef() => isMagic | 339 PackageRef toRef() => isMagic |
| 340 ? new PackageRef.magic(name) | 340 ? new PackageRef.magic(name) |
| 341 : new PackageRef(name, source, description); | 341 : new PackageRef(name, source, description); |
| 342 | 342 |
| 343 /// Returns a [PackageId] for this package with the given concrete version. | |
| 344 PackageId atVersion(Version version) => | |
| 345 new PackageId(name, source, version, description); | |
| 346 | |
| 347 /// Returns a [PackageDep] for this package with the given version constraint. | 343 /// Returns a [PackageDep] for this package with the given version constraint. |
| 348 PackageDep withConstraint(VersionConstraint constraint) => | 344 PackageDep withConstraint(VersionConstraint constraint) => |
| 349 new PackageDep(name, source, constraint, description); | 345 new PackageDep(name, source, constraint, description); |
| 350 } | 346 } |
| 351 | 347 |
| 352 /// A reference to a [Package], but not any particular version(s) of it. | 348 /// A reference to a [Package], but not any particular version(s) of it. |
| 353 class PackageRef extends _PackageName { | 349 class PackageRef extends _PackageName { |
| 350 /// Creates a reference to a package with the given [name], [source], and |
| 351 /// [description]. |
| 352 /// |
| 353 /// Since an ID's description is an implementation detail of its source, this |
| 354 /// should generally not be called outside of [Source] subclasses. A reference |
| 355 /// can be obtained from a user-supplied description using [Source.parseRef]. |
| 354 PackageRef(String name, String source, description) | 356 PackageRef(String name, String source, description) |
| 355 : super(name, source, description); | 357 : super(name, source, description); |
| 356 | 358 |
| 357 /// Creates a reference to a magic package (see [isMagic]). | 359 /// Creates a reference to a magic package (see [isMagic]). |
| 358 PackageRef.magic(String name) | 360 PackageRef.magic(String name) |
| 359 : super.magic(name); | 361 : super.magic(name); |
| 360 | 362 |
| 361 int get hashCode => name.hashCode ^ source.hashCode; | 363 int get hashCode => name.hashCode ^ source.hashCode; |
| 362 | 364 |
| 363 bool operator ==(other) { | 365 bool operator ==(other) { |
| 364 // TODO(rnystrom): We're assuming here that we don't need to delve into the | 366 // TODO(rnystrom): We're assuming here that we don't need to delve into the |
| 365 // description. | 367 // description. |
| 366 return other is PackageRef && | 368 return other is PackageRef && |
| 367 other.name == name && | 369 other.name == name && |
| 368 other.source == source; | 370 other.source == source; |
| 369 } | 371 } |
| 370 } | 372 } |
| 371 | 373 |
| 372 /// A reference to a specific version of a package. | 374 /// A reference to a specific version of a package. |
| 373 /// | 375 /// |
| 374 /// A package ID contains enough information to correctly get the package. | 376 /// A package ID contains enough information to correctly get the package. |
| 375 /// | 377 /// |
| 376 /// Note that it's possible for multiple distinct package IDs to point to | 378 /// It's possible for multiple distinct package IDs to point to different |
| 377 /// different packages that have identical contents. For example, the same | 379 /// packages that have identical contents. For example, the same package may be |
| 378 /// package may be available from multiple sources. As far as Pub is concerned, | 380 /// available from multiple sources. As far as Pub is concerned, those packages |
| 379 /// those packages are different. | 381 /// are different. |
| 382 /// |
| 383 /// Note that a package ID's [description] field has a different structure than |
| 384 /// the [PackageRef.description] or [PackageDep.description] fields for some |
| 385 /// sources. For example, the `git` source adds revision information to the |
| 386 /// description to ensure that the same ID always points to the same source. |
| 380 class PackageId extends _PackageName { | 387 class PackageId extends _PackageName { |
| 381 /// The package's version. | 388 /// The package's version. |
| 382 final Version version; | 389 final Version version; |
| 383 | 390 |
| 391 /// Creates an ID for a package with the given [name], [source], [version], |
| 392 /// and [description]. |
| 393 /// |
| 394 /// Since an ID's description is an implementation detail of its source, this |
| 395 /// should generally not be called outside of [Source] subclasses. |
| 384 PackageId(String name, String source, this.version, description) | 396 PackageId(String name, String source, this.version, description) |
| 385 : super(name, source, description); | 397 : super(name, source, description); |
| 386 | 398 |
| 387 /// Creates an ID for a magic package (see [isMagic]). | 399 /// Creates an ID for a magic package (see [isMagic]). |
| 388 PackageId.magic(String name) | 400 PackageId.magic(String name) |
| 389 : super.magic(name), | 401 : super.magic(name), |
| 390 version = Version.none; | 402 version = Version.none; |
| 391 | 403 |
| 392 /// Creates an ID for the given root package. | 404 /// Creates an ID for the given root package. |
| 393 PackageId.root(Package package) | 405 PackageId.root(Package package) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 410 if (isMagic) return name; | 422 if (isMagic) return name; |
| 411 return "$name $version from $source"; | 423 return "$name $version from $source"; |
| 412 } | 424 } |
| 413 } | 425 } |
| 414 | 426 |
| 415 /// A reference to a constrained range of versions of one package. | 427 /// A reference to a constrained range of versions of one package. |
| 416 class PackageDep extends _PackageName { | 428 class PackageDep extends _PackageName { |
| 417 /// The allowed package versions. | 429 /// The allowed package versions. |
| 418 final VersionConstraint constraint; | 430 final VersionConstraint constraint; |
| 419 | 431 |
| 432 /// Creates a reference to package with the given [name], [source], |
| 433 /// [constraint], and [description]. |
| 434 /// |
| 435 /// Since an ID's description is an implementation detail of its source, this |
| 436 /// should generally not be called outside of [Source] subclasses. |
| 420 PackageDep(String name, String source, this.constraint, description) | 437 PackageDep(String name, String source, this.constraint, description) |
| 421 : super(name, source, description); | 438 : super(name, source, description); |
| 422 | 439 |
| 423 PackageDep.magic(String name) | 440 PackageDep.magic(String name) |
| 424 : super.magic(name), | 441 : super.magic(name), |
| 425 constraint = Version.none; | 442 constraint = Version.none; |
| 426 | 443 |
| 427 String toString() { | 444 String toString() { |
| 428 if (isRoot) return "$name $constraint (root)"; | 445 if (isRoot) return "$name $constraint (root)"; |
| 429 if (isMagic) return name; | 446 if (isMagic) return name; |
| 430 return "$name $constraint from $source ($description)"; | 447 return "$name $constraint from $source ($description)"; |
| 431 } | 448 } |
| 432 | 449 |
| 433 int get hashCode => name.hashCode ^ source.hashCode; | 450 int get hashCode => name.hashCode ^ source.hashCode; |
| 434 | 451 |
| 435 bool operator ==(other) { | 452 bool operator ==(other) { |
| 436 // TODO(rnystrom): We're assuming here that we don't need to delve into the | 453 // TODO(rnystrom): We're assuming here that we don't need to delve into the |
| 437 // description. | 454 // description. |
| 438 return other is PackageDep && | 455 return other is PackageDep && |
| 439 other.name == name && | 456 other.name == name && |
| 440 other.source == source && | 457 other.source == source && |
| 441 other.constraint == constraint; | 458 other.constraint == constraint; |
| 442 } | 459 } |
| 443 } | 460 } |
| OLD | NEW |