
1 // 2 // Copyright (c) 2006, Brian Frank and Andy Frank 3 // Licensed under the Academic Free License version 3.0 4 // 5 // History: 6 // 3 Nov 06 Brian Frank Creation 7 // 8 9 ** 10 ** Depend models a dependency as a pod name and a version 11 ** constraint. Convention for Fan pods is a four part 12 ** version format of 'major.minor.build.patch'. 13 ** 14 ** The string format for Depend: 15 ** 16 ** <depend> := <name> space* <constraints> 17 ** <constraints> := <constraint> [space* "," space* <constraint>]* 18 ** <constraint> := <versionSimple> | <versionPlus> | <versionRange> 19 ** <versionSimple> := <version> 20 ** <versionPlus> := <version> space* "+" 21 ** <versionRange> := <version> space* "-" space* <version> 22 ** <version> := <digit> ["." <digit>]* 23 ** <digit> := "0" - "9" 24 ** 25 ** Note a simple version constraint such as "foo 1.2" really means 26 ** "1.2.*" - it will match all build numbers and patch numbers 27 ** within "1.2". Likewise "foo 1.2.64" will match all patch numbers 28 ** within the "1.2.64" build. The "+" plus sign is used to specify a 29 ** given version and anything greater. The "-" dash is used to 30 ** specify an inclusive range. When using a range, then end version 31 ** is matched using the same rules as a simple version - for example 32 ** "4", "4.2", and "4.0.99" are all matches for "foo 1.2-4". You may 33 ** specify a list of potential constraints separated by commas - a match 34 ** for the entire dependency is made if any one constraint is matched. 35 ** 36 ** Examples: 37 ** "foo 1.2" Any version of foo 1.2 with any build or patch number 38 ** "foo 1.2.64" Any version of foo 1.2.64 with any patch number 39 ** "foo 0+" Any version of foo - version wildcard 40 ** "foo 1.2+" Any version of foo 1.2 or greater 41 ** "foo 1.2-1.4" Any version between 1.2 and 1.4 inclusive 42 ** "foo 1.2,1.4" Any version of 1.2 or 1.4 43 ** 44 @simple 45 final class Depend 46 { 47 48 ////////////////////////////////////////////////////////////////////////// 49 // Construction 50 ////////////////////////////////////////////////////////////////////////// 51 52 ** 53 ** Parse the string according into a dependency. See class 54 ** header for specification of the format. Throw ParseErr if 55 ** string is illegally formatted. 56 ** 57 static Depend fromStr(Str s) 58 59 ** 60 ** Private constructor 61 ** 62 private new privateMake() 63 64 ////////////////////////////////////////////////////////////////////////// 65 // Identity 66 ////////////////////////////////////////////////////////////////////////// 67 68 ** 69 ** Two Depends are equal if they have same normalized string representation. 70 ** 71 override Bool equals(Obj that) 72 73 ** 74 ** Return a hash code based on the normalized string representation. 75 ** 76 override Int hash() 77 78 ** 79 ** Get the normalized string format of this dependency. Normalized 80 ** dependency strings do not contain any optional spaces. See class 81 ** header for specification of the format. 82 ** 83 override Str toStr() 84 85 ** 86 ** Get the pod name of the dependency. 87 ** 88 Str name() 89 90 ////////////////////////////////////////////////////////////////////////// 91 // Version Constraints 92 ////////////////////////////////////////////////////////////////////////// 93 94 ** 95 ** Get the number of version constraints. There is always 96 ** at least one constraint. 97 ** 98 Int size() 99 100 ** 101 ** Get the version constraint at specified index: 102 ** - versionSimple: returns the version 103 ** - versionPlus: returns the version 104 ** - versionRange: returns the start version 105 ** 106 Version version(Int index := 0) 107 108 ** 109 ** Return if the constraint at the specified index is a versionPlus: 110 ** - versionSimple: returns false 111 ** - versionPlus: returns true 112 ** - versionRange: returns false 113 ** 114 Bool isPlus(Int index := 0) 115 116 ** 117 ** Return if the constraint at the specified index is a versionRange: 118 ** - versionSimple: returns false 119 ** - versionPlus: returns false 120 ** - versionRange: returns true 121 ** 122 Bool isRange(Int index := 0) 123 124 ** 125 ** Return the ending version if versionRange: 126 ** - versionSimple: returns null 127 ** - versionPlus: returns null 128 ** - versionRange: returns end version 129 ** 130 Version endVersion(Int index := 0) 131 132 ** 133 ** Return if the specified version is a match against 134 ** this dependencies constraints. See class header for 135 ** matching rules. 136 ** 137 Bool match(Version version) 138 139 140 }