My only thought after reading this, is that these would make good unit tests inside the project, so that the answers would become explicitly defined.
On Tue, Aug 5, 2025 at 12:21 PM Ron Desmond <rhdesm...@google.com.invalid> wrote: > Hi, > > I'm ironing out my understanding of the Maven Version Order Spec > <https://maven.apache.org/pom.html#Version_Order_Specification> and had > three questions: one was related to an implicit separator before the > beginning of versions, and the next two were related to trimming. > > ------------ > *Implicit Separator* > > From my (limited) understanding, the maven-artifact-3.9.11 tool seems to > use hyphens to create a ListItem, and an initial hyphen would suggest the > creation of the tokens list. So if the version begins with a '-', there's > a nested list because the tokens are an empty non-numeric segment (the > implicit initial hyphen) followed by the hyphen-separator numeric token > "-1". The maven-artifact jar confirms this for versions "1" and "-1", > which results in 1 > -1: > > tokens(1) = [1] > tokens(-1) = [[1]] > > 1 > -1 > > ---- > > I did run into one seeming inconsistency for this idea when the tool > compares "sp" and "ga-1" > > tokens(sp) = -sp = [sp] > tokens(ga-1) = -1 = [[1]] // trimming removes "ga" > > > *sp < ga-1 // maven-artifact output is unexpected because sp > "" * > > > ---- > > The argument may be made that the *initial implicit separator is a period*, > and that all versions are enclosed by a list. This would explain the > nested list of "-1": > > tokens(sp) = .sp = [sp] // all versions are a ListItem > > tokens(ga-1) = .ga-1 > = -1 // trimming starting from the last hyphen > > = [[1]] // ListItem "-1" is enclosed within the initial list > > sp < [-1] // special qualifier "sp" is less than hyphen-numeric token [1] > > ---- > > The implicit period separator still holds for "-1" due to normalization and > trimming: > > tokens(-1) = .-1 > > = 0.0-1 // normalization adds zeroes > = -1 // trimming removes zeroes > = [[1]] // initial list holds a hyphen-numeric token > > > ------------ > > *Trimming* > The remaining confusion I had was related to trimming: consider "--1--" and > "--1-" > > My understanding of the spec would be the following (excluding the initial > separator idea above): > > tokens(--1--) > > = -0-1-0-0 // normalization: "Empty tokens are replaced with "0" " > = -1 // trimming: "the trailing "null" values...are > trimmed. This process is repeated at each remaining hyphen " > = [[1]] // initial list (or implicit hyphen) enclosing > hyphen-numeric token > > tokens(--1-) > = -0-1-0 > = -1 > = [[1]] > > However, the maven-artifact output is different: > > > > *1. -1-- -> 1; tokens: [[1]] -1-- > --1-2. --1- -> 1; tokens: [[[1]]]* > > It seems like trimming is not happening after the "-1" token. > > ---- > ABC vs. -ABC Problem > > I'm having trouble reconciling the following case of "abc" vs. "-abc". Via > the trimming logic, I'd expect > > tokens(-abc) = "0-abc" (empty tokens replace with "0") > = "abc" (trimming) > = tokens(abc) > > but the output of the tool is below: > > > > *1. abc -> abc; tokens: [abc] abc < -abc2. -abc -> abc; tokens: [[abc]]* > > ------------ > > > So to recap, had three questions: > > 1) should versions be treated as if there's an implicit separator? > 2) how should trimming/tokenization work for "--1--" and "--1-"? > 3) how should trimming/tokenization work for "abc" and "-abc"? > > Hope this isn't too confusing and/or lengthy. Thanks for your time and > have a good day! > > > Best, > > Ron >