gin.2024.3.2.source-code.BuildPackageMap.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plugin Show documentation
Show all versions of plugin Show documentation
Questioner Gradle plugin for CS 124.
The newest version!
package edu.illinois.cs.cs125.questioner.plugin
import com.squareup.moshi.Types
import edu.illinois.cs.cs125.questioner.lib.moshi.moshi
import edu.illinois.cs.cs125.questioner.plugin.parse.buildPackageMap
import org.gradle.api.DefaultTask
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.TaskAction
import java.io.File
import java.nio.file.Path
abstract class BuildPackageMap : DefaultTask() {
@Internal
val sourceSet: SourceSet =
project.extensions.getByType(JavaPluginExtension::class.java).sourceSets.getByName("main")
@Internal
val sourceDirectorySet: MutableSet = sourceSet.java.srcDirs
@Internal
val sourceDirectoryPath: Path = sourceDirectorySet.first().toPath()
@InputFiles
@Suppress("unused")
val inputFiles: Set =
sourceSet.allSource.filter { it.name.endsWith(".java") || it.name.endsWith(".kt") }.files.otherFiles().toSet()
@OutputFile
val outputFile: File = project.layout.buildDirectory.dir("questioner/packageMap.json").get().asFile
@TaskAction
fun build() = sourceDirectoryPath.buildPackageMap().writeToFile(outputFile)
}
private fun Map>.writeToFile(file: File) {
file.writeText(
moshi.adapter