Skip to content

Commit

Permalink
Merge pull request #120 from refactorfirst/minor-enhancements
Browse files Browse the repository at this point in the history
#116 #119 Minor enhancements
  • Loading branch information
jimbethancourt authored Nov 17, 2024
2 parents 03b29ed + 795f153 commit 44ee1ae
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 171 deletions.
42 changes: 24 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<sonar.organization>jimbethancourt-github</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>

<maven.core.version>3.9.4</maven.core.version>
<maven.core.version>3.9.9</maven.core.version>
</properties>

<modules>
Expand Down Expand Up @@ -140,7 +140,7 @@
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>6.7.0.202309050840-r</version>
<version>6.10.0.202406032230-r</version>
<scope>compile</scope>
</dependency>

Expand Down Expand Up @@ -183,7 +183,6 @@


<dependencies>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down Expand Up @@ -338,21 +337,6 @@
</executions>
-->
</plugin>
<!-- <plugin>-->
<!-- <groupId>org.owasp</groupId>-->
<!-- <artifactId>dependency-check-maven</artifactId>-->
<!-- <version>6.1.0</version>-->
<!-- <configuration>-->
<!-- <failBuildOnCVSS>8.0</failBuildOnCVSS>-->
<!-- </configuration>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <goals>-->
<!-- <goal>check</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<!--TODO: Add the SNYK plugin-->
<!-- https://github.com/snyk/snyk-maven-plugin -->

Expand Down Expand Up @@ -395,6 +379,28 @@


<profiles>
<profile>
<id>local</id>
<build>
<plugins>
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>6.1.0</version>
<configuration>
<failBuildOnCVSS>8.0</failBuildOnCVSS>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>snapshot-release</id>
<build>
Expand Down
48 changes: 14 additions & 34 deletions refactor-first-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,6 @@
<groupId>org.hjug.refactorfirst.report</groupId>
<artifactId>report</artifactId>
</dependency>
<!-- Doxia -->
<!-- Needed since maven-reporting-impl brings in Struts 1.3.8 jars that have CVSS > 8 -->
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-sink-api</artifactId>
<version>2.0.0-M6</version>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-decoration-model</artifactId>
<version>2.0.0-M6</version>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-core</artifactId>
<version>2.0.0-M7</version>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-site-renderer</artifactId>
<version>2.0.0-M11</version>
</dependency>

<!-- Maven Reporting -->
<dependency>
Expand All @@ -52,35 +30,37 @@
<version>${maven.core.version}</version>
</dependency>

<!-- Maven Reporting -->
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-impl</artifactId>
<version>3.2.0</version>
<version>4.0.0</version>
<exclusions>
<!-- Remediates xz-1.9.jar: CVE-2022-1271 -->
<!-- Unused transitive dependency -->
<exclusion>
<groupId>org.tukaani</groupId>
<artifactId>xz</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-api</artifactId>
<version>3.1.1</version>
<version>4.0.0</version>
</dependency>

