diff --git a/dist/java/build.gradle b/dist/java/build.gradle index fd7fba2..9496a40 100644 --- a/dist/java/build.gradle +++ b/dist/java/build.gradle @@ -57,3 +57,47 @@ tasks.register('cargoBuild', Exec) { processResources.dependsOn cargoBuild build.finalizedBy shadowJar + +publishing { + publications { + mavenJava(MavenPublication) { + artifactId = 'my-library' + from components.java + versionMapping { + usage('java-api') { + fromResolutionOf('runtimeClasspath') + } + usage('java-runtime') { + fromResolutionResult() + } + } + pom { + name = 'My Library' + description = 'A concise description of my library' + url = 'http://www.example.com/library' + properties = [ + myProp: "value", + "prop.with.dots": "anotherValue" + ] + licenses { + license { + name = 'The Apache License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + developers { + developer { + id = 'johnd' + name = 'John Doe' + email = 'john.doe@example.com' + } + } + scm { + connection = 'scm:git:git://example.com/my-library.git' + developerConnection = 'scm:git:ssh://example.com/my-library.git' + url = 'http://example.com/my-library/' + } + } + } + } +} diff --git a/dist/java/src/mp/code/Client.java b/dist/java/src/mp/code/Client.java index b70292d..e9b715e 100644 --- a/dist/java/src/mp/code/Client.java +++ b/dist/java/src/mp/code/Client.java @@ -155,4 +155,3 @@ public final class Client { Extensions.loadLibraryIfNotPresent(); } } - diff --git a/dist/java/src/mp/code/data/Config.java b/dist/java/src/mp/code/data/Config.java index 49c7e6e..7864e97 100644 --- a/dist/java/src/mp/code/data/Config.java +++ b/dist/java/src/mp/code/data/Config.java @@ -47,7 +47,7 @@ public class Config { * @param username the username * @param password the password * @param host the host server - * @param port the port CodeMP is running on, must be between 0 and 65535 + * @param port the port CodeMP is running on, must be between 0 and 65535 (will be clamped) * @param tls whether to use TLS */ public Config(String username, String password, String host, int port, boolean tls) { @@ -55,14 +55,8 @@ public class Config { username, password, Optional.of(host), - OptionalInt.of(checkPort(port)), + OptionalInt.of(port), Optional.of(tls) ); } - - private static int checkPort(int port) { - if(port < 0 || port > 65535) - throw new IllegalArgumentException("Port value must be between 0 and 65535!"); - return port; - } } diff --git a/dist/java/src/mp/code/data/TextChange.java b/dist/java/src/mp/code/data/TextChange.java index e656b55..33e7561 100644 --- a/dist/java/src/mp/code/data/TextChange.java +++ b/dist/java/src/mp/code/data/TextChange.java @@ -19,13 +19,13 @@ public class TextChange { * The starting position of the change. * If negative, it is clamped to 0. */ - public final int start; + public final long start; /** * The endomg position of the change. * If negative, it is clamped to 0. */ - public final int end; + public final long end; /** * The content of the change. @@ -74,14 +74,14 @@ public class TextChange { * @return the mutated string */ public String apply(String input) { - int preIndex = Math.min(this.start, input.length()); + long preIndex = Math.min(this.start, input.length()); String pre = ""; try { - pre = input.substring(0, preIndex); + pre = input.substring(0, (int) preIndex); } catch(IndexOutOfBoundsException ignored) {} String post = ""; try { - post = input.substring(this.end); + post = input.substring((int) this.end); } catch(IndexOutOfBoundsException ignored) {} return pre + this.content + post; } diff --git a/src/ffi/java/mod.rs b/src/ffi/java/mod.rs index da37a23..d99c157 100644 --- a/src/ffi/java/mod.rs +++ b/src/ffi/java/mod.rs @@ -126,7 +126,7 @@ macro_rules! jobjectify_error { fn jobjectify($self, env: &mut jni::JNIEnv<'local>) -> Result, jni::errors::Error> { let class = env.find_class($jclass)?; let msg = env.new_string(format!("{:#?}", $self))?; - env.new_object(class, "(Ljava/lang/String)V", &[jni::objects::JValueGen::Object(&msg)]) + env.new_object(class, "(Ljava/lang/String;)V", &[jni::objects::JValueGen::Object(&msg)]) } } }; @@ -332,7 +332,7 @@ impl<'local> Deobjectify<'local, Self> for crate::api::Config { let port = { let jfield = env.get_field(&config, "port", "Ljava/util/OptionalInt;")?.l()?; if env.call_method(&jfield, "isPresent", "()Z", &[])?.z()? { - let ivalue = env.call_method(&jfield, "get", "()I", &[])?.i()?; + let ivalue = env.call_method(&jfield, "getAsInt", "()I", &[])?.i()?; Some(ivalue.clamp(0, 65535) as u16) } else { None @@ -343,7 +343,13 @@ impl<'local> Deobjectify<'local, Self> for crate::api::Config { let jfield = env.get_field(&config, "host", "Ljava/util/Optional;")?.l()?; if env.call_method(&jfield, "isPresent", "()Z", &[])?.z()? { let field = env.call_method(&jfield, "get", "()Ljava/lang/Object;", &[])?.l()?; - Some(env.call_method(field, "booleanValue", "()Z", &[])?.z()?) + let bool_true = env.get_static_field("java/lang/Boolean", "TRUE", "Ljava/lang/Boolean;")?.l()?; + Some(env.call_method( + field, + "equals", + "(Ljava/lang/Object;)Z", + &[jni::objects::JValueGen::Object(&bool_true)] + )?.z()?) // what a joke } else { None } @@ -383,8 +389,8 @@ impl<'local> Deobjectify<'local, Self> for crate::api::Cursor { impl<'local> Deobjectify<'local, Self> for crate::api::TextChange { fn deobjectify(env: &mut jni::JNIEnv<'local>, change: jni::objects::JObject<'local>) -> Result { - let start = env.get_field(&change, "start", "I")?.j()?.max(0) as u32; - let end = env.get_field(&change, "end", "I")?.j()?.max(0) as u32; + let start = env.get_field(&change, "start", "J")?.j()?.clamp(0, u32::MAX.into()) as u32; + let end = env.get_field(&change, "end", "J")?.j()?.clamp(0, u32::MAX.into()) as u32; let content = { let jfield = env.get_field(&change, "content", "Ljava/lang/String;")?.l()?;