Skip to content

Commit 8cc3627

Browse files
authored
Merge pull request #30 from kiwix/Issue#29
2 parents 66ebc4e + 932faed commit 8cc3627

17 files changed

Lines changed: 341 additions & 322 deletions

File tree

.github/workflows/pull_request.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99

1010
build_job:
1111
name: Build Pull Request
12-
runs-on: ubuntu-18.04
12+
runs-on: ubuntu-20.04
1313

1414
steps:
1515
- uses: actions/checkout@v1
@@ -26,7 +26,7 @@ jobs:
2626

2727
- name: Compile Project
2828
run: |
29-
./gradlew generateHeaderFilesFromJavaWrapper build
29+
./gradlew buildHeaders build
3030
3131
- name: create unit coverage
3232
run: |

.github/workflows/release.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ jobs:
3030

3131
- name: Compile Project
3232
run: |
33-
./gradlew generateHeaderFilesFromJavaWrapper
34-
./gradlew build
33+
./gradlew buildHeaders build
3534
3635
- name: Release build
3736
run: |
3837
./gradlew assemble
3938
40-
- name: Genrate Source jar
39+
- name: Generate Source jar
4140
run: |
4241
./gradlew androidSourcesJar
4342

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ cd java-libkiwix
2525

2626

2727
```bash
28-
./gradlew generateHeaderFilesFromJavaWrapper
28+
./gradlew buildHeaders
2929
./gradlew build
3030
```
3131

install_deps.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ printf "${Green}Downloading libzim ${NC}\n"
1515
printf "\n${Green}Done! ${NC}\n"
1616

1717
printf "${Green}Coping libzim header and so files ${NC}\n"
18-
./gradlew checkCurrentLibzimDate checkCurrentLinuxLibzimDate copyLibzimHeaderFiles copyLibzimAndroidArm copyLibzimAndroidArm64 copyLibzimAndroidx86 copyLibzimAndroidx86_64 copyLibzimLinux_x86_64 renameLibzimSoFile
18+
./gradlew renameLibzimFolders copyLibzimHeaderAndSoFiles renameLibzimSoFile
1919
printf "\n${Green}Down! ${NC}\n"
2020

2121
printf "${Green}Downloading libkiwix ${NC}\n"
2222
./gradlew downloadLibkiwixSoAndHeaderFiles unzipLibkiwix
2323
printf "\n${Green}Done! ${NC}\n"
2424

2525
printf "${Green}Coping libkiwix header and so files ${NC}\n"
26-
./gradlew checkCurrentLibkiwixDate checkCurrentLinuxLibkiwixDate copyLibkiwixHeaderFiles copyLibkiwixAndroidArm copyLibkiwixAndroidArm64 copyLibkiwixAndroidx86 copyLibkiwixAndroidx86_64 copyLibkiwixLinux_x86_64 renameLibkiwixSoFile
26+
./gradlew renameLibkiwixFolders copyLibkiwixHeaderAndSoFiles renameLibkiwixSoFile
2727
printf "\n${Green}Done! ${NC}\n"

lib/build.gradle

Lines changed: 119 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ android {
6767
viewBinding true
6868
}
6969
ndkVersion '21.4.7075529'
70-
7170
}
7271

