QualInsight / qualinsight-plugins-sonarqube-badges

Plugin for SonarQube that generates badges displaying information about a project's or view's quality.
GNU Lesser General Public License v3.0
110 stars 141 forks source link

Bug: plugin might fail the server startup with IndexOutOfBoundsException #31

Closed bellingard closed 8 years ago

bellingard commented 8 years ago

We got this error while trying to install the latest 2.0.0 version of the plugin on Nemo. Root cause is:

Caused by: java.lang.IndexOutOfBoundsException: start index (-1) must not be negative at com.google.common.base.Preconditions.checkPositionIndexes(Preconditions.java:389) ~[guava-17.0.jar:na] at com.google.common.collect.ImmutableList.subList(ImmutableList.java:381) ~[guava-17.0.jar:na] at com.google.common.collect.ImmutableList.subList(ImmutableList.java:61) ~[guava-17.0.jar:na] at com.qualinsight.plugins.sonarqube.badges.font.FontManager.detectFontFamily(FontManager.java:109) ~[na:na] at com.qualinsight.plugins.sonarqube.badges.font.FontManager.(FontManager.java:60) ~[na:na]

You can find the full log here: http://pastebin.com/8nUvbdAE

pawlakm commented 8 years ago

Hi Fabrice,

The problem occurs when none of the fonts specified as "preferred" in the plugin's code are available on the machine running SQ. It seems that none of "DejaVu Sans", "Verdana", "Tahoma", "Helvetica", "Arial", "sans-serif", is available on Nemo (which is quite odd as Helvetica is available on most Mac OS X / Linux boxes, and Arial is available on Windows ones).

As discussed per email, please compile this little program, execute it then send me back the file it produces: FontLister.java.gz It will allow me to improve font selection.

gunzip FontLister.java.gz
javac FontLister.java
java FontLister

For now, I fixed the NPE in f51f79c, but the width of produced SVG images is probably wrong if the plugin cannot use a font that is available.

Thanks and sorry for the inconvenience.

Michel

mdiskin commented 8 years ago

I had the same error on our RHEL server (2.6.32-573.22.1.el6.x86_64)

Available fonts: Century Schoolbook L Bold:Century Schoolbook L Century Schoolbook L Bold Italic:Century Schoolbook L Century Schoolbook L Italic:Century Schoolbook L Century Schoolbook L Roman:Century Schoolbook L Dialog.bold:Dialog Dialog.bolditalic:Dialog Dialog.italic:Dialog Dialog.plain:Dialog DialogInput.bold:DialogInput DialogInput.bolditalic:DialogInput DialogInput.italic:DialogInput DialogInput.plain:DialogInput Dingbats :Dingbats Hershey Gothic- English:Hershey Hershey Gothic- German:Hershey Hershey Gothic- Italian:Hershey Hershey Plain- Duplex:Hershey Hershey Plain- Duplex- Italic:Hershey Hershey Plain- Triplex:Hershey Hershey Plain- Triplex- Italic:Hershey Hershey Script- Complex:Hershey Hershey Script- Simplex:Hershey Lucida Bright Demibold:Lucida Bright Lucida Bright Demibold Italic:Lucida Bright Lucida Bright Italic:Lucida Bright Lucida Bright Regular:Lucida Bright Lucida Sans Demibold:Lucida Sans Lucida Sans Regular:Lucida Sans Lucida Sans Typewriter Bold:Lucida Sans Typewriter Lucida Sans Typewriter Regular:Lucida Sans Typewriter Monospaced.bold:Monospaced Monospaced.bolditalic:Monospaced Monospaced.italic:Monospaced Monospaced.plain:Monospaced Nimbus Mono L Bold:Nimbus Mono L Nimbus Mono L Bold Oblique:Nimbus Mono L Nimbus Mono L Regular:Nimbus Mono L Nimbus Mono L Regular Oblique:Nimbus Mono L Nimbus Roman No9 L Medium:Nimbus Roman No9 L Nimbus Roman No9 L Medium Italic:Nimbus Roman No9 L Nimbus Roman No9 L Regular:Nimbus Roman No9 L Nimbus Roman No9 L Regular Italic:Nimbus Roman No9 L Nimbus Sans L Bold:Nimbus Sans L Nimbus Sans L Bold Condensed:Nimbus Sans L Nimbus Sans L Bold Condensed Italic:Nimbus Sans L Nimbus Sans L Bold Italic:Nimbus Sans L Nimbus Sans L Regular:Nimbus Sans L Nimbus Sans L Regular Condensed:Nimbus Sans L Nimbus Sans L Regular Condensed Italic:Nimbus Sans L Nimbus Sans L Regular Italic:Nimbus Sans L SansSerif.bold:SansSerif SansSerif.bolditalic:SansSerif SansSerif.italic:SansSerif SansSerif.plain:SansSerif Serif.bold:Serif Serif.bolditalic:Serif Serif.italic:Serif Serif.plain:Serif Standard Symbols L:Standard Symbols L URW Bookman L Demi Bold:URW Bookman L URW Bookman L Demi Bold Italic:URW Bookman L URW Bookman L Light:URW Bookman L URW Bookman L Light Italic:URW Bookman L URW Chancery L Medium Italic:URW Chancery L URW Gothic L Book:URW Gothic L URW Gothic L Book Oblique:URW Gothic L URW Gothic L Demi:URW Gothic L URW Gothic L Demi Oblique:URW Gothic L URW Palladio L Bold:URW Palladio L URW Palladio L Bold Italic:URW Palladio L URW Palladio L Italic:URW Palladio L URW Palladio L Roman:URW Palladio L Utopia Bold:Utopia Utopia Bold Italic:Utopia Utopia Italic:Utopia Utopia Regular:Utopia

