Skip to content

Commit aacd41b

Browse files
Merge pull request #212 from refactorfirst/#169-generate-report-with-moustache-and-json
Generating report using JSON Data and Moustache template for use in GitHub Page. Has feature parity with HtmlReport generator.
2 parents 5c494f8 + 78bae44 commit aacd41b

28 files changed

Lines changed: 3089 additions & 126 deletions
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.hjug.mavenreport;
2+
3+
import java.io.File;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.apache.maven.plugin.AbstractMojo;
6+
import org.apache.maven.plugins.annotations.LifecyclePhase;
7+
import org.apache.maven.plugins.annotations.Mojo;
8+
import org.apache.maven.plugins.annotations.Parameter;
9+
import org.apache.maven.plugins.annotations.ResolutionScope;
10+
import org.apache.maven.project.MavenProject;
11+
import org.hjug.refactorfirst.report.JsonGenerator;
12+
13+
@Slf4j
14+
@Mojo(
15+
name = "jsonReport",
16+
defaultPhase = LifecyclePhase.SITE,
17+
requiresDependencyResolution = ResolutionScope.RUNTIME,
18+
requiresProject = true,
19+
threadSafe = true,
20+
inheritByDefault = false)
21+
public class RefactorFirstMavenJsonGenerator extends AbstractMojo {
22+
23+
@Parameter(property = "showDetails")
24+
private boolean showDetails;
25+
26+
@Parameter(property = "backEdgeAnalysisCount")
27+
protected int backEdgeAnalysisCount = 50;
28+
29+
@Parameter(property = "analyzeCycles")
30+
private boolean analyzeCycles = true;
31+
32+
@Parameter(property = "excludeTests")
33+
private boolean excludeTests = true;
34+
35+
@Parameter(property = "testSourceDirectory")
36+
private String testSourceDirectory;
37+
38+
@Parameter(defaultValue = "${project.name}")
39+
private String projectName;
40+
41+
@Parameter(defaultValue = "${project.version}")
42+
private String projectVersion;
43+
44+
@Parameter(readonly = true, defaultValue = "${project}")
45+
private MavenProject project;
46+
47+
@Parameter(property = "project.build.directory")
48+
protected File outputDirectory;
49+
50+
/** Generates the RefactorFirst JSON report for the current Maven project. */
51+
@Override
52+
public void execute() {
53+
JsonGenerator generator = new JsonGenerator();
54+
generator.execute(
55+
backEdgeAnalysisCount,
56+
analyzeCycles,
57+
showDetails,
58+
excludeTests,
59+
testSourceDirectory,
60+
projectName,
61+
projectVersion,
62+
project.getBasedir(),
63+
outputDirectory);
64+
}
65+
}

‎report/pom.xml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
<groupId>in.wilsonl.minifyhtml</groupId>
2727
<artifactId>minify-html</artifactId>
2828
</dependency>
29+
30+
<dependency>
31+
<groupId>com.github.spullara.mustache.java</groupId>
32+
<artifactId>compiler</artifactId>
33+
<version>0.9.10</version>
34+
<scope>test</scope>
35+
</dependency>
2936
</dependencies>
3037

3138
</project>

‎report/src/main/java/org/hjug/refactorfirst/report/HtmlReport.java‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,8 @@ private static String generateDotImage(String graphName) {
561561
+ " }\n" + "</script>\n";
562562
}
563563

564-
String buildClassGraphDot(
564+
/** Builds raw DOT source for the complete class relationship graph. */
565+
String buildRawClassGraphDot(
565566
Graph<String, DefaultWeightedEdge> classGraph, String repoUrl, CodebaseGraphDTO codebaseGraphDTO) {
566567
StringBuilder dot = new StringBuilder();
567568
dot.append("strict digraph G {\n");
@@ -583,7 +584,13 @@ String buildClassGraphDot(
583584
renderClassVertices(classGraph, repoUrl, codebaseGraphDTO, vertexesToRender, dot);
584585

585586
dot.append("}");
586-
return toJavaScriptTemplateLiteral(dot.toString());
587+
return dot.toString();
588+
}
589+
590+
/** Builds escaped class-graph DOT suitable for a JavaScript template literal. */
591+
String buildClassGraphDot(
592+
Graph<String, DefaultWeightedEdge> classGraph, String repoUrl, CodebaseGraphDTO codebaseGraphDTO) {
593+
return toJavaScriptTemplateLiteral(buildRawClassGraphDot(classGraph, repoUrl, codebaseGraphDTO));
587594
}
588595

589596
private void renderClassVertices(
@@ -942,7 +949,8 @@ public String renderClassCycleVisuals(RankedCycle cycle, String repoUrl, Codebas
942949
return stringBuilder.toString();
943950
}
944951

945-
String buildClassCycleDot(
952+
/** Builds raw DOT source for a ranked class cycle. */
953+
String buildRawClassCycleDot(
946954
Graph<String, DefaultWeightedEdge> classGraph,
947955
RankedCycle cycle,
948956
String repoUrl,
@@ -959,7 +967,16 @@ String buildClassCycleDot(
959967
renderClassVertices(classGraph, repoUrl, codebaseGraphDTO, vertexSet, dot);
960968

961969
dot.append("}");
962-
return toJavaScriptTemplateLiteral(dot.toString());
970+
return dot.toString();
971+
}
972+
973+
/** Builds escaped class-cycle DOT suitable for a JavaScript template literal. */
974+
String buildClassCycleDot(
975+
Graph<String, DefaultWeightedEdge> classGraph,
976+
RankedCycle cycle,
977+
String repoUrl,
978+
CodebaseGraphDTO codebaseGraphDTO) {
979+
return toJavaScriptTemplateLiteral(buildRawClassCycleDot(classGraph, cycle, repoUrl, codebaseGraphDTO));
963980
}
964981

965982
@Override
@@ -996,7 +1013,8 @@ public String renderPackageGraphVisuals(String repoUrl, CodebaseGraphDTO codebas
9961013
return stringBuilder.toString();
9971014
}
9981015

999-
String buildPackageGraphDot(
1016+
/** Builds raw DOT source for the package relationship graph. */
1017+
String buildRawPackageGraphDot(
10001018
Graph<String, DefaultWeightedEdge> packageGraph, String repoUrl, CodebaseGraphDTO codebaseGraphDTO) {
10011019
StringBuilder dot = new StringBuilder();
10021020
dot.append("strict digraph G {\n");
@@ -1017,7 +1035,13 @@ String buildPackageGraphDot(
10171035
renderPackageVertices(packageGraph, repoUrl, codebaseGraphDTO, vertexesToRender, dot);
10181036

10191037
dot.append("}");
1020-
return toJavaScriptTemplateLiteral(dot.toString());
1038+
return dot.toString();
1039+
}
1040+
1041+
/** Builds escaped package-graph DOT suitable for a JavaScript template literal. */
1042+
String buildPackageGraphDot(
1043+
Graph<String, DefaultWeightedEdge> packageGraph, String repoUrl, CodebaseGraphDTO codebaseGraphDTO) {
1044+
return toJavaScriptTemplateLiteral(buildRawPackageGraphDot(packageGraph, repoUrl, codebaseGraphDTO));
10211045
}
10221046

10231047
private void renderPackageGraphEdge(

0 commit comments

Comments
 (0)