changeset 1592:3c55a3f203b8

Add a proper description for profile-vm Reviewed-by: jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2014-December/011976.html
author Omair Majid <omajid@redhat.com>
date Thu, 04 Dec 2014 10:40:57 -0500
parents cce1d8d2d561
children 0133da742cc7
files launcher/src/main/java/com/redhat/thermostat/launcher/internal/PluginConfigurationParser.java launcher/src/test/java/com/redhat/thermostat/launcher/internal/PluginConfigurationParserTest.java vm-profiler/distribution/thermostat-plugin.xml
diffstat 3 files changed, 54 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/PluginConfigurationParser.java	Thu Dec 04 10:30:07 2014 -0500
+++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/PluginConfigurationParser.java	Thu Dec 04 10:40:57 2014 -0500
@@ -366,7 +366,7 @@
             } else if (node.getNodeName().equals("usage")) {
                 usage = node.getTextContent().trim();
             } else if (node.getNodeName().equals("description")) {
-                description = node.getTextContent().trim();
+                description = parseDescription(node);
             } else if (node.getNodeName().equals("arguments")) {
                 arguments = parseArguments(pluginName, name, node);
             } else if (node.getNodeName().equals("options")) {
@@ -432,6 +432,17 @@
         return new BundleInformation(name, version);
     }
 
+    private String parseDescription(Node descriptionNode) {
+        String text = descriptionNode.getTextContent().trim();
+        String[] lines = text.split("(" + System.lineSeparator() + ")+");
+        StringBuilder result = new StringBuilder();
+        for (String line : lines) {
+            result.append(line.trim());
+            result.append(" ");
+        }
+        return result.toString().trim();
+    }
+
     private List<String> parseArguments(String pluginName, String commandName, Node argumentsNode) {
         return parseNodeAsList(pluginName, commandName, argumentsNode, "argument");
     }
--- a/launcher/src/test/java/com/redhat/thermostat/launcher/internal/PluginConfigurationParserTest.java	Thu Dec 04 10:30:07 2014 -0500
+++ b/launcher/src/test/java/com/redhat/thermostat/launcher/internal/PluginConfigurationParserTest.java	Thu Dec 04 10:40:57 2014 -0500
@@ -297,6 +297,36 @@
     }
 
     @Test
+    public void testNewLinesAreRemovedFromDescription() throws UnsupportedEncodingException {
+        String newLine = System.lineSeparator();
+        String config = "<?xml version=\"1.0\"?>\n" +
+                "<plugin>\n" +
+                "  <commands>\n" +
+                "    <command type='provides'>\n" +
+                "      <name>test</name>\n" +
+                "      <description>  Line 1.  " + newLine + "Line 2. Line 3." + newLine + "Line 4.</description>\n" +
+                "      <environments>" +
+                "        <environment>shell</environment>" +
+                "        <environment>cli</environment>" +
+                "      </environments>" +
+                "    </command>\n" +
+                "  </commands>\n" +
+                "</plugin>";
+
+        PluginConfiguration result = new PluginConfigurationParser()
+                .parse("test", new ByteArrayInputStream(config.getBytes("UTF-8")));
+
+        assertEquals(0, result.getExtendedCommands().size());
+
+        List<NewCommand> newCommands = result.getNewCommands();
+        assertEquals(1, newCommands.size());
+
+        NewCommand command = newCommands.get(0);
+        assertEquals("test", command.getCommandName());
+        assertEquals("Line 1. Line 2. Line 3. Line 4.", command.getDescription());
+    }
+
+    @Test
     public void testArgumentParsing() throws UnsupportedEncodingException {
         String config = "<?xml version=\"1.0\"?>\n" +
                 "<plugin>\n" +
--- a/vm-profiler/distribution/thermostat-plugin.xml	Thu Dec 04 10:30:07 2014 -0500
+++ b/vm-profiler/distribution/thermostat-plugin.xml	Thu Dec 04 10:40:57 2014 -0500
@@ -40,7 +40,18 @@
     <commands>
         <command>
             <name>profile-vm</name>
-            <description>profile a target vm</description>
+            <description>
+            Profile a target vm. This is an instrumenting profiler that
+            modifies the bytecode of the target application to record method
+            execution times of all code. This command takes a subcommand that
+            describes what to do. 'start' sarts profiling a VM, 'stop' stops
+            the profiling, 'status' shows the current status (whether the
+            profiler is active or not), and 'show' displays the results of the
+            last profiling session. The results are only available after
+            profiling has stopped. The instrumentation (performed on both
+            'start' and 'stop') can take a while for programs with lots of
+            classes.
+            </description>
             <arguments>
             	<argument>action</argument>
             </arguments>