<!-- plugin API and plugin-tools -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.5.2</version>
<version>3.9.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.1</version>
<version>3.15.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-shared-utils</artifactId>
<version>3.3.3</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand All @@ -92,12 +72,12 @@
<plugins>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<version>3.1.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.9.0</version>
<version>3.15.1</version>
<configuration>
<goalPrefix>refactor-first</goalPrefix>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.hjug.mavenreport;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Paths;
import java.time.Instant;
import java.time.ZoneId;
Expand Down Expand Up @@ -147,20 +144,6 @@ public void executeReport(Locale locale) throws MavenReportException {
mainSink.unknown(script, new Object[] {HtmlMarkup.TAG_TYPE_START}, googleChartImport);
mainSink.unknown(script, new Object[] {HtmlMarkup.TAG_TYPE_END}, null);

SinkEventAttributeSet godClassJavascript = new SinkEventAttributeSet();
godClassJavascript.addAttribute(SinkEventAttributes.TYPE, "text/javascript");
godClassJavascript.addAttribute(SinkEventAttributes.SRC, "./godClassChart.js");

mainSink.unknown(script, new Object[] {HtmlMarkup.TAG_TYPE_START}, godClassJavascript);
mainSink.unknown(script, new Object[] {HtmlMarkup.TAG_TYPE_END}, null);

SinkEventAttributeSet cboJavascript = new SinkEventAttributeSet();
cboJavascript.addAttribute(SinkEventAttributes.TYPE, "text/javascript");
cboJavascript.addAttribute(SinkEventAttributes.SRC, "./cboChart.js");

mainSink.unknown(script, new Object[] {HtmlMarkup.TAG_TYPE_START}, cboJavascript);
mainSink.unknown(script, new Object[] {HtmlMarkup.TAG_TYPE_END}, null);

SinkEventAttributeSet d3js = new SinkEventAttributeSet();
d3js.addAttribute(SinkEventAttributes.TYPE, "text/javascript");
d3js.addAttribute(SinkEventAttributes.SRC, "https://d3js.org/d3.v5.min.js");
Expand Down Expand Up @@ -289,13 +272,19 @@ public void executeReport(Locale locale) throws MavenReportException {
mainSink.section2_();
mainSink.division_();

writeGodClassGchartJs(rankedGodClassDisharmonies, maxGodClassPriority - 1);
String godClassScript = writeGodClassGchartJs(rankedGodClassDisharmonies, maxGodClassPriority - 1);
SinkEventAttributeSet seriesChartDiv = new SinkEventAttributeSet();
seriesChartDiv.addAttribute(SinkEventAttributes.ID, "series_chart_div");
seriesChartDiv.addAttribute(SinkEventAttributes.ALIGN, "center");
mainSink.division(seriesChartDiv);
mainSink.division_();

SinkEventAttributeSet godClassJavascript = new SinkEventAttributeSet();
godClassJavascript.addAttribute(SinkEventAttributes.TYPE, "text/javascript");
mainSink.unknown(script, new Object[] {HtmlMarkup.TAG_TYPE_START}, godClassJavascript);
mainSink.rawText(godClassScript);
mainSink.unknown(script, new Object[] {HtmlMarkup.TAG_TYPE_END}, null);

renderGitHubButtons(mainSink);

String legendHeading = "God Class Chart Legend:";
Expand Down Expand Up @@ -399,7 +388,14 @@ public void executeReport(Locale locale) throws MavenReportException {
seriesChartDiv.addAttribute(SinkEventAttributes.ALIGN, "center");
mainSink.division(seriesChartDiv);
mainSink.division_();
writeGCBOGchartJs(rankedCBODisharmonies, maxCboPriority - 1);

String cboScript = writeGCBOGchartJs(rankedCBODisharmonies, maxCboPriority - 1);

SinkEventAttributeSet cboJavascript = new SinkEventAttributeSet();
cboJavascript.addAttribute(SinkEventAttributes.TYPE, "text/javascript");
mainSink.unknown(script, new Object[] {HtmlMarkup.TAG_TYPE_START}, cboJavascript);
mainSink.rawText(cboScript);
mainSink.unknown(script, new Object[] {HtmlMarkup.TAG_TYPE_END}, null);

renderGitHubButtons(mainSink);

Expand Down Expand Up @@ -775,63 +771,22 @@ private static void renderGitHubButton(
mainSink.unknown("a", new Object[] {HtmlMarkup.TAG_TYPE_END}, null);
}

// TODO: Move to another class to allow use by Gradle plugin
void writeGodClassGchartJs(List<RankedDisharmony> rankedDisharmonies, int maxPriority) {
String writeGodClassGchartJs(List<RankedDisharmony> rankedDisharmonies, int maxPriority) {
GraphDataGenerator graphDataGenerator = new GraphDataGenerator();
String scriptStart = graphDataGenerator.getGodClassScriptStart();
String bubbleChartData = graphDataGenerator.generateGodClassBubbleChartData(rankedDisharmonies, maxPriority);
String scriptEnd = graphDataGenerator.getGodClassScriptEnd();

String javascriptCode = scriptStart + bubbleChartData + scriptEnd;

String reportOutputDirectory = project.getModel().getReporting().getOutputDirectory();
File reportOutputDir = new File(reportOutputDirectory);
if (!reportOutputDir.exists()) {
reportOutputDir.mkdirs();
}
String pathname = reportOutputDirectory + File.separator + "godClassChart.js";

File scriptFile = new File(pathname);
try {
scriptFile.createNewFile();
} catch (IOException e) {
log.error("Failure creating God Class chart script file", e);
}

try (BufferedWriter writer = new BufferedWriter(new FileWriter(scriptFile))) {
writer.write(javascriptCode);
} catch (IOException e) {
log.error("Error writing chart script file", e);
}
return scriptStart + bubbleChartData + scriptEnd;
}

void writeGCBOGchartJs(List<RankedDisharmony> rankedDisharmonies, int maxPriority) {
String writeGCBOGchartJs(List<RankedDisharmony> rankedDisharmonies, int maxPriority) {
GraphDataGenerator graphDataGenerator = new GraphDataGenerator();
String scriptStart = graphDataGenerator.getCBOScriptStart();
String bubbleChartData = graphDataGenerator.generateCBOBubbleChartData(rankedDisharmonies, maxPriority);
String scriptEnd = graphDataGenerator.getCBOScriptEnd();

String javascriptCode = scriptStart + bubbleChartData + scriptEnd;

String reportOutputDirectory = project.getModel().getReporting().getOutputDirectory();
File reportOutputDir = new File(reportOutputDirectory);
if (!reportOutputDir.exists()) {
reportOutputDir.mkdirs();
}
String pathname = reportOutputDirectory + File.separator + "cboChart.js";

File scriptFile = new File(pathname);
try {
scriptFile.createNewFile();
} catch (IOException e) {
log.error("Failure creating CBO chart script file", e);
}

try (BufferedWriter writer = new BufferedWriter(new FileWriter(scriptFile))) {
writer.write(javascriptCode);
} catch (IOException e) {
log.error("Error writing CBO chart script file", e);
}
return scriptStart + bubbleChartData + scriptEnd;
}

void renderCycleImage(Graph<String, DefaultWeightedEdge> classGraph, RankedCycle cycle, Sink mainSink) {
Expand Down
Loading

0 comments on commit 44ee1ae

Please sign in to comment.