Skip to content

Commit 956bdfa

Browse files
authored
Merge pull request #519 from stleary/gradle-support
Gradle support
2 parents 1da2b98 + 8546e68 commit 956bdfa

34 files changed

Lines changed: 711 additions & 136 deletions

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ cookie lists.
8787

8888
**XMLTokener.java**: `XMLTokener` extends `JSONTokener` for parsing XML text.
8989

90-
Unit tests are maintained in a separate project. Contributing developers can test
91-
JSON-java pull requests with the code in this project:
92-
https://github.com/stleary/JSON-Java-unit-test
90+
Unit tests are now included in the project, but require Java 1.8 at the present time. This will be fixed in a forthcoming commit.
9391

9492
Numeric types in this package comply with
9593
[ECMA-404: The JSON Data Interchange Format](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf) and
@@ -153,10 +151,14 @@ and artifactId "json". For example:
153151
https://search.maven.org/search?q=g:org.json%20AND%20a:json&core=gav
154152

155153
# Unit tests
156-
The test suite can be run by calling
154+
The test suite can be executed with Maven by running:
157155
```
158156
mvn test
159157
```
158+
The test suite can be executed with Gradle (6.4 or greater) by running:
159+
```
160+
gradle clean build test
161+
```
160162

161163

162164

@@ -176,7 +178,6 @@ For example, <b>Cookie.java</b> is tested by <b>CookieTest.java</b>.
176178
* Without unit tests it is hard to feel confident about the quality of the code, especially when fixing bugs or refactoring. Good tests prevents regressions and keeps the intent of the code correct.
177179
* If you have unit test results along with pull requests, the reviewer has an easier time understanding your code and determining if the it works as intended.
178180

179-
When you start working on a test, add the empty file to the repository and update the readme, so that others will know that test is taken.
180181

181182
**Caveats:**
182183
JSON-Java is Java 1.6-compatible, but JSON-Java-unit-tests requires Java 1.8. If you see this error when building JSON-Java-unit-test, make sure you have 1.8 installed, on your path, and set in JAVA_HOME:

build.gradle

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* This file was generated by the Gradle 'init' task.
3+
*/
4+
apply plugin: 'java'
5+
apply plugin: 'eclipse'
6+
// apply plugin: 'jacoco'
7+
apply plugin: 'maven-publish'
8+
9+
//plugins {
10+
// id 'java'
11+
//id 'maven-publish'
12+
// }
13+
14+
repositories {
15+
mavenLocal()
16+
maven {
17+
url = uri('https://oss.sonatype.org/content/repositories/snapshots')
18+
}
19+
20+
maven {
21+
url = uri('http://repo.maven.apache.org/maven2')
22+
}
23+
}
24+
25+
dependencies {
26+
testImplementation 'junit:junit:4.12'
27+
testImplementation 'com.jayway.jsonpath:json-path:2.1.0'
28+
testImplementation 'org.mockito:mockito-core:1.9.5'
29+
}
30+
31+
subprojects {
32+
tasks.withType(Javadoc).all { enabled = false }
33+
}
34+
35+
group = 'org.json'
36+
version = 'v20200429-SNAPSHOT'
37+
description = 'JSON in Java'
38+
sourceCompatibility = '1.7'
39+
40+
configurations.all {
41+
}
42+
43+
java {
44+
withSourcesJar()
45+
withJavadocJar()
46+
}
47+
48+
publishing {
49+
publications {
50+
maven(MavenPublication) {
51+
from(components.java)
52+
}
53+
}
54+
}
55+
56+
tasks.withType(JavaCompile) {
57+
options.encoding = 'UTF-8'
58+
}

