You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ne...@apache.org on 2019/07/03 09:58:31 UTC

[netbeans] branch master updated: [NETBEANS-2736] Fixed customizing actions with dot in their name.

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

neilcsmith 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 65065fd  [NETBEANS-2736] Fixed customizing actions with dot in their name.
     new 5fe026f  Merge pull request #1344 from lkishalmi/NETBEANS-2736
65065fd is described below

commit 65065fdb5889a39f56e0c0b5beba91d398ee0ff9
Author: Laszlo Kishalmi <la...@gmail.com>
AuthorDate: Sun Jun 30 21:33:39 2019 -0700

    [NETBEANS-2736] Fixed customizing actions with dot in their name.
---
 .../actions/ActionMappingPropertyReader.java       | 35 ++++++++++------
 .../actions/ActionMappingPropertyReaderTest.java   | 47 +++++++++++++++++-----
 2 files changed, 59 insertions(+), 23 deletions(-)

diff --git a/groovy/gradle/src/org/netbeans/modules/gradle/actions/ActionMappingPropertyReader.java b/groovy/gradle/src/org/netbeans/modules/gradle/actions/ActionMappingPropertyReader.java
index 9540f75..75489aa 100644
--- a/groovy/gradle/src/org/netbeans/modules/gradle/actions/ActionMappingPropertyReader.java
+++ b/groovy/gradle/src/org/netbeans/modules/gradle/actions/ActionMappingPropertyReader.java
@@ -33,6 +33,14 @@ import org.netbeans.modules.gradle.api.execute.ActionMapping;
  */
 public final class ActionMappingPropertyReader {
 
+
+    private static final String PARAM_ARGS        = ".args";        //NOI18N
+    private static final String PARAM_PLUGINS     = ".plugins";     //NOI18N
+    private static final String PARAM_PRIORITY    = ".priority";    //NOI18N
+    private static final String PARAM_RELOAD_ARGS = ".reload.args"; //NOI18N
+    private static final String PARAM_RELOAD_RULE = ".reload.rule"; //NOI18N
+    private static final String PARAM_REPEATABLE  = ".repeatable";  //NOI18N
+
     final Properties props;
     ActionMappingPropertyReader(Properties props) {
         this.props = props;
@@ -55,10 +63,11 @@ public final class ActionMappingPropertyReader {
         Set<String> ret = new HashSet<>();
         for (String key : props.stringPropertyNames()) {
             if (key.startsWith(ACTION_PROP_PREFIX)) {
-                int dot = key.indexOf('.', ACTION_PROP_PREFIX.length() + 1);
-                if (dot > 0) {
-                    String name = key.substring(ACTION_PROP_PREFIX.length(), dot);
-                    ret.add(name);
+                // args and/or reload.args shall be specified for defining an action.
+                if (key.endsWith(PARAM_RELOAD_ARGS)) {
+                    ret.add(key.substring(ACTION_PROP_PREFIX.length(), key.length() - PARAM_RELOAD_ARGS.length()));
+                } else if (key.endsWith(PARAM_ARGS)) {
+                    ret.add(key.substring(ACTION_PROP_PREFIX.length(), key.length() - PARAM_ARGS.length()));
                 }
             }
         }
@@ -67,28 +76,28 @@ public final class ActionMappingPropertyReader {
 
     private ActionMapping createMapping(String name) {
         DefaultActionMapping ret = new DefaultActionMapping(name);
-        String prefix = ACTION_PROP_PREFIX + name + '.';
+        String prefix = ACTION_PROP_PREFIX + name;
         ret.displayName = props.getProperty(ACTION_PROP_PREFIX + name);
-        ret.args = props.getProperty(prefix + "args");
-        ret.reloadArgs = props.getProperty(prefix + "reload.args");
-        String rule = props.getProperty(prefix + "reload.rule", ActionMapping.ReloadRule.DEFAULT.name());
+        ret.args = props.getProperty(prefix + PARAM_ARGS);
+        ret.reloadArgs = props.getProperty(prefix + PARAM_RELOAD_ARGS);
+        String rule = props.getProperty(prefix + PARAM_RELOAD_RULE, ActionMapping.ReloadRule.DEFAULT.name());
         try {
             ret.reloadRule = ActionMapping.ReloadRule.valueOf(rule.trim());
         } catch (IllegalArgumentException ex) {
 
         }
-        String repeatable = props.getProperty(prefix + "repeatable");
+        String repeatable = props.getProperty(prefix + PARAM_REPEATABLE);
         if (repeatable != null) {
             ret.repeatableAction = Boolean.valueOf(repeatable);
         }
-        if (props.containsKey(prefix + "plugins")) {
-            String[] plugins = props.getProperty(prefix + "plugins").split(",\\s");
+        if (props.containsKey(prefix + PARAM_PLUGINS)) {
+            String[] plugins = props.getProperty(prefix + PARAM_PLUGINS).split(",\\s"); //NOI18N
             ret.withPlugins = new LinkedHashSet<>();
             ret.withPlugins.addAll(Arrays.asList(plugins));
         }
-        if (props.containsKey(prefix + "priority")) {
+        if (props.containsKey(prefix + PARAM_PRIORITY)) {
             try {
-                ret.priority = Integer.parseInt(props.getProperty(prefix + "priority"));
+                ret.priority = Integer.parseInt(props.getProperty(prefix + PARAM_PRIORITY));
             } catch(NumberFormatException ex) {
 
             }
diff --git a/groovy/gradle/test/unit/src/org/netbeans/modules/gradle/actions/ActionMappingPropertyReaderTest.java b/groovy/gradle/test/unit/src/org/netbeans/modules/gradle/actions/ActionMappingPropertyReaderTest.java
index d6ad668..d7e25cf 100644
--- a/groovy/gradle/test/unit/src/org/netbeans/modules/gradle/actions/ActionMappingPropertyReaderTest.java
+++ b/groovy/gradle/test/unit/src/org/netbeans/modules/gradle/actions/ActionMappingPropertyReaderTest.java
@@ -49,10 +49,10 @@ public class ActionMappingPropertyReaderTest {
         Set<ActionMapping> result = ActionMappingPropertyReader.loadMappings(props);
         assertEquals(result.size(), 1);
         ActionMapping mapping = result.iterator().next();
-        assertEquals(mapping.getName(), "run");
-        assertEquals(mapping.getArgs(), "runArgs");
+        assertEquals("run", mapping.getName());
+        assertEquals("runArgs", mapping.getArgs());
         assertTrue(mapping.isRepeatable());
-        assertEquals(mapping.getReloadRule(), ActionMapping.ReloadRule.DEFAULT);
+        assertEquals(ActionMapping.ReloadRule.DEFAULT, mapping.getReloadRule());
         assertTrue(mapping.getReloadArgs().isEmpty());
     }
 
@@ -67,12 +67,12 @@ public class ActionMappingPropertyReaderTest {
         Set<ActionMapping> result = ActionMappingPropertyReader.loadMappings(props);
         assertEquals(result.size(), 1);
         ActionMapping mapping = result.iterator().next();
-        assertEquals(mapping.getDisplayName(), "Build with Arguments");
-        assertEquals(mapping.getName(), "custom-1");
-        assertEquals(mapping.getArgs(), "runArgs ${test}");
+        assertEquals("Build with Arguments", mapping.getDisplayName());
+        assertEquals("custom-1", mapping.getName());
+        assertEquals("runArgs ${test}", mapping.getArgs());
         assertFalse(mapping.isRepeatable());
-        assertEquals(mapping.getReloadRule(), ActionMapping.ReloadRule.NEVER);
-        assertEquals(mapping.getReloadArgs(), "runArgs");
+        assertEquals(ActionMapping.ReloadRule.NEVER, mapping.getReloadRule());
+        assertEquals("runArgs", mapping.getReloadArgs());
     }
 
     @Test
@@ -84,10 +84,37 @@ public class ActionMappingPropertyReaderTest {
         Set<ActionMapping> result = ActionMappingPropertyReader.loadMappings(props);
         assertEquals(result.size(), 1);
         DefaultActionMapping mapping = (DefaultActionMapping) result.iterator().next();
-        assertEquals(mapping.getName(), "build");
-        assertEquals(mapping.priority, 100);
+        assertEquals("build", mapping.getName());
+        assertEquals(100, mapping.priority);
         assertTrue(mapping.isApplicable(new HashSet<String>(Arrays.asList("groovy", "root", "war"))));
         assertFalse(mapping.isApplicable(new HashSet<String>(Arrays.asList("groovy"))));
     }
 
+    @Test
+    public void testLoadMappings5() {
+        Properties props = new Properties();
+        props.put("action.test.single.args", "cleanTest test --tests ${selectedClass}");
+        Set<ActionMapping> result = ActionMappingPropertyReader.loadMappings(props);
+        assertEquals(result.size(), 1);
+        DefaultActionMapping mapping = (DefaultActionMapping) result.iterator().next();
+        assertEquals("test.single", mapping.getName());
+    }
+
+    @Test
+    public void testLoadMappings6() {
+        Properties props = new Properties();
+        props.put("action.download.javadoc.reload.args", "-PdownloadJavadoc={0}");
+        Set<ActionMapping> result = ActionMappingPropertyReader.loadMappings(props);
+        assertEquals(result.size(), 1);
+        DefaultActionMapping mapping = (DefaultActionMapping) result.iterator().next();
+        assertEquals("download.javadoc", mapping.getName());
+    }
+
+    @Test
+    public void testLoadMappings7() {
+        Properties props = new Properties();
+        props.put("action.download.javadoc_args", "-PdownloadJavadoc={0}");
+        Set<ActionMapping> result = ActionMappingPropertyReader.loadMappings(props);
+        assertEquals(result.size(), 0);
+    }
 }


---------------------------------------------------------------------
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