Skip to content

Commit

Permalink
Clarify annotation processor-related error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
autonomousapps committed Oct 3, 2023
1 parent c2359ba commit bfb785b
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ abstract class FindDeclaredProcsTask : DefaultTask() {
val types = getSupportedAnnotationTypes(procClass)
types?.let { AnnotationProcessorDependency(procName, it, artifact) }
} catch (_: ClassNotFoundException) {
logger.warn("Could not load $procName from class loader")
logger.warn("Could not load '$procName' from class loader")
null
}
}
Expand All @@ -140,24 +140,25 @@ abstract class FindDeclaredProcsTask : DefaultTask() {
zip.getInputStream(it).bufferedReader().use(BufferedReader::readLines)
// Filter out comments. For example, log4j-core has a license header in this file.
.filterNot { line -> line.trim().startsWith("#") }
.map { line -> line.trim() }
}
}

private fun <T : Processor> getSupportedAnnotationTypes(procClass: Class<T>): Set<String>? = try {
val proc = procClass.getDeclaredConstructor().newInstance()
logger.debug("Trying to initialize annotation processor with type ${proc.javaClass.name}")
logger.debug("Trying to initialize annotation processor with type '${proc.javaClass.name}'")
tryInit(proc)
proc.supportedAnnotationTypes.toSortedSet()
} catch (_: Throwable) {
logger.warn("Could not reflectively access processor class ${procClass.name}")
logger.warn("Could not reflectively access processor class '${procClass.name}'")
null
}

private fun <T : Processor> tryInit(proc: T) {
try {
proc.init(StubProcessingEnvironment())
} catch (_: Throwable) {
logger.debug("Could not initialize ${proc.javaClass.name}. May not be able to get supported annotation types.")
logger.debug("Could not initialize '${proc.javaClass.name}'. May not be able to get supported annotation types.")
}
}
}
Expand Down

0 comments on commit bfb785b

Please sign in to comment.