branch: master commit dee73ff2a96883c7c911967772ede4a453796aec Author: Filipp Gunbin <fgun...@fastmail.fm> Commit: Filipp Gunbin <fgun...@fastmail.fm>
[javaimp] Fix gradle project id output & parsing. * packages/javaimp/gradleTaskBody.inc.kts: Output project's path which is unique instead of name. Check for java plugin instead of archivesBaseName. * packages/javaimp/javaimp-gradle.el (javaimp--gradle-module-from-alist, javaimp--gradle-id-from-semi-separated): Parse path as id. --- packages/javaimp/gradleTaskBody.inc.kts | 22 ++++++++++------------ packages/javaimp/javaimp-gradle.el | 25 +++++++++++++++---------- packages/javaimp/javaimp-util.el | 2 +- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/packages/javaimp/gradleTaskBody.inc.kts b/packages/javaimp/gradleTaskBody.inc.kts index 697e743..942814f 100644 --- a/packages/javaimp/gradleTaskBody.inc.kts +++ b/packages/javaimp/gradleTaskBody.inc.kts @@ -1,21 +1,18 @@ // use syntax which is valid both in Groovy and in Kotlin doLast { - println("id=${project.group}:${project.name}:${project.version}") + println("id=${project.group};${project.path};${project.version}") if (project.parent != null) { - println("parent-id=${project.parent.group}:${project.parent.name}:${project.parent.version}") + println("parent-id=${project.parent.group};${project.parent.path};${project.parent.version}") } println("file=${project.buildFile}") - if (project.hasProperty("archivesBaseName")) { // defined by java plugin - println("final-name=" + project.configurations.getByName("archives").artifacts.stream() - .filter { it.type.equals("jar") || it.type.equals("war") } - .map { it.file.path } - .findFirst() - .orElse("")) - } else { - println("final-name=") - } println("build-dir=${project.buildDir}") - if (project.hasProperty("sourceSets")) { // defined by java plugin + if (project.pluginManager.hasPlugin("java")) { + // "archives" configuration and "sourceSets" property defined by java plugin + println("final-name=" + project.configurations.getByName("archives").artifacts.stream() + .filter { it.type.equals("jar") || it.type.equals("war") } + .map { it.file.path } + .findFirst() + .orElse("")) println("source-dirs=" + project.sourceSets.stream() .flatMap { it.allJava.srcDirs.stream().map { it.path } } .collect(Collectors.joining(File.pathSeparator))) @@ -23,6 +20,7 @@ doLast { .flatMap { it.compileClasspath.files.stream().filter { it.name.endsWith("jar") }.map { it.path } } .collect(Collectors.joining(File.pathSeparator))) } else { + println("final-name=") println("source-dirs=") println("dep-jars=") } diff --git a/packages/javaimp/javaimp-gradle.el b/packages/javaimp/javaimp-gradle.el index 77c7dae..74a956a 100644 --- a/packages/javaimp/javaimp-gradle.el +++ b/packages/javaimp/javaimp-gradle.el @@ -48,10 +48,8 @@ information." (modules (mapcar (lambda (alist) (javaimp--gradle-module-from-alist alist file)) alists))) - (prog1 - ;; first module is always root - (javaimp--build-tree (car modules) nil modules) - (message "Loaded tree for %s" file)))) + ;; first module is always root + (javaimp--build-tree (car modules) nil modules))) (defun javaimp--gradle-handler () (goto-char (point-min)) @@ -71,8 +69,8 @@ information." (defun javaimp--gradle-module-from-alist (alist file-orig) (make-javaimp-module - :id (javaimp--gradle-id-from-colon-separated (cdr (assq 'id alist))) - :parent-id (javaimp--gradle-id-from-colon-separated (cdr (assq 'parent-id alist))) + :id (javaimp--gradle-id-from-semi-separated (cdr (assq 'id alist))) + :parent-id (javaimp--gradle-id-from-semi-separated (cdr (assq 'parent-id alist))) :file (cdr (assq 'file alist)) :file-orig file-orig ;; jar/war supported @@ -91,12 +89,19 @@ information." :load-ts (current-time) :dep-jars-path-fetcher #'javaimp--gradle-fetch-dep-jars-path)) -(defun javaimp--gradle-id-from-colon-separated (str) +(defun javaimp--gradle-id-from-semi-separated (str) (when str - (let ((parts (split-string str ":" t))) + (let ((parts (split-string str ";" t)) artifact) (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))))) + (error "Invalid project id: %s" str)) + (setq artifact (nth 1 parts)) + (if (equal artifact ":") + (setq artifact "<root>") + ;; convert "[:]foo:bar:baz" into "foo.bar.baz" + (setq artifact (replace-regexp-in-string + ":" "." (string-remove-prefix ":" artifact)))) + (make-javaimp-id :group (nth 0 parts) :artifact artifact + :version (nth 2 parts))))) (defun javaimp--gradle-fetch-dep-jars-path (module) ;; always invoke on root file becase module's file may not exist diff --git a/packages/javaimp/javaimp-util.el b/packages/javaimp/javaimp-util.el index 2284ddd..8e1a06c 100644 --- a/packages/javaimp/javaimp-util.el +++ b/packages/javaimp/javaimp-util.el @@ -144,7 +144,7 @@ buffer and returns its result" (split-string converted sep-regex t)))) (defun javaimp--build-tree (this parent-node all) - (message "Building tree for module: %s" (javaimp-module-id this)) + (message "Building tree for module: %s" (javaimp-print-id (javaimp-module-id this))) (let ((children ;; more or less reliable way to find children is to look for ;; modules with "this" as the parent