Skip to content

Commit

Permalink
api-validation: Fix applying to subprojects that are not MC projects
Browse files Browse the repository at this point in the history
GitHub: #15
  • Loading branch information
DJtheRedstoner authored May 10, 2024
1 parent 3188a2d commit 673a886
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gg.essential.gradle.multiversion.apivalidation

import gg.essential.gradle.util.multiversionChildProjects
import org.gradle.api.DefaultTask
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
Expand All @@ -20,7 +21,7 @@ abstract class ExtractApiFile : DefaultTask() {

@TaskAction
fun merge() {
val parser = Parser(project.parent!!.childProjects.keys)
val parser = Parser(project.parent!!.multiversionChildProjects.keys)
val input = parser.parseFile(input.get().asFile.readText())
val outputStr = Writer(emptySet()).write(input.filtered(selector.get()))
this.output.get().asFile.writeText(outputStr)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gg.essential.gradle.multiversion.apivalidation

import gg.essential.gradle.util.multiversionChildProjects
import org.gradle.api.DefaultTask
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.RegularFileProperty
Expand All @@ -26,7 +27,7 @@ abstract class MergeApiFiles : DefaultTask() {
input.value.mergeInto(output, input.key)
}

val outputStr = Writer(project.childProjects.keys).write(output)
val outputStr = Writer(project.multiversionChildProjects.keys).write(output)
this.output.get().asFile.writeText(outputStr)
}
}
9 changes: 8 additions & 1 deletion src/main/kotlin/gg/essential/gradle/util/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gg.essential.gradle.util
import kotlinx.metadata.jvm.JvmMetadataVersion
import org.gradle.api.GradleException
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import java.util.Calendar
import java.util.GregorianCalendar

Expand All @@ -29,4 +30,10 @@ internal fun compatibleKotlinMetadataVersion(version: IntArray): JvmMetadataVers

// A safe, constant value for creating consistent zip entries
// From: https://github.com/gradle/gradle/blob/d6c7fd470449a59fc57a26b4ebc0ad83c64af50a/subprojects/core/src/main/java/org/gradle/api/internal/file/archive/ZipCopyAction.java#L42-L57
val CONSTANT_TIME_FOR_ZIP_ENTRIES = GregorianCalendar(1980, Calendar.FEBRUARY, 1, 0, 0, 0).timeInMillis
val CONSTANT_TIME_FOR_ZIP_ENTRIES = GregorianCalendar(1980, Calendar.FEBRUARY, 1, 0, 0, 0).timeInMillis

val Project.isMultiversionChildProject
get() = plugins.hasPlugin("gg.essential.multi-version")

val Project.multiversionChildProjects
get() = childProjects.filter { it.value.isMultiversionChildProject }
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package gg.essential

import gg.essential.gradle.multiversion.apivalidation.ExtractApiFile
import gg.essential.gradle.multiversion.apivalidation.MergeApiFiles
import gg.essential.gradle.util.isMultiversionChildProject
import gg.essential.gradle.util.multiversionChildProjects
import org.gradle.api.tasks.Sync

plugins {
Expand All @@ -13,24 +15,26 @@ val mergedApiFile = file("api/$name.api")
val apiDump by tasks.registering(MergeApiFiles::class) {
output.set(mergedApiFile)
evaluationDependsOnChildren()
inputs.from(subprojects.map { project ->
inputs.from(multiversionChildProjects.map { (_, project) ->
project.tasks.named("apiDump").map { project.file("api/${project.name}.api") }
})
}

subprojects {
val projectApiDir = project.file("api").also { it.mkdirs() }
val extractApiDefinition by tasks.registering(ExtractApiFile::class) {
selector.set(project.name)
input.set(mergedApiFile)
output.set(projectApiDir.resolve("${project.name}.api"))
}
afterEvaluate {
tasks.named("apiCheck") {
dependsOn(extractApiDefinition)
pluginManager.withPlugin("gg.essential.multi-version") {
val projectApiDir = project.file("api").also { it.mkdirs() }
val extractApiDefinition by tasks.registering(ExtractApiFile::class) {
selector.set(project.name)
input.set(mergedApiFile)
output.set(projectApiDir.resolve("${project.name}.api"))
}
tasks.named<Sync>("apiDump") {
finalizedBy(apiDump)
afterEvaluate {
tasks.named("apiCheck") {
dependsOn(extractApiDefinition)
}
tasks.named<Sync>("apiDump") {
finalizedBy(apiDump)
}
}
}
}

0 comments on commit 673a886

Please sign in to comment.