Skip to content

Commit 1d94da9

Browse files
Quickjs (#5)
* init optimization * add json element support * add JSParamters and JSResult * segregate conversions * reorg files * remove js executor * safe v8 + unit tests fix * update export method to be more readable * update settings.gradle * Squashed 'quickjs/quickjs/' content from commit 3bb2ca3 git-subtree-dir: quickjs/quickjs git-subtree-split: 3bb2ca360e994c93e9bf273a685c061d5e0b58f4 * init setup of jni * draft conversion and memory management * draft array, object, and function * finalize Conversions.kt and JSContext.kt * draft engine * draft jni * bug fix * use delegation on jsobject and jsarray * add support for json element * json array bug fix * add test for json array * bug fix * make JSConvertible also Releasable * memory manager optimization * add delegation for JSNull and JSUndefined * implement JSFunction * remove unnecessary code * export function * implement extend * add console * fix crash when atom hash returns 0 * clean up * draft exporting class * bug fix * bug fix * bug fix for JSClass function with parameters * implement exporting property, replace java reflection with kotlin reflection * bug fix * bug fix for prototype instance method * clean up JSFunctionBody * memory leak fix * revert changes made to quickjs.c * add launch * clean up * make exception handler easier to use * add completion closure to loadBundle * fix jsCallback always return undefine instead of null for actual null value * update env * clean up * Downgrade Gradle to get ./gradlew publishToSonatype to work * Bump version of io.github.gradle-nexus.publish-plugin to 2.0.0 * Adding github workflows for build, release, and snapshot. * Uncommit the MainActivity. * Remove unused old imports. --------- Co-authored-by: Wenxi Zeng <[email protected]> Co-authored-by: Wenxi Zeng <[email protected]>
1 parent 24c9330 commit 1d94da9

File tree

106 files changed

+103832
-1469
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+103832
-1469
lines changed

.github/workflows/build.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
12+
cancel_previous:
13+
permissions: write-all
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: styfle/[email protected]
17+
with:
18+
workflow_id: ${{ github.event.workflow.id }}
19+
20+
build:
21+
22+
needs: cancel_previous
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- uses: actions/checkout@v2
27+
- name: Grant execute permission for gradlew
28+
run: chmod +x gradlew
29+
- name: cache gradle dependencies
30+
uses: actions/cache@v2
31+
with:
32+
path: |
33+
~/.gradle/caches
34+
~/.gradle/wrapper
35+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
36+
restore-keys: |
37+
${{ runner.os }}-gradle-
38+
- name: Run Tests
39+
run: ./gradlew check

.github/workflows/release.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- '*.*.*'
7+
8+
jobs:
9+
release:
10+
permissions: write-all
11+
runs-on: ubuntu-latest
12+
environment: deployment
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Get tag
16+
id: vars
17+
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
18+
- name: Verify tag
19+
run: |
20+
VERSION=$(grep VERSION_NAME gradle.properties | awk -F= '{ print $2 }' | sed "s/-SNAPSHOT//")
21+
if [ "${{ steps.vars.outputs.tag }}" != "$VERSION" ]; then {
22+
echo "Tag ${{ steps.vars.outputs.tag }} does not match the package version ($VERSION)"
23+
exit 1
24+
} fi
25+
26+
- name: Grant execute permission for gradlew
27+
run: chmod +x gradlew
28+
- name: cache gradle dependencies
29+
uses: actions/cache@v2
30+
with:
31+
path: |
32+
~/.gradle/caches
33+
~/.gradle/wrapper
34+
key: ${{ runner.os }}-gradle-core-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
35+
restore-keys: |
36+
${{ runner.os }}-gradle-core-
37+
- name: Publush release to sonatype
38+
run: ./gradlew publishToSonatype -Prelease closeAndReleaseSonatypeStagingRepository
39+
env:
40+
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
41+
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
42+
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.NEXUS_USERNAME }}
43+
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.NEXUS_PASSWORD }}
44+
SIGNING_PRIVATE_KEY_BASE64: ${{ secrets.SIGNING_PRIVATE_KEY_BASE64 }}
45+
46+
- name: create release
47+
run: |
48+
curl \
49+
-X POST \
50+
-H "Authorization: token $GITHUB_TOKEN" \
51+
https://api.github.com/repos/${{github.repository}}/releases \
52+
-d '{"tag_name": "${{ env.RELEASE_VERSION }}", "name": "${{ env.RELEASE_VERSION }}", "body": "Release of version ${{ env.RELEASE_VERSION }}", "draft": false, "prerelease": false, "generate_release_notes": true}'
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}

