Skip to content

Commit

Permalink
make actually able to debug coverage, fix constructor adapter coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Jul 31, 2024
1 parent 2e96c65 commit 94aae1e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,45 @@ import org.gradle.api.tasks.*
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.jvm.toolchain.JavaToolchainService

abstract class CoverageRunTask : ConventionTask() {
abstract class CoverageRunTask : JavaExec() {

@get:InputFile
abstract val apiJar: RegularFileProperty

@get:Internal
abstract var classpath: FileCollection

@get:InputFile
abstract val ctSym: RegularFileProperty

@get:Input
abstract val javaVersion: Property<JavaVersion>
@get:Suppress("ACCIDENTAL_OVERRIDE")
var javaVersion: JavaVersion?
get() = super.getJavaVersion()
set(value) {
val toolchains = project.extensions.getByType(JavaToolchainService::class.java)
if (value == null) {
javaLauncher.set(toolchains.launcherFor { })
} else {
javaLauncher.set(toolchains.launcherFor {
it.languageVersion.set(JavaLanguageVersion.of(value.majorVersion))
})
}
}

@get:OutputDirectory
@get:Optional
abstract var coverageReports: FileCollection


init {
group = "jvmdg"
coverageReports = project.files(project.layout.buildDirectory.asFile.get().resolve("coverage"))
mainClass.set("xyz.wagyourtail.jvmdg.coverage.ApiCoverageChecker")
}

@TaskAction
fun run() {
val toolchains = project.extensions.getByType(JavaToolchainService::class.java)

project.javaexec { spec ->
spec.executable = toolchains.launcherFor {
it.languageVersion.set(JavaLanguageVersion.of(javaVersion.get().majorVersion))
}.get().executablePath.asFile.absolutePath

spec.workingDir = project.layout.buildDirectory.asFile.get()
spec.mainClass.set("xyz.wagyourtail.jvmdg.coverage.ApiCoverageChecker")
spec.classpath = classpath
spec.jvmArgs("-Djvmdg.java-api=${apiJar.get().asFile.absolutePath}", "-Djvmdg.quiet=true")
spec.args(ctSym.get().asFile.absolutePath)

}.assertNormalExitValue().rethrowFailure()
override fun exec() {
workingDir = project.layout.buildDirectory.asFile.get()
jvmArgs("-Djvmdg.java-api=${apiJar.get().asFile.absolutePath}", "-Djvmdg.quiet=true")
args(ctSym.get().asFile.absolutePath)

super.exec()
}


Expand Down
15 changes: 3 additions & 12 deletions java-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -132,27 +132,18 @@ tasks.getByName<JavaCompile>("compileCoverageJava") {
configCompile(testVersion)
}

val coverageApiJar by tasks.registering(Jar::class) {
from(sourceSets.main.get().output)
from(*((fromVersion..toVersion).map { sourceSets["java${it.ordinal + 1}"].output }).toTypedArray())
from(rootProject.sourceSets.getByName("shared").output)

destinationDirectory = temporaryDir
}


val genCtSym by tasks.registering(GenerateCtSymTask::class) {
group = "jvmdg"
upperVersion = toVersion - 1
}

val coverageReport by tasks.registering(CoverageRunTask::class) {
group = "jvmdg"
dependsOn(coverageApiJar, genCtSym, tasks.getByName("compileCoverageJava"))
apiJar.set(coverageApiJar.get().archiveFile.get().asFile)
dependsOn(testJar, genCtSym, tasks.getByName("compileCoverageJava"))
apiJar.set(testJar.get().archiveFile.get().asFile)
classpath = coverage.runtimeClasspath
ctSym.set(genCtSym.get().ctSym)
javaVersion.set(testVersion)
javaVersion = testVersion
}

tasks.jar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,23 @@ public static void main(String[] args) throws IOException, URISyntaxException {
try {
Class<?> cls = Class.forName(clsStub.getFirst().getInternalName().replace('/', '.'), true, ClassDowngrader.getCurrentVersionDowngrader().getClassLoader());
// check if has matching method
for (var m : cls.getMethods()) {
if (m.getName().equals(member.getName()) && Type.getType(m).equals(member.getDesc())) {
availableStubCount++;
continue outer;
if (member.getName().equals("<init>")) {
for (var m : cls.getConstructors()) {
if ((m.getModifiers() & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) == 0 || (m.getModifiers() & Opcodes.ACC_SYNTHETIC) != 0)
continue;
if (Type.getType(m).equals(member.getDesc())) {
availableStubCount++;
continue outer;
}
}
} else {
for (var m : cls.getDeclaredMethods()) {
if ((m.getModifiers() & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) == 0 || (m.getModifiers() & Opcodes.ACC_SYNTHETIC) != 0)
continue;
if (m.getName().equals(member.getName()) && Type.getType(m).equals(member.getDesc())) {
availableStubCount++;
continue outer;
}
}
}
} catch (ClassNotFoundException e) {
Expand Down

0 comments on commit 94aae1e

Please sign in to comment.