Rename to minify-html

This commit is contained in:
Wilson Lin 2020-07-12 01:29:34 +10:00
commit dc376d7c7f
47 changed files with 182 additions and 191 deletions

View file

@ -1,12 +1,12 @@
[package]
name = "hyperbuild-java"
publish = false
name = "minify-html-java"
version = "0.2.4"
authors = ["Wilson Lin <code@wilsonl.in>"]
edition = "2018"
[dependencies]
hyperbuild = { path = "..", features = ["js-esbuild"] }
minify-html = { path = "..", features = ["js-esbuild"] }
jni = "0.14.0"
[lib]

View file

@ -2,8 +2,7 @@
set -e
# Builds hyperbuild-java with native module for local testing.
# Built JAR will only run current platform.
# Build JAR with native module for current platform.
pushd "$(dirname "$0")"
@ -35,17 +34,9 @@ else
exit 1
fi
if [ -f Cargo.toml.orig ]; then
echo 'Not altering Java Cargo.toml file'
else
cp Cargo.toml Cargo.toml.orig
# Don't use -i as macOS requires '' argument but then Ubuntu will treat as pattern.
sed 's%^hyperbuild = .*$%hyperbuild = { path = ".." }%' Cargo.toml.orig > Cargo.toml
fi
cargo build $rust_build_arg
mv Cargo.toml.orig Cargo.toml
mkdir -p src/main/resources/
cp target/rust/$rust_build_dir/libhyperbuild_java.$ext src/main/resources/$os_name-x86_64.nativelib
cp target/rust/$rust_build_dir/libminify_html_java.$ext src/main/resources/$os_name-x86_64.nativelib
mvn clean package

View file

@ -4,13 +4,13 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>in.wilsonl.hyperbuild</groupId>
<artifactId>hyperbuild</artifactId>
<groupId>in.wilsonl.minify_html</groupId>
<artifactId>minify-html</artifactId>
<version>0.2.4</version>
<name>hyperbuild</name>
<name>minify-html</name>
<description>Fast allocation-less HTML minifier with smart whitespace handling</description>
<url>https://github.com/wilsonzlin/hyperbuild</url>
<url>https://github.com/wilsonzlin/minify-html</url>
<developers>
<developer>
<name>Wilson Lin</name>
@ -28,9 +28,9 @@
</licenses>
<scm>
<url>https://github.com/wilsonzlin/hyperbuild</url>
<connection>scm:git:git@github.com:wilsonzlin/hyperbuild.git</connection>
<developerConnection>scm:git:git@github.com:wilsonzlin/hyperbuild.git</developerConnection>
<url>https://github.com/wilsonzlin/minify-html</url>
<connection>scm:git:git@github.com:wilsonzlin/minify-html.git</connection>
<developerConnection>scm:git:git@github.com:wilsonzlin/minify-html.git</developerConnection>
</scm>
<distributionManagement>

View file

@ -1,4 +1,4 @@
package in.wilsonl.hyperbuild;
package in.wilsonl.minify_html;
import java.io.File;
import java.io.InputStream;
@ -13,7 +13,7 @@ import static java.lang.String.format;
* Methods call to native compiled Rust code using JNI.
* When this class is loaded, a static initialiser will attempt to load a prebuilt native library for the running operating system and architecture from the JAR. If it cannot, a {@link RuntimeException} will be thrown.
*/
public class Hyperbuild {
public class MinifyHtml {
static {
String osName = System.getProperty("os.name").toLowerCase();
String osArch = System.getProperty("os.arch").toLowerCase();
@ -33,8 +33,8 @@ public class Hyperbuild {
String nativeLibFile = format("/%s-%s.nativelib", nativeLibNameOs, nativeLibNameArch);
try (InputStream is = Hyperbuild.class.getResourceAsStream(nativeLibFile)) {
File temp = File.createTempFile("hyperbuild-java-nativelib", nativeLibFile.substring(1));
try (InputStream is = MinifyHtml.class.getResourceAsStream(nativeLibFile)) {
File temp = File.createTempFile("minify-html-java-nativelib", nativeLibFile.substring(1));
temp.deleteOnExit();
Files.copy(is, temp.toPath(), StandardCopyOption.REPLACE_EXISTING);
System.load(temp.getAbsolutePath());
@ -43,7 +43,7 @@ public class Hyperbuild {
}
}
private Hyperbuild() {
private MinifyHtml() {
}
/**

View file

@ -1,4 +1,4 @@
use hyperbuild::{hyperbuild, Cfg};
use minify_html::{in_place as minify_html_native, Cfg};
use jni::JNIEnv;
use jni::objects::{JByteBuffer, JClass, JObject, JString};
use jni::sys::{jint, jstring};
@ -14,7 +14,7 @@ fn build_cfg(
}
#[no_mangle]
pub extern "system" fn Java_in_wilsonl_hyperbuild_Hyperbuild_minifyInPlace(
pub extern "system" fn Java_in_wilsonl_minify_1html_MinifyHtml_minifyInPlace(
env: JNIEnv,
_class: JClass,
input: JByteBuffer,
@ -29,11 +29,11 @@ pub extern "system" fn Java_in_wilsonl_hyperbuild_Hyperbuild_minifyInPlace(
}
};
(match hyperbuild(source, &build_cfg(&env, &cfg)) {
(match minify_html_native(source, &build_cfg(&env, &cfg)) {
Ok(out_len) => out_len,
Err((err, pos)) => {
env.throw_new(
"in/wilsonl/hyperbuild/HyperbuildException",
"in/wilsonl/minify_html/MinifyHtml$SyntaxException",
format!("{} [Character {}]", err.message(), pos),
).unwrap();
0
@ -42,7 +42,7 @@ pub extern "system" fn Java_in_wilsonl_hyperbuild_Hyperbuild_minifyInPlace(
}
#[no_mangle]
pub extern "system" fn Java_in_wilsonl_hyperbuild_Hyperbuild_minify(
pub extern "system" fn Java_in_wilsonl_minify_1html_MinifyHtml_minify(
env: JNIEnv,
_class: JClass,
input: JString,
@ -52,11 +52,11 @@ pub extern "system" fn Java_in_wilsonl_hyperbuild_Hyperbuild_minify(
let source: String = env.get_string(input).unwrap().into();
let mut code = source.into_bytes();
match hyperbuild(&mut code, &build_cfg(&env, &cfg)) {
match minify_html_native(&mut code, &build_cfg(&env, &cfg)) {
Ok(out_len) => env.new_string(unsafe { from_utf8_unchecked(&code[0..out_len]) }).unwrap().into_inner(),
Err((err, pos)) => {
env.throw_new(
"in/wilsonl/hyperbuild/Hyperbuild$SyntaxException",
"in/wilsonl/minify_html/MinifyHtml$SyntaxException",
format!("{} [Character {}]", err.message(), pos),
).unwrap();
JObject::null().into_inner()