Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/yegor256/jpeek into LCOM2…
Browse files Browse the repository at this point in the history
…_LCOM3_Impl
  • Loading branch information
Yildirim authored and Yildirim committed Oct 31, 2017
2 parents ab64b12 + ddb0af5 commit 28f769c
Show file tree
Hide file tree
Showing 18 changed files with 483 additions and 55 deletions.
1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -126,6 +126,7 @@ SOFTWARE.
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-xml</artifactId>
<version>0.21</version>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
Expand Down
26 changes: 25 additions & 1 deletion src/main/java/org/jpeek/App.java
Expand Up @@ -58,12 +58,19 @@
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.
*/
Expand Down Expand Up @@ -144,6 +151,23 @@ 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(
Expand Down
71 changes: 71 additions & 0 deletions src/main/java/org/jpeek/Header.java
@@ -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);
}
}

}
23 changes: 4 additions & 19 deletions src/main/java/org/jpeek/Index.java
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 Down
124 changes: 124 additions & 0 deletions src/main/java/org/jpeek/Matrix.java
@@ -0,0 +1,124 @@
/**
* 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 com.jcabi.xml.XMLDocument;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.stream.Collectors;
import org.cactoos.Scalar;
import org.cactoos.collection.Filtered;
import org.cactoos.collection.Joined;
import org.cactoos.iterable.Mapped;
import org.cactoos.scalar.And;
import org.cactoos.scalar.IoCheckedScalar;
import org.xembly.Directive;
import org.xembly.Directives;

/**
* Matrix.
*
* <p>There is no thread-safety guarantee.
*
* @author Yegor Bugayenko (yegor256@gmail.com)
* @version $Id$
* @since 0.6
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
final class Matrix implements Scalar<Iterable<Directive>> {

/**
* Directory to save index to.
*/
private final Path output;

/**
* Ctor.
* @param target Target dir
*/
Matrix(final Path target) {
this.output = target;
}

@Override
public Iterable<Directive> value() throws IOException {
final SortedMap<String, Map<String, String>> matrix = new TreeMap<>();
new IoCheckedScalar<>(
new And(
new Filtered<>(
Files.list(this.output)
.collect(Collectors.toList()),
path -> path.getFileName()
.toString()
.matches("^[A-Z].+\\.xml$")
),
path -> {
new And(
new XMLDocument(path.toFile()).nodes("//class"),
node -> {
final String name = String.format(
"%s.%s",
node.xpath("../../package/@id").get(0),
node.xpath("@id").get(0)
);
matrix.putIfAbsent(name, new TreeMap<>());
matrix.get(name).put(
node.xpath("/metric/title/text()").get(0),
node.xpath("@color").get(0)
);
}
).value();
}
)
).value();
return new Directives()
.add("matrix")
.append(new Header())
.add("classes")
.append(
new Joined<Directive>(
new Mapped<>(
matrix.entrySet(),
ent -> new Directives().add("class").append(
new Joined<Directive>(
new Mapped<>(
ent.getValue().entrySet(),
mtd -> new Directives()
.add("metric")
.attr("name", mtd.getKey())
.attr("color", mtd.getValue())
.up()
)
)
).attr("id", ent.getKey()).up()
)
)
);
}

}
19 changes: 1 addition & 18 deletions src/main/java/org/jpeek/Report.java
Expand Up @@ -32,12 +32,8 @@
import com.jcabi.xml.XSLDocument;
import java.io.IOException;
import java.nio.file.Path;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import org.cactoos.io.LengthOf;
import org.cactoos.io.ResourceOf;
import org.cactoos.io.TeeInput;
import org.cactoos.iterable.PropertiesOf;
import org.xembly.Directives;
import org.xembly.Xembler;

Expand Down Expand Up @@ -125,20 +121,7 @@ private XML xml() throws IOException {
.pi("xml-stylesheet", "href='jpeek.xsl' type='text/xsl'")
.append(this.metric.xembly())
.xpath("/metric")
.attr(
"date",
ZonedDateTime.now().format(
DateTimeFormatter.ISO_INSTANT
)
)
.attr(
"version",
new PropertiesOf(
new ResourceOf(
"org/jpeek/jpeek.properties"
)
).value().getProperty("org.jpeek.version")
)
.append(new Header())
.add("title")
.set(this.metric.getClass().getSimpleName())
.up()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jpeek/metrics/Colors.java
Expand Up @@ -62,7 +62,7 @@ public String toString() {
if (this.low < this.high) {
text = String.format("(%.2f .. %.2f]", this.low, this.high);
} else {
text = String.format("[%.2f .. %.2f)", this.high, this.low);
text = String.format("[%.2f .. %.2f)", this.low, this.high);
}
return text;
}
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/org/jpeek/metrics/cohesion/CAMC.java
Expand Up @@ -61,6 +61,7 @@
* <p>There is no thread-safety guarantee.
*
* @author Yegor Bugayenko (yegor256@gmail.com)
* @author Mehmet Yildirim (memoyil@gmail.com)
* @version $Id$
* @see <a href="https://pdfs.semanticscholar.org/2709/1005bacefaee0242cf2643ba5efa20fa7c47.pdf">A class cohesion metric for object-oriented designs</a>
* @since 0.1
Expand All @@ -87,7 +88,7 @@ public Iterable<Directive> xembly() throws IOException {
return new JavassistClasses(
this.base, CAMC::cohesion,
// @checkstyle MagicNumberCheck (1 line)
new Colors(0.15d, 0.35d)
new Colors(0.10d, 0.35d)
).xembly();
}

Expand All @@ -100,18 +101,18 @@ public Iterable<Directive> xembly() throws IOException {
private static double cohesion(final CtClass ctc) throws NotFoundException {
final Collection<Collection<String>> methods = CAMC.methods(ctc);
final Collection<String> types = new HashSet<>(
new Joined<String>(
new Joined<>(
() -> new Mapped<>(
methods.iterator(),
strings -> strings
)
)
);
int sum = 0;
for (final Collection<String> mtd : methods) {
for (final String type : types) {
int mine = 0;
for (final String arg : mtd) {
if (types.contains(arg)) {
for (final Collection<String> mtd : methods) {
if (mtd.contains(type)) {
++mine;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jpeek/metrics/cohesion/LCOM.java
Expand Up @@ -87,7 +87,7 @@ public Iterable<Directive> xembly() throws IOException {
return new JavassistClasses(
this.base, LCOM::cohesion,
// @checkstyle MagicNumberCheck (1 line)
new Colors(30.0d, 5.0d)
new Colors(100.0d, 5.0d)
).xembly();
}

Expand Down

0 comments on commit 28f769c

Please sign in to comment.