Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/yegor256/jpeek into CAMC_Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Yildirim authored and Yildirim committed Oct 30, 2017
2 parents 37dc097 + 54ae503 commit 517af9e
Show file tree
Hide file tree
Showing 39 changed files with 1,806 additions and 176 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
web: java -Dfile.encoding=UTF-8 -Xmx400m -XX:MaxPermSize=64m -cp target/jpeek.jar:target/deps/* org.jpeek.TkApp --port=${PORT} --threads=50 --max-latency=45000
web: java -Dfile.encoding=UTF-8 -Xmx400m -XX:MaxPermSize=64m -cp target/jpeek.jar:target/deps/* org.jpeek.web.TkApp --port=${PORT} --threads=50 --max-latency=45000

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[![Maven Central](https://img.shields.io/maven-central/v/org.jpeek/jpeek.svg)](https://maven-badges.herokuapp.com/maven-central/org.jpeek/jpeek)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/jpeek/blob/master/LICENSE.txt)

[![jpeek report](http://i.jpeek.org/org.jpeek/jpeek/badge.svg)](http://i.jpeek.org/org.jpeek/jpeek/)
[![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)

Expand All @@ -29,10 +30,10 @@ book series make sense.

## How to use?

Load [this JAR file](http://repo1.maven.org/maven2/org/jpeek/jpeek/0.3/jpeek-0.3-jar-with-dependencies.jar) and then:
Load [this JAR file](http://repo1.maven.org/maven2/org/jpeek/jpeek/0.5/jpeek-0.5-jar-with-dependencies.jar) and then:

```bash
$ java -jar jpeek-0.1-jar-with-dependencies.jar . ./jpeek
$ java -jar jpeek-0.5-jar-with-dependencies.jar . ./jpeek
```

jPeek will analyze Java files in the current directory.
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ SOFTWARE.
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-xml</artifactId>
<version>0.21</version>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-log</artifactId>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
Expand Down
60 changes: 58 additions & 2 deletions src/main/java/org/jpeek/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
import org.cactoos.scalar.IoCheckedScalar;
import org.jpeek.metrics.cohesion.CAMC;
import org.jpeek.metrics.cohesion.LCOM;
import org.jpeek.metrics.cohesion.NHD;
import org.jpeek.metrics.cohesion.OCC;
import org.xembly.Directives;
import org.xembly.Xembler;

/**
Expand All @@ -54,12 +56,26 @@
public final class App {

/**
* XSL stylesheet.
* Index XSL stylesheet.
*/
private static final XSL STYLESHEET = XSLDocument.make(
App.class.getResourceAsStream("index.xsl")
);

/**
* Matrix XSL stylesheet.
*/
private static final XSL MATRIX = XSLDocument.make(
App.class.getResourceAsStream("matrix.xsl")
);

/**
* XSL stylesheet.
*/
private static final XSL BADGE = XSLDocument.make(
App.class.getResourceAsStream("badge.xsl")
);

/**
* Location of the project to analyze.
*/
Expand Down Expand Up @@ -97,7 +113,8 @@ public void analyze() throws IOException {
final Iterable<Metric> metrics = new ListOf<>(
new CAMC(base),
new LCOM(base),
new OCC(base)
new OCC(base),
new NHD(base)
);
new IoCheckedScalar<>(
new And(
Expand Down Expand Up @@ -130,6 +147,45 @@ public void analyze() throws IOException {
this.output.resolve("index.html")
)
).value();
final XML matrix = new XMLDocument(
new Xembler(
new Matrix(this.output).value()
).xmlQuietly()
);
new LengthOf(
new TeeInput(
matrix.toString(),
this.output.resolve("matrix.xml")
)
).value();
new LengthOf(
new TeeInput(
App.MATRIX.transform(matrix).toString(),
this.output.resolve("matrix.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();
}

}
71 changes: 71 additions & 0 deletions src/main/java/org/jpeek/Header.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2017 Yegor Bugayenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.jpeek;

import java.io.IOException;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Iterator;
import org.cactoos.io.ResourceOf;
import org.cactoos.iterable.PropertiesOf;
import org.xembly.Directive;
import org.xembly.Directives;

/**
* Xembly header for the report.
*
* <p>There is no thread-safety guarantee.
*
* @author Yegor Bugayenko (yegor256@gmail.com)
* @version $Id$
* @since 0.8
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
final class Header implements Iterable<Directive> {

@Override
public Iterator<Directive> iterator() {
try {
return new Directives()
.attr(
"date",
ZonedDateTime.now().format(
DateTimeFormatter.ISO_INSTANT
)
)
.attr(
"version",
new PropertiesOf(
new ResourceOf(
"org/jpeek/jpeek.properties"
)
).value().getProperty("org.jpeek.version")
)
.iterator();
} catch (final IOException ex) {
throw new IllegalStateException(ex);
}
}

}
33 changes: 14 additions & 19 deletions src/main/java/org/jpeek/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,13 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import org.cactoos.Scalar;
import org.cactoos.collection.Filtered;
import org.cactoos.collection.Joined;
import org.cactoos.io.ResourceOf;
import org.cactoos.iterable.Mapped;
import org.cactoos.iterable.PropertiesOf;
import org.cactoos.list.Sorted;
import org.xembly.Directive;
import org.xembly.Directives;
Expand Down Expand Up @@ -72,31 +68,20 @@ final class Index implements Scalar<Iterable<Directive>> {
public Iterable<Directive> value() throws IOException {
return new Directives()
.add("metrics")
.append(new Header())
.append(
new Joined<>(
new Mapped<Path, Iterable<Directive>>(
new Filtered<Path>(
Files.list(this.output)
.collect(Collectors.toList()),
path -> path.toString().endsWith(".xml")
path -> path.getFileName()
.toString()
.matches("^[A-Z].+\\.xml$")
),
Index::metric
)
)
)
.attr(
"date",
ZonedDateTime.now().format(
DateTimeFormatter.ISO_INSTANT
)
)
.attr(
"version",
new PropertiesOf(
new ResourceOf(
"org/jpeek/jpeek.properties"
)
).value().getProperty("org.jpeek.version")
);
}

Expand All @@ -117,6 +102,12 @@ private static Iterable<Directive> metric(final Path file)
Double::parseDouble
)
);
final double green = (double) xml.nodes("//*[@color='green']").size();
final double yellow = (double) xml.nodes("//*[@color='yellow']").size();
final double red = (double) xml.nodes("//*[@color='red']").size();
final double score = 10.0d
* (green + yellow * 0.25d + red * 0.05d)
/ (green + yellow + red);
return new Directives()
.add("metric")
.attr("name", name)
Expand All @@ -126,6 +117,10 @@ private static Iterable<Directive> metric(final Path file)
.add("average").set(Index.avg(values)).up()
.add("min").set(values.get(0)).up()
.add("max").set(values.get(values.size() - 1)).up()
.add("green").set((int) green).up()
.add("yellow").set((int) yellow).up()
.add("red").set((int) red).up()
.add("score").set(score).up()
.up();
}

Expand Down
Loading

0 comments on commit 517af9e

Please sign in to comment.