[elpa] branch scratch/javaimp-gradle created (now edc0e55)

2019-10-23 Thread Filipp Gunbin
fgunbin pushed a change to branch scratch/javaimp-gradle.

at  edc0e55   packages/javaimp: Support gradle (wip)

This branch includes the following new commits:

   new  edc0e55   packages/javaimp: Support gradle (wip)




[elpa] scratch/javaimp-gradle edc0e55: packages/javaimp: Support gradle (wip)

2019-10-23 Thread Filipp Gunbin
branch: scratch/javaimp-gradle
commit edc0e55b4292985fa0ceaf47dc767fbb524f6e8d
Author: Filipp Gunbin 
Commit: Filipp Gunbin 

packages/javaimp: Support gradle (wip)
---
 packages/javaimp/javaimp-gradle.el | 135 ++
 packages/javaimp/javaimp-maven.el  | 170 +
 packages/javaimp/javaimp-tests.el  |  14 +-
 packages/javaimp/javaimp-util.el   | 131 +
 packages/javaimp/javaimp.el| 366 +++--
 5 files changed, 505 insertions(+), 311 deletions(-)

diff --git a/packages/javaimp/javaimp-gradle.el 
b/packages/javaimp/javaimp-gradle.el
new file mode 100644
index 000..2bf8e8e
--- /dev/null
+++ b/packages/javaimp/javaimp-gradle.el
@@ -0,0 +1,135 @@
+;;; javaimp-gradle.el --- javaimp gradle support  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2019  Free Software Foundation, Inc.
+
+;; Author: Filipp Gunbin 
+;; Maintainer: Filipp Gunbin 
+;; Version: 0.6.1
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see .
+
+(require 'javaimp-util)
+
+(defcustom javaimp-gradle-program "gradle"
+  "Path to the `gradle' program.  Customize it if the program is
+not on `exec-path'.")
+
+(defun javaimp--gradle-visit (file)
+  "Calls gradle on FILE to get various project information.
+
+Passes specially crafted init file as -I argument to gradle and
+invokes task contained in it.  This task returns all needed
+information."
+  (message "Visiting Gradle build file %s..." file)
+  (let* ((init-file (make-temp-file "javaimp" nil ".kts"
+javaimp--gradle-init-file-contents))
+ (modules
+ (javaimp--call-build-tool javaimp-gradle-program
+#'javaimp--gradle-handler
+"-q"
+"-b" (javaimp-cygpath-convert-maybe file)
+"-I" (javaimp-cygpath-convert-maybe 
init-file)
+"javaimpTask")))
+(prog1
+;; first module is always root
+(javaimp--build-tree (car modules) nil modules))
+(message "Loaded tree for %s" file)))
+
+(defun javaimp--gradle-handler ()
+  (goto-char (point-min))
+  (let (modules alist pair sym val)
+(while (not (eobp))
+  (setq pair (split-string (thing-at-point 'line) "="))
+  (unless (= (length pair) 2)
+(error "Invalid pair from gradle output: %s" pair))
+  (setq sym (intern (car pair))
+val (cadr pair))
+  (when (and (eq sym 'id) alist);start of next module
+(push (javaimp--gradle-module-from-alist alist) modules)
+(setq alist nil))
+  (push (cons sym val) alist)
+  (forward-line 1))
+(when alist ;last module
+  (push (javaimp--gradle-module-from-alist alist) modules))
+modules))
+
+(defun javaimp--gradle-module-from-alist (alist)
+  (make-javaimp-module
+   :id (javaimp--gradle-id-from-colon-separated (cadr (assq 'id alist)))
+   :parent-id (javaimp--gradle-id-from-colon-separated (cadr (assq 'parent-id 
alist)))
+   :file (cadr (assq 'file alist))
+   :final-name (cadr (assq 'final-name alist))
+   :packaging "jar" ;TODO
+   :source-dir (file-name-as-directory
+(javaimp-cygpath-convert-maybe
+ (cadr (assq 'source-dir alist
+   :test-source-dir (file-name-as-directory
+ (javaimp-cygpath-convert-maybe
+  (cadr (assq 'test-source-dir alist
+   :build-dir (file-name-as-directory
+   (javaimp-cygpath-convert-maybe
+(cadr (assq 'build-dir alist
+   :dep-jars (javaimp--split-native-path (cadr (assq 'dep-jars alist)))
+   :load-ts (current-time)
+   :dep-jars-path-fetcher #'javaimp--gradle-fetch-dep-jars-path))
+
+(defun javaimp--gradle-id-from-colon-separated (str)
+  (when str
+(let ((parts (split-string str ":")))
+  (unless (= (length parts) 3)
+(error "Invalid maven id: %s" str))
+  (make-javaimp-id :group (nth 0 parts) :artifact (nth 1 parts) :version 
(nth 2 parts)
+
+
+(defun javaimp--gradle-fetch-dep-jars-path (file)
+  (let ((init-file (make-temp-file "javaimp" nil ".kts"
+   
javaimp--gradle-init-file-contents-dep-jars-only)))
+(javaimp--call-build-tool javaimp-gradle-program
+  (lamb