Skip to content

Commit

Permalink
Merge pull request #519 from stleary/gradle-support
Browse files Browse the repository at this point in the history
Gradle support
  • Loading branch information
stleary authored May 23, 2020
2 parents 1da2b98 + 8546e68 commit 956bdfa
Show file tree
Hide file tree
Showing 34 changed files with 711 additions and 136 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ cookie lists.

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

Unit tests are maintained in a separate project. Contributing developers can test
JSON-java pull requests with the code in this project:
https://github.com/stleary/JSON-Java-unit-test
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.

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

# Unit tests
The test suite can be run by calling
The test suite can be executed with Maven by running:
```
mvn test
```
The test suite can be executed with Gradle (6.4 or greater) by running:
```
gradle clean build test
```



Expand All @@ -176,7 +178,6 @@ For example, <b>Cookie.java</b> is tested by <b>CookieTest.java</b>.
* 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.
* 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.

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.

**Caveats:**
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:
Expand Down
58 changes: 58 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* This file was generated by the Gradle 'init' task.
*/
apply plugin: 'java'
apply plugin: 'eclipse'
// apply plugin: 'jacoco'
apply plugin: 'maven-publish'

//plugins {
// id 'java'
//id 'maven-publish'
// }

repositories {
mavenLocal()
maven {
url = uri('https://oss.sonatype.org/content/repositories/snapshots')
}

maven {
url = uri('http://repo.maven.apache.org/maven2')
}
}

dependencies {
testImplementation 'junit:junit:4.12'
testImplementation 'com.jayway.jsonpath:json-path:2.1.0'
testImplementation 'org.mockito:mockito-core:1.9.5'
}

subprojects {
tasks.withType(Javadoc).all { enabled = false }
}

group = 'org.json'
version = 'v20200429-SNAPSHOT'
description = 'JSON in Java'
sourceCompatibility = '1.7'

configurations.all {
}

java {
withSourcesJar()
withJavadocJar()
}

publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
16 changes: 8 additions & 8 deletions src/main/java/org/json/CDL.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static String getValue(JSONTokener x) throws JSONException {
* Produce a JSONArray of strings from a row of comma delimited values.
* @param x A JSONTokener of the source text.
* @return A JSONArray of strings.
* @throws JSONException
* @throws JSONException if a called function fails
*/
public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException {
JSONArray ja = new JSONArray();
Expand Down Expand Up @@ -134,7 +134,7 @@ public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException {
* method.
* @param x A JSONTokener of the source text.
* @return A JSONObject combining the names and values.
* @throws JSONException
* @throws JSONException if a called function fails
*/
public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x)
throws JSONException {
Expand Down Expand Up @@ -184,7 +184,7 @@ public static String rowToString(JSONArray ja) {
* using the first row as a source of names.
* @param string The comma delimited text.
* @return A JSONArray of JSONObjects.
* @throws JSONException
* @throws JSONException if a called function fails
*/
public static JSONArray toJSONArray(String string) throws JSONException {
return toJSONArray(new JSONTokener(string));
Expand All @@ -195,7 +195,7 @@ public static JSONArray toJSONArray(String string) throws JSONException {
* using the first row as a source of names.
* @param x The JSONTokener containing the comma delimited text.
* @return A JSONArray of JSONObjects.
* @throws JSONException
* @throws JSONException if a called function fails
*/
public static JSONArray toJSONArray(JSONTokener x) throws JSONException {
return toJSONArray(rowToJSONArray(x), x);
Expand All @@ -207,7 +207,7 @@ public static JSONArray toJSONArray(JSONTokener x) throws JSONException {
* @param names A JSONArray of strings.
* @param string The comma delimited text.
* @return A JSONArray of JSONObjects.
* @throws JSONException
* @throws JSONException if a called function fails
*/
public static JSONArray toJSONArray(JSONArray names, String string)
throws JSONException {
Expand All @@ -220,7 +220,7 @@ public static JSONArray toJSONArray(JSONArray names, String string)
* @param names A JSONArray of strings.
* @param x A JSONTokener of the source text.
* @return A JSONArray of JSONObjects.
* @throws JSONException
* @throws JSONException if a called function fails
*/
public static JSONArray toJSONArray(JSONArray names, JSONTokener x)
throws JSONException {
Expand Down Expand Up @@ -248,7 +248,7 @@ public static JSONArray toJSONArray(JSONArray names, JSONTokener x)
* JSONObject.
* @param ja A JSONArray of JSONObjects.
* @return A comma delimited text.
* @throws JSONException
* @throws JSONException if a called function fails
*/
public static String toString(JSONArray ja) throws JSONException {
JSONObject jo = ja.optJSONObject(0);
Expand All @@ -268,7 +268,7 @@ public static String toString(JSONArray ja) throws JSONException {
* @param names A JSONArray of strings.
* @param ja A JSONArray of JSONObjects.
* @return A comma delimited text.
* @throws JSONException
* @throws JSONException if a called function fails
*/
public static String toString(JSONArray names, JSONArray ja)
throws JSONException {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/json/Cookie.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static String escape(String string) {
* @param string The cookie specification string.
* @return A JSONObject containing "name", "value", and possibly other
* members.
* @throws JSONException
* @throws JSONException if a called function fails or a syntax error
*/
public static JSONObject toJSONObject(String string) throws JSONException {
String name;
Expand Down Expand Up @@ -113,7 +113,7 @@ public static JSONObject toJSONObject(String string) throws JSONException {
* All other members are ignored.
* @param jo A JSONObject
* @return A cookie specification string
* @throws JSONException
* @throws JSONException if a called function fails
*/
public static String toString(JSONObject jo) throws JSONException {
StringBuilder sb = new StringBuilder();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/json/CookieList.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class CookieList {
* cookieJSONObject.getString("value"));
* @param string A cookie list string
* @return A JSONObject
* @throws JSONException
* @throws JSONException if a called function fails
*/
public static JSONObject toJSONObject(String string) throws JSONException {
JSONObject jo = new JSONObject();
Expand All @@ -63,7 +63,7 @@ public static JSONObject toJSONObject(String string) throws JSONException {
* in the names and values are replaced by "%hh".
* @param jo A JSONObject
* @return A cookie list string
* @throws JSONException
* @throws JSONException if a called function fails
*/
public static String toString(JSONObject jo) throws JSONException {
boolean b = false;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/json/HTTP.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public class HTTP {
* "Reason-Phrase": "OK" (for example)
* }</pre>
* In addition, the other parameters in the header will be captured, using
* the HTTP field names as JSON names, so that <pre>
* the HTTP field names as JSON names, so that <pre>{@code
* Date: Sun, 26 May 2002 18:06:04 GMT
* Cookie: Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s
* Cache-Control: no-cache</pre>
* Cache-Control: no-cache}</pre>
* become
* <pre>{...
* <pre>{@code
* Date: "Sun, 26 May 2002 18:06:04 GMT",
* Cookie: "Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s",
* "Cache-Control": "no-cache",
Expand All @@ -66,7 +66,7 @@ public class HTTP {
* @param string An HTTP header string.
* @return A JSONObject containing the elements and attributes
* of the XML string.
* @throws JSONException
* @throws JSONException if a called function fails
*/
public static JSONObject toJSONObject(String string) throws JSONException {
JSONObject jo = new JSONObject();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/json/HTTPTokener.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public HTTPTokener(String string) {

/**
* Get the next token or string. This is used in parsing HTTP headers.
* @throws JSONException
* @return A String.
* @throws JSONException if a syntax error occurs
*/
public String nextToken() throws JSONException {
char c;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/json/JSONArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@ public String toString() {
/**
* Make a pretty-printed JSON text of this JSONArray.
*
* <p>If <code>indentFactor > 0</code> and the {@link JSONArray} has only
* <p>If <pre> {@code indentFactor > 0}</pre> and the {@link JSONArray} has only
* one element, then the array will be output on a single line:
* <pre>{@code [1]}</pre>
*
Expand All @@ -1355,7 +1355,7 @@ public String toString() {
* object, beginning with <code>[</code>&nbsp;<small>(left
* bracket)</small> and ending with <code>]</code>
* &nbsp;<small>(right bracket)</small>.
* @throws JSONException
* @throws JSONException if a called function fails
*/
public String toString(int indentFactor) throws JSONException {
StringWriter sw = new StringWriter();
Expand All @@ -1370,9 +1370,9 @@ public String toString(int indentFactor) throws JSONException {
* <p><b>
* Warning: This method assumes that the data structure is acyclical.
*</b>
*
* @param writer the writer object
* @return The writer.
* @throws JSONException
* @throws JSONException if a called function fails
*/
public Writer write(Writer writer) throws JSONException {
return this.write(writer, 0, 0);
Expand All @@ -1381,7 +1381,7 @@ public Writer write(Writer writer) throws JSONException {
/**
* Write the contents of the JSONArray as JSON text to a writer.
*
* <p>If <code>indentFactor > 0</code> and the {@link JSONArray} has only
* <p>If <pre>{@code indentFactor > 0}</pre> and the {@link JSONArray} has only
* one element, then the array will be output on a single line:
* <pre>{@code [1]}</pre>
*
Expand All @@ -1404,7 +1404,7 @@ public Writer write(Writer writer) throws JSONException {
* @param indent
* The indentation of the top level.
* @return The writer.
* @throws JSONException
* @throws JSONException if a called function fails or unable to write
*/
public Writer write(Writer writer, int indentFactor, int indent)
throws JSONException {
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/org/json/JSONML.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class JSONML {
* if we are at the outermost level.
* @param keepStrings Don't type-convert text nodes and attribute values
* @return A JSONArray if the value is the outermost tag, otherwise null.
* @throws JSONException
* @throws JSONException if a parsing error occurs
*/
private static Object parse(
XMLTokener x,
Expand Down Expand Up @@ -238,7 +238,7 @@ private static Object parse(
* attributes, then the second element will be JSONObject containing the
* name/value pairs. If the tag contains children, then strings and
* JSONArrays will represent the child tags.
* Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
* Comments, prologs, DTDs, and <pre>{@code &lt;[ [ ]]>}</pre> are ignored.
* @param string The source string.
* @return A JSONArray containing the structured data from the XML string.
* @throws JSONException Thrown on error converting to a JSONArray
Expand All @@ -258,7 +258,7 @@ public static JSONArray toJSONArray(String string) throws JSONException {
* As opposed to toJSONArray this method does not attempt to convert
* any text node or attribute value to any type
* but just leaves it as a string.
* Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
* Comments, prologs, DTDs, and <pre>{@code &lt;[ [ ]]>}</pre> are ignored.
* @param string The source string.
* @param keepStrings If true, then values will not be coerced into boolean
* or numeric values and will instead be left as strings
Expand All @@ -280,7 +280,7 @@ public static JSONArray toJSONArray(String string, boolean keepStrings) throws J
* As opposed to toJSONArray this method does not attempt to convert
* any text node or attribute value to any type
* but just leaves it as a string.
* Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
* Comments, prologs, DTDs, and <pre>{@code &lt;[ [ ]]>}</pre> are ignored.
* @param x An XMLTokener.
* @param keepStrings If true, then values will not be coerced into boolean
* or numeric values and will instead be left as strings
Expand All @@ -299,7 +299,7 @@ public static JSONArray toJSONArray(XMLTokener x, boolean keepStrings) throws JS
* attributes, then the second element will be JSONObject containing the
* name/value pairs. If the tag contains children, then strings and
* JSONArrays will represent the child content and tags.
* Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
* Comments, prologs, DTDs, and <pre>{@code &lt;[ [ ]]>}</pre> are ignored.
* @param x An XMLTokener.
* @return A JSONArray containing the structured data from the XML string.
* @throws JSONException Thrown on error converting to a JSONArray
Expand All @@ -317,7 +317,7 @@ public static JSONArray toJSONArray(XMLTokener x) throws JSONException {
* contains children, the object will have a "childNodes" property which
* will be an array of strings and JsonML JSONObjects.
* Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
* Comments, prologs, DTDs, and <pre>{@code &lt;[ [ ]]>}</pre> are ignored.
* @param string The XML source text.
* @return A JSONObject containing the structured data from the XML string.
* @throws JSONException Thrown on error converting to a JSONObject
Expand All @@ -335,7 +335,7 @@ public static JSONObject toJSONObject(String string) throws JSONException {
* contains children, the object will have a "childNodes" property which
* will be an array of strings and JsonML JSONObjects.
* Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
* Comments, prologs, DTDs, and <pre>{@code &lt;[ [ ]]>}</pre> are ignored.
* @param string The XML source text.
* @param keepStrings If true, then values will not be coerced into boolean
* or numeric values and will instead be left as strings
Expand All @@ -355,7 +355,7 @@ public static JSONObject toJSONObject(String string, boolean keepStrings) throws
* contains children, the object will have a "childNodes" property which
* will be an array of strings and JsonML JSONObjects.
* Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
* Comments, prologs, DTDs, and <pre>{@code &lt;[ [ ]]>}</pre> are ignored.
* @param x An XMLTokener of the XML source text.
* @return A JSONObject containing the structured data from the XML string.
* @throws JSONException Thrown on error converting to a JSONObject
Expand All @@ -373,7 +373,7 @@ public static JSONObject toJSONObject(XMLTokener x) throws JSONException {
* contains children, the object will have a "childNodes" property which
* will be an array of strings and JsonML JSONObjects.
* Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
* Comments, prologs, DTDs, and <pre>{@code &lt;[ [ ]]>}</pre> are ignored.
* @param x An XMLTokener of the XML source text.
* @param keepStrings If true, then values will not be coerced into boolean
* or numeric values and will instead be left as strings
Expand Down
Loading

0 comments on commit 956bdfa

Please sign in to comment.