-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JSON support and Java Modules: v1.1
- Loading branch information
Showing
10 changed files
with
410 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (C) 2023 Samū | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
plugins { | ||
id("java") | ||
id("maven-publish") | ||
} | ||
|
||
group = rootProject.group | ||
version = rootProject.version | ||
|
||
repositories { | ||
mavenCentral() | ||
maven { | ||
url = uri("https://maven.shadew.net/") | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation("dev.runefox:json:0.7.2") | ||
implementation(rootProject) | ||
|
||
testImplementation(platform("org.junit:junit-bom:5.9.1")) | ||
testImplementation("org.junit.jupiter:junit-jupiter") | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
} | ||
|
||
java { | ||
withSourcesJar() | ||
withJavadocJar() | ||
} | ||
|
||
publishing { | ||
publications { | ||
create<MavenPublication>("maven") { | ||
groupId = "${project.group}" | ||
artifactId = project.name | ||
version = "${project.version}" | ||
|
||
from(components["java"]) | ||
} | ||
} | ||
repositories { | ||
maven { | ||
// You should have received these credentials when given permission | ||
// to the Runefox Maven repository | ||
val rfxMavenHost: String by properties | ||
val rfxMavenUser: String by properties | ||
val rfxMavenPass: String by properties | ||
|
||
name = "RfxMaven" | ||
url = uri(rfxMavenHost) | ||
credentials { | ||
username = rfxMavenUser | ||
password = rfxMavenPass | ||
} | ||
} | ||
} | ||
} | ||
|
73 changes: 73 additions & 0 deletions
73
rms-json/src/main/java/dev/runefox/rms/json/Json5CodecResourceType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (C) 2023 Samū | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.runefox.rms.json; | ||
|
||
import dev.runefox.json.Json; | ||
import dev.runefox.json.codec.JsonCodec; | ||
import dev.runefox.rms.Resource; | ||
import dev.runefox.rms.ResourceManager; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* A {@link Json5ResourceType} that decodes the JSON tree using a {@link JsonCodec}. You don't need to implement this | ||
* interface if you just want the default features, you can use {@link #create} to get an instance with basic | ||
* functionality. | ||
* | ||
* @author Samū | ||
* @since 1.1 | ||
*/ | ||
public interface Json5CodecResourceType<R extends Resource> extends JsonCodecResourceType<R>, Json5ResourceType<R> { | ||
// I don't know which of the interfaces takes priority if we don't | ||
// override these methods, so I'll override them just to be sure | ||
// (plus it's probably clearer what's happening). | ||
|
||
@Override | ||
default Json json() { | ||
return Json.json5(); | ||
} | ||
|
||
@Override | ||
default String extension() { | ||
return "json5"; | ||
} | ||
|
||
/** | ||
* Creates a basic {@link Json5CodecResourceType} with a fixed codec and a supplied fallback instance. This is a | ||
* convenience method to quickly have a resource type to load JSON resources. | ||
* | ||
* @param codec The codec. | ||
* @param fallback The fallback supplier. | ||
* @return A new {@link JsonCodecResourceType}. | ||
* | ||
* @since 1.1 | ||
*/ | ||
static <R extends Resource> Json5CodecResourceType<R> create(JsonCodec<R> codec, Supplier<R> fallback) { | ||
return new Json5CodecResourceType<>() { | ||
@Override | ||
public JsonCodec<R> codec(ResourceManager res, String ns, String name) { | ||
return codec; | ||
} | ||
|
||
@Override | ||
public R createFallback(ResourceManager res, String ns, String name) { | ||
return fallback.get(); | ||
} | ||
}; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
rms-json/src/main/java/dev/runefox/rms/json/Json5ResourceType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (C) 2023 Samū | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.runefox.rms.json; | ||
|
||
import dev.runefox.json.Json; | ||
import dev.runefox.rms.Resource; | ||
|
||
/** | ||
* A {@link JsonResourceType} that uses {@linkplain Json#json5() JSON 5} to parse a resource. | ||
* | ||
* @author Samū | ||
* @see JsonResourceType | ||
* @see Json5CodecResourceType | ||
* @since 1.1 | ||
*/ | ||
public interface Json5ResourceType<R extends Resource> extends JsonResourceType<R> { | ||
@Override | ||
default Json json() { | ||
return Json.json5(); | ||
} | ||
|
||
@Override | ||
default String extension() { | ||
return "json5"; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
rms-json/src/main/java/dev/runefox/rms/json/JsonCodecResourceType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (C) 2023 Samū | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.runefox.rms.json; | ||
|
||
import dev.runefox.json.JsonNode; | ||
import dev.runefox.json.codec.JsonCodec; | ||
import dev.runefox.rms.Resource; | ||
import dev.runefox.rms.ResourceManager; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* A {@link JsonResourceType} that decodes the JSON tree using a {@link JsonCodec}. You don't need to implement this | ||
* interface if you just want the default features, you can use {@link #create} to get an instance with basic | ||
* functionality. | ||
* | ||
* @author Samū | ||
* @since 1.1 | ||
*/ | ||
public interface JsonCodecResourceType<R extends Resource> extends JsonResourceType<R> { | ||
@Override | ||
default R load(ResourceManager res, String ns, String name, JsonNode in) { | ||
return codec(res, ns, name).decode(in); | ||
} | ||
|
||
/** | ||
* Returns the {@link JsonCodec} to be used to decode resource instances. | ||
* | ||
* @param res The resource manager. | ||
* @param ns The namespace. | ||
* @param name The resource's name. | ||
* @return The {@link JsonCodec} to decode with. | ||
* | ||
* @since 1.1 | ||
*/ | ||
JsonCodec<R> codec(ResourceManager res, String ns, String name); | ||
|
||
/** | ||
* Creates a basic {@link JsonCodecResourceType} with a fixed codec and a supplied fallback instance. This is a | ||
* convenience method to quickly have a resource type to load JSON resources. | ||
* | ||
* @param codec The codec. | ||
* @param fallback The fallback supplier. | ||
* @return A new {@link JsonCodecResourceType}. | ||
* | ||
* @since 1.1 | ||
*/ | ||
static <R extends Resource> JsonCodecResourceType<R> create(JsonCodec<R> codec, Supplier<R> fallback) { | ||
return new JsonCodecResourceType<>() { | ||
@Override | ||
public JsonCodec<R> codec(ResourceManager res, String ns, String name) { | ||
return codec; | ||
} | ||
|
||
@Override | ||
public R createFallback(ResourceManager res, String ns, String name) { | ||
return fallback.get(); | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.