7372
dependencies {
@@ -77,11 +76,6 @@ dependencies {
7776

7877
ext.libkiwix_base_url = 'https://download.kiwix.org/nightly'
7978
ext.libzim_base_url = 'https://download.openzim.org/nightly'
80-
// change this date to get latest libzim .so and header files
81-
ext.nightly_date_for_libkiwix = project.properties["nightly_date_for_libkiwix"] ?: ""
82-
ext.nightly_date_for_libkiwix_linux = project.properties["nightly_date_for_libkiwix_linux"] ?: ""
83-
ext.nightly_date_for_libzim = project.properties["nightly_date_for_libzim"] ?: ""
84-
ext.nightly_date_for_libzim_linux = project.properties["nightly_date_for_libzim_linux"] ?: ""
8579

8680
ext.libkiwix_version = project.properties["libkiwix_version"] ?: ""
8781
ext.libzim_version = project.properties["libzim_version"] ?: ""
@@ -98,14 +92,6 @@ task downloadLibzimSoAndHeaderFiles(type: Download) {
9892
overwrite true
9993
}
10094

101-
task checkCurrentLibzimDate() {
102-
project.ext.set("nightly_date_for_libzim", getDateFromPath(buildDir.path, "libzim_android-arm64-"))
103-
}
104-
105-
task checkCurrentLinuxLibzimDate() {
106-
project.ext.set("nightly_date_for_libzim_linux", getDateFromPath(buildDir.path, "libzim_linux-x86_64-"))
107-
}
108-
10995
task unzipLibzim(type: Copy) {
11096
// unzip android arm
11197
from tarTree(buildDir.path + "/libzim_android-arm.tar.gz")
@@ -124,41 +110,47 @@ task unzipLibzim(type: Copy) {
124110
into buildDir
125111
}
126112

127-
task copyLibzimHeaderFiles(type: Copy) {
128-
// copying header file
129-
from buildDir.path + "/libzim_android-arm-" + nightly_date_for_libzim + '/include/'
130-
into buildDir.path + "/include/libzim/"
113+
task renameLibzimFolders() {
114+
renameFolders(buildDir.path,"libzim_")
131115
}
132116

133-
task copyLibzimAndroidArm(type: Copy) {
134-
// copying android_arm so file
135-
from buildDir.path + "/libzim_android-arm-" + nightly_date_for_libzim + '/lib/arm-linux-androideabi/'
136-
into buildDir.path + "/jniLibs/armeabi-v7a/libzim/"
137-
}
117+
task copyLibzimHeaderAndSoFiles(type: Copy) {
118+
copy {
119+
// copying header file
120+
from buildDir.path + "/libzim_android-arm/include/"
121+
into buildDir.path + "/include/libzim/"
122+
}
138123

139-
task copyLibzimAndroidArm64(type: Copy) {
140-
// copying android_arm64 so file
141-
from buildDir.path + "/libzim_android-arm64-" + nightly_date_for_libzim + '/lib/aarch64-linux-android/'
142-
into buildDir.path + "/jniLibs/arm64-v8a/libzim/"
143-
}
124+
copy {
125+
// copying android_arm so file
126+
from buildDir.path + "/libzim_android-arm/lib/arm-linux-androideabi/"
127+
into buildDir.path + "/jniLibs/armeabi-v7a/libzim/"
128+
}
144129

145-
task copyLibzimAndroidx86(type: Copy) {
146-
// copying android_x86 so file
147-
from buildDir.path + "/libzim_android-x86-" + nightly_date_for_libzim + '/lib/i686-linux-android/'
148-
into buildDir.path + "/jniLibs/x86/libzim/"
149-
}
130+
copy {
131+
// copying android_arm64 so file
132+
from buildDir.path + "/libzim_android-arm64/lib/aarch64-linux-android/"
133+
into buildDir.path + "/jniLibs/arm64-v8a/libzim/"
134+
}
150135

151-
task copyLibzimAndroidx86_64(type: Copy) {
152-
// copying android_x86_64 so file
153-
from buildDir.path + "/libzim_android-x86_64-" + nightly_date_for_libzim + '/lib/x86_64-linux-android/'
154-
into buildDir.path + "/jniLibs/x86_64/libzim/"
155-
}
136+
copy {
137+
// copying android_x86 so file
138+
from buildDir.path + "/libzim_android-x86/lib/i686-linux-android/"
139+
into buildDir.path + "/jniLibs/x86/libzim/"
140+
}
141+
142+
copy {
143+
// copying android_x86_64 so file
144+
from buildDir.path + "/libzim_android-x86_64/lib/x86_64-linux-android/"
145+
into buildDir.path + "/jniLibs/x86_64/libzim/"
146+
}
156147

157-
task copyLibzimLinux_x86_64(type: Copy) {
158-
// copying linux_x86_64 so file
159-
project.ext.set("libzim_version", getFileFromFolder(buildDir.path + "/libzim_linux-x86_64-" + nightly_date_for_libzim_linux + "/lib/x86_64-linux-gnu/"))
160-
from buildDir.path + "/libzim_linux-x86_64-" + nightly_date_for_libzim_linux + "/lib/x86_64-linux-gnu/" + libzim_version
161-
into buildDir.path
148+
copy {
149+
// copying linux_x86_64 so file
150+
project.ext.set("libzim_version", getFileFromFolder(buildDir.path + "/libzim_linux-x86_64/lib/x86_64-linux-gnu/"))
151+
from buildDir.path + "/libzim_linux-x86_64/lib/x86_64-linux-gnu/" + libzim_version
152+
into buildDir.path
153+
}
162154
}
163155

164156
task renameLibzimSoFile(type: Copy) {
@@ -182,22 +174,20 @@ task downloadLibkiwixSoAndHeaderFiles(type: Download) {
182174
overwrite true
183175
}
184176

185-
task checkCurrentLibkiwixDate() {
186-
project.ext.set("nightly_date_for_libkiwix", getDateFromPath(buildDir.path, "libkiwix_android-arm64-"))
187-
}
188-
189-
task checkCurrentLinuxLibkiwixDate() {
190-
project.ext.set("nightly_date_for_libkiwix_linux", getDateFromPath(buildDir.path, "libkiwix_linux-x86_64-"))
177+
task renameLibkiwixFolders() {
178+
renameFolders(buildDir.path,"libkiwix_")
191179
}
192180

193-
static String getDateFromPath(String path, String matchesString) {
194-
File folder = new File(path)
195-
if (folder.exists()) {
196-
return folder.listFiles()
197-
.stream()
198-
.filter(f -> f.name.startsWith(matchesString))
199-
.map(s -> s.name.replace(matchesString, ""))
200-
.collect(Collectors.toList())[0]
181+
static void renameFolders(String path, String startWith) {
182+
File directory = new File(path)
183+
if (directory.exists() && directory.isDirectory()) {
184+
Arrays.stream(directory.listFiles())
185+
.filter(folder -> folder.isDirectory() && folder.getName().startsWith(startWith))
186+
.forEach(file -> {
187+
String newName = file.getName().replaceAll("-\\d{4}-\\d{2}-\\d{2}", "")
188+
File newFile = new File(directory, newName)
189+
file.renameTo(newFile)
190+
})
201191
}
202192
}
203193

@@ -219,41 +209,43 @@ task unzipLibkiwix(type: Copy) {
219209
into buildDir
220210
}
221211

222-
task copyLibkiwixHeaderFiles(type: Copy) {
223-
// copying header file
224-
from buildDir.path + "/libkiwix_android-arm-" + nightly_date_for_libkiwix + '/include/kiwix/'
225-
into buildDir.path + "/include/libkiwix/"
226-
}
212+
task copyLibkiwixHeaderAndSoFiles(type: Copy) {
213+
copy {
214+
// copying header file
215+
from buildDir.path + "/libkiwix_android-arm/include/kiwix/"
216+
into buildDir.path + "/include/libkiwix/"
217+
}
227218

228-
task copyLibkiwixAndroidArm(type: Copy) {
229-
// copying android_arm so file
230-
from buildDir.path + "/libkiwix_android-arm-" + nightly_date_for_libkiwix + '/lib/arm-linux-androideabi/'
231-
into buildDir.path + "/jniLibs/armeabi-v7a/libkiwix/"
232-
}
219+
copy {
220+
// copying android_arm so file
221+
from buildDir.path + "/libkiwix_android-arm/lib/arm-linux-androideabi/"
222+
into buildDir.path + "/jniLibs/armeabi-v7a/libkiwix/"
223+
}
233224

234-
task copyLibkiwixAndroidArm64(type: Copy) {
235-
// copying android_arm64 so file
236-
from buildDir.path + "/libkiwix_android-arm64-" + nightly_date_for_libkiwix + '/lib/aarch64-linux-android/'
237-
into buildDir.path + "/jniLibs/arm64-v8a/libkiwix/"
238-
}
225+
copy {
226+
// copying android_arm64 so file
227+
from buildDir.path + "/libkiwix_android-arm64/lib/aarch64-linux-android/"
228+
into buildDir.path + "/jniLibs/arm64-v8a/libkiwix/"
229+
}
239230

240-
task copyLibkiwixAndroidx86(type: Copy) {
241-
// copying android_x86 so file
242-
from buildDir.path + "/libkiwix_android-x86-" + nightly_date_for_libkiwix + '/lib/i686-linux-android/'
243-
into buildDir.path + "/jniLibs/x86/libkiwix/"
244-
}
231+
copy {
232+
// copying android_x86 so file
233+
from buildDir.path + "/libkiwix_android-x86/lib/i686-linux-android/"
234+
into buildDir.path + "/jniLibs/x86/libkiwix/"
235+
}
245236

246-
task copyLibkiwixAndroidx86_64(type: Copy) {
247-
// copying android_x86_64 so file
248-
from buildDir.path + "/libkiwix_android-x86_64-" + nightly_date_for_libkiwix + '/lib/x86_64-linux-android/'
249-
into buildDir.path + "/jniLibs/x86_64/libkiwix/"
250-
}
237+
copy {
238+
// copying android_x86_64 so file
239+
from buildDir.path + "/libkiwix_android-x86_64/lib/x86_64-linux-android/"
240+
into buildDir.path + "/jniLibs/x86_64/libkiwix/"
241+
}
251242

252-
task copyLibkiwixLinux_x86_64(type: Copy) {
253-
// copying linux_x86_64 so file
254-
project.ext.set("libkiwix_version", getFileFromFolder(buildDir.path + "/libkiwix_linux-x86_64-" + nightly_date_for_libkiwix_linux + "/lib/x86_64-linux-gnu/"))
255-
from buildDir.path + "/libkiwix_linux-x86_64-" + nightly_date_for_libkiwix_linux + "/lib/x86_64-linux-gnu/" + libkiwix_version
256-
into buildDir.path
243+
copy {
244+
// copying linux_x86_64 so file
245+
project.ext.set("libkiwix_version", getFileFromFolder(buildDir.path + "/libkiwix_linux-x86_64/lib/x86_64-linux-gnu/"))
246+
from buildDir.path + "/libkiwix_linux-x86_64/lib/x86_64-linux-gnu/" + libkiwix_version
247+
into buildDir.path
248+
}
257249
}
258250

259251
static String getFileFromFolder(String path) {
@@ -275,15 +267,40 @@ task renameLibkiwixSoFile(type: Copy) {
275267
}
276268
}
277269

278-
task copyBuildKiwixSoFile(type: Copy) {
279-
// copying linux_x86_64 so file
280-
from projectDir.path + "/src/test/libbuildkiwix.so"
281-
into buildDir.path
270+
task testSourceJar(type: Jar) {
271+
from android.sourceSets.test.java.srcDirs
272+
archiveName = 'test-sources.jar'
282273
}
283274

284-
task createCodeCoverageReport(type: Exec) {
275+
task compileTestFile(type: JavaCompile) {
276+
dependsOn testSourceJar
277+
source = file('src/test/test.java')
278+
destinationDirectory = file('src/test/')
279+
classpath = files("src/test/junit-4.13.jar" , "src/test/hamcrest-core-1.4.jar", "build/libs/test-sources.jar")
280+
}
281+
282+
task runTests(type: JavaExec) {
283+
workingDir("$projectDir/src/test/")
284+
dependsOn compileTestFile
285+
classpath = files('src/test/', 'src/test/java/', 'src/test/junit-4.13.jar', 'src/test/hamcrest-core-1.3.jar')
286+
main = 'org.junit.runner.JUnitCore'
287+
args = ['test']
288+
jvmArgs = [
289+
'-Djava.library.path=' + buildDir.path,
290+
'-javaagent:jacoco-0.8.7/lib/jacocoagent.jar'
291+
]
292+
}
293+
294+
task createCodeCoverageReport(type: JavaExec) {
285295
workingDir "${projectDir}/src/test/"
286-
commandLine 'sh', '-c', "bash 'compile_and_run_test.sh' ${buildDir}/libs/*lib*.jar $buildDir"
296+
dependsOn runTests
297+
classpath = files('src/test/', 'src/test/java/', 'src/test/junit-4.13.jar', 'src/test/hamcrest-core-1.3.jar', 'src/test/jacoco-0.8.7/lib/*')
298+
main = 'org.jacoco.cli.internal.Main'
299+
args = [
300+
'report', 'jacoco.exec',
301+
'--classfiles', 'java/org/kiwix/libkiwix/', '--classfiles', 'java/org/kiwix/libzim/',
302+
'--html', '../../build/coverage-report', '--xml', 'coverage.xml'
303+
]
287304
}
288305

289306
task checkCurrentJavaVersion() {
@@ -293,9 +310,9 @@ task checkCurrentJavaVersion() {
293310
}
294311

295312

296-
task generateHeaderFilesFromJavaWrapper(type: Exec) {
313+
task buildHeaders(type: Exec) {
297314
workingDir "${projectDir}/src/main/java/org/kiwix/"
298-
commandLine 'bash', '-c', "javac -h ${buildDir}/include/javah_generated/ -d ${projectDir}/src/test/ ${getLibzimFiles()} ${getLibkiwixFiles()}"
315+
commandLine 'bash', '-c', "javac -h ${buildDir}/include/javah_generated/ -d ${projectDir}/src/test/java/ ${getLibzimFiles()} ${getLibkiwixFiles()}"
299316
}
300317

301318
String getLibkiwixFiles() {
@@ -327,3 +344,10 @@ String getLibzimFiles() {
327344
"${projectDir}/src/main/java/org/kiwix/libzim/SuggestionSearch.java " +
328345
"${projectDir}/src/main/java/org/kiwix/libzim/ZimFileFormatException.java"
329346
}
347+
348+
task buildLinuxBinding(type: Exec) {
349+
workingDir "${projectDir}/src/main/cpp/"
350+
commandLine 'bash', '-c', "cmake . -B ${buildDir} && make -C ${buildDir}"
351+
}
352+
353+
build.dependsOn buildLinuxBinding

0 commit comments

Comments
 (0)