| 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 /// Attempts to resolve a set of version constraints for a package dependency | 5 /// Attempts to resolve a set of version constraints for a package dependency |
| 6 /// graph and select an appropriate set of best specific versions for all | 6 /// graph and select an appropriate set of best specific versions for all |
| 7 /// dependent packages. It works iteratively and tries to reach a stable | 7 /// dependent packages. It works iteratively and tries to reach a stable |
| 8 /// solution where the constraints of all dependencies are met. If it fails to | 8 /// solution where the constraints of all dependencies are met. If it fails to |
| 9 /// reach a solution after a certain number of iterations, it assumes the | 9 /// reach a solution after a certain number of iterations, it assumes the |
| 10 /// dependency graph is unstable and reports and error. | 10 /// dependency graph is unstable and reports and error. |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 | 495 |
| 496 /// Whether this dependency should always select the latest version. | 496 /// Whether this dependency should always select the latest version. |
| 497 bool useLatestVersion = false; | 497 bool useLatestVersion = false; |
| 498 | 498 |
| 499 /// Gets whether or not any other packages are currently depending on this | 499 /// Gets whether or not any other packages are currently depending on this |
| 500 /// one. If `false`, then it means this package is not part of the dependency | 500 /// one. If `false`, then it means this package is not part of the dependency |
| 501 /// graph and should be omitted. | 501 /// graph and should be omitted. |
| 502 bool get isDependedOn => !_refs.isEmpty; | 502 bool get isDependedOn => !_refs.isEmpty; |
| 503 | 503 |
| 504 /// The names of all the packages that depend on this dependency. | 504 /// The names of all the packages that depend on this dependency. |
| 505 Collection<String> get dependers => _refs.keys; | 505 Iterable<String> get dependers => _refs.keys; |
| 506 | 506 |
| 507 /// Gets the overall constraint that all packages are placing on this one. | 507 /// Gets the overall constraint that all packages are placing on this one. |
| 508 /// If no packages have a constraint on this one (which can happen when this | 508 /// If no packages have a constraint on this one (which can happen when this |
| 509 /// package is in the process of being added to the graph), returns `null`. | 509 /// package is in the process of being added to the graph), returns `null`. |
| 510 VersionConstraint get constraint { | 510 VersionConstraint get constraint { |
| 511 if (_refs.isEmpty) return null; | 511 if (_refs.isEmpty) return null; |
| 512 return new VersionConstraint.intersection( | 512 return new VersionConstraint.intersection( |
| 513 _refs.values.mappedBy((ref) => ref.constraint)); | 513 _refs.values.mappedBy((ref) => ref.constraint)); |
| 514 } | 514 } |
| 515 | 515 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 530 /// Return the PackageRef that has the canonical source and description for | 530 /// Return the PackageRef that has the canonical source and description for |
| 531 /// this package. If any dependency requires that this package come from a | 531 /// this package. If any dependency requires that this package come from a |
| 532 /// [RootSource], that will be used; otherwise, it will be the source and | 532 /// [RootSource], that will be used; otherwise, it will be the source and |
| 533 /// description that all dependencies agree upon. | 533 /// description that all dependencies agree upon. |
| 534 PackageRef _canonicalRef() { | 534 PackageRef _canonicalRef() { |
| 535 if (_refs.isEmpty) return null; | 535 if (_refs.isEmpty) return null; |
| 536 var refs = _refs.values; | 536 var refs = _refs.values; |
| 537 for (var ref in refs) { | 537 for (var ref in refs) { |
| 538 if (ref is RootSource) return ref; | 538 if (ref is RootSource) return ref; |
| 539 } | 539 } |
| 540 return refs[0]; | 540 return refs.first; |
| 541 } | 541 } |
| 542 | 542 |
| 543 Dependency(this.name) | 543 Dependency(this.name) |
| 544 : _refs = <String, PackageRef>{}; | 544 : _refs = <String, PackageRef>{}; |
| 545 | 545 |
| 546 Dependency._clone(Dependency other) | 546 Dependency._clone(Dependency other) |
| 547 : name = other.name, | 547 : name = other.name, |
| 548 version = other.version, | 548 version = other.version, |
| 549 _refs = new Map<String, PackageRef>.from(other._refs); | 549 _refs = new Map<String, PackageRef>.from(other._refs); |
| 550 | 550 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 571 | 571 |
| 572 _refs[package] = ref; | 572 _refs[package] = ref; |
| 573 } | 573 } |
| 574 | 574 |
| 575 /// Returns the name of a package whose constraint source and description | 575 /// Returns the name of a package whose constraint source and description |
| 576 /// all other constraints must match. Returns null if there are no | 576 /// all other constraints must match. Returns null if there are no |
| 577 /// requirements on new constraints. | 577 /// requirements on new constraints. |
| 578 String _requiredDepender() { | 578 String _requiredDepender() { |
| 579 if (_refs.isEmpty) return null; | 579 if (_refs.isEmpty) return null; |
| 580 | 580 |
| 581 var dependers = _refs.keys; | 581 var dependers = _refs.keys.toList(); |
| 582 if (dependers.length == 1) { | 582 if (dependers.length == 1) { |
| 583 var depender = dependers[0]; | 583 var depender = dependers[0]; |
| 584 if (_refs[depender].source is RootSource) return null; | 584 if (_refs[depender].source is RootSource) return null; |
| 585 return depender; | 585 return depender; |
| 586 } | 586 } |
| 587 | 587 |
| 588 return dependers[1]; | 588 return dependers[1]; |
| 589 } | 589 } |
| 590 | 590 |
| 591 /// Removes the constraint from [package] onto this. | 591 /// Removes the constraint from [package] onto this. |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 | 700 |
| 701 String toString() { | 701 String toString() { |
| 702 // TODO(nweiz): Dump descriptions to YAML when that's supported. | 702 // TODO(nweiz): Dump descriptions to YAML when that's supported. |
| 703 return "Incompatible dependencies on '$package':\n" | 703 return "Incompatible dependencies on '$package':\n" |
| 704 "- '$depender1' depends on it with description " | 704 "- '$depender1' depends on it with description " |
| 705 "${json.stringify(description1)}\n" | 705 "${json.stringify(description1)}\n" |
| 706 "- '$depender2' depends on it with description " | 706 "- '$depender2' depends on it with description " |
| 707 "${json.stringify(description2)}"; | 707 "${json.stringify(description2)}"; |
| 708 } | 708 } |
| 709 } | 709 } |
| OLD | NEW |