diff --git a/README.md b/README.md index 1271f8d..336f60c 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,12 @@ Execute the test suite with Gradlew: gradlew clean build test ``` +*Optional* Execute the test suite in strict mode with Gradlew: + +```shell +gradlew testWithStrictMode +``` + # Notes For more information, please see [NOTES.md](https://github.com/stleary/JSON-java/blob/master/docs/NOTES.md) diff --git a/build.gradle b/build.gradle index 2c0fc6d..3961e85 100644 --- a/build.gradle +++ b/build.gradle @@ -53,3 +53,75 @@ publishing { 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' + } + } + } +} \ No newline at end of file diff --git a/src/main/java/org/json/JSONParserConfiguration.java b/src/main/java/org/json/JSONParserConfiguration.java index d3420a1..3fbfb8a 100644 --- a/src/main/java/org/json/JSONParserConfiguration.java +++ b/src/main/java/org/json/JSONParserConfiguration.java @@ -15,7 +15,8 @@ public class JSONParserConfiguration extends ParserConfiguration { public JSONParserConfiguration() { super(); this.overwriteDuplicateKey = false; -// this.strictMode = true; + // DO NOT DELETE THE FOLLOWING LINE -- it is used for strictMode testing + // this.strictMode = true; } /**