| 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 dependency_validator; | 5 library dependency_validator; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import '../entrypoint.dart'; | 9 import '../entrypoint.dart'; |
| 10 import '../hosted_source.dart'; | 10 import '../hosted_source.dart'; |
| 11 import '../http.dart'; | 11 import '../http.dart'; |
| 12 import '../package.dart'; | 12 import '../package.dart'; |
| 13 import '../path_source.dart'; |
| 13 import '../utils.dart'; | 14 import '../utils.dart'; |
| 14 import '../validator.dart'; | 15 import '../validator.dart'; |
| 15 import '../version.dart'; | 16 import '../version.dart'; |
| 16 | 17 |
| 17 /// A validator that validates a package's dependencies. | 18 /// A validator that validates a package's dependencies. |
| 18 class DependencyValidator extends Validator { | 19 class DependencyValidator extends Validator { |
| 19 DependencyValidator(Entrypoint entrypoint) | 20 DependencyValidator(Entrypoint entrypoint) |
| 20 : super(entrypoint); | 21 : super(entrypoint); |
| 21 | 22 |
| 22 Future validate() { | 23 Future validate() { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 var primary = Version.primary(versions); | 56 var primary = Version.primary(versions); |
| 56 if (primary != null) { | 57 if (primary != null) { |
| 57 constraint = _constraintForVersion(primary); | 58 constraint = _constraintForVersion(primary); |
| 58 } else { | 59 } else { |
| 59 constraint = ref.constraint.toString(); | 60 constraint = ref.constraint.toString(); |
| 60 if (!ref.constraint.isAny && ref.constraint is! Version) { | 61 if (!ref.constraint.isAny && ref.constraint is! Version) { |
| 61 constraint = '"$constraint"'; | 62 constraint = '"$constraint"'; |
| 62 } | 63 } |
| 63 } | 64 } |
| 64 | 65 |
| 65 warnings.add('Don\'t depend on "${ref.name}" from the ${ref.source.name} ' | 66 // Path sources are errors. Other sources are just warnings. |
| 67 var messages = warnings; |
| 68 if (ref.source is PathSource) { |
| 69 messages = errors; |
| 70 } |
| 71 |
| 72 messages.add('Don\'t depend on "${ref.name}" from the ${ref.source.name} ' |
| 66 'source. Use the hosted source instead. For example:\n' | 73 'source. Use the hosted source instead. For example:\n' |
| 67 '\n' | 74 '\n' |
| 68 'dependencies:\n' | 75 'dependencies:\n' |
| 69 ' ${ref.name}: $constraint\n' | 76 ' ${ref.name}: $constraint\n' |
| 70 '\n' | 77 '\n' |
| 71 'Using the hosted source ensures that everyone can download your ' | 78 'Using the hosted source ensures that everyone can download your ' |
| 72 'package\'s dependencies along with your package.'); | 79 'package\'s dependencies along with your package.'); |
| 73 }); | 80 }); |
| 74 } | 81 } |
| 75 | 82 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 91 } | 98 } |
| 92 | 99 |
| 93 /// Returns the suggested version constraint for a dependency that was tested | 100 /// Returns the suggested version constraint for a dependency that was tested |
| 94 /// against [version]. | 101 /// against [version]. |
| 95 String _constraintForVersion(Version version) { | 102 String _constraintForVersion(Version version) { |
| 96 if (version.major != 0) return '">=$version <${version.major + 1}.0.0"'; | 103 if (version.major != 0) return '">=$version <${version.major + 1}.0.0"'; |
| 97 return '">=$version <${version.major}.${version.minor}.' | 104 return '">=$version <${version.major}.${version.minor}.' |
| 98 '${version.patch + 1}"'; | 105 '${version.patch + 1}"'; |
| 99 } | 106 } |
| 100 } | 107 } |
| OLD | NEW |