.github/workflows/snapshot.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Snapshot
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
jobs:
8+
snapshot:
9+
runs-on: ubuntu-latest
10+
environment: deployment
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Grant execute permission for gradlew
14+
run: chmod +x gradlew
15+
- name: cache gradle dependencies
16+
uses: actions/cache@v2
17+
with:
18+
path: |
19+
~/.gradle/caches
20+
~/.gradle/wrapper
21+
key: ${{ runner.os }}-gradle-core-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
22+
restore-keys: |
23+
${{ runner.os }}-gradle-core-
24+
- name: Publush snapshot to sonatype
25+
run: ./gradlew publishToSonatype
26+
env:
27+
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
28+
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
29+
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.NEXUS_USERNAME }}
30+
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.NEXUS_PASSWORD }}
31+
SIGNING_PRIVATE_KEY_BASE64: ${{ secrets.SIGNING_PRIVATE_KEY_BASE64 }}

app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ plugins {
44
}
55

66
android {
7-
compileSdk 31
7+
compileSdk 34
88

99
defaultConfig {
1010
applicationId "com.segment.analytics.substrata.kotlin.sample"
1111
minSdk 21
12-
targetSdk 31
12+
targetSdk 34
1313
versionCode 1
1414
versionName "1.0"
1515

@@ -29,12 +29,12 @@ android {
2929
kotlinOptions {
3030
jvmTarget = '1.8'
3131
}
32+
namespace 'com.segment.analytics.substrata.kotlin.sample'
3233
}
3334

3435
dependencies {
3536
// api 'com.segment.analytics.kotlin:substrata-kotlin:0.0.2'
3637
api project(':substrata-kotlin')
37-
implementation 'com.eclipsesource.j2v8:j2v8:6.2.0@aar'
3838
implementation 'androidx.core:core-ktx:1.7.0'
3939
implementation 'androidx.appcompat:appcompat:1.4.1'
4040
implementation 'com.google.android.material:material:1.5.0'

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.segment.analytics.substrata.kotlin.sample">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
43

54
<!-- Required for internet. -->
65
<uses-permission android:name="android.permission.INTERNET" />

app/src/main/java/com/segment/analytics/substrata/kotlin/sample/MainActivity.kt

Lines changed: 73 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -3,101 +3,88 @@ package com.segment.analytics.substrata.kotlin.sample
33
import android.os.Bundle
44
import android.util.Log
55
import androidx.appcompat.app.AppCompatActivity
6-
import com.segment.analytics.substrata.kotlin.JSValue
7-
import com.segment.analytics.substrata.kotlin.j2v8.J2V8Engine
86

97
class MainActivity : AppCompatActivity() {
108

119
override fun onCreate(savedInstanceState: Bundle?) {
1210
Log.d("PRAY", "Starting")
1311
super.onCreate(savedInstanceState)
1412
setContentView(R.layout.activity_main)
15-
val engine = J2V8Engine()
16-
Log.d("PRAY", "Created engine")
17-
engine["foo"] = JSValue.JSString("")
18-
val script1 = applicationContext.assets.open("sample.js")
19-
val script2 = applicationContext.assets.open("sample2.js").bufferedReader().readText()
20-
engine.bridge["foo"] = JSValue.JSString("bar")
21-
engine.loadBundle(script1) { }
22-
val res = engine.execute(
23-
"""
24-
function barFoo() {
25-
return "Foo";
26-
}
27-
const foo = {x: "Test"};
28-
const bar = [10, 2, "foo", true];
29-
console.log("123");
30-
console.log(1);
31-
console.log(2.9);
32-
console.log(true);
33-
console.log(foo);
34-
console.log(bar);
35-
console.log(DataBridge["foo"]);
36-
foo.y = 2.8;
37-
foo
38-
39-
""".trimIndent()
40-
)
41-
42-
Log.d("PRAY", res.toString())
43-
val res2 = engine.call("fooBar")
44-
Log.d("PRAY", res2.toString())
45-
val res3 = engine.call("barFoo")
46-
Log.d("PRAY", res3.toString())
47-
engine.execute(script2)
48-
// engine.exec(
13+
// val engine = J2V8Engine()
14+
// Log.d("PRAY", "Created engine")
15+
// engine["foo"] = JSValue.JSString("")
16+
// val script1 = applicationContext.assets.open("sample.js")
17+
// val script2 = applicationContext.assets.open("sample2.js").bufferedReader().readText()
18+
// engine.bridge["foo"] = JSValue.JSString("bar")
19+
// engine.loadBundle(script1) { }
20+
// val res = engine.execute(
4921
// """
50-
// pray
51-
// """.trimIndent() // ReferenceError
52-
// )
53-
// engine.exec(
54-
// """
55-
// pray()
56-
// """.trimIndent() // ReferenceError
57-
// )
58-
// engine.exec(
59-
// """
60-
// throw "pray-error"
61-
// """.trimIndent() // String "pray-error"
62-
// )
63-
// engine.exec(
64-
// """
65-
// throw 'Parameter is not a number!';
66-
// """.trimIndent() // String "pray-error"
67-
// )
68-
// engine.exec(
69-
// """
70-
// function
71-
// """.trimIndent() // SyntaxError
72-
// )
73-
// engine.exec(
74-
// """
75-
// var x = ""
76-
// var x = 2
22+
// function barFoo() {
23+
// return "Foo";
24+
// }
25+
// const foo = {x: "Test"};
26+
// const bar = [10, 2, "foo", true];
27+
// console.log("123");
28+
// console.log(1);
29+
// console.log(2.9);
30+
// console.log(true);
31+
// console.log(foo);
32+
// console.log(bar);
33+
// console.log(DataBridge["foo"]);
34+
// foo.y = 2.8;
35+
// foo
36+
//
7737
// """.trimIndent()
7838
// )
79-
// engine.exec(
80-
// """
81-
// const y = ""
82-
// const y = 2
83-
// """.trimIndent() // SyntaxError
84-
// )
85-
// try {
86-
// engine.call("playa")
87-
// } catch (ex: Exception) {
88-
// ex.printStackTrace()
89-
// Log.d("PRAY", ex.toString())
90-
// }
91-
92-
}
93-
94-
fun J2V8Engine.exec(script: String) {
95-
Log.d("PRAY-errorHandler", "Execing $script")
96-
try {
97-
execute(script)
98-
} catch (ex: Exception) {
99-
ex.printStackTrace()
100-
}
101-
Log.d("PRAY-errorHandler", "DONE Execing $script")
39+
//
40+
// Log.d("PRAY", res.toString())
41+
// val res2 = engine.call("fooBar")
42+
// Log.d("PRAY", res2.toString())
43+
// val res3 = engine.call("barFoo")
44+
// Log.d("PRAY", res3.toString())
45+
// engine.execute(script2)
46+
//// engine.exec(
47+
//// """
48+
//// pray
49+
//// """.trimIndent() // ReferenceError
50+
//// )
51+
//// engine.exec(
52+
//// """
53+
//// pray()
54+
//// """.trimIndent() // ReferenceError
55+
//// )
56+
//// engine.exec(
57+
//// """
58+
//// throw "pray-error"
59+
//// """.trimIndent() // String "pray-error"
60+
//// )
61+
//// engine.exec(
62+
//// """
63+
//// throw 'Parameter is not a number!';
64+
//// """.trimIndent() // String "pray-error"
65+
//// )
66+
//// engine.exec(
67+
//// """
68+
//// function
69+
//// """.trimIndent() // SyntaxError
70+
//// )
71+
//// engine.exec(
72+
//// """
73+
//// var x = ""
74+
//// var x = 2
75+
//// """.trimIndent()
76+
//// )
77+
//// engine.exec(
78+
//// """
79+
//// const y = ""
80+
//// const y = 2
81+
//// """.trimIndent() // SyntaxError
82+
//// )
83+
//// try {
84+
//// engine.call("playa")
85+
//// } catch (ex: Exception) {
86+
//// ex.printStackTrace()
87+
//// Log.d("PRAY", ex.toString())
88+
//// }
10289
}
10390
}

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ buildscript {
1111
}
1212

1313
plugins {
14-
id 'com.android.application' version '7.1.2' apply false
15-
id 'com.android.library' version '7.1.2' apply false
16-
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
17-
id 'io.github.gradle-nexus.publish-plugin' version "1.1.0"
14+
id 'com.android.application' version '7.4.2' apply false
15+
id 'com.android.library' version '7.4.2' apply false
16+
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
17+
id 'io.github.gradle-nexus.publish-plugin' version "2.0.0"
1818
}
1919

2020
task clean(type: Delete) {

gradle.properties

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ android.nonTransitiveRClass=true
2424

2525
GROUP=com.segment.analytics.kotlin
2626

27-
VERSION_CODE=006
28-
VERSION_NAME=0.0.6
27+
VERSION_CODE=008
28+
VERSION_NAME=0.0.8
2929

3030
POM_NAME=Substrata
3131
POM_DESCRIPTION=The hassle-free way to add analytics to your Kotlin app.
@@ -43,4 +43,6 @@ POM_LICENCE_URL=http://opensource.org/licenses/MIT
4343
POM_LICENCE_DIST=repo
4444

4545
POM_DEVELOPER_ID=segmentio
46-
POM_DEVELOPER_NAME=Segment, Inc.
46+
POM_DEVELOPER_NAME=Segment, Inc.
47+
android.defaults.buildfeatures.buildconfig=true
48+
android.nonFinalResIds=false
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed Apr 06 14:54:34 PDT 2022
1+
#Thu Apr 11 17:16:54 EDT 2024
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
43
distributionPath=wrapper/dists
5-
zipStorePath=wrapper/dists
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip
65
zipStoreBase=GRADLE_USER_HOME
6+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)