Skip to content

Commit

Permalink
Merge pull request #44 from boschglobal/fix-43
Browse files Browse the repository at this point in the history
fix: Fix exception on empty VssDefinition asset file
  • Loading branch information
SebastianSchildt authored Nov 24, 2023
2 parents dbd4e19 + c0b4ebe commit c0ab1f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
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

0 comments on commit c0ab1f2

Please sign in to comment.