quickjs-kt
This commit is contained in:
parent
148bca1c7d
commit
2bf43c3602
|
|
@ -36,15 +36,16 @@ android {
|
|||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
sourceCompatibility JavaVersion.VERSION_11
|
||||
targetCompatibility JavaVersion.VERSION_11
|
||||
}
|
||||
testOptions {
|
||||
unitTests.returnDefaultValues = true
|
||||
unitTests.includeAndroidResources = true
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
jvmTarget = "11"
|
||||
|
||||
}
|
||||
|
||||
configurations.configureEach {
|
||||
|
|
@ -65,12 +66,14 @@ dependencies {
|
|||
implementation 'com.orhanobut:logger:2.2.0'
|
||||
implementation 'org.jsoup:jsoup:1.15.3'
|
||||
implementation 'androidx.core:core-ktx:1.10.1'
|
||||
testImplementation "io.github.dokar3:quickjs-kt-jvm:1.0.0-alpha13"
|
||||
|
||||
// Required -- JUnit 4 framework
|
||||
testImplementation 'junit:junit:4.12'
|
||||
// Optional -- Mockito framework(可选,用于模拟一些依赖对象,以达到隔离依赖的效果)
|
||||
testImplementation 'org.mockito:mockito-core:5.12.0'
|
||||
testImplementation "org.robolectric:robolectric:4.13"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1"
|
||||
//implementation 'wang.harlon.quickjs:wrapper-java:1.0.0'
|
||||
// implementation(ext: 'aar', name: 'quickjs', group: 'fongmi', version: 'release')
|
||||
// api 'wang.harlon.quickjs:wrapper-android:2.0.0'
|
||||
|
|
|
|||
|
|
@ -1,42 +1,63 @@
|
|||
import android.app.Application;
|
||||
import android.app.Application
|
||||
import com.dokar.quickjs.QuickJs
|
||||
import com.dokar.quickjs.binding.function
|
||||
import com.dokar.quickjs.quickJs
|
||||
import com.github.catvod.net.OkHttp
|
||||
import com.github.catvod.spider.ChangZhang
|
||||
import com.github.catvod.spider.Init
|
||||
import com.github.catvod.utils.FileUtil
|
||||
import com.github.catvod.utils.Util
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import java.io.FileWriter
|
||||
import kotlin.io.encoding.Base64
|
||||
|
||||
import com.github.catvod.net.OkHttp;
|
||||
import com.github.catvod.spider.ChangZhang;
|
||||
import com.github.catvod.spider.Init;
|
||||
import com.github.catvod.utils.Util;
|
||||
import com.whl.quickjs.android.QuickJSLoader;
|
||||
import com.whl.quickjs.wrapper.QuickJSContext;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class CompileJSTest {
|
||||
class CompileJSTest {
|
||||
// @Mock
|
||||
private Application mockContext;
|
||||
|
||||
private ChangZhang spider;
|
||||
QuickJSContext context;
|
||||
|
||||
@org.junit.Before
|
||||
public void setUp() throws Exception {
|
||||
QuickJSLoader.init();
|
||||
mockContext = RuntimeEnvironment.application;
|
||||
Init.init(mockContext);
|
||||
context = QuickJSContext.create();
|
||||
|
||||
@Before
|
||||
@Throws(Exception::class)
|
||||
fun setUp() {
|
||||
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void homeContent() throws Exception {
|
||||
String content = OkHttp.string("https://androidcatvodspider.pages.dev/json/js/newvision.js");
|
||||
byte[] bytes = context.compileModule(content, "newvision.js");
|
||||
String result = "//bb" + Util.base64Encode(bytes);
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun homeContent(): Unit {
|
||||
|
||||
//Assert.assertFalse(map.getAsJsonArray("list").isEmpty());
|
||||
val content =
|
||||
OkHttp.string("https://androidcatvodspider.pages.dev/json/js/jpyy2.js")/* val bytes = context!!.compileModule(content, "newvision.js")
|
||||
val result = "//bb" + Util.base64Encode(bytes)*/
|
||||
|
||||
val scope = CoroutineScope(Dispatchers.Default)
|
||||
|
||||
fun startTask() = runBlocking {
|
||||
launch {
|
||||
quickJs {
|
||||
|
||||
val bytecode = compile(
|
||||
code = content,
|
||||
filename = "jpyy",
|
||||
asModule = true,
|
||||
)
|
||||
val str = org.bouncycastle.util.encoders.Base64.encode(bytecode);
|
||||
FileWriter("jpyy.j").write("//bb" +String(str))
|
||||
System.out.println("//bb" +String(str))
|
||||
//assertEquals("Hi from the hello module!", result)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
startTask()
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
pluginManagement {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url 'https://maven.aliyun.com/repository/public/' }
|
||||
maven { url 'https://maven.aliyun.com/repository/google/' }
|
||||
maven { url 'https://maven.aliyun.com/repository/gradle-plugin/' }
|
||||
|
|
@ -8,7 +9,7 @@ pluginManagement {
|
|||
maven { url 'https://maven.aliyun.com/repository/mapr-public/' }
|
||||
gradlePluginPortal()
|
||||
google()
|
||||
mavenCentral()
|
||||
|
||||
maven { url "https://plugins.gradle.org/m2/" }
|
||||
maven { url "https://www.jitpack.io" }
|
||||
}
|
||||
|
|
@ -16,6 +17,7 @@ pluginManagement {
|
|||
dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url 'https://maven.aliyun.com/repository/public/' }
|
||||
maven { url 'https://maven.aliyun.com/repository/google/' }
|
||||
maven { url 'https://maven.aliyun.com/repository/gradle-plugin/' }
|
||||
|
|
@ -23,7 +25,6 @@ dependencyResolutionManagement {
|
|||
maven { url 'https://maven.aliyun.com/repository/central/'}
|
||||
maven { url 'https://maven.aliyun.com/repository/mapr-public/' }
|
||||
google()
|
||||
mavenCentral()
|
||||
maven { url "https://www.jitpack.io" }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue