-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gradle bump strategy #33453
base: main
Are you sure you want to change the base?
Gradle bump strategy #33453
Changes from all commits
e961b3e
2e43ff0
f1d94c9
ffa0f59
36c766c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
import upath from 'upath'; | ||
import { regEx } from '../../../util/regex'; | ||
import type { PackageDependency } from '../types'; | ||
import type { | ||
GradleManagerData, | ||
PackageVariables, | ||
VariableRegistry, | ||
} from './types'; | ||
import type { GradleManagerData, PackageVariables, VariableRegistry } from './types'; | ||
|
||
const artifactRegex = regEx( | ||
'^[a-zA-Z][-_a-zA-Z0-9]*(?:\\.[a-zA-Z0-9][-_a-zA-Z0-9]*?)*$', | ||
'^[a-zA-Z][-_a-zA-Z0-9]*(?:\\.[a-zA-Z0-9][-_a-zA-Z0-9]*?)*$' | ||
); | ||
|
||
const versionLikeRegex = regEx('^(?<version>[-_.\\[\\](),a-zA-Z0-9+]+)'); | ||
const versionLikeRegex = regEx('^(?<version>[-_.\\[\\](),a-zA-Z0-9+! ]*[-_.\\[\\](),a-zA-Z0-9+])'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the intention here? Is it an attempt to add |
||
|
||
const mavenStyleRangeRegex = regEx(/^[[\](](?<lowerBound>[-._+a-zA-Z0-9]+)?\s*,\s*(?<upperBound>[-._+a-zA-Z0-9]+)?[[\])](?:!!>[-._+a-zA-Z0-9]+)?$/) | ||
|
||
// Extracts version-like and range-like strings | ||
// from the beginning of input | ||
export function versionLikeSubstring( | ||
input: string | null | undefined, | ||
input: string | null | undefined | ||
): string | null { | ||
if (!input) { | ||
return null; | ||
|
@@ -31,6 +29,17 @@ export function versionLikeSubstring( | |
return version; | ||
} | ||
|
||
export function parseMavenStyleRange(input: string): { | ||
lowerBound: string | null, upperBound: string | null, strict: string | null | ||
} | null { | ||
const match = mavenStyleRangeRegex.exec(input); | ||
const lowerBound = match?.groups?.lower_bound ?? null; | ||
const upperBound = match?.groups?.upper_bound ?? null; | ||
const strict = match?.groups?.strict ?? null; | ||
if (!lowerBound && !upperBound) {return null;} | ||
return { lowerBound, upperBound, strict }; | ||
} | ||
|
||
export function isDependencyString(input: string): boolean { | ||
const split = input?.split(':'); | ||
if (split?.length !== 3 && split?.length !== 4) { | ||
|
@@ -44,6 +53,11 @@ export function isDependencyString(input: string): boolean { | |
return false; | ||
} | ||
|
||
const mavenStyleRange = parseMavenStyleRange(tempVersionPart); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see no need for this here. Should be enough to have |
||
if (mavenStyleRange) { | ||
return true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wrong as it bypasses all subsequent checks |
||
} | ||
|
||
if ( | ||
tempVersionPart !== versionLikeSubstring(tempVersionPart) && | ||
tempVersionPart.includes('@') | ||
|
@@ -57,7 +71,7 @@ export function isDependencyString(input: string): boolean { | |
const [groupId, artifactId, versionPart] = [ | ||
tempGroupId, | ||
tempArtifactId, | ||
tempVersionPart, | ||
tempVersionPart | ||
]; | ||
return !!( | ||
groupId && | ||
|
@@ -70,23 +84,33 @@ export function isDependencyString(input: string): boolean { | |
} | ||
|
||
export function parseDependencyString( | ||
input: string, | ||
input: string | ||
): PackageDependency<GradleManagerData> | null { | ||
if (!isDependencyString(input)) { | ||
return null; | ||
} | ||
const [groupId, artifactId, FullValue] = input.split(':'); | ||
if (FullValue === versionLikeSubstring(FullValue)) { | ||
const [groupId, artifactId, fullValue] = input.split(':'); | ||
if (fullValue === versionLikeSubstring(fullValue)) { | ||
|
||
const mavenStyleRange = parseMavenStyleRange(fullValue); | ||
if (mavenStyleRange) { | ||
const updatablePart = mavenStyleRange.upperBound ?? mavenStyleRange.lowerBound; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess |
||
return { | ||
depName: `${groupId}:${artifactId}`, | ||
currentValue: updatablePart, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The only thing that may need adaptation here is the addition of |
||
} | ||
} | ||
|
||
return { | ||
depName: `${groupId}:${artifactId}`, | ||
currentValue: FullValue, | ||
currentValue: fullValue | ||
}; | ||
} | ||
const [currentValue, dataType] = FullValue.split('@'); | ||
const [currentValue, dataType] = fullValue.split('@'); | ||
return { | ||
depName: `${groupId}:${artifactId}`, | ||
currentValue, | ||
dataType, | ||
dataType | ||
}; | ||
} | ||
|
||
|
@@ -176,7 +200,7 @@ export function reorderFiles(packageFiles: string[]): string[] { | |
export function getVars( | ||
registry: VariableRegistry, | ||
dir: string, | ||
vars: PackageVariables = registry[dir] || {}, | ||
vars: PackageVariables = registry[dir] || {} | ||
): PackageVariables { | ||
const dirAbs = toAbsolutePath(dir); | ||
const parentDir = upath.dirname(dirAbs); | ||
|
@@ -190,7 +214,7 @@ export function getVars( | |
export function updateVars( | ||
registry: VariableRegistry, | ||
dir: string, | ||
newVars: PackageVariables, | ||
newVars: PackageVariables | ||
): void { | ||
const oldVars = registry[dir] ?? {}; | ||
registry[dir] = { ...oldVars, ...newVars }; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -253,6 +253,84 @@ export function parsePrefixRange(input: string): PrefixRange | null { | |
return null; | ||
} | ||
|
||
export type MavenStyleRange = { | ||
lowerBound: MavenStyleRangeBound, | ||
upperBound: MavenStyleRangeBound, | ||
preferredVersion: string | null, | ||
seperator: string, | ||
} | ||
|
||
export type MavenStyleRangeBound = { | ||
version: string | null, | ||
type: 'inclusive' | 'exclusive', | ||
bracket: string, | ||
} | ||
|
||
const mavenStyleRangeRegex = regEx(/^(?<openingBracket>[[\](])(?<lowerBound>[-._+a-zA-Z0-9]+)?(?<seperator>\s*,\s*)(?<upperBound>[-._+a-zA-Z0-9]+)?(?<closingBracket>[[\])])(?:!!(?<preferredVersion>[-._+a-zA-Z0-9]+))?$/) | ||
|
||
export function parseMavenStyleRange(input: string): MavenStyleRange | null { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There already is |
||
const matchGroups = mavenStyleRangeRegex.exec(input)?.groups; | ||
if (!matchGroups) {return null;} | ||
const lowerVersion = matchGroups.lowerBound ?? null; | ||
const upperVersion = matchGroups.upperBound ?? null; | ||
const preferredVersion = matchGroups?.preferredVersion ?? null; | ||
|
||
const validVersion = (version: string | null): boolean => version === null || isVersion(version) | ||
if (!validVersion(lowerVersion) || !validVersion(upperVersion) || !validVersion(preferredVersion)) {return null;} | ||
if (lowerVersion && upperVersion && compare(lowerVersion, upperVersion) === 0) {return null;} | ||
|
||
const openingBracket = matchGroups.openingBracket; | ||
const closingBracket = matchGroups.closingBracket; | ||
const lowerBoundType = openingBracket === '[' ? 'inclusive' : 'exclusive'; | ||
const upperBoundType = closingBracket === ']' ? 'inclusive' : 'exclusive'; | ||
const seperator = matchGroups.seperator; | ||
|
||
if (preferredVersion) { | ||
if (lowerVersion) { | ||
const delta = compare(lowerVersion, preferredVersion); | ||
if (upperBoundType === 'inclusive' && delta !== 1) {return null;} | ||
if (upperBoundType === 'exclusive' && delta === -1) {return null;} | ||
} | ||
if (upperVersion) { | ||
const delta = compare(preferredVersion, upperVersion); | ||
if (upperBoundType === 'inclusive' && delta !== 1) {return null;} | ||
if (upperBoundType === 'exclusive' && delta === -1) {return null;} | ||
} | ||
} | ||
|
||
return { | ||
lowerBound: { | ||
version: lowerVersion, | ||
type: lowerBoundType, | ||
bracket: openingBracket, | ||
}, | ||
upperBound: { | ||
version: upperVersion, | ||
type: upperBoundType, | ||
bracket: closingBracket, | ||
}, | ||
preferredVersion, | ||
seperator, | ||
} | ||
} | ||
|
||
export function constructMavenStyleRange(range: MavenStyleRange): string { | ||
let temp = ''; | ||
temp += range.lowerBound.bracket; | ||
if (range.lowerBound.version) { | ||
temp += range.lowerBound.version | ||
} | ||
temp += range.seperator; | ||
if (range.upperBound.version) { | ||
temp += range.upperBound.version; | ||
} | ||
temp += range.upperBound.bracket; | ||
if (range.preferredVersion) { | ||
temp += `!!${range.preferredVersion}`; | ||
} | ||
return temp; | ||
} | ||
|
||
const mavenBasedRangeRegex = regEx( | ||
/^(?<leftBoundStr>[[\](]\s*)(?<leftVal>[-._+a-zA-Z0-9]*?)(?<separator>\s*,\s*)(?<rightVal>[-._+a-zA-Z0-9]*?)(?<rightBoundStr>\s*[[\])])$/, | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct but please keep your changes strictly limited to what's relevant for the functionality you'd like to add. Refactoring can be done separately.