Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ private J.MethodInvocation updateDependency(J.MethodInvocation m, ExecutionConte
if (!StringUtils.isBlank(newArtifactId) && !updated.getArtifactId().equals(newArtifactId)) {
updated = updated.withGav(updated.getGav().withArtifactId(newArtifactId));
}
if (!StringUtils.isBlank(newVersion)) {
if (!StringUtils.isBlank(newVersion) && (!StringUtils.isBlank(original.getVersion()) || Boolean.TRUE.equals(overrideManagedVersion))) {
String resolvedVersion;
try {
resolvedVersion = new DependencyVersionSelector(metadataFailures, gradleProject, null)
Expand All @@ -315,10 +315,23 @@ private J.MethodInvocation updateDependency(J.MethodInvocation m, ExecutionConte
}
}
if (original != updated) {
String replacement = DependencyNotation.toStringNotation(updated);
J.Literal newLiteral = literal.withValue(replacement)
.withValueSource(gstring.getDelimiter() + replacement + gstring.getDelimiter());
m = m.withArguments(singletonList(newLiteral));
if (Objects.equals(original.getVersion(), updated.getVersion())) {
// Version unchanged: preserve GString structure, only update the literal prefix
String oldGav = original.getGroupId() + ":" + original.getArtifactId();
String newGav = updated.getGroupId() + ":" + updated.getArtifactId();
String oldValue = (String) literal.getValue();
String updatedValue = oldValue.replace(oldGav, newGav);
J.Literal updatedLiteral = literal.withValue(updatedValue).withValueSource(updatedValue);
m = m.withArguments(singletonList(
gstring.withStrings(ListUtils.mapFirst(strings, s -> updatedLiteral))
));
} else {
// Version changed: collapse GString to a literal
String replacement = DependencyNotation.toStringNotation(updated);
J.Literal newLiteral = literal.withValue(replacement)
.withValueSource(gstring.getDelimiter() + replacement + gstring.getDelimiter());
m = m.withArguments(singletonList(newLiteral));
}
}
}
}
Expand Down Expand Up @@ -595,7 +608,7 @@ private J.MethodInvocation updateDependency(J.MethodInvocation m, ExecutionConte
if (!StringUtils.isBlank(newArtifactId) && !updated.getArtifactId().equals(newArtifactId)) {
updated = updated.withGav(updated.getGav().withArtifactId(newArtifactId));
}
if (!StringUtils.isBlank(newVersion)) {
if (!StringUtils.isBlank(newVersion) && (!StringUtils.isBlank(original.getVersion()) || Boolean.TRUE.equals(overrideManagedVersion))) {
String resolvedVersion;
try {
resolvedVersion = new DependencyVersionSelector(metadataFailures, gradleProject, null)
Expand All @@ -608,10 +621,23 @@ private J.MethodInvocation updateDependency(J.MethodInvocation m, ExecutionConte
}
}
if (original != updated) {
String replacement = DependencyNotation.toStringNotation(updated);
J.Literal newLiteral = literal.withValue(replacement)
.withValueSource(template.getDelimiter() + replacement + template.getDelimiter());
m = m.withArguments(singletonList(newLiteral));
if (Objects.equals(original.getVersion(), updated.getVersion())) {
// Version unchanged: preserve StringTemplate structure, only update the literal prefix
String oldGav = original.getGroupId() + ":" + original.getArtifactId();
String newGav = updated.getGroupId() + ":" + updated.getArtifactId();
String oldValue = (String) literal.getValue();
String updatedValue = oldValue.replace(oldGav, newGav);
J.Literal updatedLiteral = literal.withValue(updatedValue).withValueSource(updatedValue);
m = m.withArguments(singletonList(
template.withStrings(ListUtils.mapFirst(strings, s -> updatedLiteral))
));
} else {
// Version changed: collapse StringTemplate to a literal
String replacement = DependencyNotation.toStringNotation(updated);
J.Literal newLiteral = literal.withValue(replacement)
.withValueSource(template.getDelimiter() + replacement + template.getDelimiter());
m = m.withArguments(singletonList(newLiteral));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ implementation platform("commons-lang:commons-lang:${version}")

def version = '2.6'
dependencies {
implementation platform("org.apache.commons:commons-lang3:3.11")
implementation platform("org.apache.commons:commons-lang3:${version}")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we're effectively not making any change, other than the markers; We should add gradle.properties files here and assert those are updated.

}
"""
)
Expand Down Expand Up @@ -574,7 +574,7 @@ void kotlinDslStringInterpolation() {

dependencies {
val commonsLangVersion = "2.6"
implementation("org.apache.commons:commons-lang3:3.11")
implementation("org.apache.commons:commons-lang3:${commonsLangVersion}")
}
"""
)
Expand Down