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

Conversation

marciosmiderle
Copy link

When compiling a test file its target directory is normally something bellow "test-classes". Regular classes are compiled to "classes" directory. Thus regular classes and test classes have different jdee-compile-option-directory in the same project.
A solution to this issue is to make jdee-compile-option-directory a buffer local variable and set its value accordingly in prj.el . But flycheck cannot known where to put the compiled file, so the solution I propose is to copy jdee-compile-option-directory value from original buffer if it was set.

The greater goal here is to have the compiled file in the right place as maven/ant would do, without compiling it twice (one for check, other the "real" compilation).

Thanks

…compiled

When compiling a test file its target directory is normally something bellow "test-classes". Regular classes are compiled to "classes" directory. Thus regular classes and test classes have different jdee-compile-option-directory in the same project.
A solution to this issue is to make jdee-compile-option-directory a buffer local variable and set its value accordingly in prj.el . But flycheck cannot known where to put the compiled file, so the solution I propose is to copy jdee-compile-option-directory value from original buffer if it was set.
;; 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants