From 3eccb21cd7840e44a5ce8e96f6d21e994b555bd8 Mon Sep 17 00:00:00 2001 From: Luis Marsano Date: Tue, 7 May 2019 03:05:36 -0400 Subject: [PATCH 1/2] test gradle projects add tests for gradle DSLs - groovy - kotlin import fails for gradle kotlin DSL --- features/ImportProject.feature | 16 +++++++++ features/step-definitions/lsp-java-steps.el | 39 ++++++++++++++++++--- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/features/ImportProject.feature b/features/ImportProject.feature index dbf840b..9b625f6 100644 --- a/features/ImportProject.feature +++ b/features/ImportProject.feature @@ -7,3 +7,19 @@ Feature: Importing projects And I add project "m" folder "tmp" to the list of workspace folders And I start lsp-java Then The server status must become "LSP::Started" + + Scenario: Gradle Groovy DSL projects + Given I have gradle groovy DSL project "m" in "tmp" + And I have a java file "tmp/m/src/main/java/temp/App.java" + And I clear the buffer + And I add project "m" folder "tmp" to the list of workspace folders + And I start lsp-java + Then The server status must become "LSP::Started" + + Scenario: Gradle Kotlin DSL projects + Given I have gradle kotlin DSL project "m" in "tmp" + And I have a java file "tmp/m/src/main/java/temp/App.java" + And I clear the buffer + And I add project "m" folder "tmp" to the list of workspace folders + And I start lsp-java + Then The server status must become "LSP::Started" diff --git a/features/step-definitions/lsp-java-steps.el b/features/step-definitions/lsp-java-steps.el index 5d7b4ee..412fe7d 100644 --- a/features/step-definitions/lsp-java-steps.el +++ b/features/step-definitions/lsp-java-steps.el @@ -39,8 +39,7 @@ (setq retry-count (1+ retry-count)) (message "The function failed, attempt %s" retry-count))))))) -(Given "^I have maven project \"\\([^\"]+\\)\" in \"\\([^\"]+\\)\"$" - (lambda (project-name dir-name) +(defun lsp-java-steps-project (project-name dir-name config-name config) (setq default-directory lsp-java-test-root) ;; delete old directory @@ -52,8 +51,12 @@ (f-join dir-name project-name "src" "main" "java" "temp")) t) ;; add pom.xml - (with-temp-file (expand-file-name "pom.xml" (f-join dir-name project-name)) - (insert " + (with-temp-file (expand-file-name config-name (f-join dir-name project-name)) + (insert config))) + +(Given "^I have maven project \"\\([^\"]+\\)\" in \"\\([^\"]+\\)\"$" + (lambda (project-name dir-name) + (lsp-java-steps-project project-name dir-name "pom.xml" " 4.0.0 @@ -68,7 +71,33 @@ 1.8 1.8 -")))) +"))) + +(Given "^I have gradle groovy DSL project \"\\([^\"]+\\)\" in \"\\([^\"]+\\)\"$" + (lambda (project-name dir-name) + (lsp-java-steps-project project-name dir-name "build.gradle" " +plugins { + id 'java' +} +repositories { + jcenter() +} +dependencies { + implementation 'com.google.guava:guava:27.0.1-jre' +}"))) + +(Given "^I have gradle kotlin DSL project \"\\([^\"]+\\)\" in \"\\([^\"]+\\)\"$" + (lambda (project-name dir-name) + (lsp-java-steps-project project-name dir-name "build.gradle.kts" " +plugins { + java +} +repositories { + jcenter() +} +dependencies { + implementation(\"com.google.guava:guava:27.0.1-jre\") +}"))) (And "^I have a java file \"\\([^\"]+\\)\"$" (lambda (file-name) From 44b77e797fad7f5867d1a27ce85f3d3909805278 Mon Sep 17 00:00:00 2001 From: Luis Marsano Date: Tue, 7 May 2019 04:33:57 -0400 Subject: [PATCH 2/2] detect gradle kotlin DSL files convert `project-types` local variable to a custom variable for extendability include build.gradle.kts to detect all gradle projects update glob patterns to watch these files --- lsp-java.el | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lsp-java.el b/lsp-java.el index 48608e9..e57685a 100644 --- a/lsp-java.el +++ b/lsp-java.el @@ -65,6 +65,11 @@ Use http://download.eclipse.org/che/che-ls-jdt/snapshots/che-jdt-language-server "face for activity message" :group 'lsp-java) +(defcustom lsp-java-project-types '("pom.xml" "build.gradle" "build.gradle.kts" ".project") + "File names of possible project configuration files found at project root." + :group 'lsp-java + :type '(repeat file)) + (defcustom lsp-java-workspace-dir (expand-file-name (locate-user-emacs-file "workspace/")) "LSP java workspace directory." :group 'lsp-java @@ -472,9 +477,8 @@ The current directory is assumed to be the java project’s root otherwise." ((string= default-directory lsp-java-workspace-cache-dir) default-directory) ((and (featurep 'projectile) (projectile-project-p)) (projectile-project-root)) ((vc-backend default-directory) (expand-file-name (vc-root-dir))) - (t (let ((project-types '("pom.xml" "build.gradle" ".project"))) - (or (seq-some (lambda (file) (locate-dominating-file default-directory file)) project-types) - default-directory))))) + (t (or (seq-some (lambda (file) (locate-dominating-file default-directory file)) lsp-java-project-types) + default-directory)))) (defun lsp-java--language-status-callback (workspace params) "Callback for client initialized. @@ -1122,7 +1126,7 @@ PROJECT-URI uri of the item." ("registerOptions" (ht ("watchers" (vector (ht ("globPattern" "**/*.java")) (ht ("globPattern" "**/pom.xml")) - (ht ("globPattern" "**/*.gradle")) + (ht ("globPattern" "**/*.gradle{,.kts}")) (ht ("globPattern" "**/.project")) (ht ("globPattern" "**/.classpath")) (ht ("globPattern" "**/settings/*.prefs"))))))))))