Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix exception on empty VssDefinition asset file #44

Merged
merged 3 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion vss-processor/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
kotlin("jvm")
`maven-publish`
publish
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ class VssDefinitionProcessor(
annotatedProcessorFileName,
)

val vssDefinition = classDeclaration.getAnnotationsByType(VssDefinition::class).first()
val vssDefinition = classDeclaration.getAnnotationsByType(VssDefinition::class).firstOrNull() ?: return
val vssDefinitionPath = vssDefinition.vssDefinitionPath

val definitionFile = loadAssetFile(vssDefinitionPath)
if (!definitionFile.exists()) {
logger.error("No VSS definition file was found!")
if (definitionFile == null || !definitionFile.exists()) {
logger.info("No VSS definition file was found!")
return
}

Expand All @@ -97,13 +97,14 @@ class VssDefinitionProcessor(
}

// Uses the default file path for generated files (from the code generator) and searches for the given file.
private fun loadAssetFile(fileName: String): File {
val generationPath = codeGenerator.generatedFile.first().absolutePath
private fun loadAssetFile(fileName: String): File? {
val generatedFile = codeGenerator.generatedFile.firstOrNull() ?: return null
val generationPath = generatedFile.absolutePath
val buildPath = generationPath.replaceAfter(BUILD_FOLDER_NAME, "")
val assetsFilePath = "$buildPath/$ASSETS_BUILD_DIRECTORY"
val assetsFolder = File(assetsFilePath)

return assetsFolder.walk().first { it.name == fileName }
return assetsFolder.walk().firstOrNull { it.name == fileName }
}

private fun generateModelFiles(vssPathToSpecification: Map<VssPath, VssSpecificationSpecModel>) {
Expand All @@ -112,7 +113,7 @@ class VssDefinitionProcessor(
.filter { it.value.size > 1 }
.keys

logger.logging("Ambiguous specifications - Generate nested classes: $duplicateSpecificationNames")
logger.info("Ambiguous specifications - Generate nested classes: $duplicateSpecificationNames")

for ((vssPath, specModel) in vssPathToSpecification) {
// Every duplicate is produced as a nested class - No separate file should be generated
Expand Down