Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-325

Emma plugin - fix for Ratio.parseValue() and EmmaProjectAction.getLastResult()

    XMLWordPrintable

    Details

    • Type: Patch
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Component/s: core
    • Labels:
      None
    • Environment:
      Platform: All, OS: All
    • Similar Issues:

      Description

      Hi.
      There is a locale related problem with the Emma plugin.
      Emma writes fraction numbers with the locale specifc decimal
      separator (checked with Emma version 2.0.5312 and 2.1.5320).
      When comma is used as a separator, then the Emma plugin fails to
      parse the coverage XML report file. See the patch for the
      Ratio class below, and a test case at the end of the message.

      Additionally there is a patch for the EmmaProjectAction.getLastResult()
      method which (looks like) incorrectly calls b=b.getPreviousBuild()
      twice in each for loop.

      Cheers,
      Maciek

      Index: src/main/java/hudson/plugins/emma/EmmaProjectAction.java
      ===================================================================
      RCS file: /cvs/hudson/hudson/plugins/emma/src/main/java/hudson/plugins/emma/
      EmmaProjectAction.java,v
      retrieving revision 1.5
      diff -r1.5 EmmaProjectAction.java
      46d45
      < b = b.getPreviousBuild();
      Index: src/main/java/hudson/plugins/emma/Ratio.java
      ===================================================================
      RCS file: /cvs/hudson/hudson/plugins/emma/src/main/java/hudson/plugins/emma/
      Ratio.java,v
      retrieving revision 1.6
      diff -r1.6 Ratio.java
      66a67,79
      >
      > /**
      > * Parses the float value stored in a string. Uses simple heuristics to
      > * handle comma or dot as a decimal point.
      > */
      > private static float parseFloat(String v) {
      > int idx = v.indexOf(',');
      > if (idx >= 0)

      { > v = v.substring(0, idx) + "." + v.substring(idx+1); > }

      > return Float.parseFloat(v);
      > }
      >
      80,81c93,94
      < Float.parseFloat(v.substring(0,idx)),
      < Float.parseFloat(v.substring(idx+1)));

      > parseFloat(v.substring(0,idx)),
      > parseFloat(v.substring(idx+1)));

      And here is a test for Ratio.parseValue()

      package hudson.plugins.emma;

      /**

      • JUnit test for {@link Ratio}

        */
        public class RatioTest extends AbstractEmmaTestBase {

      /**

      • Tests that {@link Ratio#parseValue(String)}

        parses correctly float

      • numbers with either dot or comma as decimal point.
        *
      • @throws Exception
        */
        public void testParseValue() throws Exception
        Unknown macro: { assertRatio(Ratio.parseValue("X% (1/2)"), 1.0f, 2.0f); assertRatio(Ratio.parseValue("X% (1,3/2)"), 1.3f, 2.0f); assertRatio(Ratio.parseValue("X% (1.3/2)"), 1.3f, 2.0f); assertRatio(Ratio.parseValue("X% (,3/2)"), 0.3f, 2.0f); assertRatio(Ratio.parseValue("X% (.3/2)"), 0.3f, 2.0f); assertRatio(Ratio.parseValue("X% (1./2)"), 1.0f, 2.0f); assertRatio(Ratio.parseValue("X% (1,/2)"), 1.0f, 2.0f); try { Ratio.parseValue("X% (1.a/2)"); fail("Ratio.parseValue() should have raised NumberFormatException."); } catch (NumberFormatException e) { // OK, we are expecting this. } }

        }

        Attachments

          Activity

          Hide
          kohsuke Kohsuke Kawaguchi added a comment -

          Applied. Thanks for the patch. Should be released as emma plugin 1.4 with hudson
          1.84.

          Would be interested in becoming a committor so that you can make changes like
          this directly?

          Show
          kohsuke Kohsuke Kawaguchi added a comment - Applied. Thanks for the patch. Should be released as emma plugin 1.4 with hudson 1.84. Would be interested in becoming a committor so that you can make changes like this directly?

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            mstarzyk mstarzyk
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: