oracle / opengrok

OpenGrok is a fast and usable source code search and cross reference engine, written in Java
http://oracle.github.io/opengrok/
Other
4.35k stars 745 forks source link

genre check for hasAnnotation() is not enough #4515

Closed vladak closed 8 months ago

vladak commented 9 months ago

After the changes in PR #4476 annotation links for some files are no longer displayed. This is happening e.g. for makefiles with .targ suffix but also for files with .txt suffix or README.md files. In the webapp logs this looks like this:

15-Dec-2023 17:12:29.769 INFO [http-nio-8080-exec-347] org.opengrok.indexer.history.HistoryGuru.hasAnnotation will not produce annotation for '/ws-local/opengrok-master/.gitattributes' with unknown genre
15-Dec-2023 17:12:29.770 INFO [http-nio-8080-exec-347] org.opengrok.indexer.history.HistoryGuru.hasAnnotation will not produce annotation for '/ws-local/opengrok-master/.gitignore' with unknown genre
15-Dec-2023 17:12:29.770 INFO [http-nio-8080-exec-347] org.opengrok.indexer.history.HistoryGuru.hasAnnotation will not produce annotation for '/ws-local/opengrok-master/CONTRIBUTING.md' with unknown genre
15-Dec-2023 17:12:29.771 INFO [http-nio-8080-exec-347] org.opengrok.indexer.history.HistoryGuru.hasAnnotation will not produce annotation for '/ws-local/opengrok-master/Dockerfile' with unknown genre
15-Dec-2023 17:12:29.771 INFO [http-nio-8080-exec-347] org.opengrok.indexer.history.HistoryGuru.hasAnnotation will not produce annotation for '/ws-local/opengrok-master/LICENSE-adaic.org.txt' with unknown genre
15-Dec-2023 17:12:29.771 INFO [http-nio-8080-exec-347] org.opengrok.indexer.history.HistoryGuru.hasAnnotation will not produce annotation for '/ws-local/opengrok-master/LICENSE-eclipse.txt' with unknown genre
15-Dec-2023 17:12:29.772 INFO [http-nio-8080-exec-347] org.opengrok.indexer.history.HistoryGuru.hasAnnotation will not produce annotation for '/ws-local/opengrok-master/LICENSE-ecma.txt' with unknown genre
15-Dec-2023 17:12:29.772 INFO [http-nio-8080-exec-347] org.opengrok.indexer.history.HistoryGuru.hasAnnotation will not produce annotation for '/ws-local/opengrok-master/LICENSE-mandoc.txt' with unknown genre
15-Dec-2023 17:12:29.772 INFO [http-nio-8080-exec-347] org.opengrok.indexer.history.HistoryGuru.hasAnnotation will not produce annotation for '/ws-local/opengrok-master/LICENSE-ruby.txt' with unknown genre
15-Dec-2023 17:12:29.773 INFO [http-nio-8080-exec-347] org.opengrok.indexer.history.HistoryGuru.hasAnnotation will not produce annotation for '/ws-local/opengrok-master/LICENSE-scala.txt' with unknown genre
15-Dec-2023 17:12:29.773 INFO [http-nio-8080-exec-347] org.opengrok.indexer.history.HistoryGuru.hasAnnotation will not produce annotation for '/ws-local/opengrok-master/LICENSE.txt' with unknown genre
15-Dec-2023 17:12:29.774 INFO [http-nio-8080-exec-347] org.opengrok.indexer.history.HistoryGuru.hasAnnotation will not produce annotation for '/ws-local/opengrok-master/NOTICE.txt' with unknown genre
15-Dec-2023 17:12:29.774 INFO [http-nio-8080-exec-347] org.opengrok.indexer.history.HistoryGuru.hasAnnotation will not produce annotation for '/ws-local/opengrok-master/README.md' with unknown genre
15-Dec-2023 17:12:29.774 INFO [http-nio-8080-exec-347] org.opengrok.indexer.history.HistoryGuru.hasAnnotation will not produce annotation for '/ws-local/opengrok-master/SECURITY.md' with unknown genre
15-Dec-2023 17:12:29.775 INFO [http-nio-8080-exec-347] org.opengrok.indexer.history.HistoryGuru.hasAnnotation will not produce annotation for '/ws-local/opengrok-master/apiary.apib' with unknown genre
15-Dec-2023 17:12:29.775 INFO [http-nio-8080-exec-347] org.opengrok.indexer.history.HistoryGuru.hasAnnotation will not produce annotation for '/ws-local/opengrok-master/logging.properties' with unknown genre
15-Dec-2023 17:12:29.775 INFO [http-nio-8080-exec-347] org.opengrok.indexer.history.HistoryGuru.hasAnnotation will not produce annotation for '/ws-local/opengrok-master/mvnw' with unknown genre
15-Dec-2023 17:12:29.776 INFO [http-nio-8080-exec-347] org.opengrok.indexer.history.HistoryGuru.hasAnnotation will not produce annotation for '/ws-local/opengrok-master/mvnw.cmd' with unknown genre
15-Dec-2023 17:12:29.776 INFO [http-nio-8080-exec-347] org.opengrok.indexer.history.HistoryGuru.hasAnnotation will not produce annotation for '/ws-local/opengrok-master/sonar-project.properties' with unknown genre
vladak commented 9 months ago

For the webapp, it might make sense to consult the type of the file stored in the index first, something like it is done in FileController#getContentPlain(), and if not found fall back to the AnalyzerGuru approach.

vladak commented 9 months ago

The change done in PR #4476 added basically a genre check to HistoryGuru#hasAnnotation(). The main problem is that this kind of genre check merely checks the file prefix/suffix via AnalyzerGuru#find(String) (unlike AnalyzerGuru#find(InputStream in, String file) which uses file content as well - that would be undesired however because it would introduce additional I/O when listing directory contents) so files that do fail this match, like README.md will have the annotate capability disabled in the UI and actually also when creating annotation cache, because no analyzer has a filename match.