Skip to content

Commit

Permalink
#85 Skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jan 10, 2018
1 parent 7e528ed commit 8296674
Show file tree
Hide file tree
Showing 27 changed files with 399 additions and 2,485 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ SOFTWARE.
<dependency>
<groupId>org.cactoos</groupId>
<artifactId>cactoos</artifactId>
<version>0.25.5</version>
<version>0.28.2</version>
</dependency>
<dependency>
<groupId>org.takes</groupId>
Expand Down
43 changes: 21 additions & 22 deletions src/main/java/org/jpeek/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@
import org.cactoos.scalar.And;
import org.cactoos.scalar.AndInThreads;
import org.cactoos.scalar.IoCheckedScalar;
import org.jpeek.metrics.cohesion.CAMC;
import org.jpeek.metrics.cohesion.LCOM;
import org.jpeek.metrics.cohesion.LCOM2;
import org.jpeek.metrics.cohesion.LCOM3;
import org.jpeek.metrics.cohesion.MMAC;
import org.jpeek.metrics.cohesion.NHD;
import org.jpeek.metrics.cohesion.OCC;
import org.xembly.Directives;
import org.xembly.Xembler;

Expand Down Expand Up @@ -98,14 +91,16 @@ public void analyze() throws IOException {
);
}
final Base base = new DefaultBase(this.input);
final XML skeleton = new Skeleton(base).xml();
this.save(skeleton.toString(), "skeleton.xml");
final Iterable<Report> reports = new ListOf<>(
new Report(new CAMC(base), 0.45d, 0.10d),
new Report(new LCOM(base), 14.0d, 77.0d),
new Report(new LCOM2(base), 0.83d, -0.10d),
new Report(new LCOM3(base), 0.96d, -0.11d),
new Report(new MMAC(base), 0.08d, 0.11d),
new Report(new NHD(base), 0.53d, -0.08d),
new Report(new OCC(base), 0.43d, -0.10d)
new Report(skeleton, "CAMC", 0.45d, 0.10d),
new Report(skeleton, "LCOM", 14.0d, 77.0d),
new Report(skeleton, "LCOM2", 0.83d, -0.10d),
new Report(skeleton, "LCOM3", 0.96d, -0.11d),
new Report(skeleton, "MMAC", 0.08d, 0.11d),
new Report(skeleton, "NHD", 0.53d, -0.08d),
new Report(skeleton, "OCC", 0.43d, -0.10d)
);
new IoCheckedScalar<>(
new AndInThreads(
Expand Down Expand Up @@ -170,10 +165,12 @@ public void analyze() throws IOException {
* @throws IOException If fails
*/
private void copy(final String name) throws IOException {
new LengthOf(
new TeeInput(
new ResourceOf(String.format("org/jpeek/%s", name)),
this.output.resolve(name)
new IoCheckedScalar<>(
new LengthOf(
new TeeInput(
new ResourceOf(String.format("org/jpeek/%s", name)),
this.output.resolve(name)
)
)
).value();
}
Expand All @@ -194,10 +191,12 @@ private void copyXsl(final String name) throws IOException {
* @throws IOException If fails
*/
private void save(final String data, final String name) throws IOException {
new LengthOf(
new TeeInput(
data,
this.output.resolve(name)
new IoCheckedScalar<>(
new LengthOf(
new TeeInput(
data,
this.output.resolve(name)
)
)
).value();
}
Expand Down
68 changes: 0 additions & 68 deletions src/main/java/org/jpeek/Metric.java

This file was deleted.

60 changes: 35 additions & 25 deletions src/main/java/org/jpeek/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
package org.jpeek;

import com.jcabi.xml.ClasspathSources;
import com.jcabi.xml.Sources;
import com.jcabi.xml.StrictXML;
import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import com.jcabi.xml.XSD;
import com.jcabi.xml.XSDDocument;
import com.jcabi.xml.XSL;
Expand All @@ -36,10 +36,12 @@
import org.cactoos.io.LengthOf;
import org.cactoos.io.TeeInput;
import org.cactoos.iterable.IterableOf;
import org.cactoos.map.MapEntry;
import org.cactoos.map.MapOf;
import org.cactoos.scalar.IoCheckedScalar;
import org.cactoos.scalar.Reduced;
import org.xembly.Directives;
import org.xembly.Xembler;
import org.cactoos.text.TextOf;
import org.cactoos.time.DateAsText;

/**
* Single report.
Expand Down Expand Up @@ -67,10 +69,15 @@ final class Report {
Report.class.getResourceAsStream("xsl/metric.xsl")
).with(new ClasspathSources());

/**
* The skeleton.
*/
private final XML skeleton;

/**
* The metric.
*/
private final Metric metric;
private final String metric;

/**
* Post processing XSLs.
Expand All @@ -79,21 +86,24 @@ final class Report {

/**
* Ctor.
* @param mtc Metric
* @param xml Skeleton
* @param name Name of the metric
*/
Report(final Metric mtc) {
// @checkstyle MagicNumber (1 line)
this(mtc, 0.5d, 0.25d);
Report(final XML xml, final String name) {
this(xml, name, 0.5d, 0.1d);
}

/**
* Ctor.
* @param mtc Metric
* @param xml Skeleton
* @param name Name of the metric
* @param mean Mean
* @param sigma Sigma
*/
Report(final Metric mtc, final double mean, final double sigma) {
this.metric = mtc;
Report(final XML xml, final String name,
final double mean, final double sigma) {
this.skeleton = xml;
this.metric = name;
this.post = new IterableOf<>(
new XSLDocument(
Report.class.getResourceAsStream("xsl/metric-post-colors.xsl")
Expand Down Expand Up @@ -135,7 +145,7 @@ public void save(final Path target) throws IOException {
)
)
)
).value();
).intValue();
new LengthOf(
new TeeInput(
Report.STYLESHEET.transform(xml).toString(),
Expand All @@ -146,7 +156,7 @@ public void save(final Path target) throws IOException {
)
)
)
).value();
).intValue();
}

/**
Expand All @@ -155,18 +165,18 @@ public void save(final Path target) throws IOException {
* @throws IOException If fails
*/
private XML xml() throws IOException {
return new XMLDocument(
new Xembler(
new Directives()
.pi("xml-stylesheet", "href='metric.xsl' type='text/xsl'")
.append(this.metric.xembly())
.xpath("/metric")
.append(new Header())
.add("title")
.set(this.metric.getClass().getSimpleName())
.up()
).xmlQuietly()
);
return new XSLDocument(
new TextOf(
this.getClass().getResource(
String.format("metrics/%s.xsl", this.metric)
)
).asString(),
Sources.DUMMY,
new MapOf<>(
new MapEntry<>("version", new Version().value()),
new MapEntry<>("date", new DateAsText())
)
).transform(this.skeleton);
}

}
Loading

0 comments on commit 8296674

Please sign in to comment.