PageRenderTime 51ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/site-elisp/jdee/lisp/jde-compile.el

https://bitbucket.org/nivox/emacs-config
Emacs Lisp | 1447 lines | 1086 code | 232 blank | 129 comment | 63 complexity | c45b028899cd79ccf88ed3fbfbbcf5be MD5 | raw file
Possible License(s): LGPL-2.1
  1. ;;; jde-compile.el -- Integrated Development Environment for Java.
  2. ;; $Id$
  3. ;; Author: Paul Kinnucan <paulk@mathworks.com>
  4. ;; Author: Suraj Acharya <sacharya@cs.indiana.edu>
  5. ;; Maintainer: Paul Landes <landes <at> mailc dt net>
  6. ;; Keywords: java, tools
  7. ;; Copyright (C) 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2008 Paul Kinnucan.
  8. ;; Copyright (C) 2009 by Paul Landes
  9. ;; Copyright (C) 2006-2007 by Suraj Acharya
  10. ;; GNU Emacs is free software; you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  20. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. ;; Boston, MA 02111-1307, USA.
  22. ;;; Commentary:
  23. ;; This is one of a set of packages that make up the Java Development
  24. ;; Environment (JDE) for Emacs. See the JDE User's Guide for more
  25. ;; information. It includes code for using the Eclipse compiler
  26. ;; originally written by Suraj Acharya.
  27. ;; When customizing the jde-compiler variable to use the option for
  28. ;; "eclipse java compiler server" you will also need to specify the
  29. ;; location of the eclipse java compiler classes.
  30. ;; If you've installed eclipse locally then this is the jdtcore.jar
  31. ;; under <eclipse dir>/plugins/org.eclipse.jdt.core_x.x.x/, where
  32. ;; x.x.x depends on the version of eclipse you have.
  33. ;; If you don't have eclipse you can download just the JDT
  34. ;; compiler. Go to http://download.eclipse.org/eclipse/downloads/ and
  35. ;; pick the release you want, the latest release is usually stable
  36. ;; enough to use. Once you get to the downloads page for the release,
  37. ;; scroll down to find the link to download the "JDT Core Batch
  38. ;; Compiler". The 1 MB ecj.jar file is all you need to download.
  39. ;; Check that you have the correct jar by trying to run the compiler
  40. ;; from a command line like so:
  41. ;; java -cp <path to jar> org.eclipse.jdt.internal.compiler.batch.Main
  42. ;; This should print out a usage message for the "Eclipse Java Compiler".
  43. ;; The latest version of the JDE is available at
  44. ;; <URL:http://jdee.sourceforge.net/>.
  45. ;; Please send any comments, bugs, or upgrade requests to
  46. ;; Paul Landes <landes <at> mailc dt net>
  47. ;;; Code:
  48. (require 'eieio)
  49. (require 'cl)
  50. (require 'compile)
  51. ;; quiet "reference to free variable" build-time warnings
  52. (defvar jde-complete-last-compiled-class)
  53. (defvar jde-classpath-separator)
  54. (defgroup jde-compile-options nil
  55. "JDE Compiler Options"
  56. :group 'jde
  57. :prefix "jde-compile-option-")
  58. ;; (makunbound 'jde-compiler)
  59. (defcustom jde-compiler '("javac server")
  60. "Specify the type, and if necessary, the location of the compiler to
  61. be used to compile source files for the current project. The JDE
  62. supports three compilers: javac server, javac executable, and
  63. the eclipse java compiler (ecj). The javac server runs the com.sun.tools.javac package included
  64. with the JDK in the Beanshell. The javac executable shipped with the
  65. JDK also uses this package. The advantage of the javac server is that
  66. it avoids the vm startup time that accounts for most of the
  67. compilation time consumed by the javac executable. The javac server
  68. uses the version of com.sun.tools.javac included in the JDK for the
  69. current project. See `jde-jdk' for more information. If you want to
  70. use the javac executable to compile your project's source files,
  71. select \"javac\" as the compiler type and, optionally, specify
  72. the path to the executable in the \"Path\" field. If you do
  73. not specify a path, the JDE uses the javac executable included in the
  74. JDK for the current project. Similarly, to use ecj, select \"eclipse java compiler server\"
  75. and specify the path of the eclipse compiler ecj.jar."
  76. :group 'jde-project
  77. :type '(list
  78. (radio-button-choice
  79. :format "%t \n%v"
  80. :tag "Compiler type"
  81. (item "javac")
  82. (item "javac server")
  83. (list :format "%v"
  84. (const "eclipse java compiler server")
  85. (file :tag "Path to ecj.jar (or jdt core jar)"))
  86. ))
  87. )
  88. ;; convert jde-compiler values from the old format to the one used these days
  89. (let ((compiler-name (car jde-compiler)))
  90. (when (not (listp compiler-name))
  91. (setq jde-compiler
  92. (cond
  93. ((equal compiler-name "javac") '("javac"))
  94. ((equal compiler-name "javac server") '("javac server"))
  95. (t "javac server")))))
  96. (defcustom jde-read-compile-args nil
  97. "*Specify whether to prompt for additional compiler arguments.
  98. If this variable is non-nil, the jde-compile command prompts
  99. you to enter additional compiler arguments in the minibuffer.
  100. These arguments are appended to those specified by customization
  101. variables. The JDE maintains a history list of arguments
  102. entered in the minibuffer."
  103. :group 'jde-project
  104. :type 'boolean)
  105. (defcustom jde-compiler-new-compile-el
  106. (boundp 'compilation-error-regexp-alist-alist)
  107. "Check if we have the new (21.3+) compile.el.
  108. Set this to t if you are running an Emacs with the new compile.el
  109. and want to get slightly better font-locking in the compile
  110. buffer. A value of nil will force the use of older style
  111. compilation-error-regexp. This variable tries to auto-detect the
  112. compile.el version by checking if
  113. `compilation-error-regexp-alist-alist' is defined."
  114. :group 'jde-compile-options
  115. :type 'boolean)
  116. (if jde-compiler-new-compile-el
  117. (progn
  118. (setq compilation-error-regexp-alist
  119. (cons '("----------\n\\([0-9]+. ERROR in \\(.*\\)\n (at line \\([0-9]+\\))\n\\(\\(.*\n\\)+?\\).*^+\n\\(.*\n\\)\\)"
  120. 2 3 nil 2 1 (6 compilation-error-face)
  121. )
  122. compilation-error-regexp-alist))
  123. (setq compilation-error-regexp-alist
  124. (cons '("----------\n\\([0-9]+. WARNING in \\(.*\\)\n (at line \\([0-9]+\\))\n\\(\\(.*\n\\)+?\\).*^+\n\\(.*\n\\)\\)"
  125. 2 3 nil 1 1 (6 compilation-warning-face)
  126. )
  127. compilation-error-regexp-alist)))
  128. ;; else
  129. (setq compilation-error-regexp-alist
  130. (cons '("----------\n[0-9]+. \\(ERROR\\|WARNING\\) in \\(.*\\)\n (at line \\([0-9]+\\))\n\\(\\(.*\n\\)+?\\).*^+\n\\(.*\n\\)"
  131. 2 3)
  132. compilation-error-regexp-alist)))
  133. (defvar jde-interactive-compile-args ""
  134. "String of compiler arguments entered in the minibuffer.")
  135. (defvar jde-interactive-compile-arg-history nil
  136. "History of compiler arguments entered in the minibuffer.")
  137. ;; (makunbound 'jde-compile-finish-hook)
  138. (defcustom jde-compile-finish-hook
  139. '(jde-compile-finish-kill-buffer
  140. jde-compile-finish-refresh-speedbar
  141. jde-compile-finish-update-class-info)
  142. "List of functions to be invoked when compilation of a
  143. Java source file terminates. Each function should accept
  144. two arguments: the compilation buffer and a string
  145. describing how the compilation finished."
  146. :group 'jde
  147. :type 'hook)
  148. (defcustom jde-compile-option-hide-classpath nil
  149. "Substitute the classpath in the compilation window for
  150. ..."
  151. :group 'jde-compile-options
  152. :type 'boolean)
  153. (defun jde-compile-update-class-list ()
  154. (let ((class-dir
  155. (if (string= jde-compile-option-directory "")
  156. (expand-file-name ".")
  157. (jde-normalize-path
  158. jde-compile-option-directory
  159. 'jde-compile-option-directory))))
  160. (message (concat "Updating class list for " class-dir))
  161. (jde-jeval (concat
  162. "jde.util.JdeUtilities.updateClassList(\""
  163. class-dir
  164. "\");"))
  165. (message "Updating class list...done.")))
  166. (defun jde-compile-finish-update-class-info (buf msg)
  167. "Flush the classinfo cache and update the class list used by
  168. JDEE wizards at the end of compilation. Flush the entire cache as we
  169. don't know which classes were recompiled."
  170. ;;Setting the last java buffer as the current buffer
  171. (condition-case nil
  172. (progn
  173. (if jde-xemacsp
  174. (set-buffer (cadr (buffer-list)))
  175. (set-buffer (car (buffer-list))))
  176. (if (eq major-mode 'jde-mode)
  177. (progn
  178. (setq jde-complete-last-compiled-class (jde-parse-get-buffer-class))
  179. (jde-complete-flush-classes-in-cache (list jde-complete-last-compiled-class))
  180. (message "Flushed completion cache.")
  181. (setq jde-complete-last-compiled-class nil)
  182. (jde-compile-update-class-list))))
  183. (error nil)))
  184. (defun jde-compile-finish-refresh-speedbar (buf msg)
  185. "Refresh speedbar at the end of a compilation."
  186. (if (and (frame-live-p speedbar-frame)
  187. (frame-visible-p speedbar-frame))
  188. (speedbar-refresh)))
  189. (defcustom jde-compile-jump-to-first-error t
  190. "*Automatically jump to the first error when a compilation process completes."
  191. :group 'jde-compile-options
  192. :type 'boolean)
  193. (defun jde-compile-kill-buffer (buf)
  194. (delete-windows-on buf)
  195. (kill-buffer buf))
  196. ;; Thanks to Jack Donohue <donohuej@synovation.com>.
  197. (defun jde-compile-finish-kill-buffer (buf msg)
  198. "Removes the jde-compile window after a few seconds if no errors."
  199. (save-excursion
  200. (set-buffer buf)
  201. (if (null (or (string-match ".*exited abnormally.*" msg)
  202. (string-match ".*BUILD FAILED.*" (buffer-string))))
  203. ;;no errors, make the compilation window go away in a few seconds
  204. (if (if (numberp jde-compile-enable-kill-buffer)
  205. (not (minusp jde-compile-enable-kill-buffer))
  206. jde-compile-enable-kill-buffer)
  207. (lexical-let ((compile-buffer buf))
  208. (run-at-time
  209. (format "%d sec" (if (numberp jde-compile-enable-kill-buffer)
  210. jde-compile-enable-kill-buffer 2))
  211. nil 'jde-compile-kill-buffer
  212. compile-buffer)
  213. (message "No compilation errors")))
  214. ;;there were errors, so jump to the first error
  215. (if jde-compile-jump-to-first-error (next-error 1)))))
  216. (defcustom jde-compile-option-command-line-args nil
  217. "*Specify options as a string of command-line arguments.
  218. The value of this variable should be a list of switches understood
  219. by the compiler, for example, -depend -g. This variable is intended to
  220. be used to set compile options not otherwise defined by the JDE, in
  221. particular, options not defined by javac but used by another compiler
  222. that you might want to use with the JDE."
  223. :group 'jde-compile-options
  224. :type '(repeat (string :tag "Argument:")))
  225. (defcustom jde-compile-option-classpath nil
  226. "*Specify paths of classes required to compile this project.
  227. The JDEE uses the specified paths to construct a -classpath
  228. argument to pass to the compiler. If you do not specify this
  229. option, the JDEE uses the value of the `jde-global-classpath'
  230. option to compile this project.
  231. Starting in JDK 1.6, a class path element containing a basename
  232. of * is considered equivalent to specifying a list of all the
  233. files in the directory with the extension .jar or .JAR. For
  234. example, if directory foo contains a.jar and b.JAR, then the
  235. class path element foo/* is expanded to A.jar;b.JAR, except that
  236. the order of jar files is unspecified. All jar files in the
  237. specified directory, even hidden ones, are included in the
  238. list. A classpath entry consisting simply of * expands to a list
  239. of all the jar files in the current directory. The CLASSPATH
  240. environment variable, where defined, will be similarly
  241. expanded. Note: Depending of the configuration of your command
  242. line environment, you may have to quote the wild card character,
  243. for example, javac -cp \"*.jar\" MyClass.java."
  244. :group 'jde-compile-options
  245. :type '(repeat (file :tag "Path")))
  246. (defcustom jde-compile-option-sourcepath nil
  247. "*Specify the source code path to search for class or interface definitions.
  248. As with the user class path, source path entries can be directories, JAR
  249. archives, or ZIP archives. If packages are used, the local path name within
  250. the directory or archive must reflect the package name.
  251. Note that classes found through the classpath are subject to automatic
  252. recompilation if their sources are found."
  253. :group 'jde-compile-options
  254. :type '(repeat (file :tag "Path")))
  255. (defcustom jde-compile-option-directory ""
  256. "*Specifies the root directory of the class file hierarchy.
  257. The compiler places compiled classes in the specified
  258. directory. For example, specifying the class
  259. directory as:
  260. C:\\users\\dac\\classes
  261. causes the class files for the classes in the MyProgram.java source
  262. file to be saved in the directory C:\\users\\dac\\classes. If your class
  263. is in the package demos\\awt, the class files would be placed in directory
  264. C:\\users\\dac\\classes\\demos\\awt."
  265. :group 'jde-compile-options
  266. :type 'directory)
  267. (defcustom jde-compile-option-deprecation nil
  268. "*Warn use or override of a deprecated member or class.
  269. A member or class is deprecated if its documentation comment contains
  270. the @deprecated tag. The compiler will emit a warning at the end of
  271. compilation whether or not the deprecation option is on; this option
  272. causes the location of each individual use or override to be noted.
  273. Deprecated members or classes are deliberately not mentioned if the
  274. source file containing the deprecation is being recompiled. This can
  275. happen because the file is on the command line or because the depend
  276. option is on and the source file is out of date.
  277. "
  278. :group 'jde-compile-options
  279. :type 'boolean)
  280. (defcustom jde-compile-option-debug
  281. (list "selected" (list t nil nil))
  282. "*Include debug information in classes.
  283. The compiler includes line number information by default.
  284. Before JDK 1.2, the the debug and optimize options were
  285. mutually exclusive. In JDK 1.2, it is possible to combine debug and
  286. optimize, but the shortcuts taken by optimized code may occasionally
  287. produce surprising debugging results. For example, declared variables
  288. may not exist and code may appear to move or not be executed at all.
  289. The JDK 1.1.x versions of javac do not support inclusion of selected
  290. debug information."
  291. :group 'jde-compile-options
  292. :type '(list
  293. (radio-button-choice
  294. :format "%t \n%v"
  295. :tag "Debug info to include in class:"
  296. (const "all")
  297. (const "none")
  298. (const "selected"))
  299. (list
  300. :tag " info"
  301. :indent 4
  302. (checkbox :format "%[%v%] %t \n"
  303. :tag "Line Numbers")
  304. (checkbox :format "%[%v%] %t \n"
  305. :tag "Variables")
  306. (checkbox :format "%[%v%] %t \n"
  307. :tag "Source")))
  308. )
  309. (defcustom jde-compile-option-optimize nil
  310. "*Directs the compiler to try to generate faster code.
  311. This may slow down compilation, make larger class files, and/or make
  312. it difficult to debug.
  313. Prior to 1.2, the optimize option tried to inline methods across
  314. classes. This created compatibility problems and sometimes generated
  315. illegal bytecode. The optimize option also implicitly turned on the
  316. depend option and implicitly turned off the debug option.
  317. In JDK 1.2, the optimize option no longer inlines across classes and
  318. so may safely be used for any java compilation. Optimize no longer
  319. implicitly turns on depend or implicitly turns off debug."
  320. :group 'jde-compile-options
  321. :type 'boolean)
  322. (defcustom jde-compile-option-depend nil
  323. "*Analyze dependencies.
  324. Causes recompilation of class files on which the source files given as
  325. command line arguments recursively depend. Without this option, only
  326. files that are directly depended on and missing or out-of-date will be
  327. recompiled. Recompilation does not extend to missing or out-of-date
  328. files only depended on by already up-to-date class files.
  329. Note: if you are using a compiler other than post JDK 1.1.6 versions
  330. of javac, you may need to specify the command-line switch used by
  331. the compiler to specify dependency checking. See
  332. `jde-compile-option-depend-switch' for more information."
  333. :group 'jde-compile-options
  334. :type 'boolean)
  335. (defcustom jde-compile-option-depend-switch (list "-Xdepend")
  336. "*Specify command line switch for depend option.
  337. This option is necessary because the command-line switch for
  338. dependency checking differs among Java compilers. Choose
  339. from the following options:
  340. -Xdepend Full dependency checking (post JDK 1.1.6)
  341. -depend Full dependency checking (pre-JDK 1.1.6)"
  342. :group 'jde-compile-options
  343. :type '(list
  344. (radio-button-choice
  345. :format "%t \n%v"
  346. :tag "Select -Xdepend (javac) or -depend (pre-JDK 1.1.6):"
  347. (const "-Xdepend")
  348. (const "-depend"))))
  349. (defcustom jde-compile-option-vm-args nil
  350. "*Specify command-line arguments for Java interpreter.
  351. Passes the specified arguments to the Java interpreter that runs the
  352. compiler. The argument should not contain spaces. This is useful for
  353. adjusting the compiler's execution environment or memory usage."
  354. :group 'jde-compile-options
  355. :type '(repeat (string :tag "Option")))
  356. (defcustom jde-compile-option-verbose nil
  357. "*Print verbose messages.
  358. Causes the compiler and linker to print out messages about what source
  359. files are being compiled and what class files are being loaded."
  360. :group 'jde-compile-options
  361. :type 'boolean)
  362. (defcustom jde-compile-option-nowarn nil
  363. "*Turn off warnings.
  364. If this option is specified, the compiler does not print out any
  365. warnings."
  366. :group 'jde-compile-options
  367. :type 'boolean)
  368. ;;(makunbound 'jde-compile-option-annotation-processors)
  369. (defcustom jde-compile-option-annotation-processors nil
  370. "*Names of the annotation processors to run. This bypasses the default discovery process."
  371. :group 'jde-compile-options
  372. :type '(repeat (string :tag "Name")))
  373. ;;(makunbound 'jde-compile-option-annotation-processing)
  374. (defcustom jde-compile-option-annotation-processing
  375. (list "compile and process annotations")
  376. "*Controls whether annotation processing and/or compilation is done."
  377. :group 'jde-compile-options
  378. :type '(list
  379. (radio-button-choice
  380. :format "%t \n%v"
  381. :tag "Processing:"
  382. (const "compile and process annotations")
  383. (const "compile only")
  384. (const "process annotations only"))))
  385. ;;(makunbound 'jde-compile-option-annotation-processor-options)
  386. (defcustom jde-compile-option-annotation-processor-options nil
  387. "*Options to pass to annotation processors. These are not
  388. interpreted by javac directly, but are made available for use by
  389. individual processors. key should be one or more identifiers
  390. separated by \".\"."
  391. :group 'jde-compile-options
  392. :type '(repeat
  393. (cons :tag "Option"
  394. (string :tag "Key")
  395. (string :tag "Value"))))
  396. (defcustom jde-compile-option-encoding ""
  397. "*Specify the source file encoding name, such as EUCJIS\\SJIS.
  398. If this option is not specified, the platform default converter
  399. is used."
  400. :group 'jde-compile-options
  401. :type 'string)
  402. ;;(makunbound 'jde-compile-option-implicit)
  403. (defcustom jde-compile-option-implicit
  404. (list "Generate and warn")
  405. "*Specify whether to generate class files for source files loaded in
  406. order to get type information needed to compile and/or process
  407. annotations in other files. Options are:
  408. * Generate and warn
  409. Generate class files for source files loaded to get type info for other files.
  410. Do not generate class files for source files needed only to process
  411. annotations. Instead issue a warning.
  412. * Generate and do not warn
  413. Generate class files for source files needed to compile other files. Do
  414. not generate class files for source needed for processing annotions
  415. in other files and do not warn that class files are not generated.
  416. * Do not generate
  417. Do not generate class files for implicitly loaded source files.
  418. "
  419. :group 'jde-compile-options
  420. :type '(list
  421. (radio-button-choice
  422. :format "%t \n%v"
  423. :tag "Processing:"
  424. (const "Generate and warn")
  425. (const "Generate and do not warn")
  426. (const "Do not generate"))))
  427. ;;(makunbound 'jde-compile-option-source)
  428. (defcustom jde-compile-option-source (list "default")
  429. "*Enables JDK version-specific features to be used in
  430. source files.
  431. 1.3 The compiler does not support assertions
  432. 1.4 The compiler accepts code containing assertions.
  433. 1.5 Enables 1.5-specific features.
  434. 1.6 Enables 1.6-specific features.
  435. Select \"default\" to use the source features that
  436. the compiler supports by default, i.e., to not include the -source
  437. switch on the compiler command line. For example, the javac compiler
  438. defaults to 1.3 source features if the -source flag is not
  439. used.
  440. ***NOTE***
  441. This option is supported only by versions of javac shipped
  442. starting with J2SDK 1.4."
  443. :group 'jde-compile-options
  444. :type '(list
  445. (radio-button-choice
  446. :format "%t \n%v"
  447. :tag "Source release:"
  448. (const "default")
  449. (const "1.3")
  450. (const "1.4")
  451. (const "1.5")
  452. (const "1.6"))))
  453. ;;(makunbound 'jde-compile-option-target)
  454. (defcustom jde-compile-option-target (list "default")
  455. "*Generate class files that will work on VMs with the specified version.
  456. 1.1 Ensure that generated class files will be compatible
  457. with 1.1 and 1.2 VMs.
  458. 1.2 Generate class files that will run on 1.2 VMs, but
  459. not on 1.1 VMs.
  460. 1.3 Generate class files that will run on VMs in the
  461. Java 2 SDK, v 1.3 and later, but will not run
  462. on 1.1 or 1.2 VMs
  463. 1.4 Generate class files that are compatible only with
  464. 1.4 VMs.
  465. 1.5 Generate class files that are compatible only with
  466. 1.5 VMs.
  467. 1.6 Generate class files that are compatible only with
  468. 1.6 VMs.
  469. Select \"default\" to use the source features that the compiler
  470. supports by default, i.e., to not include the -target switch on
  471. the compiler command line.
  472. By default, classes are compiled against the bootstrap and extension classes
  473. of the JDK that javac shipped with. But javac also supports cross-compiling,
  474. where classes are compiled against a bootstrap and extension classes of a
  475. different Java platform implementation. It is important to use
  476. `jde-compile-option-bootclasspath' and `jde-compile-option-extdirs' when
  477. cross-compiling."
  478. :group 'jde-compile-options
  479. :type '(list
  480. (radio-button-choice
  481. :format "%t \n%v"
  482. :tag "Target VM:"
  483. (const "default")
  484. (const "1.1")
  485. (const "1.2")
  486. (const "1.3")
  487. (const "1.4")
  488. (const "1.5")
  489. (const "1.6"))))
  490. (defcustom jde-compile-option-bootclasspath nil
  491. "*Cross-compile against the specified set of boot classes.
  492. As with the user class path, boot class path entries can be
  493. directories, JAR archives, or ZIP archives."
  494. :group 'jde-compile-options
  495. :type '(repeat (file :tag "Path")))
  496. (defcustom jde-compile-option-extdirs nil
  497. "*Cross-compile against the specified extension directories.
  498. Each JAR archive in the specified directories is searched for class files."
  499. :group 'jde-compile-options
  500. :type '(repeat (file :tag "Path")))
  501. ;;(makunbound 'jde-compile-option-verbose-path)
  502. (defcustom jde-compile-option-verbose-path nil
  503. "*Describe how paths and standard extensions were searched to find
  504. source and class files.
  505. ***NOTE***
  506. This option is supported only by the versions of javac shipped
  507. with JDK 1.1.x and 1.2.x and oldjavac in JDK 1.3."
  508. :group 'jde-compile-options
  509. :type 'boolean)
  510. (defcustom jde-compile-enable-kill-buffer -1
  511. "* Time in seconds to display the compilation buffer before
  512. `jde-compile-finish-kill-buffer' will kill the compilation buffer.
  513. If less than zero (or nil), do not kill the compilation buffer.
  514. If t (or other non-nil non-number) then kill in 2 secs."
  515. :group 'jde-compile-options
  516. :type 'number)
  517. (defun jde-compile-show-options-buffer ()
  518. "Show the JDE Compile Options panel."
  519. (interactive)
  520. (customize-apropos "jde-compile-options" 'groups))
  521. (defclass jde-compile-server-buffer (bsh-compilation-buffer) ()
  522. "Compiler server buffer.")
  523. (defmethod bsh-compilation-buffer-create-native-buffer ((this jde-compile-server-buffer))
  524. "Creates the native Emacs buffer for the JDEE compile server."
  525. (oset this buffer-name "*JDEE Compile Server*")
  526. (oset this buffer (get-buffer-create (oref this buffer-name))))
  527. (defclass jde-compile-exec-buffer (bsh-compilation-buffer) ()
  528. "Compiler exec buffer.")
  529. (defmethod initialize-instance ((this jde-compile-exec-buffer) &rest fields)
  530. "Constructor for exec compilation buffer instance."
  531. (bsh-compilation-buffer-create-native-buffer this)
  532. (oset
  533. this
  534. filter
  535. (lexical-let ((this-buf this))
  536. (lambda (process output)
  537. (bsh-compilation-buffer-filter this-buf process output))))
  538. (oset this process (get-buffer-process (oref this buffer)))
  539. ;; Make sure this buffer is not associated with a compiler process that is
  540. ;; already running.
  541. (if (oref this process)
  542. (if (or (not (eq (process-status (oref this process)) 'run))
  543. (yes-or-no-p
  544. "A compilation process is running; kill it?"))
  545. (condition-case ()
  546. (progn
  547. (interrupt-process (oref this process))
  548. (sit-for 1)
  549. (delete-process (oref this process)))
  550. (error nil))
  551. (error "Cannot have two processes in `%s' at once"
  552. (oref this buffer-name))))
  553. (bsh-compilation-buffer-set-mode this))
  554. (defmethod bsh-compilation-buffer-create-native-buffer ((this jde-compile-exec-buffer))
  555. "Creates the native Emacs buffer for the JDEE compile server."
  556. (oset this buffer-name "*compilation*")
  557. (oset this buffer (get-buffer-create (oref this buffer-name))))
  558. (defclass jde-compile-compiler ()
  559. ((name :initarg :name
  560. :type string
  561. :documentation
  562. "Name of compiler")
  563. (version :initarg :version
  564. :type string
  565. :documentation
  566. "Compiler version.")
  567. (path :initarg :path
  568. :type string
  569. :documentation
  570. "Path of the compiler executable.")
  571. (buffer :initarg :buffer
  572. :type bsh-compilation-buffer
  573. :documentation
  574. "Compilation buffer")
  575. (window :initarg :window
  576. :type window
  577. :documentation
  578. "Window that displays the compilation buffer.")
  579. (interactive-args :initarg :interactive-args
  580. :type list
  581. :documentation
  582. "Arguments entered in the minibuffer.")
  583. (use-server-p :initarg :use-server-p
  584. :type boolean
  585. :documentation
  586. "Run as a compile server in the Beanshell."))
  587. "Class of Java compilers.")
  588. (defmethod jde-compile-classpath-arg ((this jde-compile-compiler))
  589. "Returns the classpath argument for this compiler."
  590. (let ((classpath
  591. (if jde-compile-option-classpath
  592. jde-compile-option-classpath
  593. (jde-get-global-classpath)))
  594. (symbol
  595. (if jde-compile-option-classpath
  596. 'jde-compile-option-classpath
  597. 'jde-global-classpath)))
  598. (if classpath
  599. (list
  600. "-classpath"
  601. (jde-build-classpath
  602. classpath
  603. symbol)
  604. ))))
  605. (defmethod jde-compile-sourcepath-arg ((this jde-compile-compiler))
  606. "Get the source path argument for this compiler."
  607. (if jde-compile-option-sourcepath
  608. (list
  609. "-sourcepath"
  610. (jde-build-classpath
  611. jde-compile-option-sourcepath
  612. 'jde-compile-option-sourcepath))))
  613. (defmethod jde-compile-bootclasspath-arg ((this jde-compile-compiler))
  614. "Get the boot classpath argument for this compiler."
  615. (if jde-compile-option-bootclasspath
  616. (list
  617. "-bootclasspath"
  618. (jde-build-classpath jde-compile-option-bootclasspath
  619. 'jde-compile-option-bootclasspath))))
  620. (defmethod jde-compile-extdirs-arg ((this jde-compile-compiler))
  621. "Get the extdirs argument for this compiler."
  622. (if jde-compile-option-extdirs
  623. (list
  624. "-extdirs"
  625. (jde-build-classpath
  626. jde-compile-option-extdirs
  627. 'jde-compile-option-extdirs))))
  628. (defmethod jde-compile-encoding-arg ((this jde-compile-compiler))
  629. (if (not (string= jde-compile-option-encoding ""))
  630. (list
  631. "-encoding"
  632. jde-compile-option-encoding)))
  633. (defmethod jde-compile-debug-arg ((this jde-compile-compiler))
  634. "Get the debug arg for this compiler."
  635. (let* ((include-option (nth 0 jde-compile-option-debug))
  636. (selected (nth 1 jde-compile-option-debug))
  637. (lines (nth 0 selected))
  638. (vars (nth 1 selected))
  639. (src (nth 2 selected)))
  640. (cond
  641. ((and
  642. (string= include-option "selected")
  643. lines
  644. (not vars)
  645. (not src))
  646. nil)
  647. ((string= include-option "all")
  648. (list "-g"))
  649. ((string= include-option "none")
  650. (list "-g:none"))
  651. ((and
  652. (string= include-option "selected")
  653. (or lines vars src))
  654. (list
  655. (concat
  656. "-g:"
  657. (if lines
  658. (if (or vars src) "lines,"
  659. "lines"))
  660. (if vars
  661. (if vars
  662. (if src "vars," "vars")))
  663. (if src "source")))))))
  664. (defmethod jde-compile-output-dir-arg ((this jde-compile-compiler))
  665. "Get the ouput directory arg for this compiler."
  666. (if (not (string= jde-compile-option-directory ""))
  667. (list
  668. "-d"
  669. (jde-normalize-path 'jde-compile-option-directory))))
  670. (defmethod jde-compile-deprecation-arg ((this jde-compile-compiler))
  671. "Get deprecation argument for this compiler."
  672. (if jde-compile-option-deprecation
  673. (list "-deprecation")))
  674. (defmethod jde-compile-optimize-arg ((this jde-compile-compiler))
  675. "Get optimization argument for this compiler."
  676. (if jde-compile-option-optimize
  677. (list "-O")))
  678. (defmethod jde-compile-depend-arg ((this jde-compile-compiler))
  679. "Get dependency-checking argument for this compiler."
  680. (if jde-compile-option-depend
  681. (list (car jde-compile-option-depend-switch))))
  682. (defmethod jde-compile-vm-args ((this jde-compile-compiler))
  683. "Get arguments to pass to the vm used to run this compiler."
  684. (if jde-compile-option-vm-args
  685. (mapcan
  686. (lambda (arg)
  687. (list (concat "-J" arg)))
  688. jde-compile-option-vm-args)))
  689. (defmethod jde-compile-verbose-arg ((this jde-compile-compiler))
  690. "Get verbosity level argument for this compiler."
  691. (if jde-compile-option-verbose
  692. (list "-verbose")))
  693. (defmethod jde-compile-verbose-path-arg ((this jde-compile-compiler))
  694. "Get verbose path argument for this compiler."
  695. (if jde-compile-option-verbose-path
  696. (list "-Xverbosepath")))
  697. (defmethod jde-compile-nowarn-arg ((this jde-compile-compiler))
  698. "Get no warning argument for this compiler."
  699. (if jde-compile-option-nowarn
  700. (list "-nowarn")))
  701. (defmethod jde-compile-command-line-args ((this jde-compile-compiler))
  702. "Get additional command line arguments for this compiler."
  703. jde-compile-option-command-line-args)
  704. (defmethod jde-compile-target-arg ((this jde-compile-compiler))
  705. "Get compiler target argument for this compiler."
  706. (let ((target (car jde-compile-option-target)))
  707. (if (not (string= target "default"))
  708. (list "-target" target))))
  709. (defmethod jde-compile-source-arg ((this jde-compile-compiler))
  710. "Get compiler source argument for this compiler."
  711. (let ((source (car jde-compile-option-source)))
  712. (if (not (string= source "default"))
  713. (list "-source" source))))
  714. (defmethod jde-compile-get-args ((this jde-compile-compiler))
  715. (append
  716. (jde-compile-classpath-arg this)
  717. (jde-compile-sourcepath-arg this)
  718. (jde-compile-bootclasspath-arg this)
  719. (jde-compile-extdirs-arg this)
  720. (jde-compile-encoding-arg this)
  721. (jde-compile-debug-arg this)
  722. (jde-compile-output-dir-arg this)
  723. (jde-compile-deprecation-arg this)
  724. (jde-compile-optimize-arg this)
  725. (jde-compile-depend-arg this)
  726. (jde-compile-vm-args this)
  727. (jde-compile-verbose-arg this)
  728. (jde-compile-verbose-path-arg this)
  729. (jde-compile-nowarn-arg this)
  730. (jde-compile-target-arg this)
  731. (jde-compile-source-arg this)
  732. (jde-compile-command-line-args this)))
  733. (defmethod jde-compile-run-exec ((this jde-compile-compiler))
  734. (let* ((outbuf (oref (oref this buffer) buffer))
  735. (compiler-path (oref this :path))
  736. (source-file (file-name-nondirectory buffer-file-name))
  737. (flag nil)
  738. (args (append
  739. (jde-compile-get-args this)
  740. (oref this :interactive-args)
  741. (list source-file))))
  742. (save-excursion
  743. (set-buffer outbuf)
  744. (let ((inhibit-read-only t)) ; make compilation buffer temporarily writable
  745. (insert (format "cd %s\n" default-directory))
  746. (insert (concat
  747. compiler-path
  748. " "
  749. (mapconcat (lambda (x)
  750. (if (and flag
  751. jde-compile-option-hide-classpath)
  752. (progn
  753. (setq flag nil)
  754. "...")
  755. (if (not (string= x "-classpath"))
  756. x
  757. (progn
  758. (setq flag t)
  759. x)))) args " ")
  760. "\n\n")))
  761. (let* ((process-environment (cons "EMACS=t" process-environment))
  762. (w32-quote-process-args ?\")
  763. (win32-quote-process-args ?\") ;; XEmacs
  764. (proc (apply 'start-process
  765. (downcase mode-name)
  766. outbuf
  767. compiler-path
  768. args)))
  769. (set-process-sentinel proc 'compilation-sentinel)
  770. (set-process-filter proc 'compilation-filter)
  771. (set-marker (process-mark proc) (point) outbuf)
  772. (setq compilation-in-progress
  773. (cons proc compilation-in-progress))))))
  774. (defmethod jde-compile-run-server ((this jde-compile-compiler))
  775. (let* ((directory-sep-char ?/)
  776. (args
  777. (append
  778. (jde-compile-get-args this)))
  779. (source-path
  780. (jde-normalize-path buffer-file-name))
  781. (arg-array (concat "new String[] {\"" source-path "\"")))
  782. (if args
  783. (setq arg-array
  784. (concat
  785. arg-array
  786. ","
  787. (mapconcat
  788. (lambda (arg)
  789. (concat "\"" arg "\""))
  790. args
  791. ","))))
  792. (setq arg-array (concat arg-array "}"))
  793. (save-excursion
  794. (set-buffer (oref (oref this buffer) buffer))
  795. (insert "CompileServer output:\n\n")
  796. (let* ((inhibit-read-only t)
  797. flag
  798. (arg-string
  799. (mapconcat
  800. (lambda (x)
  801. (if (and flag
  802. jde-compile-option-hide-classpath)
  803. (progn
  804. (setq flag nil)
  805. "...")
  806. (if (not (string= x "-classpath"))
  807. x
  808. (progn
  809. (setq flag t)
  810. x))))
  811. args " ")))
  812. (insert arg-string " " source-path "\n")))
  813. (if (not (jde-bsh-running-p))
  814. (progn
  815. (bsh-launch (oref 'jde-bsh the-bsh))
  816. (bsh-eval (oref 'jde-bsh the-bsh) (jde-create-prj-values-str))))
  817. (bsh-buffer-eval
  818. (oref 'jde-bsh the-bsh)
  819. (concat
  820. (format
  821. "jde.util.CompileServer.compile(%s);"
  822. arg-array)
  823. "\n")
  824. (oref this buffer))))
  825. (defmethod jde-compile-launch ((this jde-compile-compiler))
  826. (if (oref this :use-server-p)
  827. (jde-compile-run-server this)
  828. (jde-compile-run-exec this))
  829. (set-buffer-modified-p nil))
  830. (defmethod jde-compile-compile ((this jde-compile-compiler))
  831. (if (oref this :use-server-p)
  832. (oset this buffer (jde-compile-server-buffer "compilation buffer"))
  833. (oset this buffer (jde-compile-exec-buffer "compilation buffer")))
  834. ;; Pop to compilation buffer.
  835. (let* ((outbuf (oref (oref this buffer) buffer))
  836. (outwin (display-buffer outbuf)))
  837. (compilation-set-window-height outwin)
  838. (oset this :window outwin)
  839. (if (not jde-xemacsp)
  840. (if compilation-process-setup-function
  841. (funcall compilation-process-setup-function)))
  842. (jde-compile-launch this)
  843. (setq compilation-last-buffer outbuf)))
  844. (defclass jde-compile-javac (jde-compile-compiler)
  845. ()
  846. "Class of javac compilers.")
  847. (defmethod initialize-instance ((this jde-compile-javac) &rest fields)
  848. ;; Call parent initializer.
  849. (call-next-method)
  850. ;; Set compiler name.
  851. (oset this name "javac")
  852. )
  853. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  854. ;; ;;
  855. ;; JDK 1.1 Compiler ;;
  856. ;; ;;
  857. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  858. (defclass jde-compile-javac-11 (jde-compile-compiler)
  859. ()
  860. "Class of JDK 1.1 javac compilers.")
  861. (defmethod initialize-instance ((this jde-compile-javac-11) &rest fields)
  862. ;; Call parent initializer.
  863. (call-next-method)
  864. ;; Set compiler version.
  865. (oset this version "1.1"))
  866. (defmethod jde-compile-debug-arg ((this jde-compile-javac-11))
  867. "Get the debug arg for this compiler."
  868. (let ((include-option (nth 0 jde-compile-option-debug)))
  869. (cond
  870. ((string= include-option "all")
  871. (list "-g"))
  872. ((string= include-option "selected")
  873. (error "JDK 1.1 version of javac does not support selected debug info.")))))
  874. (defmethod jde-compile-depend-arg ((this jde-compile-javac-11))
  875. "Get dependency-checking argument for this compiler."
  876. (if jde-compile-option-depend
  877. (list "-depend")))
  878. (defmethod jde-compile-get-args ((this jde-compile-javac-11))
  879. (append
  880. (jde-compile-classpath-arg this)
  881. (jde-compile-encoding-arg this)
  882. (jde-compile-debug-arg this)
  883. (jde-compile-output-dir-arg this)
  884. (jde-compile-deprecation-arg this)
  885. (jde-compile-optimize-arg this)
  886. (jde-compile-depend-arg this)
  887. (jde-compile-vm-args this)
  888. (jde-compile-verbose-arg this)
  889. (jde-compile-nowarn-arg this)
  890. (jde-compile-command-line-args this)))
  891. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  892. ;; ;;
  893. ;; JDK 1.2 Compiler ;;
  894. ;; ;;
  895. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  896. (defclass jde-compile-javac-12 (jde-compile-compiler)
  897. ()
  898. "Class of JDK 1.2 javac compilers.")
  899. (defmethod initialize-instance ((this jde-compile-javac-12) &rest fields)
  900. ;; Call parent initializer.
  901. (call-next-method)
  902. ;; Set compiler version.
  903. (oset this version "1.2"))
  904. (defmethod jde-compile-depend-arg ((this jde-compile-javac-12))
  905. "Get dependency-checking argument for this compiler."
  906. (if jde-compile-option-depend
  907. (list "-Xdepend")))
  908. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  909. ;; ;;
  910. ;; JDK 1.3 Compiler ;;
  911. ;; ;;
  912. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  913. (defclass jde-compile-javac-13 (jde-compile-javac-12)
  914. ()
  915. "Class of JDK 1.3 javac compilers.")
  916. (defmethod initialize-instance ((this jde-compile-javac-13) &rest fields)
  917. ;; Call parent initializer.
  918. (call-next-method)
  919. ;; Set compiler version.
  920. (oset this version "1.3"))
  921. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  922. ;; ;;
  923. ;; JDK 1.4 Compiler ;;
  924. ;; ;;
  925. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  926. (defclass jde-compile-javac-14 (jde-compile-javac-13)
  927. ()
  928. "Class of JDK 1.4 javac compilers.")
  929. (defmethod initialize-instance ((this jde-compile-javac-14) &rest fields)
  930. ;; Call parent initializer.
  931. (call-next-method)
  932. ;; Set compiler version.
  933. (oset this version "1.4"))
  934. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  935. ;; ;;
  936. ;; J2SDK 1.5 Compiler ;;
  937. ;; ;;
  938. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  939. (defclass jde-compile-javac-15 (jde-compile-javac-14)
  940. ()
  941. "Class of J2SDK 1.5 javac compilers.")
  942. (defmethod initialize-instance ((this jde-compile-javac-15) &rest fields)
  943. ;; Call parent initializer.
  944. (call-next-method)
  945. ;; Set compiler version.
  946. (oset this version "1.5"))
  947. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  948. ;; ;;
  949. ;; J2SDK 1.6 Compiler ;;
  950. ;; ;;
  951. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  952. (defclass jde-compile-javac-16 (jde-compile-javac-15)
  953. ()
  954. "Class of JDK 1.6 javac compilers.")
  955. (defmethod initialize-instance ((this jde-compile-javac-16) &rest fields)
  956. ;; Call parent initializer.
  957. (call-next-method)
  958. ;; Set compiler version.
  959. (oset this version "1.6"))
  960. (defmethod jde-compile-annotation-processors-arg ((this jde-compile-javac-16))
  961. "Get the annotation processors argument for this compiler."
  962. (if jde-compile-option-annotation-processors
  963. (list
  964. "-processor"
  965. (mapconcat 'identity
  966. jde-compile-option-annotation-processors
  967. ","))))
  968. (defmethod jde-compile-annotation-processing-arg ((this jde-compile-javac-16))
  969. (let ((option (car jde-compile-option-annotation-processing)))
  970. (cond
  971. ((string= option "compile and process annotations")
  972. nil)
  973. ((string= option "compile only")
  974. (list "-proc:none"))
  975. ((string= option "process annotations only")
  976. (list "-proc:only")))))
  977. (defmethod jde-compile-annotation-processor-options-args ((this jde-compile-javac-16))
  978. "Get property arguments."
  979. (mapcar
  980. (lambda (option)
  981. (let ((key (car option))
  982. (value (cdr option)))
  983. (if (string= value "")
  984. (format "-A%s" key)
  985. (format "-A%s=%s" key value))))
  986. jde-compile-option-annotation-processor-options))
  987. (defmethod jde-compile-implicit-arg ((this jde-compile-javac-16))
  988. (let ((option (car jde-compile-option-implicit)))
  989. (cond
  990. ((string= option "Generate and warn")
  991. nil)
  992. ((string= option "Generate and do not warn")
  993. (list "-implicit:class"))
  994. ((string= option "Do not generate")
  995. (list "-implicit:none")))))
  996. (defmethod jde-compile-get-args ((this jde-compile-javac-16))
  997. (append
  998. (jde-compile-classpath-arg this)
  999. (jde-compile-sourcepath-arg this)
  1000. (jde-compile-bootclasspath-arg this)
  1001. (jde-compile-extdirs-arg this)
  1002. (jde-compile-encoding-arg this)
  1003. (jde-compile-debug-arg this)
  1004. (jde-compile-output-dir-arg this)
  1005. (jde-compile-deprecation-arg this)
  1006. (jde-compile-optimize-arg this)
  1007. (jde-compile-depend-arg this)
  1008. (jde-compile-annotation-processing-arg this)
  1009. (jde-compile-annotation-processors-arg this)
  1010. (jde-compile-annotation-processor-options-args this)
  1011. (jde-compile-implicit-arg this)
  1012. (jde-compile-vm-args this)
  1013. (jde-compile-verbose-arg this)
  1014. (jde-compile-nowarn-arg this)
  1015. (jde-compile-target-arg this)
  1016. (jde-compile-source-arg this)
  1017. (jde-compile-command-line-args this)))
  1018. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1019. ;; ;;
  1020. ;; Eclipse Compiler ;;
  1021. ;; ;;
  1022. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1023. (defclass jde-compile-ejc-server (jde-compile-compiler)
  1024. ()
  1025. "Class for using the Eclipse java compiler as a JDEE compile server."
  1026. )
  1027. (defmethod jde-compile-run-server ((this jde-compile-ejc-server))
  1028. (let* ((directory-sep-char ?/)
  1029. (args
  1030. (append
  1031. (list
  1032. "-Xemacs"
  1033. "-noExit"
  1034. ;; "-sourcepath"
  1035. ;; (mapconcat 'identity (jde-expand-wildcards-and-normalize jde-sourcepath) ":")
  1036. )
  1037. (jde-compile-get-args this)))
  1038. (source-path
  1039. (jde-normalize-path buffer-file-name))
  1040. (arg-array (concat "new String[] {\"" source-path "\"")))
  1041. (if args
  1042. (setq arg-array
  1043. (concat
  1044. arg-array
  1045. ","
  1046. (mapconcat
  1047. (lambda (arg)
  1048. (concat "\"" arg "\""))
  1049. args
  1050. ","))))
  1051. (setq arg-array (concat arg-array "}"))
  1052. (save-excursion
  1053. (set-buffer (oref (oref this buffer) buffer))
  1054. (insert "CompileServer output:\n\n")
  1055. (let (flag temp)
  1056. (setq temp
  1057. (mapconcat
  1058. (lambda (x)
  1059. (if (and flag
  1060. jde-compile-option-hide-classpath)
  1061. (progn
  1062. (setq flag nil)
  1063. "...")
  1064. (if (not (string= x "-classpath"))
  1065. x
  1066. (progn
  1067. (setq flag t)
  1068. x)))) args " "))
  1069. (insert temp " "))
  1070. (insert source-path "\n"))
  1071. (if (not (jde-bsh-running-p))
  1072. (progn
  1073. (bsh-launch (oref 'jde-bsh the-bsh))
  1074. (bsh-eval (oref 'jde-bsh the-bsh) (jde-create-prj-values-str))))
  1075. (bsh-eval (oref 'jde-bsh the-bsh)
  1076. (format "addClassPath(\"%s\");" (oref this :path)))
  1077. (bsh-buffer-eval
  1078. (oref 'jde-bsh the-bsh)
  1079. (concat
  1080. (format
  1081. "if ((new org.eclipse.jdt.internal.compiler.batch.Main(new java.io.PrintWriter(System.out), new java.io.PrintWriter(System.out), true, null, null)).compile(%s)) { print (\"0\");} else {print (\"1\");};"
  1082. arg-array)
  1083. "\n")
  1084. (oref this buffer))))
  1085. (defvar jde-compile-javac-compilers
  1086. (list
  1087. (jde-compile-javac-11 "javac 1.1.x")
  1088. (jde-compile-javac-12 "javac 1.2.x")
  1089. (jde-compile-javac-13 "javac 1.3.x")
  1090. (jde-compile-javac-14 "javac 1.4.x")
  1091. (jde-compile-javac-15 "javac 1.5.x")
  1092. (jde-compile-javac-16 "javac 1.6.x"))
  1093. "List of supported javac compilers.")
  1094. (defun jde-compile-get-javac ()
  1095. (let* ((jdk-version (jde-java-version))
  1096. (jdk-split-version (split-string jdk-version "[.]"))
  1097. (jdk-major-version (nth 0 jdk-split-version))
  1098. (jdk-minor-version (nth 1 jdk-split-version))
  1099. (compiler
  1100. (find-if
  1101. (lambda (compiler-x)
  1102. (let* ((compiler-split-version (split-string (oref compiler-x :version) "[.]"))
  1103. (compiler-major-version (nth 0 compiler-split-version))
  1104. (compiler-minor-version (nth 1 compiler-split-version)))
  1105. (and
  1106. (string= jdk-major-version compiler-major-version)
  1107. (string= jdk-minor-version compiler-minor-version))))
  1108. jde-compile-javac-compilers)))
  1109. (unless compiler
  1110. (let ((latest-javac (car (last jde-compile-javac-compilers))))
  1111. (if
  1112. (yes-or-no-p
  1113. (format "The JDE does not recognize JDK %s javac. Assume JDK %s javac?"
  1114. jdk-version (oref latest-javac :version)))
  1115. (setq compiler latest-javac))))
  1116. (if compiler
  1117. (if (string= (car jde-compiler) "javac server")
  1118. (oset compiler :use-server-p t)
  1119. (progn
  1120. (oset compiler :use-server-p nil)
  1121. (oset compiler
  1122. :path
  1123. (let ((compiler-path
  1124. (if (listp (car jde-compiler))
  1125. (substitute-in-file-name (nth 1 (car jde-compiler)))
  1126. "")))
  1127. (if (string= compiler-path "")
  1128. (setq compiler-path (jde-get-jdk-prog 'javac))
  1129. (if (file-exists-p compiler-path)
  1130. compiler-path
  1131. (error (format "Invalid compiler path %s"
  1132. compiler-path)))))))))
  1133. compiler))
  1134. (defun jde-compile-get-ejc ()
  1135. "Get the ejc compiler object."
  1136. (let ((compiler-path
  1137. (substitute-in-file-name (nth 1 (car jde-compiler)))))
  1138. (if (string= compiler-path "")
  1139. (error "Cannot find jdt core jar"))
  1140. (jde-compile-ejc-server
  1141. "Eclipse java compiler server"
  1142. :use-server-p t
  1143. :path compiler-path)))
  1144. (defun jde-compile-get-the-compiler ()
  1145. "Get a compiler object that represents the compiler specified
  1146. by `jde-compiler'."
  1147. (let* ((car-jde-compiler (car jde-compiler))
  1148. (compiler-name (if (listp car-jde-compiler) (car car-jde-compiler) car-jde-compiler)))
  1149. (cond
  1150. ((string-match "javac" compiler-name)
  1151. (jde-compile-get-javac))
  1152. ((string-match "eclipse java compiler server" compiler-name)
  1153. (jde-compile-get-ejc))
  1154. (t
  1155. (error "The JDEE does not support a compiler named %s" compiler-name)))))
  1156. ;;;###autoload
  1157. (defun jde-set-compile-options (options)
  1158. "Sets the compile options.
  1159. Enter the options as you would on the command line, e.g.,
  1160. -depend -verbose."
  1161. (interactive
  1162. "sEnter options: ")
  1163. (setq jde-compile-option-command-line-args (split-string options " ")))
  1164. ;;;###autoload
  1165. (defun jde-compile ()
  1166. "Compile the Java program in the current buffer.
  1167. This command invokes the compiler specified by `jde-compiler'
  1168. with the options specified by the JDE customization variables
  1169. that begin with `jde-compile'. If the variable
  1170. `jde-read-compile-args' is non-nil, this command reads
  1171. additional compilation options from the minibuffer, with
  1172. history enabled. If `jde-compiler' specifies the JDE compile
  1173. server, this command uses the compile server. Otherwise, it
  1174. uses the compiler executable specified by
  1175. `jde-compiler' to compile."
  1176. (interactive)
  1177. (if jde-read-compile-args
  1178. (setq jde-interactive-compile-args
  1179. (read-from-minibuffer
  1180. "Compile args: "
  1181. jde-interactive-compile-args
  1182. nil nil
  1183. '(jde-interactive-compile-arg-history . 1))))
  1184. ;; Force save-some-buffers to use the minibuffer
  1185. ;; to query user about whether to save modified buffers.
  1186. ;; Otherwise, when user invokes jde-compile from
  1187. ;; menu, save-some-buffers tries to popup a menu
  1188. ;; which seems not to be supported--at least on
  1189. ;; the PC.
  1190. (if (and (eq system-type 'windows-nt)
  1191. (not jde-xemacsp))
  1192. (let ((temp last-nonmenu-event))
  1193. ;; The next line makes emacs think that jde-compile
  1194. ;; was invoked from the minibuffer, even when it
  1195. ;; is actually invoked from the menu-bar.
  1196. (setq last-nonmenu-event t)
  1197. (save-some-buffers (not compilation-ask-about-save) nil)
  1198. (setq last-nonmenu-event temp))
  1199. (save-some-buffers (not compilation-ask-about-save) nil))
  1200. (setq compilation-finish-function
  1201. (lambda (buf msg)
  1202. (run-hook-with-args 'jde-compile-finish-hook buf msg)
  1203. (setq compilation-finish-function nil)))
  1204. (let ((compiler (jde-compile-get-the-compiler)))
  1205. (if compiler
  1206. (progn
  1207. (oset compiler
  1208. :interactive-args
  1209. (if (and jde-interactive-compile-args
  1210. (not (string= jde-interactive-compile-args "")))
  1211. (split-string jde-interactive-compile-args " ")))
  1212. (jde-compile-compile compiler))
  1213. (error "Unknown compiler. Aborting compilation."))))
  1214. (provide 'jde-compile)
  1215. ;; End of jde-compile.el