-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gradle): add UpgradeAction for gradle 8.11 (#580)
* feat(gradle): Add UpgradeAction for gradle 8.11
- Loading branch information
1 parent
ba8e38b
commit f60d6c1
Showing
8 changed files
with
390 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/co/com/bancolombia/factory/upgrades/actions/UpgradeY2024M11D16Gradle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package co.com.bancolombia.factory.upgrades.actions; | ||
|
||
import static co.com.bancolombia.Constants.MainFiles.MAIN_GRADLE; | ||
|
||
import co.com.bancolombia.factory.ModuleBuilder; | ||
import co.com.bancolombia.factory.upgrades.UpdateUtils; | ||
import co.com.bancolombia.factory.upgrades.UpgradeAction; | ||
import lombok.SneakyThrows; | ||
|
||
public class UpgradeY2024M11D16Gradle implements UpgradeAction { | ||
private static final String JAVA_BLOCK_CONFIG = | ||
"java {\n {{sourceCompatibilityLoaded}}\n }"; | ||
|
||
@Override | ||
@SneakyThrows | ||
public boolean up(ModuleBuilder builder) { | ||
return builder.updateFile( | ||
MAIN_GRADLE, | ||
content -> { | ||
String sourceCompatibilityLoaded = | ||
builder | ||
.findExpressions( | ||
MAIN_GRADLE, "sourceCompatibility = JavaVersion.VERSION_(\\d{2})") | ||
.stream() | ||
.findFirst() | ||
.orElse(null); | ||
|
||
if (sourceCompatibilityLoaded == null) { | ||
sourceCompatibilityLoaded = "sourceCompatibility = JavaVersion.{{javaVersion}}"; | ||
} | ||
|
||
return UpdateUtils.replace( | ||
content, | ||
sourceCompatibilityLoaded, | ||
JAVA_BLOCK_CONFIG.replace( | ||
"{{sourceCompatibilityLoaded}}", sourceCompatibilityLoaded)); | ||
}); | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return "3.18.2->3.18.3"; | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return "Add java { } configuration block, backed by JavaPluginExtension"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/test/java/co/com/bancolombia/factory/upgrades/actions/UpgradeY2024M11D16GradleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package co.com.bancolombia.factory.upgrades.actions; | ||
|
||
import static co.com.bancolombia.Constants.MainFiles.MAIN_GRADLE; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import co.com.bancolombia.factory.ModuleBuilder; | ||
import co.com.bancolombia.factory.upgrades.UpgradeAction; | ||
import co.com.bancolombia.utils.FileUtils; | ||
import com.github.mustachejava.resolver.DefaultResolver; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.logging.Logger; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class UpgradeY2024M11D16GradleTest { | ||
|
||
@Mock private Project project; | ||
@Mock private Logger logger; | ||
|
||
private ModuleBuilder builder; | ||
private UpgradeAction updater; | ||
|
||
@BeforeEach | ||
public void setup() throws IOException { | ||
when(project.getName()).thenReturn("UtilsTest"); | ||
when(project.getLogger()).thenReturn(logger); | ||
when(project.getProjectDir()).thenReturn(Files.createTempDirectory("sample").toFile()); | ||
|
||
builder = spy(new ModuleBuilder(project)); | ||
updater = new UpgradeY2024M11D16Gradle(); | ||
|
||
assertNotNull(updater.name()); | ||
assertNotNull(updater.description()); | ||
} | ||
|
||
@Test | ||
void shouldApplyUpdate() throws IOException { | ||
DefaultResolver resolver = new DefaultResolver(); | ||
// Arrange | ||
builder.addFile( | ||
MAIN_GRADLE, FileUtils.getResourceAsString(resolver, "gradle-8.11-sample/main-before.txt")); | ||
// Act | ||
boolean applied = updater.up(builder); | ||
// Assert | ||
assertTrue(applied); | ||
verify(builder) | ||
.addFile( | ||
MAIN_GRADLE, | ||
FileUtils.getResourceAsString(resolver, "gradle-8.11-sample/main-after.txt")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
apply plugin: 'info.solidsoft.pitest.aggregator' | ||
|
||
allprojects { | ||
repositories { | ||
mavenCentral() | ||
maven { url "https://repo.spring.io/snapshot" } | ||
maven { url "https://repo.spring.io/milestone" } | ||
} | ||
} | ||
|
||
subprojects { | ||
apply plugin: 'info.solidsoft.pitest' | ||
apply plugin: 'java' | ||
apply plugin: 'jacoco' | ||
apply plugin: 'io.spring.dependency-management' | ||
|
||
compileJava.dependsOn validateStructure | ||
java { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} | ||
|
||
dependencies { | ||
implementation platform('software.amazon.awssdk:bom:2.29.15') | ||
implementation 'io.projectreactor:reactor-core' | ||
implementation 'io.projectreactor.addons:reactor-extra' | ||
|
||
testImplementation 'io.projectreactor.tools:blockhound-junit-platform:1.0.10.RELEASE' | ||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher' | ||
|
||
testImplementation 'io.projectreactor:reactor-test' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
compileOnly "org.projectlombok:lombok:${lombokVersion}" | ||
annotationProcessor "org.projectlombok:lombok:${lombokVersion}" | ||
testCompileOnly "org.projectlombok:lombok:${lombokVersion}" | ||
testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}" | ||
implementation platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}") | ||
} | ||
|
||
tasks.withType(Test).configureEach { | ||
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_13)) { | ||
jvmArgs += [ | ||
"-XX:+AllowRedefinitionToAddDeleteMethods" | ||
] | ||
} | ||
} | ||
|
||
test.finalizedBy(project.tasks.jacocoTestReport) | ||
|
||
pitest { | ||
targetClasses = ['your.package.*'] | ||
excludedClasses = [] | ||
excludedTestClasses = [] | ||
pitestVersion = '1.16.1' | ||
verbose = true | ||
outputFormats = ['XML', 'HTML'] | ||
threads = 8 | ||
exportLineCoverage = true | ||
timestampedReports = false | ||
//mutators = ['STRONGER', 'DEFAULTS'] | ||
fileExtensionsToFilter.addAll('xml', 'orbit') | ||
junit5PluginVersion = '1.2.1' | ||
failWhenNoMutations = false | ||
jvmArgs = ["-XX:+AllowRedefinitionToAddDeleteMethods"] | ||
} | ||
|
||
jacocoTestReport { | ||
dependsOn test, 'pitest' | ||
reports { | ||
xml.setRequired true | ||
xml.setOutputLocation layout.buildDirectory.file("reports/jacoco.xml") | ||
csv.setRequired false | ||
html.setOutputLocation layout.buildDirectory.dir("reports/jacocoHtml") | ||
} | ||
} | ||
|
||
} | ||
|
||
jacoco { | ||
toolVersion = "${jacocoVersion}" | ||
reportsDirectory.set(layout.buildDirectory.dir("reports")) | ||
} | ||
|
||
tasks.register('jacocoMergedReport', JacocoReport) { | ||
dependsOn = [test, subprojects.jacocoTestReport, pitestReportAggregate] | ||
additionalSourceDirs.setFrom files(subprojects.sourceSets.main.allSource.srcDirs) | ||
sourceDirectories.setFrom files(subprojects.sourceSets.main.allSource.srcDirs) | ||
classDirectories.setFrom files(subprojects.sourceSets.main.output) | ||
executionData.setFrom project.fileTree(dir: '.', include: '**/build/jacoco/test.exec') | ||
reports { | ||
xml.setRequired true | ||
csv.setRequired false | ||
html.setRequired true | ||
} | ||
} | ||
|
||
tasks.withType(JavaCompile).configureEach { | ||
options.compilerArgs = [ | ||
'-Amapstruct.suppressGeneratorTimestamp=true' | ||
] | ||
} | ||
|
||
|
||
pitestReportAggregate { | ||
doLast { | ||
def reportDir = layout.buildDirectory.dir("reports/pitest").get().asFile | ||
def consolidatedReport = new File(reportDir, 'mutations.xml') | ||
consolidatedReport.withWriter { writer -> | ||
writer.write("<mutations>\n") | ||
subprojects.each { subproject -> | ||
def xmlReport = subproject.layout.buildDirectory.file("reports/pitest/mutations.xml").get().asFile | ||
if (xmlReport.exists()) { | ||
def xmlContent = xmlReport.text | ||
xmlContent = xmlContent.replaceAll("<\\?xml[^>]*>", "") | ||
xmlContent = xmlContent.replaceAll("</?mutations( partial=\"true\")?>", "") | ||
writer.write(xmlContent.trim() + "\n") | ||
} | ||
} | ||
writer.write("</mutations>") | ||
} | ||
} | ||
} | ||
|
||
tasks.named('wrapper') { | ||
gradleVersion = '8.10.2' | ||
} |
Oops, something went wrong.