Skip to content

Commit

Permalink
Use first 4 components of a version to determine the priority
Browse files Browse the repository at this point in the history
  • Loading branch information
xiwenc committed Nov 8, 2024
1 parent 6ca40e2 commit ba83f8f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions cmd/mendix-userlib-cleaner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,18 +418,28 @@ func cleanJars(remove bool, filePaths []string, jars []JarProperties, keepJars m
}

func convertVersionToNumber(version string) int {
// naive implementation. Feel free to suggest improvements

// Split version into numeric components
re := regexp.MustCompile("[0-9]+")
parts := re.FindAllString(version, -1)

// Pad with zeros to handle versions with different component counts
for len(parts) < 4 {
parts = append(parts, "0")
}

multiplier := 1000
// Use decreasing multipliers to ensure proper version ordering
// This allows for up to 999 in each component
multipliers := []int{1000000000, 1000000, 1000, 1}
number := 0
for _, c := range re.FindAllString(version, -1) {
t, _ := strconv.Atoi(c)
if number > 0 {
number = number * multiplier

for i, part := range parts[:4] { // Only use first 4 components
val, _ := strconv.Atoi(part)
// Clamp values to avoid overflow
if val > 999 {
val = 999
}
number += t
number += val * multipliers[i]
}

return number
}
Binary file added resources/jars/jackson-databind-2.13.4.2.jar
Binary file not shown.
Binary file added resources/jars/jackson-databind-2.14.1.jar
Binary file not shown.

0 comments on commit ba83f8f

Please sign in to comment.