Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more features #11

Merged
merged 24 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ the terms of this License".
A tiny JSON5 parsing library for Java 8, with a focus on simplicity and minimizing size.

## Usage
First, include the library in your project. You can do this by adding the following to your build.gradle(.kts):
First, include the library in your project. You can do this by adding the following to your `build.gradle(.kts)`:
<details>
<summary>Kotlin</summary>

Expand All @@ -19,7 +19,7 @@ repositories {
}

dependencies {
implementation("dev.nolij:zson:version")
implementation("dev.nolij:zson:[version]")
}
```
</details>
Expand All @@ -32,14 +32,26 @@ repositories {
}

dependencies {
implementation 'dev.nolij:zson:version'
implementation 'dev.nolij:zson:[version]'
}
```
</details>

Replace `version` with the version of the library you want to use.
Replace `[version]` with the version of the library you want to use.
You can find the latest version on the [releases page](https://github.com/Nolij/ZSON/releases).

If you wish to use an older version of Java, we provide 2 downgraded jars for Java 17 and 8.
You can use them by appending a classifier `downgraded-[java version]` to the dependency, for example:
`implementation("dev.nolij:zson:[version]:downgraded-8")`.

<details>
<summary>A note about Java 8</summary>

The Java 8 version actually uses Java 5 bytecode (classfile version 49), but because we use Java 8 features (namely NIO),
it still requires Java 8 to run. The reason for doing this is that Java 5 bytecode doesn't have stack maps, which significantly
reduces the size of the resulting jar.
</details>

Then, you can use the library like so:
```java
import dev.nolij.zson.Zson; // static helper/parsing methods, instantiate for a writer
Expand All @@ -65,6 +77,7 @@ public class ZsonExample {
)),
entry("null", "comments can also\nbe multiple lines", null)
);
String jsonString = writer.stringify(map);
System.out.println(jsonString);
}
}
Expand All @@ -77,14 +90,14 @@ This prints out:
// comment
"key": 4,
// look, arrays work too!
"arr": [ 1, 2, 3, ],
"arr": [ 1, 2, 3 ],
// and objects!
"obj": {
"key": "value",
"key": "value"
},
// comments can also
// be multiple lines
"null": null,
"null": null
}
```

Expand All @@ -108,7 +121,8 @@ public class Example {
public static void main(String[] args) {
Example example = new Example();
Map<String, ZsonValue> zson = Zson.obj2map(example);
System.out.println(new Zson().stringify(zson));
System.out.println(new Zson()
.withQuoteKeys(false).stringify(zson));
}
}
```
Expand All @@ -117,8 +131,8 @@ This prints out:
```json5
{
// This is a comment
"key": "value",
"number": 4,
key: "value",
number: 4
}
```

Expand Down
63 changes: 56 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import org.objectweb.asm.tools.Retrofitter
import xyz.wagyourtail.jvmdg.gradle.task.DowngradeJar
import java.time.ZonedDateTime
import java.util.jar.JarEntry
import java.util.jar.JarOutputStream
import java.util.zip.Deflater

plugins {
id("idea")
Expand Down Expand Up @@ -45,7 +49,7 @@ val releaseIncrement = if (isExternalCI) 0 else 1
val releaseChannel: ReleaseChannel =
if (isExternalCI) {
val tagName = releaseTags.first().name
val suffix = """\-(\w+)\.\d+$""".toRegex().find(tagName)?.groupValues?.get(1)
val suffix = """-(\w+)\.\d+$""".toRegex().find(tagName)?.groupValues?.get(1)
if (suffix != null)
ReleaseChannel.values().find { channel -> channel.suffix == suffix }!!
else
Expand Down Expand Up @@ -89,6 +93,14 @@ val versionTagName = "${releaseTagPrefix}${versionString}"
version = versionString
println("ZSON Version: $versionString")

java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

withSourcesJar()
withJavadocJar()
}

repositories {
mavenCentral()
}
Expand All @@ -100,10 +112,44 @@ dependencies {
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

tasks.javadoc {
val options = options as StandardJavadocDocletOptions
options.addBooleanOption("Xdoclint:none", true)
}

tasks.downgradeJar {
dependsOn(tasks.jar)
downgradeTo = JavaVersion.VERSION_1_8
archiveClassifier = "downgraded-8"

doLast {
val jar = archiveFile.get().asFile
val dir = temporaryDir.resolve("downgradeJar5")
dir.mkdirs()

copy {
from(zipTree(jar))
into(dir)
}

Retrofitter().run {
retrofit(dir.toPath())
//verify(dir.toPath())
}

JarOutputStream(archiveFile.get().asFile.outputStream()).use { jos ->
jos.setLevel(Deflater.BEST_COMPRESSION)
dir.walkTopDown().forEach { file ->
if (file.isFile) {
jos.putNextEntry(JarEntry(file.relativeTo(dir).toPath().toString()))
file.inputStream().use { it.copyTo(jos) }
jos.closeEntry()
}
}
jos.flush()
jos.finish()
}
}
}

val downgradeJar17 = tasks.register<DowngradeJar>("downgradeJar17") {
Expand All @@ -114,29 +160,26 @@ val downgradeJar17 = tasks.register<DowngradeJar>("downgradeJar17") {
}

tasks.jar {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
Nolij marked this conversation as resolved.
Show resolved Hide resolved

from(rootProject.file("LICENSE")) {
rename { "${it}_${rootProject.name}" }
}

finalizedBy(tasks.downgradeJar, downgradeJar17)
}

java.withSourcesJar()
val sourcesJar: Jar = tasks.withType<Jar>()["sourcesJar"].apply {
val sourcesJar = tasks.getByName<Jar>("sourcesJar") {
from(rootProject.file("LICENSE")) {
rename { "${it}_${rootProject.name}" }
}
}

tasks.assemble {
dependsOn(tasks.jar, sourcesJar)
dependsOn(tasks.jar, sourcesJar, downgradeJar17)
}

tasks.test {
useJUnitPlatform()
outputs.upToDateWhen { false }
}

tasks.withType<GenerateModuleMetadata> {
Expand All @@ -151,6 +194,11 @@ tasks.withType<JavaCompile> {
}
}

tasks.withType<AbstractArchiveTask> {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}

githubRelease {
setToken(providers.environmentVariable("GITHUB_TOKEN"))
setTagName(versionTagName)
Expand All @@ -175,6 +223,7 @@ publishing {
artifact(downgradeJar17) // java 17
artifact(tasks.downgradeJar) // java 8
artifact(sourcesJar) // java 21 sources
artifact(tasks["javadocJar"])
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repositories.mavenCentral()
dependencies {
implementation("org.ow2.asm:asm:9.7")
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
Loading
Loading