[java] Move inner classes to package level
This commit is contained in:
parent
a2c9f1a5d8
commit
a1df68e213
|
@ -80,6 +80,9 @@
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>2.9.1</version>
|
<version>2.9.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${java.version}</source>
|
||||||
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>attach-javadocs</id>
|
<id>attach-javadocs</id>
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package in.wilsonl.minifyhtml;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class representing minification configuration.
|
||||||
|
*/
|
||||||
|
public class Configuration {
|
||||||
|
private final boolean minifyJs;
|
||||||
|
|
||||||
|
public Configuration(boolean minifyJs) {
|
||||||
|
this.minifyJs = minifyJs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder to help create configuration.
|
||||||
|
*/
|
||||||
|
public static class Builder {
|
||||||
|
private boolean minifyJs = false;
|
||||||
|
|
||||||
|
public Builder setMinifyJs(boolean minifyJs) {
|
||||||
|
this.minifyJs = minifyJs;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Configuration build() {
|
||||||
|
return new Configuration(this.minifyJs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -53,7 +53,7 @@ public class MinifyHtml {
|
||||||
* If the code fails to be minified, a {@link SyntaxException} will be thrown with a descriptive English message and position in code where the error occurred.
|
* If the code fails to be minified, a {@link SyntaxException} will be thrown with a descriptive English message and position in code where the error occurred.
|
||||||
*
|
*
|
||||||
* @param code {@link ByteBuffer} containing HTML code to minify
|
* @param code {@link ByteBuffer} containing HTML code to minify
|
||||||
* @param cfg {@link Configuration} minification settings to use
|
* @param cfg {@link Configuration} minification settings to use
|
||||||
* @return length of the written minified code in the {@link ByteBuffer}
|
* @return length of the written minified code in the {@link ByteBuffer}
|
||||||
*/
|
*/
|
||||||
public static native int minifyInPlace(ByteBuffer code, Configuration cfg);
|
public static native int minifyInPlace(ByteBuffer code, Configuration cfg);
|
||||||
|
@ -64,44 +64,8 @@ public class MinifyHtml {
|
||||||
* If the code fails to be minified, a {@link SyntaxException} will be thrown with a descriptive English message and position in code where the error occurred.
|
* If the code fails to be minified, a {@link SyntaxException} will be thrown with a descriptive English message and position in code where the error occurred.
|
||||||
*
|
*
|
||||||
* @param code HTML code to minify
|
* @param code HTML code to minify
|
||||||
* @param cfg {@link Configuration} minification settings to use
|
* @param cfg {@link Configuration} minification settings to use
|
||||||
* @return minified HTML code
|
* @return minified HTML code
|
||||||
*/
|
*/
|
||||||
public static native String minify(String code, Configuration cfg);
|
public static native String minify(String code, Configuration cfg);
|
||||||
|
|
||||||
/**
|
|
||||||
* Basic exception class representing minification errors.
|
|
||||||
*/
|
|
||||||
public static class SyntaxException extends RuntimeException {
|
|
||||||
private SyntaxException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class representing minification configuration.
|
|
||||||
*/
|
|
||||||
public static class Configuration {
|
|
||||||
private final boolean minifyJs;
|
|
||||||
|
|
||||||
public Configuration(boolean minifyJs) {
|
|
||||||
this.minifyJs = minifyJs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builder to help create configuration.
|
|
||||||
*/
|
|
||||||
public static class Builder {
|
|
||||||
private boolean minifyJs = false;
|
|
||||||
|
|
||||||
public Builder setMinifyJs(boolean minifyJs) {
|
|
||||||
this.minifyJs = minifyJs;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Configuration build() {
|
|
||||||
return new Configuration(this.minifyJs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package in.wilsonl.minifyhtml;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic exception class representing minification errors.
|
||||||
|
*/
|
||||||
|
public class SyntaxException extends RuntimeException {
|
||||||
|
private SyntaxException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,8 @@ use jni::objects::{JByteBuffer, JClass, JObject, JString};
|
||||||
use jni::sys::{jint, jstring};
|
use jni::sys::{jint, jstring};
|
||||||
use std::str::from_utf8_unchecked;
|
use std::str::from_utf8_unchecked;
|
||||||
|
|
||||||
|
const SYNTAX_EXCEPTION_CLASS: &str = "in/wilsonl/minifyhtml/SyntaxException";
|
||||||
|
|
||||||
fn build_cfg(
|
fn build_cfg(
|
||||||
env: &JNIEnv,
|
env: &JNIEnv,
|
||||||
obj: &JObject,
|
obj: &JObject,
|
||||||
|
@ -33,7 +35,7 @@ pub extern "system" fn Java_in_wilsonl_minifyhtml_MinifyHtml_minifyInPlace(
|
||||||
Ok(out_len) => out_len,
|
Ok(out_len) => out_len,
|
||||||
Err(Error { error_type, position }) => {
|
Err(Error { error_type, position }) => {
|
||||||
env.throw_new(
|
env.throw_new(
|
||||||
"in/wilsonl/minifyhtml/MinifyHtml$SyntaxException",
|
SYNTAX_EXCEPTION_CLASS,
|
||||||
format!("{} [Character {}]", error_type.message(), position),
|
format!("{} [Character {}]", error_type.message(), position),
|
||||||
).unwrap();
|
).unwrap();
|
||||||
0
|
0
|
||||||
|
@ -56,7 +58,7 @@ pub extern "system" fn Java_in_wilsonl_minifyhtml_MinifyHtml_minify(
|
||||||
Ok(out_len) => env.new_string(unsafe { from_utf8_unchecked(&code[0..out_len]) }).unwrap().into_inner(),
|
Ok(out_len) => env.new_string(unsafe { from_utf8_unchecked(&code[0..out_len]) }).unwrap().into_inner(),
|
||||||
Err(Error { error_type, position }) => {
|
Err(Error { error_type, position }) => {
|
||||||
env.throw_new(
|
env.throw_new(
|
||||||
"in/wilsonl/minifyhtml/MinifyHtml$SyntaxException",
|
SYNTAX_EXCEPTION_CLASS,
|
||||||
format!("{} [Character {}]", error_type.message(), position),
|
format!("{} [Character {}]", error_type.message(), position),
|
||||||
).unwrap();
|
).unwrap();
|
||||||
JObject::null().into_inner()
|
JObject::null().into_inner()
|
||||||
|
|
Loading…
Reference in New Issue