-
Patch
-
Resolution: Fixed
-
Major
-
None
-
Platform: All, OS: All
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)
> 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 ExceptionUnknown 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. } }}