Skip to content

Commit c8d02fd

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents ce051e7 + 8bc5627 commit c8d02fd

File tree

14 files changed

+202
-3
lines changed

14 files changed

+202
-3
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[versions]
22
download = "5.6.0"
3-
junit = "5.10.3"
3+
junit = "5.11.0"
44
nexus-staging-version = "0.30.0"
55

66
[libraries]

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,4 @@ include 'tree-sitter-ohm'
117117
include 'tree-sitter-p4'
118118
include 'tree-sitter-nginx'
119119
include 'tree-sitter-nim'
120+
include 'tree-sitter-hocon'

tree-sitter-demo/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ dependencies {
1616
testImplementation 'org.junit.jupiter:junit-jupiter'
1717
implementation project(":tree-sitter")
1818
implementation project(":tree-sitter-json")
19-
implementation project(":tree-sitter")
2019
}
2120

2221
test {

tree-sitter-hocon/build.gradle

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
import org.treesitter.build.Utils
2+
3+
plugins {
4+
id 'java'
5+
id 'signing'
6+
id 'maven-publish'
7+
}
8+
9+
group = 'io.github.bonede'
10+
version = libVersion
11+
12+
repositories {
13+
mavenCentral()
14+
}
15+
16+
dependencies {
17+
testImplementation platform(libs.junit.bom)
18+
testImplementation 'org.junit.jupiter:junit-jupiter'
19+
implementation project(":tree-sitter")
20+
}
21+
22+
test {
23+
useJUnitPlatform()
24+
}
25+
26+
def libName = "tree-sitter-hocon"
27+
28+
29+
java {
30+
withJavadocJar()
31+
withSourcesJar()
32+
}
33+
34+
publishing {
35+
repositories {
36+
maven {
37+
name = "MavenCentral"
38+
def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
39+
def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
40+
credentials {
41+
username = ossrhUsername
42+
password = ossrhPassword
43+
}
44+
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
45+
}
46+
}
47+
publications {
48+
maven(MavenPublication) {
49+
from components.java
50+
pom {
51+
name = libName
52+
url = 'https://github.com/bonede/tree-sitter-ng'
53+
description = "Next generation Tree Sitter Java binding"
54+
licenses {
55+
license {
56+
name = 'MIT'
57+
}
58+
}
59+
scm {
60+
connection = 'scm:git:https://github.com/bonede/tree-sitter-ng.git'
61+
developerConnection = 'scm:git:https://github.com/bonede/tree-sitter-ng.git'
62+
url = 'https://github.com/bonede/tree-sitter-ng'
63+
}
64+
developers {
65+
developer {
66+
id = 'bonede'
67+
name = 'Wang Liang'
68+
email = 'bonede@qq.com'
69+
}
70+
}
71+
}
72+
}
73+
}
74+
}
75+
76+
77+
signing {
78+
sign configurations.archives
79+
sign publishing.publications
80+
}
81+
tasks.register('downloadSource') {
82+
group = "build setup"
83+
description = "Download parser source"
84+
def zipUrl = "https://github.com/antosha417/tree-sitter-hocon/archive/refs/heads/master.zip"
85+
def downloadDir = Utils.libDownloadDir(project, libName)
86+
def zip = Utils.libZipFile(project, libName, libVersion)
87+
def parserCFile = Utils.libParserCFile(project, libName, libVersion)
88+
inputs.files(layout.projectDirectory.file("gradle.properties"))
89+
outputs.files(parserCFile)
90+
doLast {
91+
download.run {
92+
src zipUrl
93+
dest zip
94+
overwrite false
95+
}
96+
copy {
97+
from zipTree(zip)
98+
into downloadDir
99+
}
100+
}
101+
102+
}
103+
104+
tasks.register("buildNative") {
105+
group = "build"
106+
description = "Build parser native modules"
107+
dependsOn "downloadSource", rootProject.bootstrap
108+
def jniSrcDir = Utils.jniSrcDir(project)
109+
def outDir = Utils.jniOutDir(project)
110+
def jniCFile = Utils.jniCFile(project, "org_treesitter_TreeSitterHocon.c")
111+
def parserCFile = Utils.libParserCFile(project, libName, libVersion)
112+
def libSrcDir = Utils.libSrcDir(project, libName, libVersion)
113+
def jniInclude = Utils.jniIncludeDir(project)
114+
115+
def targets = Utils.treeSitterTargets(project)
116+
def outputFiles = targets.collect()
117+
{ t -> Utils.jniOutFile(project, t, libName)}
118+
def srcFiles = project.fileTree(libSrcDir) {
119+
include(Utils.libFiles())
120+
}.toList()
121+
outputs.files(outputFiles)
122+
def inputFiles = srcFiles + [parserCFile, rootProject.layout.projectDirectory.file("gradle.properties")]
123+
inputs.files(inputFiles)
124+
doLast{
125+
mkdir(outDir)
126+
targets.each {target ->
127+
def jniMdInclude = Utils.jniMdInclude(project, target)
128+
def jniOutFile = Utils.jniOutFile(project, target, libName)
129+
def files = project.fileTree(libSrcDir) {
130+
include(Utils.libFiles())
131+
}.toList()
132+
def cmd = [
133+
rootProject.downloadZig.zigExe, "c++",
134+
"-g0",
135+
"-shared",
136+
"-target", target,
137+
"-I", libSrcDir,
138+
"-I", jniInclude,
139+
"-I", jniMdInclude,
140+
"-o", jniOutFile,
141+
jniCFile,
142+
]
143+
144+
cmd.addAll(files)
145+
exec{
146+
workingDir jniSrcDir
147+
commandLine(cmd)
148+
}
149+
}
150+
Utils.removeWindowsDebugFiles(project)
151+
}
152+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
libVersion=master-a
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <jni.h>
2+
void *tree_sitter_hocon();
3+
/*
4+
* Class: org_treesitter_TreeSitterHocon
5+
* Method: tree_sitter_hocon
6+
* Signature: ()J
7+
*/
8+
JNIEXPORT jlong JNICALL Java_org_treesitter_TreeSitterHocon_tree_1sitter_1hocon
9+
(JNIEnv *env, jclass clz){
10+
return (jlong) tree_sitter_hocon();
11+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.treesitter;
2+
3+
import org.treesitter.utils.NativeUtils;
4+
5+
public class TreeSitterHocon extends TSLanguage {
6+
7+
static {
8+
NativeUtils.loadLib("lib/tree-sitter-hocon");
9+
}
10+
11+
private native static long tree_sitter_hocon();
12+
13+
public TreeSitterHocon() {
14+
super(tree_sitter_hocon());
15+
}
16+
17+
private TreeSitterHocon(long ptr) {
18+
super(ptr);
19+
}
20+
21+
@Override
22+
public TSLanguage copy() {
23+
return new TreeSitterHocon(copyPtr());
24+
}
25+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)