@@ -53,3 +53,75 @@ publishing {
53
53
tasks. withType(JavaCompile ) {
54
54
options. encoding = ' UTF-8'
55
55
}
56
+ // Add these imports at the top of your build.gradle file
57
+ import java.nio.file.Files
58
+ import java.nio.file.Path
59
+ import java.nio.file.Paths
60
+ import java.nio.file.StandardCopyOption
61
+
62
+ // Your existing build configurations...
63
+
64
+ // Add a new task to modify the file
65
+ task modifyStrictMode {
66
+ doLast {
67
+ println " Modifying JSONParserConfiguration.java to enable strictMode..."
68
+
69
+ def filePath = project. file(' src/main/java/org/json/JSONParserConfiguration.java' )
70
+
71
+ if (! filePath. exists()) {
72
+ throw new GradleException (" Could not find file: ${ filePath.absolutePath} " )
73
+ }
74
+
75
+ // Create a backup of the original file
76
+ def backupFile = new File (filePath. absolutePath + ' .bak' )
77
+ Files . copy(filePath. toPath(), backupFile. toPath(), StandardCopyOption . REPLACE_EXISTING )
78
+
79
+ // Read and modify the file content
80
+ def content = filePath. text
81
+ def modifiedContent = content. replace(' // this.strictMode = true;' , ' this.strictMode = true;' )
82
+
83
+ // Write the modified content back to the file
84
+ filePath. text = modifiedContent
85
+
86
+ println " File modified successfully at: ${ filePath.absolutePath} "
87
+ }
88
+ }
89
+
90
+ // Add a task to restore the original file
91
+ task restoreStrictMode {
92
+ doLast {
93
+ println " Restoring original JSONParserConfiguration.java..."
94
+
95
+ def filePath = project. file(' src/main/java/org/json/JSONParserConfiguration.java' )
96
+ def backupFile = new File (filePath. absolutePath + ' .bak' )
97
+
98
+ if (backupFile. exists()) {
99
+ Files . copy(backupFile. toPath(), filePath. toPath(), StandardCopyOption . REPLACE_EXISTING )
100
+ backupFile. delete()
101
+ println " Original file restored successfully at: ${ filePath.absolutePath} "
102
+ } else {
103
+ println " Backup file not found at: ${ backupFile.absolutePath} . No restoration performed."
104
+ }
105
+ }
106
+ }
107
+
108
+ // Create a task to run the workflow
109
+ task testWithStrictMode {
110
+ dependsOn modifyStrictMode
111
+ finalizedBy restoreStrictMode
112
+
113
+ doLast {
114
+ // This will trigger a clean build and run tests with strictMode enabled
115
+ if (org.gradle.internal.os.OperatingSystem . current(). isWindows()) {
116
+ exec {
117
+ executable ' cmd'
118
+ args ' /c' , ' gradlew.bat' , ' clean' , ' build'
119
+ }
120
+ } else {
121
+ exec {
122
+ executable ' ./gradlew'
123
+ args ' clean' , ' build'
124
+ }
125
+ }
126
+ }
127
+ }
0 commit comments