Browse Source

Merge pull request #7570 in CORE/base-third from final/11.0 to release/11.0

* commit '7a1a6ea34c669916b5ad6609bcd60d98d419fd86':
  REPORT-85397 patch 图表对库的适配
release/11.0
superman 2 years ago
parent
commit
ada4ff40c2
  1. 53
      fine-j2v8/src/main/java/com/eclipsesource/v8/LibraryLoader.java
  2. 9
      fine-j2v8/src/main/java/com/eclipsesource/v8/PlatformDetector.java
  3. 1
      fine-j2v8/src/main/java/com/eclipsesource/v8/V8.java
  4. 17
      fine-j2v8/src/main/java/com/eclipsesource/v8/V8OutOfMemoryError.java

53
fine-j2v8/src/main/java/com/eclipsesource/v8/LibraryLoader.java

@ -15,6 +15,7 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.management.ManagementFactory;
public class LibraryLoader { public class LibraryLoader {
@ -23,6 +24,8 @@ public class LibraryLoader {
static final String SWT_LIB_DIR = ".j2v8"; static final String SWT_LIB_DIR = ".j2v8";
static final String MINIMUM_VERSION = "6.2";
static { static {
DELIMITER = System.getProperty("line.separator"); //$NON-NLS-1$ DELIMITER = System.getProperty("line.separator"); //$NON-NLS-1$
SEPARATOR = System.getProperty("file.separator"); //$NON-NLS-1$ SEPARATOR = System.getProperty("file.separator"); //$NON-NLS-1$
@ -30,6 +33,7 @@ public class LibraryLoader {
/** /**
* Returns the base-name for the native J2V8 library file. * Returns the base-name for the native J2V8 library file.
*
* @param withLinuxVendor include/exclude the {vendor} part from the returned filename * @param withLinuxVendor include/exclude the {vendor} part from the returned filename
* <p>NOTE: Vendors are only included for linux systems</p> * <p>NOTE: Vendors are only included for linux systems</p>
* @return The filename string has the following structure: * @return The filename string has the following structure:
@ -141,6 +145,7 @@ public class LibraryLoader {
FileOutputStream os = null; FileOutputStream os = null;
InputStream is = null; InputStream is = null;
File file = new File(fileName); File file = new File(fileName);
String absoluteName = file.getAbsolutePath();
boolean extracted = false; boolean extracted = false;
try { try {
if (file.exists()) { if (file.exists()) {
@ -158,7 +163,7 @@ public class LibraryLoader {
os.close(); os.close();
is.close(); is.close();
chmod("755", fileName); chmod("755", fileName);
if (load(fileName, message)) { if (load(absoluteName, message)) {
return true; return true;
} }
} }
@ -187,8 +192,52 @@ public class LibraryLoader {
return; return;
} }
try { try {
Runtime.getRuntime().exec(new String[] { "chmod", permision, path }).waitFor(); //$NON-NLS-1$ Runtime.getRuntime().exec(new String[]{"chmod", permision, path}).waitFor(); //$NON-NLS-1$
} catch (Throwable e) { } catch (Throwable e) {
} }
} }
//内核版本windows NT6.2以下存在加载dll之后无法正常退出的问题,注册钩子函数退出时杀掉进程
static void checkExceptionVersion() {
String version = System.getProperty("os.version");
if (PlatformDetector.OS.isWindows() && belowMinimumVersion(version)) {
registerExit();
}
}
//低于指定版本,6.2以下
private static boolean belowMinimumVersion(String version) {
return compareVersion(version, MINIMUM_VERSION) < 0;
}
private static int compareVersion(String version1, String version2) {
String[] versionArray1 = version1.split("\\.");//注意此处为正则匹配,不能用".";
String[] versionArray2 = version2.split("\\.");
int idx = 0;
int minLength = Math.min(versionArray1.length, versionArray2.length);//取最小长度值
int diff = 0;
while (idx < minLength
&& (diff = versionArray1[idx].length() - versionArray2[idx].length()) == 0//先比较长度
&& (diff = versionArray1[idx].compareTo(versionArray2[idx])) == 0) {//再比较字符
++idx;
}
//如果已经分出大小,则直接返回,如果未分出大小,则再比较位数,有子版本的为大;
diff = (diff != 0) ? diff : versionArray1.length - versionArray2.length;
return diff;
}
//低于指定版本,6.2以下
private static void registerExit() {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
String name = ManagementFactory.getRuntimeMXBean().getName();
String pid = name.split("@")[0];
try {
Runtime.getRuntime().exec("taskkill /F /PID " + pid);
} catch (Exception ignore) {
}
}
});
}
} }

9
fine-j2v8/src/main/java/com/eclipsesource/v8/PlatformDetector.java

@ -124,8 +124,9 @@ public class PlatformDetector {
if (OS.isAndroid()) { if (OS.isAndroid()) {
return "google"; return "google";
} }
//如果if条件全部不符合,就会陷入死循环,代码存在风险
throw new UnsatisfiedLinkError("Unsupported vendor: " + getName()); //throw new UnsatisfiedLinkError("Unsupported vendor: " + getName());
return null;
} }
private static String getLinuxOsReleaseId() { private static String getLinuxOsReleaseId() {
@ -144,7 +145,9 @@ public class PlatformDetector {
return parseLinuxRedhatReleaseFile(file); return parseLinuxRedhatReleaseFile(file);
} }
throw new UnsatisfiedLinkError("Unsupported linux vendor: " + getName()); //linux系统下如果缺失/etc/os-release,/usr/lib/os-release,/etc/redhat-release三个文件,就会和getName方法就会一直互相调用
//throw new UnsatisfiedLinkError("Unsupported linux vendor: " + getName());
return null;
} }
private static String parseLinuxOsReleaseFile(final File file) { private static String parseLinuxOsReleaseFile(final File file) {

1
fine-j2v8/src/main/java/com/eclipsesource/v8/V8.java

@ -75,6 +75,7 @@ public class V8 extends V8Object {
try { try {
LibraryLoader.loadLibrary(tmpDirectory); LibraryLoader.loadLibrary(tmpDirectory);
nativeLibraryLoaded = true; nativeLibraryLoaded = true;
LibraryLoader.checkExceptionVersion();
} catch (Error e) { } catch (Error e) {
nativeLoadError = e; nativeLoadError = e;
} catch (Exception e) { } catch (Exception e) {

17
fine-j2v8/src/main/java/com/eclipsesource/v8/V8OutOfMemoryError.java

@ -0,0 +1,17 @@
package com.eclipsesource.v8;
/**
* @author Bjorn
* @version 10.0
* Created by Bjorn on 2020-11-26
*/
public class V8OutOfMemoryError extends V8RuntimeException {
V8OutOfMemoryError(final String message) {
super(message);
}
V8OutOfMemoryError() {
super();
}
}
Loading…
Cancel
Save