Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test files have different target directories than program files when compiled (flycheck) #151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions jdee-flycheck.el
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ file and buffer with the contents of the current buffer and compiles that one."
(unless jdee-compile-option-directory
(set (make-local-variable 'jdee-compile-option-directory)
(expand-file-name "classes" dir)))
;; Use jdee-compile-option-directory dir from orig-buffer if it is set
;; as a local variable. When compiling a test file this dir is normally
;; test-classes, not classes. Runtime classes and test classes have
;; different jdee-compile-option-directory in the same project.
(let ((v (buffer-local-value 'jdee-compile-option-directory orig-buffer)))
(if v (set 'jdee-compile-option-directory v)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But where jdee-compile-option-directory will be set to test-classes value? You would need to recognize if you are in test sources or main sources.

Copy link
Member

@pwojnowski pwojnowski Aug 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for such a late reply.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In prj.el it is possible to set the jdee-compile-option-directory based in the full path filename, in a local version of the variable. In my case I do it like this:

(setq
   jdee-compile-option-directory
   (cond
    ((string-match
      ".*\\(/\\(src/main/java\\)/.*\\)" default-directory)
     (replace-match "/target/classes/" t nil default-directory 1))
    ((string-match
      ".*\\(/\\(src/test/java\\)/.*\\)" default-directory)
     (replace-match "/target/test-classes/" t nil default-directory 1))

    (t (error "%s" (concat "Destiny of '" (buffer-file-name)
			   "' compiled file is unknown")))) )

With the change jdee-flycheck can give one a chance to set the compiled file location. I hope this patch can flourish a better idea!


(setq compilation-finish-functions
(lambda (buf msg)
Expand Down