Skip to content

Commit

Permalink
fix(gradle): fix UpgradeAction for gradle 8.11 (#586)
Browse files Browse the repository at this point in the history
  • Loading branch information
luisgomez29 authored Nov 20, 2024
1 parent d6715a7 commit 0f5073d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public boolean up(ModuleBuilder builder) {
return builder.updateFile(
MAIN_GRADLE,
content -> {
if (!builder.findExpressions(MAIN_GRADLE, "java\\s*\\{").isEmpty()) {
return content;
}

String sourceCompatibilityLoaded =
builder
.findExpressions(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package co.com.bancolombia.factory.upgrades.actions;

import static co.com.bancolombia.Constants.MainFiles.MAIN_GRADLE;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.spy;
Expand Down Expand Up @@ -58,4 +59,20 @@ void shouldApplyUpdate() throws IOException {
MAIN_GRADLE,
FileUtils.getResourceAsString(resolver, "gradle-8.11-sample/main-after.txt"));
}

@Test
void shouldNotApplyUpdateIfJavaBlockExists() throws IOException {
DefaultResolver resolver = new DefaultResolver();
// Arrange
builder.addFile(
MAIN_GRADLE, FileUtils.getResourceAsString(resolver, "gradle-8.11-sample/main-after.txt"));
// Act
boolean applied = updater.up(builder);
// Assert
assertFalse(applied);
verify(builder)
.addFile(
MAIN_GRADLE,
FileUtils.getResourceAsString(resolver, "gradle-8.11-sample/main-after.txt"));
}
}

0 comments on commit 0f5073d

Please sign in to comment.