pawlakm commented 8 years ago

Hi, thanks for your feedback. As it seems that the problem isn't isolated, I'll change the way the plugin generates SVG files in order to use CSS style sheets. This will remove the need to have fonts installed on the machine running SQ.

bellingard commented 8 years ago

👍 :-)

pawlakm commented 8 years ago

I spent the whole evening trying to use CSS instead of fixed widths and my conclusions are the following:

Unless someone has a brilliant idea in order to generate easily SVG with CSS, I won't spend more time on trying to fix this issue using CSS until SVG generation is made easier / until someone contributes a SVG image template that uses CSS I could use (instead of having to generate SVG images, I would then fill the template with data such as label text, value text, colors and background colors).

Until then, instead of using CSS, I fixed the issue as follows:

The result is the following:

There are two shortcomings:

I'll release the plugin with version 2.0.1-RC1, it would be great if you could try it and send me a feedback.

Thanks in advance,

Michel

mdiskin commented 8 years ago

Sorry a little out of my depth; I hear good things on D3 if that's not something you came across in your travels.

I can try the RC tomorrow and report back.

Thanks

Sent with Good (www.good.com)


From: Michel Pawlak Sent: Thursday, May 12, 2016 7:52:24 PM To: QualInsight/qualinsight-plugins-sonarqube-badges Cc: Mark Diskin; Manual Subject: Re: [QualInsight/qualinsight-plugins-sonarqube-badges] Bug: plugin might fail the server startup with IndexOutOfBoundsException (#31)

I spent the whole evening trying to use CSS instead of fixed widths and my conclusions are the following:

Unless someone has a brilliant idea in order to generate easily SVG with CSS, I won't spend more time on trying to fix this issue using CSS until SVG generation is made easier / until someone contributes a SVG image template that uses CSS I could use (instead of having to generate SVG images, I would then fill the template with data such as label text, value text, colors and background colors).

Until then, instead of using CSS, I fixed the issue as follows:

The result is the following:

There are two shortcomings:

I'll release the plugin with version 2.0.1-RC1, it would be great if you could try it and send me a feedback.

Thanks in advance,

Michel

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHubhttps://github.com/QualInsight/qualinsight-plugins-sonarqube-badges/issues/31#issuecomment-218917900

pawlakm commented 8 years ago

@mdiskin unfortunately javascript / D3 is not an option here as for instance Javascript cannot be added as markdown / added to GitHub *.md files.

I finally decided to adopt another strategy based on Font properties.

Result:

Can you please test release 2.0.1-RC2 ? Thanks in advance !

Michel

mdiskin commented 8 years ago

I cannot see the RC2 jar just source zip.

Did you look at shields.io they use SVG images for MD pages and maybe see how they did it.

pawlakm commented 8 years ago

I uploaded the jar meantime: https://github.com/QualInsight/qualinsight-plugins-sonarqube-badges/releases/download/qualinsight-plugins-sonarqube-badges-2.0.1-RC2/qualinsight-sonarqube-badges-2.0.1-RC2.jar

I'll have a look at shields.io, thanks

mdiskin commented 8 years ago

The server starts up with plugin installed and I'm able to render badges (see attached in IE11 zoomed to 400%)

passing

pawlakm commented 8 years ago

Ok, thanks, the image (label width) isn't perfect, but it's better. There is still room for improvement ^^'

I had a look at shields.io, it provides a standalone service that needs to be deployed along with (or needs to be accessible to) the service using it. This is a heavier solution (install shields.io server, or configure network to be able to call the service) than just having a plugin that does the job. At my company this approach wouldn't be accepted (they would not accept to have to install and maintain a "badges" server that requires npm, nor would accept to open ports.) I'll continue thus trying to improve the plugin.

Concerning the images that are generated by shields.io, they provide the templates they use. I saw that they used some smart tricks to lower the weight. Food for the brain ;-)

Side note: they are facing exactly the same issue I'm facing: they base their width computation on Verdana.ttf, and, if not found, they use Helvetica.ttf for width approximation. The problem is that they do not embed these fonts in their application as these are paid fonts (that's why I decided to use and embed an open source font in my plugin) and unlike what they argue, font width will always be an approximation, unless both server and client have verdana.ttf installed (which exclude all *nix users).

Cheers and thanks for your help.

pawlakm commented 8 years ago

FYI, I released version 2.0.1-RC3. It uses a template based approach similar to what shields.io is doing, instead of using Apache Batik for SVG image generation. As a result, the images are nicer (text positioning), the weight of generated images is < 1KB and the plugin weights 3 MB less.

As the reported bug is now fixed I close this issue. I'll proceed with a vote for release soon.

Again thanks for your help.