From ac0daff59c70553536f7f1cf7675b9fc4961e3fe Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Fri, 27 Oct 2017 20:56:27 +0300 Subject: [PATCH] #30 badge --- README.md | 2 + src/main/java/org/jpeek/App.java | 30 ++++++++ src/main/resources/org/jpeek/badge.xsl | 94 ++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 src/main/resources/org/jpeek/badge.xsl diff --git a/README.md b/README.md index ff42df02..343ed469 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,8 @@ [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/jpeek.svg)](https://codecov.io/github/yegor256/jpeek?branch=master) [![SonarQube](https://img.shields.io/badge/sonar-ok-green.svg)](https://sonarcloud.io/dashboard?id=org.jpeek%3Ajpeek) +[![jpeek report](https://i.jpeek.org/org.jpeek/jpeek/badge.svg)](http://i.jpeek.org/org.jpeek/jpeek/) + jPeek is a static collector of Java code metrics. **Motivation**: diff --git a/src/main/java/org/jpeek/App.java b/src/main/java/org/jpeek/App.java index daa809d3..7f33a8cb 100644 --- a/src/main/java/org/jpeek/App.java +++ b/src/main/java/org/jpeek/App.java @@ -39,6 +39,7 @@ import org.jpeek.metrics.cohesion.CAMC; import org.jpeek.metrics.cohesion.LCOM; import org.jpeek.metrics.cohesion.OCC; +import org.xembly.Directives; import org.xembly.Xembler; /** @@ -60,6 +61,13 @@ public final class App { App.class.getResourceAsStream("index.xsl") ); + /** + * XSL stylesheet. + */ + private static final XSL BADGE = XSLDocument.make( + App.class.getResourceAsStream("badge.xsl") + ); + /** * Location of the project to analyze. */ @@ -130,6 +138,28 @@ public void analyze() throws IOException { this.output.resolve("index.html") ) ).value(); + new LengthOf( + new TeeInput( + App.BADGE.transform( + new XMLDocument( + new Xembler( + new Directives().add("score").set( + String.format( + "%.4f", + Double.parseDouble( + index.xpath( + // @checkstyle LineLength (1 line) + "sum(//metric/score) div count(//metric)" + ).get(0) + ) + ) + ).attr("style", "round") + ).xmlQuietly() + ) + ).toString(), + this.output.resolve("badge.svg") + ) + ).value(); } } diff --git a/src/main/resources/org/jpeek/badge.xsl b/src/main/resources/org/jpeek/badge.xsl new file mode 100644 index 00000000..5c02d1b5 --- /dev/null +++ b/src/main/resources/org/jpeek/badge.xsl @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + 3 + + + + + + + + + + + #44cc11 + + + #dfb317 + + + #d9644d + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +