You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by lk...@apache.org on 2019/12/07 06:16:04 UTC

[netbeans] branch master updated: [NETBEANS-3411] Added support for reading Kotlin based Gradle projects.

This is an automated email from the ASF dual-hosted git repository.

lkishalmi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 72367db  [NETBEANS-3411] Added support for reading Kotlin based Gradle projects.
72367db is described below

commit 72367db6f0badd5a0261395e22339288355ca1a9
Author: Laszlo Kishalmi <la...@gmail.com>
AuthorDate: Tue Dec 3 23:49:22 2019 -0800

    [NETBEANS-3411] Added support for reading Kotlin based Gradle projects.
---
 .../modules/gradle/ActionProviderImpl.java         |   1 +
 .../netbeans/modules/gradle/GradleDataObject.java  | 132 +++++++++++++++++++--
 .../modules/gradle/gradle-mime-resolver.xml        |  35 ++++++
 .../src/org/netbeans/modules/gradle/layer.xml      |  64 ----------
 .../netbeans/modules/gradle/spi/GradleFiles.java   |  17 ++-
 .../modules/gradle/spi/GradleFilesTest.java        |  50 ++++++++
 .../modules/kotlin/editor/KtDataObject.java        |  17 ++-
 7 files changed, 235 insertions(+), 81 deletions(-)

diff --git a/groovy/gradle/src/org/netbeans/modules/gradle/ActionProviderImpl.java b/groovy/gradle/src/org/netbeans/modules/gradle/ActionProviderImpl.java
index ca5410c..9b12828 100644
--- a/groovy/gradle/src/org/netbeans/modules/gradle/ActionProviderImpl.java
+++ b/groovy/gradle/src/org/netbeans/modules/gradle/ActionProviderImpl.java
@@ -391,6 +391,7 @@ public class ActionProviderImpl implements ActionProvider {
     @ActionReferences({
         @ActionReference(position = 1400, path = "Projects/" + NbGradleProject.GRADLE_PROJECT_TYPE + "/Actions"),
         @ActionReference(position = 250, path = "Loaders/text/x-gradle+x-groovy/Actions"),
+        @ActionReference(position = 250, path = "Loaders/text/x-gradle+x-kotlin/Actions"),
         @ActionReference(position = 1295, path = "Loaders/text/x-java/Actions"),
         @ActionReference(position = 1821, path = "Editors/text/x-java/Popup"),
         @ActionReference(position = 1295, path = "Loaders/text/x-groovy/Actions"),
diff --git a/groovy/gradle/src/org/netbeans/modules/gradle/GradleDataObject.java b/groovy/gradle/src/org/netbeans/modules/gradle/GradleDataObject.java
index fd05cf2..cece1f8 100644
--- a/groovy/gradle/src/org/netbeans/modules/gradle/GradleDataObject.java
+++ b/groovy/gradle/src/org/netbeans/modules/gradle/GradleDataObject.java
@@ -27,6 +27,10 @@ import org.netbeans.api.project.Project;
 import org.netbeans.api.project.ProjectManager;
 import org.netbeans.api.project.ProjectUtils;
 import org.netbeans.core.api.multiview.MultiViews;
+import org.netbeans.modules.gradle.spi.GradleFiles;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionReferences;
 import org.openide.cookies.CloseCookie;
 import org.openide.cookies.EditCookie;
 import org.openide.cookies.EditorCookie;
@@ -51,22 +55,132 @@ import org.openide.windows.CloneableOpenSupport;
     "LBL_GradleFile_LOADER=Gradle Script",
     "CTL_SourceTabCaption=&Source"
 })
-@MIMEResolver.ExtensionRegistration(
-        displayName = "#LBL_GradleFile_LOADER",
-        mimeType = GradleDataObject.MIME_TYPE,
-        extension = {"gradle"},
-        position = 290
+@MIMEResolver.Registration(
+        displayName="#LBL_GradleFile_LOADER",
+        resource="gradle-mime-resolver.xml",
+        position = 300
 )
-@DataObject.Registration(
+@ActionReferences({
+    @ActionReference(
+            path = "Loaders/text/x-gradle+x-kotlin/Actions",
+            id = @ActionID(category = "System", id = "org.openide.actions.OpenAction"),
+            position = 100,
+            separatorAfter = 300
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-gradle+x-kotlin/Actions",
+            id = @ActionID(category = "Edit", id = "org.openide.actions.CutAction"),
+            position = 400
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-gradle+x-kotlin/Actions",
+            id = @ActionID(category = "Edit", id = "org.openide.actions.CopyAction"),
+            position = 500,
+            separatorAfter = 600
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-gradle+x-kotlin/Actions",
+            id = @ActionID(category = "Edit", id = "org.openide.actions.DeleteAction"),
+            position = 700
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-gradle+x-kotlin/Actions",
+            id = @ActionID(category = "System", id = "org.openide.actions.RenameAction"),
+            position = 800,
+            separatorAfter = 900
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-gradle+x-kotlin/Actions",
+            id = @ActionID(category = "System", id = "org.openide.actions.SaveAsTemplateAction"),
+            position = 1000,
+            separatorAfter = 1100
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-gradle+x-kotlin/Actions",
+            id = @ActionID(category = "System", id = "org.openide.actions.FileSystemAction"),
+            position = 1200,
+            separatorAfter = 1300
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-gradle+x-kotlin/Actions",
+            id = @ActionID(category = "System", id = "org.openide.actions.ToolsAction"),
+            position = 1400
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-gradle+x-kotlin/Actions",
+            id = @ActionID(category = "System", id = "org.openide.actions.PropertiesAction"),
+            position = 1500
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-gradle+x-groovy/Actions",
+            id = @ActionID(category = "System", id = "org.openide.actions.OpenAction"),
+            position = 100,
+            separatorAfter = 300
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-gradle+x-groovy/Actions",
+            id = @ActionID(category = "Edit", id = "org.openide.actions.CutAction"),
+            position = 400
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-gradle+x-groovy/Actions",
+            id = @ActionID(category = "Edit", id = "org.openide.actions.CopyAction"),
+            position = 500,
+            separatorAfter = 600
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-gradle+x-groovy/Actions",
+            id = @ActionID(category = "Edit", id = "org.openide.actions.DeleteAction"),
+            position = 700
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-gradle+x-groovy/Actions",
+            id = @ActionID(category = "System", id = "org.openide.actions.RenameAction"),
+            position = 800,
+            separatorAfter = 900
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-gradle+x-groovy/Actions",
+            id = @ActionID(category = "System", id = "org.openide.actions.SaveAsTemplateAction"),
+            position = 1000,
+            separatorAfter = 1100
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-gradle+x-groovy/Actions",
+            id = @ActionID(category = "System", id = "org.openide.actions.FileSystemAction"),
+            position = 1200,
+            separatorAfter = 1300
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-gradle+x-groovy/Actions",
+            id = @ActionID(category = "System", id = "org.openide.actions.ToolsAction"),
+            position = 1400
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-gradle+x-groovy/Actions",
+            id = @ActionID(category = "System", id = "org.openide.actions.PropertiesAction"),
+            position = 1500
+    )
+})
+
+@DataObject.Registrations({
+        @DataObject.Registration(
         mimeType = GradleDataObject.MIME_TYPE,
         iconBase = "org/netbeans/modules/gradle/resources/gradle.png",
         displayName = "#LBL_GradleFile_LOADER",
         position = 300
-)
+    ),
+    @DataObject.Registration(
+        mimeType = GradleDataObject.KOTLIN_MIME_TYPE,
+        iconBase = "org/netbeans/modules/gradle/resources/gradle.png",
+        displayName = "#LBL_GradleFile_LOADER",
+        position = 290
+    )
+})
 public class GradleDataObject extends MultiDataObject {
 
     public static final String MIME_TYPE = "text/x-gradle+x-groovy"; //NOI18N
-    private static final String BUILD_GRADLE = "build.gradle";       //NOI18N
+    public static final String KOTLIN_MIME_TYPE = "text/x-gradle+x-kotlin"; //NOI18N
 
     public GradleDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
         super(pf, loader);
@@ -161,7 +275,7 @@ public class GradleDataObject extends MultiDataObject {
     static String getFileOrProjectName(FileObject primaryFile) {
         String ret = primaryFile.getNameExt();
 
-        if (BUILD_GRADLE.equals(ret)) {
+        if (GradleFiles.BUILD_FILE_NAME.equals(ret) || GradleFiles.BUILD_FILE_NAME_KTS.equals(ret)) {
             try {
                 Project prj = ProjectManager.getDefault().findProject(primaryFile.getParent());
                 if (prj != null) {
diff --git a/groovy/gradle/src/org/netbeans/modules/gradle/gradle-mime-resolver.xml b/groovy/gradle/src/org/netbeans/modules/gradle/gradle-mime-resolver.xml
new file mode 100644
index 0000000..140a00a
--- /dev/null
+++ b/groovy/gradle/src/org/netbeans/modules/gradle/gradle-mime-resolver.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+-->
+
+<!DOCTYPE MIME-resolver PUBLIC '-//NetBeans//DTD MIME Resolver 1.1//EN' 'https://netbeans.apache.org/dtds/mime-resolver-1_1.dtd'>
+
+<MIME-resolver>
+    <file>
+        <ext name="gradle"/>
+        <resolver mime="text/x-gradle+x-groovy"/>
+    </file>
+    <file>
+        <ext name="kts"/>
+        <name name=".gradle.kts" substring="true"/>
+        <resolver mime="text/x-gradle+x-kotlin" />
+    </file>
+</MIME-resolver>
diff --git a/groovy/gradle/src/org/netbeans/modules/gradle/layer.xml b/groovy/gradle/src/org/netbeans/modules/gradle/layer.xml
index 90cd2e4..a95a945 100644
--- a/groovy/gradle/src/org/netbeans/modules/gradle/layer.xml
+++ b/groovy/gradle/src/org/netbeans/modules/gradle/layer.xml
@@ -148,70 +148,6 @@
             </folder>
         </folder>
     </folder>
-    <folder name="Loaders">
-        <folder name="text">
-            <folder name="x-gradle+x-groovy">
-                <folder name="Actions">
-                    <file name="org-openide-actions-OpenAction.shadow">
-                        <attr name="originalFile" stringvalue="Actions/System/org-openide-actions-OpenAction.instance"/>
-                        <attr name="position" intvalue="100"/>
-                    </file>
-                    <file name="sep-1.instance">
-                        <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
-                        <attr name="position" intvalue="300"/>
-                    </file>
-                    <file name="org-openide-actions-CutAction.shadow">
-                        <attr name="originalFile" stringvalue="Actions/Edit/org-openide-actions-CutAction.instance"/>
-                        <attr name="position" intvalue="400"/>
-                    </file>
-                    <file name="org-openide-actions-CopyAction.shadow">
-                        <attr name="originalFile" stringvalue="Actions/Edit/org-openide-actions-CopyAction.instance"/>
-                        <attr name="position" intvalue="500"/>
-                    </file>
-                    <file name="sep-2.instance">
-                        <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
-                        <attr name="position" intvalue="600"/>
-                    </file>
-                    <file name="org-openide-actions-DeleteAction.shadow">
-                        <attr name="originalFile" stringvalue="Actions/Edit/org-openide-actions-DeleteAction.instance"/>
-                        <attr name="position" intvalue="700"/>
-                    </file>
-                    <file name="org-openide-actions-RenameAction.shadow">
-                        <attr name="originalFile" stringvalue="Actions/System/org-openide-actions-RenameAction.instance"/>
-                        <attr name="position" intvalue="800"/>
-                    </file>
-                    <file name="sep-3.instance">
-                        <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
-                        <attr name="position" intvalue="900"/>
-                    </file>
-                    <file name="org-openide-actions-SaveAsTemplateAction.shadow">
-                        <attr name="originalFile" stringvalue="Actions/System/org-openide-actions-SaveAsTemplateAction.instance"/>
-                        <attr name="position" intvalue="1000"/>
-                    </file>
-                    <file name="sep-4.instance">
-                        <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
-                        <attr name="position" intvalue="1100"/>
-                    </file>
-                    <file name="org-openide-actions-FileSystemAction.shadow">
-                        <attr name="originalFile" stringvalue="Actions/System/org-openide-actions-FileSystemAction.instance"/>
-                        <attr name="position" intvalue="1200"/>
-                    </file>
-                    <file name="sep-5.instance">
-                        <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
-                        <attr name="position" intvalue="1300"/>
-                    </file>
-                    <file name="org-openide-actions-ToolsAction.shadow">
-                        <attr name="originalFile" stringvalue="Actions/System/org-openide-actions-ToolsAction.instance"/>
-                        <attr name="position" intvalue="1400"/>
-                    </file>
-                    <file name="org-openide-actions-PropertiesAction.shadow">
-                        <attr name="originalFile" stringvalue="Actions/System/org-openide-actions-PropertiesAction.instance"/>
-                        <attr name="position" intvalue="1500"/>
-                    </file>
-                </folder>
-            </folder>
-        </folder>
-    </folder>
     <folder name="CslPlugins">
         <folder name="text">
             <folder name="x-gradle+x-groovy">
diff --git a/groovy/gradle/src/org/netbeans/modules/gradle/spi/GradleFiles.java b/groovy/gradle/src/org/netbeans/modules/gradle/spi/GradleFiles.java
index d27e074..28679ec 100644
--- a/groovy/gradle/src/org/netbeans/modules/gradle/spi/GradleFiles.java
+++ b/groovy/gradle/src/org/netbeans/modules/gradle/spi/GradleFiles.java
@@ -63,7 +63,9 @@ public final class GradleFiles implements Serializable {
     }
 
     public static final String SETTINGS_FILE_NAME     = "settings.gradle"; //NOI18N
+    public static final String SETTINGS_FILE_NAME_KTS = "settings.gradle.kts"; //NOI18N
     public static final String BUILD_FILE_NAME        = "build.gradle"; //NOI18N
+    public static final String BUILD_FILE_NAME_KTS    = "build.gradle.kts"; //NOI18N
     public static final String GRADLE_PROPERTIES_NAME = "gradle.properties"; //NOI18N
     public static final String WRAPPER_PROPERTIES     = "gradle/wrapper/gradle-wrapper.properties"; //NOI18N
 
@@ -105,10 +107,19 @@ public final class GradleFiles implements Serializable {
     }
 
     private void searchBuildScripts() {
-        File f1 = new File(projectDir, BUILD_FILE_NAME);
-        File f2 = new File(projectDir, projectDir.getName() + ".gradle");
+        File f1 = new File(projectDir, BUILD_FILE_NAME_KTS);
+        if (!f1.canRead()) {
+            f1 = new File(projectDir, BUILD_FILE_NAME);
+        }
+        File f2 = new File(projectDir, projectDir.getName() + ".gradle.kts");
+        if (!f2.canRead()) {
+            f2 = new File(projectDir, projectDir.getName() + ".gradle");
+        }
 
-        settingsScript = searchPathUp(projectDir, SETTINGS_FILE_NAME);
+        settingsScript = searchPathUp(projectDir, SETTINGS_FILE_NAME_KTS);
+        if (settingsScript == null) {
+            settingsScript = searchPathUp(projectDir, SETTINGS_FILE_NAME);
+        }
         File settingsDir = settingsScript != null ? settingsScript.getParentFile() : null;
         buildScript = f1.canRead() ? f1 : f2.canRead() ? f2 : null;
         if (settingsDir != null) {
diff --git a/groovy/gradle/test/unit/src/org/netbeans/modules/gradle/spi/GradleFilesTest.java b/groovy/gradle/test/unit/src/org/netbeans/modules/gradle/spi/GradleFilesTest.java
index adcd7b4..ff516ac 100644
--- a/groovy/gradle/test/unit/src/org/netbeans/modules/gradle/spi/GradleFilesTest.java
+++ b/groovy/gradle/test/unit/src/org/netbeans/modules/gradle/spi/GradleFilesTest.java
@@ -83,6 +83,46 @@ public class GradleFilesTest {
     }
 
     @Test
+    public void testGetBuildScriptKotlin() throws IOException {
+        File build = root.newFile("build.gradle.kts");
+        GradleFiles gf = new GradleFiles(root.getRoot());
+        assertEquals(build, gf.getBuildScript());
+    }
+
+    @Test
+    public void testGetBuildScriptKotlin2() throws IOException {
+        File build = root.newFile("build.gradle.kts");
+        File settings = root.newFile("settings.gradle.kts");
+        File module = root.newFolder("module");
+        Files.write(settings.toPath(), Arrays.asList("include ':module'"));
+        GradleFiles gf = new GradleFiles(module);
+        assertEquals(null, gf.getBuildScript());
+    }
+
+    @Test
+    public void testGetBuildScriptKotlin3() throws IOException {
+        File build = root.newFile("build.gradle.kts");
+        File settings = root.newFile("settings.gradle.kts");
+        File module = root.newFolder("module");
+        Files.write(settings.toPath(), Arrays.asList("include(\":module\")"));
+        File subBuild = root.newFile("module/module.gradle.kts");
+        GradleFiles gf = new GradleFiles(module);
+        assertEquals("module.gradle.kts", gf.getBuildScript().getName());
+    }
+
+    @Test
+    public void testGetBuildScriptKotlin4() throws IOException {
+        File build = root.newFile("build.gradle.kts");
+        File settings = root.newFile("settings.gradle.kts");
+        File module = root.newFolder("module");
+        Files.write(settings.toPath(), Arrays.asList("include(\":module\")"));
+        File subBuild = root.newFile("module/module.gradle.kts");
+        File subBuild2 = root.newFile("module/build.gradle.kts");
+        GradleFiles gf = new GradleFiles(module);
+        assertEquals("build.gradle.kts", gf.getBuildScript().getName());
+    }
+
+    @Test
     public void testGetParentScript() throws IOException{
         File build = root.newFile("build.gradle");
         File settings = root.newFile("settings.gradle");
@@ -93,6 +133,16 @@ public class GradleFilesTest {
     }
 
     @Test
+    public void testGetParentScriptKotlin() throws IOException{
+        File build = root.newFile("build.gradle.kts");
+        File settings = root.newFile("settings.gradle");
+        File module = root.newFolder("module");
+        Files.write(settings.toPath(), Arrays.asList("include ':module'"));
+        GradleFiles gf = new GradleFiles(root.getRoot());
+        assertEquals(null, gf.getParentScript());
+    }
+
+    @Test
     public void testGetParentScript2() throws IOException{
         File build = root.newFile("build.gradle");
         File settings = root.newFile("settings.gradle");
diff --git a/java/kotlin.editor/src/org/netbeans/modules/kotlin/editor/KtDataObject.java b/java/kotlin.editor/src/org/netbeans/modules/kotlin/editor/KtDataObject.java
index 59cc2b4..be53abf 100644
--- a/java/kotlin.editor/src/org/netbeans/modules/kotlin/editor/KtDataObject.java
+++ b/java/kotlin.editor/src/org/netbeans/modules/kotlin/editor/KtDataObject.java
@@ -21,6 +21,7 @@ package org.netbeans.modules.kotlin.editor;
 import java.io.IOException;
 import org.netbeans.core.spi.multiview.MultiViewElement;
 import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
+import org.netbeans.modules.textmate.lexer.api.GrammarRegistrations;
 import org.netbeans.modules.textmate.lexer.api.GrammarRegistration;
 import org.openide.awt.ActionID;
 import org.openide.awt.ActionReference;
@@ -35,10 +36,16 @@ import org.openide.util.Lookup;
 import org.openide.util.NbBundle.Messages;
 import org.openide.windows.TopComponent;
 
-@GrammarRegistration(
-    mimeType="text/x-kotlin",
-    grammar="Kotlin.tmLanguage.json"
-)
+@GrammarRegistrations({
+    @GrammarRegistration(
+            mimeType = "text/x-kotlin",
+            grammar = "Kotlin.tmLanguage.json"
+    ),
+    @GrammarRegistration(
+            mimeType = "text/x-gradle+x-kotlin",
+            grammar = "Kotlin.tmLanguage.json"
+    )
+})
 @Messages({
     "LBL_Kt_LOADER=Kotlin Files"
 })
@@ -121,7 +128,7 @@ public class KtDataObject extends MultiDataObject {
     @MultiViewElement.Registration(
             displayName = "#LBL_Kt_EDITOR",
             iconBase = "org/netbeans/modules/kotlin/editor/kotlin_file.png",
-            mimeType = "text/x-kotlin",
+            mimeType = {"text/x-kotlin", "text/x-gradle+x-kotlin"},
             persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED,
             preferredID = "Kt",
             position = 1000


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists