;;; flycheck-android-experimental.el --- Flycheck for Android using experimental ;;; gradle plugin ;; Copyright (C) 2017 by Joel Klinghed ;; Author: Joel Klinghed ;;; Commentary: ;;; Code: (require 'flycheck) (defvar flycheck-android-sessiondir nil "Session directory used for caching.") (flycheck-def-option-var flycheck-android-java-checkstyle-jar nil android-java "Path to checkstyle-VERSION-all.jar." :safe #'stringp) (make-variable-buffer-local 'flycheck-android-java-checkstyle-jar) (flycheck-def-option-var flycheck-android-java-checkstyle-path nil android-java "Path to use as workdir and base for config and properties." :safe #'stringp) (make-variable-buffer-local 'flycheck-android-java-checkstyle-path) (flycheck-def-option-var flycheck-android-java-checkstyle-config nil android-java "Path to checkstyle-config.xml if one should be used." :safe #'stringp) (make-variable-buffer-local 'flycheck-android-java-checkstyle-config) (flycheck-def-option-var flycheck-android-java-checkstyle-properties nil android-java "Path to checkstyle.properties if one should be used." :safe #'stringp) (make-variable-buffer-local 'flycheck-android-java-checkstyle-properties) (flycheck-define-checker android-java "Java syntax checker using javac." :command ("python" (eval (flycheck-android-find-tool "java")) (option "--checkstyle-jar=" flycheck-android-java-checkstyle-jar concat) (option "--checkstyle-path=" flycheck-android-java-checkstyle-path concat) (option "--checkstyle-config=" flycheck-android-java-checkstyle-config concat) (option "--checkstyle-properties=" flycheck-android-java-checkstyle-properties concat) (eval (flycheck-android-get-sessiondir)) (eval buffer-file-name) source) :error-patterns ((warning line-start (file-name) ":" line ": warning:" (message (one-or-more (not (any "^"))) (any "^")) line-end) (error line-start (file-name) ":" line ": error:" (message (one-or-more (not (any "^"))) (any "^")) line-end) ;; checkstyle messages (warning line-start (file-name) ":" line ": warning: " (message) line-end) (error line-start (file-name) ":" line ":" column ": " (message) line-end) (error line-start (file-name) ":" line ": " (message) line-end)) :modes java-mode) (defun flycheck-android-find-tool (tool) "Find flycheck-android-TOOL.py. TOOL=name of tool" (let ((filename (concat "flycheck-android-" tool ".py"))) (expand-file-name filename (concat (file-name-directory (symbol-file 'flycheck-android-find-tool)) (file-name-as-directory "bin"))))) (defun flycheck-android-remove-sessiondir () "Delete session dir if it exists and unsets the variable." (when flycheck-android-sessiondir (delete-directory flycheck-android-sessiondir t) (setq flycheck-android-sessiondir nil))) (defun flycheck-android-get-sessiondir () "Return sessiondir if already set otherwise create and set it." (or flycheck-android-sessiondir (progn (add-hook 'kill-emacs-hook 'flycheck-android-remove-sessiondir) (setq flycheck-android-sessiondir (make-temp-file "flycheck-android" t))))) (add-to-list 'flycheck-checkers 'android-java) (provide 'flycheck-android-experimental) ;;; flycheck-android-experimental.el ends here