|
|
|
@ -15,9 +15,6 @@ internal abstract class GenerateExpectResourceCollectorsTask : IdeaImportTask()
|
|
|
|
|
@get:Input |
|
|
|
|
abstract val packageName: Property<String> |
|
|
|
|
|
|
|
|
|
@get:Input |
|
|
|
|
abstract val shouldGenerateCode: Property<Boolean> |
|
|
|
|
|
|
|
|
|
@get:Input |
|
|
|
|
abstract val makeAccessorsPublic: Property<Boolean> |
|
|
|
|
|
|
|
|
@ -31,14 +28,12 @@ internal abstract class GenerateExpectResourceCollectorsTask : IdeaImportTask()
|
|
|
|
|
kotlinDir.deleteRecursively() |
|
|
|
|
kotlinDir.mkdirs() |
|
|
|
|
|
|
|
|
|
if (shouldGenerateCode.get()) { |
|
|
|
|
logger.info("Generate expect ResourceCollectors for $kotlinDir") |
|
|
|
|
logger.info("Generate expect ResourceCollectors for $kotlinDir") |
|
|
|
|
|
|
|
|
|
val pkgName = packageName.get() |
|
|
|
|
val isPublic = makeAccessorsPublic.get() |
|
|
|
|
val spec = getExpectResourceCollectorsFileSpec(pkgName, "ExpectResourceCollectors", isPublic) |
|
|
|
|
spec.writeTo(kotlinDir) |
|
|
|
|
} |
|
|
|
|
val pkgName = packageName.get() |
|
|
|
|
val isPublic = makeAccessorsPublic.get() |
|
|
|
|
val spec = getExpectResourceCollectorsFileSpec(pkgName, "ExpectResourceCollectors", isPublic) |
|
|
|
|
spec.writeTo(kotlinDir) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -46,9 +41,6 @@ internal abstract class GenerateActualResourceCollectorsTask : IdeaImportTask()
|
|
|
|
|
@get:Input |
|
|
|
|
abstract val packageName: Property<String> |
|
|
|
|
|
|
|
|
|
@get:Input |
|
|
|
|
abstract val shouldGenerateCode: Property<Boolean> |
|
|
|
|
|
|
|
|
|
@get:Input |
|
|
|
|
abstract val makeAccessorsPublic: Property<Boolean> |
|
|
|
|
|
|
|
|
@ -73,44 +65,39 @@ internal abstract class GenerateActualResourceCollectorsTask : IdeaImportTask()
|
|
|
|
|
val inputFiles = inputDirs.flatMap { dir -> |
|
|
|
|
dir.walkTopDown().filter { !it.isHidden && it.isFile && it.extension == "kt" }.toList() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (shouldGenerateCode.get()) { |
|
|
|
|
logger.info("Generate actual ResourceCollectors for $kotlinDir") |
|
|
|
|
val funNames = inputFiles.mapNotNull { inputFile -> |
|
|
|
|
if (inputFile.nameWithoutExtension.contains('.')) { |
|
|
|
|
val (fileName, suffix) = inputFile.nameWithoutExtension.split('.') |
|
|
|
|
val type = ResourceType.values().firstOrNull { fileName.startsWith(it.accessorName, true) } |
|
|
|
|
val name = "_collect${suffix.uppercaseFirstChar()}${fileName}Resources" |
|
|
|
|
|
|
|
|
|
if (type == null) { |
|
|
|
|
logger.warn("Unknown resources type: `$inputFile`") |
|
|
|
|
null |
|
|
|
|
} else if (!inputFile.readText().contains(name)) { |
|
|
|
|
logger.warn("A function '$name' is not found in the `$inputFile` file!") |
|
|
|
|
null |
|
|
|
|
} else { |
|
|
|
|
logger.info("Found collector function: `$name`") |
|
|
|
|
type to name |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
logger.warn("Unknown file name: `$inputFile`") |
|
|
|
|
logger.info("Generate actual ResourceCollectors for $kotlinDir") |
|
|
|
|
val funNames = inputFiles.mapNotNull { inputFile -> |
|
|
|
|
if (inputFile.nameWithoutExtension.contains('.')) { |
|
|
|
|
val (fileName, suffix) = inputFile.nameWithoutExtension.split('.') |
|
|
|
|
val type = ResourceType.values().firstOrNull { fileName.startsWith(it.accessorName, true) } |
|
|
|
|
val name = "_collect${suffix.uppercaseFirstChar()}${fileName}Resources" |
|
|
|
|
|
|
|
|
|
if (type == null) { |
|
|
|
|
logger.warn("Unknown resources type: `$inputFile`") |
|
|
|
|
null |
|
|
|
|
} else if (!inputFile.readText().contains(name)) { |
|
|
|
|
logger.warn("A function '$name' is not found in the `$inputFile` file!") |
|
|
|
|
null |
|
|
|
|
} else { |
|
|
|
|
logger.info("Found collector function: `$name`") |
|
|
|
|
type to name |
|
|
|
|
} |
|
|
|
|
}.groupBy({ it.first }, { it.second }) |
|
|
|
|
|
|
|
|
|
val pkgName = packageName.get() |
|
|
|
|
val isPublic = makeAccessorsPublic.get() |
|
|
|
|
val useActual = useActualModifier.get() |
|
|
|
|
val spec = getActualResourceCollectorsFileSpec( |
|
|
|
|
pkgName, |
|
|
|
|
"ActualResourceCollectors", |
|
|
|
|
isPublic, |
|
|
|
|
useActual, |
|
|
|
|
funNames |
|
|
|
|
) |
|
|
|
|
spec.writeTo(kotlinDir) |
|
|
|
|
} else { |
|
|
|
|
logger.info("Generation ResourceCollectors for $kotlinDir is disabled") |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
logger.warn("Unknown file name: `$inputFile`") |
|
|
|
|
null |
|
|
|
|
} |
|
|
|
|
}.groupBy({ it.first }, { it.second }) |
|
|
|
|
|
|
|
|
|
val pkgName = packageName.get() |
|
|
|
|
val isPublic = makeAccessorsPublic.get() |
|
|
|
|
val useActual = useActualModifier.get() |
|
|
|
|
val spec = getActualResourceCollectorsFileSpec( |
|
|
|
|
pkgName, |
|
|
|
|
"ActualResourceCollectors", |
|
|
|
|
isPublic, |
|
|
|
|
useActual, |
|
|
|
|
funNames |
|
|
|
|
) |
|
|
|
|
spec.writeTo(kotlinDir) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|