/* * This file was generated by the Gradle 'init' task. */ apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'jacoco' apply plugin: 'maven-publish' // for now, publishing to maven is still a manual process //plugins { // id 'java' //id 'maven-publish' // } repositories { mavenLocal() mavenCentral() maven { url = uri('https://oss.sonatype.org/content/repositories/snapshots') } } // To view the report open build/reports/jacoco/test/html/index.html jacocoTestReport { reports { html.required = true } } test { finalizedBy jacocoTestReport } dependencies { testImplementation 'junit:junit:4.13.2' testImplementation 'com.jayway.jsonpath:json-path:2.9.0' testImplementation 'org.mockito:mockito-core:4.2.0' } subprojects { tasks.withType(Javadoc).all { enabled = false } } group = 'org.json' version = 'v20250517-SNAPSHOT' description = 'JSON in Java' sourceCompatibility = '1.8' configurations.all { } java { withSourcesJar() withJavadocJar() } publishing { publications { maven(MavenPublication) { from(components.java) } } } tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } // Add these imports at the top of your build.gradle file import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths import java.nio.file.StandardCopyOption // Your existing build configurations... // Add a new task to modify the file task modifyStrictMode { doLast { println "Modifying JSONParserConfiguration.java to enable strictMode..." def filePath = project.file('src/main/java/org/json/JSONParserConfiguration.java') if (!filePath.exists()) { throw new GradleException("Could not find file: ${filePath.absolutePath}") } // Create a backup of the original file def backupFile = new File(filePath.absolutePath + '.bak') Files.copy(filePath.toPath(), backupFile.toPath(), StandardCopyOption.REPLACE_EXISTING) // Read and modify the file content def content = filePath.text def modifiedContent = content.replace('// this.strictMode = true;', 'this.strictMode = true;') // Write the modified content back to the file filePath.text = modifiedContent println "File modified successfully at: ${filePath.absolutePath}" } } // Add a task to restore the original file task restoreStrictMode { doLast { println "Restoring original JSONParserConfiguration.java..." def filePath = project.file('src/main/java/org/json/JSONParserConfiguration.java') def backupFile = new File(filePath.absolutePath + '.bak') if (backupFile.exists()) { Files.copy(backupFile.toPath(), filePath.toPath(), StandardCopyOption.REPLACE_EXISTING) backupFile.delete() println "Original file restored successfully at: ${filePath.absolutePath}" } else { println "Backup file not found at: ${backupFile.absolutePath}. No restoration performed." } } } // Create a task to run the workflow task testWithStrictMode { dependsOn modifyStrictMode finalizedBy restoreStrictMode doLast { // This will trigger a clean build and run tests with strictMode enabled if (org.gradle.internal.os.OperatingSystem.current().isWindows()) { exec { executable 'cmd' args '/c', 'gradlew.bat', 'clean', 'build' } } else { exec { executable './gradlew' args 'clean', 'build' } } } }