Removed javac bash commands to compile and run test cases, now we are using the gradle tasks to compile and run test cases

This commit is contained in:
MohitMaliFtechiz 2023-03-31 15:58:59 +05:30 committed by Matthieu Gautier
parent fb380e208a
commit 84235ee822

View File

@ -67,13 +67,6 @@ android {
viewBinding true viewBinding true
} }
ndkVersion '21.4.7075529' ndkVersion '21.4.7075529'
configurations {
testCompileClasspath.extendsFrom(compileClasspath)
testRuntimeClasspath.extendsFrom(testCompileClasspath)
testImplementation.extendsFrom(implementation)
testRuntimeOnly.extendsFrom(runtimeOnly)
}
} }
dependencies { dependencies {
@ -274,21 +267,40 @@ task renameLibkiwixSoFile(type: Copy) {
} }
} }
task compileTestFile(type: Exec) { task testSourceJar(type: Jar) {
workingDir "${projectDir}/src/test/" from android.sourceSets.test.java.srcDirs
commandLine 'javac', '-g', '-d', '.', '-s', '.', '-cp', 'junit-4.13.jar:' + buildDir.path +'/libs/*', 'test.java' archiveName = 'test-sources.jar'
} }
task runTests(type: Exec) { task compileTestFile(type: JavaCompile) {
workingDir "${projectDir}/src/test/" dependsOn testSourceJar
source = fileTree('src/test/')
destinationDirectory = file('src/test/')
classpath = files("src/test/junit-4.13.jar" , "src/test/hamcrest-core-1.4.jar", "build/libs/test-sources.jar")
}
task runTests(type: JavaExec) {
workingDir("$projectDir/src/test/")
dependsOn compileTestFile dependsOn compileTestFile
commandLine 'java', '-Djava.library.path=' + buildDir.path, '-javaagent:jacoco-0.8.7/lib/jacocoagent.jar', '-cp', 'junit-4.13.jar:hamcrest-core-1.3.jar:' + buildDir.path +'/libs/*lib*.jar' + ':.', 'org.junit.runner.JUnitCore', 'test' classpath = files('src/test/', 'src/test/java/', 'src/test/junit-4.13.jar', 'src/test/hamcrest-core-1.3.jar')
main = 'org.junit.runner.JUnitCore'
args = ['test']
jvmArgs = [
'-Djava.library.path=' + buildDir.path,
'-javaagent:jacoco-0.8.7/lib/jacocoagent.jar'
]
} }
task createCodeCoverageReport(type: Exec) { task createCodeCoverageReport(type: JavaExec) {
workingDir "${projectDir}/src/test/" workingDir "${projectDir}/src/test/"
dependsOn runTests dependsOn runTests
commandLine 'java', '-jar', 'jacoco-0.8.7/lib/jacococli.jar', 'report', 'jacoco.exec', '--classfiles', 'org/kiwix/libkiwix/', '--classfiles', 'org/kiwix/libzim/', '--html', '../../build/coverage-report', '--xml', 'coverage.xml' 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/*')
main = 'org.jacoco.cli.internal.Main'
args = [
'report', 'jacoco.exec',
'--classfiles', 'java/org/kiwix/libkiwix/', '--classfiles', 'java/org/kiwix/libzim/',
'--html', '../../build/coverage-report', '--xml', 'coverage.xml'
]
} }
task checkCurrentJavaVersion() { task checkCurrentJavaVersion() {
@ -300,7 +312,7 @@ task checkCurrentJavaVersion() {
task generateHeader(type: Exec) { task generateHeader(type: Exec) {
workingDir "${projectDir}/src/main/java/org/kiwix/" workingDir "${projectDir}/src/main/java/org/kiwix/"
commandLine 'bash', '-c', "javac -h ${buildDir}/include/javah_generated/ -d ${projectDir}/src/test/ ${getLibzimFiles()} ${getLibkiwixFiles()}" commandLine 'bash', '-c', "javac -h ${buildDir}/include/javah_generated/ -d ${projectDir}/src/test/java/ ${getLibzimFiles()} ${getLibkiwixFiles()}"
} }
String getLibkiwixFiles() { String getLibkiwixFiles() {