Merge branch 'master' into issue813

This commit is contained in:
rudrajyoti biswas 2023-10-27 17:09:01 +05:30
commit 07a358449a
3 changed files with 114 additions and 54 deletions

View File

@ -11,10 +11,37 @@ on:
types: [published] types: [published]
jobs: jobs:
publish: # old-school build and jar method. No tests run or compiled.
publish-1_6:
name: Publish Java 1.6 to GitHub Release
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: read contents: write
steps:
- uses: actions/checkout@v4
- name: Setup java
uses: actions/setup-java@v1
with:
java-version: 1.6
- name: Compile Java 1.6
run: |
mkdir -p target/classes
javac -version
javac -source 1.6 -target 1.6 -d target/classes/ src/main/java/org/json/*.java
- name: Create JAR 1.6
run: |
jar cvf "target/org.json-1.6-${{ github.ref_name }}.jar" -C target/classes .
- name: Add 1.6 Jar To Release
uses: softprops/action-gh-release@v1
with:
append_body: true
files: |
target/*.jar
publish:
name: Publish Java 8 to Maven Central and GitHub Release
runs-on: ubuntu-latest
permissions:
contents: write
packages: write packages: write
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@ -36,6 +63,13 @@ jobs:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
- name: Add Jar To Release
uses: softprops/action-gh-release@v1
with:
append_body: true
files: |
target/*.jar
# - name: Set up Java for publishing to GitHub Packages # - name: Set up Java for publishing to GitHub Packages
# uses: actions/setup-java@v3 # uses: actions/setup-java@v3
# with: # with:

View File

@ -10,9 +10,35 @@ on:
branches: [ master ] branches: [ master ]
jobs: jobs:
# old-school build and jar method. No tests run or compiled.
build-1_6:
name: Java 1.6
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup java
uses: actions/setup-java@v1
with:
java-version: 1.6
- name: Compile Java 1.6
run: |
mkdir -p target/classes
javac -version
javac -source 1.6 -target 1.6 -d target/classes/ src/main/java/org/json/*.java
- name: Create java 1.6 JAR
run: |
jar cvf target/org.json.jar -C target/classes .
- name: Upload JAR 1.6
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: Create java 1.6 JAR
path: target/*.jar
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
fail-fast: false
max-parallel: 2
matrix: matrix:
# build against supported Java LTS versions: # build against supported Java LTS versions:
java: [ 8, 11, 17, 21 ] java: [ 8, 11, 17, 21 ]

View File

@ -44,24 +44,24 @@ The org.json package can be built from the command line, Maven, and Gradle. The
**Building from the command line** **Building from the command line**
*Build the class files from the package root directory src/main/java* *Build the class files from the package root directory src/main/java*
```` ```shell
javac org/json/*.java javac org/json/*.java
```` ```
*Create the jar file in the current directory* *Create the jar file in the current directory*
```` ```shell
jar cf json-java.jar org/json/*.class jar cf json-java.jar org/json/*.class
```` ```
*Compile a program that uses the jar (see example code below)* *Compile a program that uses the jar (see example code below)*
```` ```shell
javac -cp .;json-java.jar Test.java (Windows) javac -cp .;json-java.jar Test.java (Windows)
javac -cp .:json-java.jar Test.java (Unix Systems) javac -cp .:json-java.jar Test.java (Unix Systems)
```` ```
*Test file contents* *Test file contents*
```` ```java
import org.json.JSONObject; import org.json.JSONObject;
public class Test { public class Test {
public static void main(String args[]){ public static void main(String args[]){
@ -69,31 +69,31 @@ public class Test {
System.out.println(jo.toString()); System.out.println(jo.toString());
} }
} }
```` ```
*Execute the Test file* *Execute the Test file*
```` ```shell
java -cp .;json-java.jar Test (Windows) java -cp .;json-java.jar Test (Windows)
java -cp .:json-java.jar Test (Unix Systems) java -cp .:json-java.jar Test (Unix Systems)
```` ```
*Expected output* *Expected output*
```` ```json
{"abc":"def"} {"abc":"def"}
```` ```
**Tools to build the package and execute the unit tests** **Tools to build the package and execute the unit tests**
Execute the test suite with Maven: Execute the test suite with Maven:
``` ```shell
mvn clean test mvn clean test
``` ```
Execute the test suite with Gradlew: Execute the test suite with Gradlew:
``` ```shell
gradlew clean build test gradlew clean build test
``` ```