Skip to content

Commit 9bb7ee6

Browse files
committed
enh: fail on errors at the end of classgraph process
1 parent 1ed4d34 commit 9bb7ee6

File tree

6 files changed

+41
-16
lines changed

6 files changed

+41
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package godot.annotation.processor.classgraph
2+
3+
object ErrorsDatabase {
4+
val errors = mutableListOf<String>()
5+
6+
fun add(error: String) = errors.add(error)
7+
fun isEmpty() = errors.isEmpty()
8+
}

kt/entry-generation/godot-class-graph-symbol-processor/src/main/kotlin/godot/annotation/processor/classgraph/extensions/AnnotationExtensions.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import godot.annotation.Sync
1818
import godot.annotation.Tool
1919
import godot.annotation.TransferMode
2020
import godot.annotation.processor.classgraph.Context
21+
import godot.annotation.processor.classgraph.ErrorsDatabase
2122
import godot.annotation.processor.classgraph.constants.SET
2223
import godot.entrygenerator.model.ColorNoAlphaHintAnnotation
2324
import godot.entrygenerator.model.DirHintAnnotation
@@ -64,16 +65,22 @@ fun AnnotationInfo.mapToGodotAnnotation(parentDeclaration: Any): GodotAnnotation
6465
)
6566
"godot.annotation.GodotBaseType" -> GodotBaseTypeAnnotation(this) // is internal
6667
EnumFlag::class.java.name -> {
67-
require(parentDeclaration is FieldInfo) {
68-
"EnumFlag annotation should be placed on property."
68+
if (parentDeclaration !is FieldInfo) {
69+
ErrorsDatabase.add(
70+
"EnumFlag annotation should be placed on property."
71+
)
72+
return EnumFlagHintStringAnnotation(enumValueNames = listOf(), source = this)
6973
}
7074

7175
val typeDescriptor = parentDeclaration.typeSignature
7276

7377
require(typeDescriptor is ClassRefTypeSignature)
7478

75-
require(typeDescriptor.fullyQualifiedClassName == SET) {
76-
"Property annotated with EnumFlag should be of type $SET"
79+
if (typeDescriptor.fullyQualifiedClassName != SET) {
80+
ErrorsDatabase.add(
81+
"Property annotated with EnumFlag should be of type $SET"
82+
)
83+
return EnumFlagHintStringAnnotation(enumValueNames = listOf(), source = this)
7784
}
7885

7986
val typeArgument = typeDescriptor.typeArguments.first().typeSignature as ClassRefTypeSignature

kt/entry-generation/godot-class-graph-symbol-processor/src/main/kotlin/godot/annotation/processor/classgraph/extensions/ClassExtentions.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import godot.annotation.RegisterClass
44
import godot.annotation.RegisterFunction
55
import godot.annotation.RegisterProperty
66
import godot.annotation.RegisterSignal
7+
import godot.annotation.processor.classgraph.ErrorsDatabase
78
import godot.annotation.processor.classgraph.Settings
89
import godot.annotation.processor.classgraph.constants.KOTLIN_ANY
910
import godot.core.KtObject
@@ -44,8 +45,10 @@ fun ClassInfo.mapToClazz(settings: Settings): Clazz {
4445
val shouldBeRegistered = shouldBeRegistered(methods, fields, signals)
4546

4647
return if (shouldBeRegistered) {
47-
require(constructorInfo.any { it.isPublic && it.parameterInfo.isEmpty() }) {
48-
"You should provide a default constructor for class $fqName"
48+
if (!constructorInfo.any { it.isPublic && it.parameterInfo.isEmpty() }) {
49+
ErrorsDatabase.add(
50+
"You should provide a default constructor for class $fqName"
51+
)
4952
}
5053

5154
RegisteredClass(

kt/entry-generation/godot-class-graph-symbol-processor/src/main/kotlin/godot/annotation/processor/classgraph/process.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ fun generateEntryUsingClassGraph(
4040
classInfo.mapToClazz(settings)
4141
}
4242

43+
require(ErrorsDatabase.isEmpty()) {
44+
buildString {
45+
for (error in ErrorsDatabase.errors) {
46+
appendLine(error)
47+
}
48+
}
49+
}
50+
4351
val registeredClasses = classes.filterIsInstance<RegisteredClass>().distinctBy { clazz -> clazz.fqName }
4452

4553
RegisteredClassMetadataContainerDatabase.populateCurrentProject(registeredClasses, settings)

kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/tasks/classGraphSymbolsProcess.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ fun Project.classGraphSymbolsProcess(
3131

3232
generateEntryUsingClassGraph(
3333
Settings(
34-
godotJvmExtension.classPrefix.orNull,
35-
godotJvmExtension.isFqNameRegistrationEnabled.get(),
36-
(godotJvmExtension.projectName.orNull ?: project.name).replace(" ", "_"),
37-
File(projectDir.absolutePath.replace(File.separator, "/")),
38-
(
34+
classPrefix = godotJvmExtension.classPrefix.orNull,
35+
isFqNameRegistrationEnabled = godotJvmExtension.isFqNameRegistrationEnabled.get(),
36+
projectName = (godotJvmExtension.projectName.orNull ?: project.name).replace(" ", "_"),
37+
projectBaseDir = File(projectDir.absolutePath.replace(File.separator, "/")),
38+
registrationBaseDirPathRelativeToProjectDir = (
3939
godotJvmExtension
4040
.registrationFileBaseDir
4141
.orNull
@@ -53,9 +53,9 @@ fun Project.classGraphSymbolsProcess(
5353
.replace(File.separator, "/")
5454
.removePrefix("/")
5555
.removeSuffix("/"),
56-
godotJvmExtension.isRegistrationFileHierarchyEnabled.get(),
57-
godotJvmExtension.isRegistrationFileGenerationEnabled.getOrElse(true),
58-
layout.buildDirectory.get()
56+
isRegistrationFileHierarchyEnabled = godotJvmExtension.isRegistrationFileHierarchyEnabled.get(),
57+
isRegistrationFileGenerationEnabled = godotJvmExtension.isRegistrationFileGenerationEnabled.getOrElse(true),
58+
generatedSourceRootDir = layout.buildDirectory.get()
5959
.asFile
6060
.resolve("generated")
6161
.resolve("classgraph")

kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/tasks/setupBuildTask.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ fun Project.setupBuildTask(
2828
task.finalizedBy(
2929
copyJarTask,
3030
packageBootstrapJarTask,
31-
packageMainJarTask,
32-
// packageMainJarWithClassGraph
31+
packageMainJarTask
3332
)
3433

3534
if (godotJvmExtension.isAndroidExportEnabled.get()) {

0 commit comments

Comments
 (0)