jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • Sonar
  • SONAR-1749

MavenPlugin api, offer way to build nested xml-elements

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.2
  • Fix Version/s: 2.3
  • Component/s: API
  • Labels:
    None
  • Testcase included:
    yes

Description

Motiviation

Some maven plugins need to be configured by nested elements (e.g. taglist-maven-plugin with tag-configuration). Improve MavenPlugin api to offer a stronger building functionality.

Sample XML

I want to build a configuration like:

<entries>
 <entry>
   <key>...</key>
   <value>...</value>
 </entry>
 <entry>
   <key>...</key>
   <value>...</value>
 </entry>
</entries>

what the configuration builder in fact does is:

<entries>
 <entry>
   <key>...</key>
   <value>...</value>
   <key>...</key>
   <value>...</value>
 </entry>
</entries>

Test-Case

The test-case reproduces problem:

public class MavenPluginBuildConfigTest {

   private MavenPlugin plugin;

   @Before
   public void setUp() {
       plugin = new MavenPlugin("group", "artifact", "1.0");
   }

   @Test //SUCCESS
   public void first_level_container() {
       //SETUP
       plugin.addParameter("entries/entry", "value1");
       plugin.addParameter("entries/entry", "value2");

       //ASSERT
       assertTrue(pluginConfig().contains("<entry>value1</entry>"));
       assertTrue(pluginConfig().contains("<entry>value2</entry>"));
   }

   @Test //FAILS
   public void second_level_container() {
       //SETUP
       plugin.addParameter("entries/entry/key", "key1");
       plugin.addParameter("entries/entry/value", "value1");

       plugin.addParameter("entries/entry/key", "key2");
       plugin.addParameter("entries/entry/value", "value2");

       //ASSERT
       assertTrue(pluginConfig().contains("<entry><key>key1</key><value>value1</value></entry>"));
       assertTrue(pluginConfig().contains("<entry><key>key2</key><value>value2</value></entry>"));
   }

   private String pluginConfig() {
       //strip whitespace away easier to compare
       return StringUtils.deleteWhitespace(plugin.getPlugin().getConfiguration().toString());
   }

}
  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Text File
    SONAR-1749_1.patch
    04/Sep/10 9:01 AM
    7 kB
    manuel aldana

Issue Links

is depended upon by

Improvement - An improvement or enhancement to an existing feature or task. SONARPLUGINS-240 Add the matching method management

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
manuel aldana added a comment - 04/Sep/10 9:01 AM

Patch introduces possibility to uniquely address list-containers with special key-index syntax.

Key-Syntax:

  • item['index']
  • if no index provided *item[0]* is taken as default (important for less verbosity and for down-compatiblity of api)

Example

plugin.setParameter("/items/item[0]/key","key1");
plugin.setParameter("/items/item[0]/value","value1");
plugin.setParameter("/items/item[1]/key","key2");
plugin.setParameter("/items/item[1]/value","value2");

would generate:

<configuration>
  <items>
    <item>
      <key>key1</key>
      <value>value1</value>
    </item>
    <item>
      <key>key2</key>
      <value>value2</value>
    </item>
  </items>
</configuration>

Please review patch and also its new test-cases. Regression tests of MavenPluginTest are
on green.

Show
manuel aldana added a comment - 04/Sep/10 9:01 AM Patch introduces possibility to uniquely address list-containers with special key-index syntax. Key-Syntax:
  • item['index']
  • if no index provided *item[0]* is taken as default (important for less verbosity and for down-compatiblity of api)

Example

plugin.setParameter("/items/item[0]/key","key1");
plugin.setParameter("/items/item[0]/value","value1");
plugin.setParameter("/items/item[1]/key","key2");
plugin.setParameter("/items/item[1]/value","value2");
would generate:
<configuration>
  <items>
    <item>
      <key>key1</key>
      <value>value1</value>
    </item>
    <item>
      <key>key2</key>
      <value>value2</value>
    </item>
  </items>
</configuration>
Please review patch and also its new test-cases. Regression tests of MavenPluginTest are on green.
Hide
Permalink
manuel aldana added a comment - 14/Sep/10 5:23 PM

The MavenPlugin element addressing syntax seems to be simple subset of XPath. I just noticed, that XPath first element is element[1] instead element[0] (see http://www.w3.org/TR/xpath20/#dt-dynamic-context). Maybe it makes sense to also use 1 instead of 0 for the maven-plugin api?

Show
manuel aldana added a comment - 14/Sep/10 5:23 PM The MavenPlugin element addressing syntax seems to be simple subset of XPath. I just noticed, that XPath first element is element[1] instead element[0] (see http://www.w3.org/TR/xpath20/#dt-dynamic-context). Maybe it makes sense to also use 1 instead of 0 for the maven-plugin api?
Hide
Permalink
Simon Brandhof added a comment - 30/Sep/10 4:35 AM

Thanks for the patch. It's applied in version 2.3. It's just my feeling, but I prefer starting from 0, it's more intuitive for Java developers.

Show
Simon Brandhof added a comment - 30/Sep/10 4:35 AM Thanks for the patch. It's applied in version 2.3. It's just my feeling, but I prefer starting from 0, it's more intuitive for Java developers.

People

  • Assignee:
    Simon Brandhof
    Reporter:
    manuel aldana
Vote (0)
Watch (0)

Dates

  • Created:
    30/Aug/10 5:19 AM
    Updated:
    04/Oct/10 4:47 PM
    Resolved:
    14/Sep/10 4:12 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.