src/main/java/org/json/CDL.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private static String getValue(JSONTokener x) throws JSONException {
9898
* Produce a JSONArray of strings from a row of comma delimited values.
9999
* @param x A JSONTokener of the source text.
100100
* @return A JSONArray of strings.
101-
* @throws JSONException
101+
* @throws JSONException if a called function fails
102102
*/
103103
public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException {
104104
JSONArray ja = new JSONArray();
@@ -134,7 +134,7 @@ public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException {
134134
* method.
135135
* @param x A JSONTokener of the source text.
136136
* @return A JSONObject combining the names and values.
137-
* @throws JSONException
137+
* @throws JSONException if a called function fails
138138
*/
139139
public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x)
140140
throws JSONException {
@@ -184,7 +184,7 @@ public static String rowToString(JSONArray ja) {
184184
* using the first row as a source of names.
185185
* @param string The comma delimited text.
186186
* @return A JSONArray of JSONObjects.
187-
* @throws JSONException
187+
* @throws JSONException if a called function fails
188188
*/
189189
public static JSONArray toJSONArray(String string) throws JSONException {
190190
return toJSONArray(new JSONTokener(string));
@@ -195,7 +195,7 @@ public static JSONArray toJSONArray(String string) throws JSONException {
195195
* using the first row as a source of names.
196196
* @param x The JSONTokener containing the comma delimited text.
197197
* @return A JSONArray of JSONObjects.
198-
* @throws JSONException
198+
* @throws JSONException if a called function fails
199199
*/
200200
public static JSONArray toJSONArray(JSONTokener x) throws JSONException {
201201
return toJSONArray(rowToJSONArray(x), x);
@@ -207,7 +207,7 @@ public static JSONArray toJSONArray(JSONTokener x) throws JSONException {
207207
* @param names A JSONArray of strings.
208208
* @param string The comma delimited text.
209209
* @return A JSONArray of JSONObjects.
210-
* @throws JSONException
210+
* @throws JSONException if a called function fails
211211
*/
212212
public static JSONArray toJSONArray(JSONArray names, String string)
213213
throws JSONException {
@@ -220,7 +220,7 @@ public static JSONArray toJSONArray(JSONArray names, String string)
220220
* @param names A JSONArray of strings.
221221
* @param x A JSONTokener of the source text.
222222
* @return A JSONArray of JSONObjects.
223-
* @throws JSONException
223+
* @throws JSONException if a called function fails
224224
*/
225225
public static JSONArray toJSONArray(JSONArray names, JSONTokener x)
226226
throws JSONException {
@@ -248,7 +248,7 @@ public static JSONArray toJSONArray(JSONArray names, JSONTokener x)
248248
* JSONObject.
249249
* @param ja A JSONArray of JSONObjects.
250250
* @return A comma delimited text.
251-
* @throws JSONException
251+
* @throws JSONException if a called function fails
252252
*/
253253
public static String toString(JSONArray ja) throws JSONException {
254254
JSONObject jo = ja.optJSONObject(0);
@@ -268,7 +268,7 @@ public static String toString(JSONArray ja) throws JSONException {
268268
* @param names A JSONArray of strings.
269269
* @param ja A JSONArray of JSONObjects.
270270
* @return A comma delimited text.
271-
* @throws JSONException
271+
* @throws JSONException if a called function fails
272272
*/
273273
public static String toString(JSONArray names, JSONArray ja)
274274
throws JSONException {

src/main/java/org/json/Cookie.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static String escape(String string) {
7676
* @param string The cookie specification string.
7777
* @return A JSONObject containing "name", "value", and possibly other
7878
* members.
79-
* @throws JSONException
79+
* @throws JSONException if a called function fails or a syntax error
8080
*/
8181
public static JSONObject toJSONObject(String string) throws JSONException {
8282
String name;
@@ -113,7 +113,7 @@ public static JSONObject toJSONObject(String string) throws JSONException {
113113
* All other members are ignored.
114114
* @param jo A JSONObject
115115
* @return A cookie specification string
116-
* @throws JSONException
116+
* @throws JSONException if a called function fails
117117
*/
118118
public static String toString(JSONObject jo) throws JSONException {
119119
StringBuilder sb = new StringBuilder();

src/main/java/org/json/CookieList.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class CookieList {
4242
* cookieJSONObject.getString("value"));
4343
* @param string A cookie list string
4444
* @return A JSONObject
45-
* @throws JSONException
45+
* @throws JSONException if a called function fails
4646
*/
4747
public static JSONObject toJSONObject(String string) throws JSONException {
4848
JSONObject jo = new JSONObject();
@@ -63,7 +63,7 @@ public static JSONObject toJSONObject(String string) throws JSONException {
6363
* in the names and values are replaced by "%hh".
6464
* @param jo A JSONObject
6565
* @return A cookie list string
66-
* @throws JSONException
66+
* @throws JSONException if a called function fails
6767
*/
6868
public static String toString(JSONObject jo) throws JSONException {
6969
boolean b = false;

src/main/java/org/json/HTTP.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ public class HTTP {
5151
* "Reason-Phrase": "OK" (for example)
5252
* }</pre>
5353
* In addition, the other parameters in the header will be captured, using
54-
* the HTTP field names as JSON names, so that <pre>
54+
* the HTTP field names as JSON names, so that <pre>{@code
5555
* Date: Sun, 26 May 2002 18:06:04 GMT
5656
* Cookie: Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s
57-
* Cache-Control: no-cache</pre>
57+
* Cache-Control: no-cache}</pre>
5858
* become
59-
* <pre>{...
59+
* <pre>{@code
6060
* Date: "Sun, 26 May 2002 18:06:04 GMT",
6161
* Cookie: "Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s",
6262
* "Cache-Control": "no-cache",
@@ -66,7 +66,7 @@ public class HTTP {
6666
* @param string An HTTP header string.
6767
* @return A JSONObject containing the elements and attributes
6868
* of the XML string.
69-
* @throws JSONException
69+
* @throws JSONException if a called function fails
7070
*/
7171
public static JSONObject toJSONObject(String string) throws JSONException {
7272
JSONObject jo = new JSONObject();

src/main/java/org/json/HTTPTokener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public HTTPTokener(String string) {
4343

4444
/**
4545
* Get the next token or string. This is used in parsing HTTP headers.
46-
* @throws JSONException
4746
* @return A String.
47+
* @throws JSONException if a syntax error occurs
4848
*/
4949
public String nextToken() throws JSONException {
5050
char c;

src/main/java/org/json/JSONArray.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ public String toString() {
13331333
/**
13341334
* Make a pretty-printed JSON text of this JSONArray.
13351335
*
1336-
* <p>If <code>indentFactor > 0</code> and the {@link JSONArray} has only
1336+
* <p>If <pre> {@code indentFactor > 0}</pre> and the {@link JSONArray} has only
13371337
* one element, then the array will be output on a single line:
13381338
* <pre>{@code [1]}</pre>
13391339
*
@@ -1355,7 +1355,7 @@ public String toString() {
13551355
* object, beginning with <code>[</code>&nbsp;<small>(left
13561356
* bracket)</small> and ending with <code>]</code>
13571357
* &nbsp;<small>(right bracket)</small>.
1358-
* @throws JSONException
1358+
* @throws JSONException if a called function fails
13591359
*/
13601360
public String toString(int indentFactor) throws JSONException {
13611361
StringWriter sw = new StringWriter();
@@ -1370,9 +1370,9 @@ public String toString(int indentFactor) throws JSONException {
13701370
* <p><b>
13711371
* Warning: This method assumes that the data structure is acyclical.
13721372
*</b>
1373-
*
1373+
* @param writer the writer object
13741374
* @return The writer.
1375-
* @throws JSONException
1375+
* @throws JSONException if a called function fails
13761376
*/
13771377
public Writer write(Writer writer) throws JSONException {
13781378
return this.write(writer, 0, 0);
@@ -1381,7 +1381,7 @@ public Writer write(Writer writer) throws JSONException {
13811381
/**
13821382
* Write the contents of the JSONArray as JSON text to a writer.
13831383
*
1384-
* <p>If <code>indentFactor > 0</code> and the {@link JSONArray} has only
1384+
* <p>If <pre>{@code indentFactor > 0}</pre> and the {@link JSONArray} has only
13851385
* one element, then the array will be output on a single line:
13861386
* <pre>{@code [1]}</pre>
13871387
*
@@ -1404,7 +1404,7 @@ public Writer write(Writer writer) throws JSONException {
14041404
* @param indent
14051405
* The indentation of the top level.
14061406
* @return The writer.
1407-
* @throws JSONException
1407+
* @throws JSONException if a called function fails or unable to write
14081408
*/
14091409
public Writer write(Writer writer, int indentFactor, int indent)
14101410
throws JSONException {

src/main/java/org/json/JSONML.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class JSONML {
4141
* if we are at the outermost level.
4242
* @param keepStrings Don't type-convert text nodes and attribute values
4343
* @return A JSONArray if the value is the outermost tag, otherwise null.
44-
* @throws JSONException
44+
* @throws JSONException if a parsing error occurs
4545
*/
4646
private static Object parse(
4747
XMLTokener x,
@@ -238,7 +238,7 @@ private static Object parse(
238238
* attributes, then the second element will be JSONObject containing the
239239
* name/value pairs. If the tag contains children, then strings and
240240
* JSONArrays will represent the child tags.
241-
* Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
241+
* Comments, prologs, DTDs, and <pre>{@code &lt;[ [ ]]>}</pre> are ignored.
242242
* @param string The source string.
243243
* @return A JSONArray containing the structured data from the XML string.
244244
* @throws JSONException Thrown on error converting to a JSONArray
@@ -258,7 +258,7 @@ public static JSONArray toJSONArray(String string) throws JSONException {
258258
* As opposed to toJSONArray this method does not attempt to convert
259259
* any text node or attribute value to any type
260260
* but just leaves it as a string.
261-
* Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
261+
* Comments, prologs, DTDs, and <pre>{@code &lt;[ [ ]]>}</pre> are ignored.
262262
* @param string The source string.
263263
* @param keepStrings If true, then values will not be coerced into boolean
264264
* or numeric values and will instead be left as strings
@@ -280,7 +280,7 @@ public static JSONArray toJSONArray(String string, boolean keepStrings) throws J
280280
* As opposed to toJSONArray this method does not attempt to convert
281281
* any text node or attribute value to any type
282282
* but just leaves it as a string.
283-
* Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
283+
* Comments, prologs, DTDs, and <pre>{@code &lt;[ [ ]]>}</pre> are ignored.
284284
* @param x An XMLTokener.
285285
* @param keepStrings If true, then values will not be coerced into boolean
286286
* or numeric values and will instead be left as strings
@@ -299,7 +299,7 @@ public static JSONArray toJSONArray(XMLTokener x, boolean keepStrings) throws JS
299299
* attributes, then the second element will be JSONObject containing the
300300
* name/value pairs. If the tag contains children, then strings and
301301
* JSONArrays will represent the child content and tags.
302-
* Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
302+
* Comments, prologs, DTDs, and <pre>{@code &lt;[ [ ]]>}</pre> are ignored.
303303
* @param x An XMLTokener.
304304
* @return A JSONArray containing the structured data from the XML string.
305305
* @throws JSONException Thrown on error converting to a JSONArray
@@ -317,7 +317,7 @@ public static JSONArray toJSONArray(XMLTokener x) throws JSONException {
317317
* contains children, the object will have a "childNodes" property which
318318
* will be an array of strings and JsonML JSONObjects.
319319
320-
* Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
320+
* Comments, prologs, DTDs, and <pre>{@code &lt;[ [ ]]>}</pre> are ignored.
321321
* @param string The XML source text.
322322
* @return A JSONObject containing the structured data from the XML string.
323323
* @throws JSONException Thrown on error converting to a JSONObject
@@ -335,7 +335,7 @@ public static JSONObject toJSONObject(String string) throws JSONException {
335335
* contains children, the object will have a "childNodes" property which
336336
* will be an array of strings and JsonML JSONObjects.
337337
338-
* Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
338+
* Comments, prologs, DTDs, and <pre>{@code &lt;[ [ ]]>}</pre> are ignored.
339339
* @param string The XML source text.
340340
* @param keepStrings If true, then values will not be coerced into boolean
341341
* or numeric values and will instead be left as strings
@@ -355,7 +355,7 @@ public static JSONObject toJSONObject(String string, boolean keepStrings) throws
355355
* contains children, the object will have a "childNodes" property which
356356
* will be an array of strings and JsonML JSONObjects.
357357
358-
* Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
358+
* Comments, prologs, DTDs, and <pre>{@code &lt;[ [ ]]>}</pre> are ignored.
359359
* @param x An XMLTokener of the XML source text.
360360
* @return A JSONObject containing the structured data from the XML string.
361361
* @throws JSONException Thrown on error converting to a JSONObject
@@ -373,7 +373,7 @@ public static JSONObject toJSONObject(XMLTokener x) throws JSONException {
373373
* contains children, the object will have a "childNodes" property which
374374
* will be an array of strings and JsonML JSONObjects.
375375
376-
* Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
376+
* Comments, prologs, DTDs, and <pre>{@code &lt;[ [ ]]>}</pre> are ignored.
377377
* @param x An XMLTokener of the XML source text.
378378
* @param keepStrings If true, then values will not be coerced into boolean
379379
* or numeric values and will instead be left as strings

0 commit comments

Comments
 (0)