Skip to content

Commit

Permalink
up to 0.1.1-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
hangga committed Dec 6, 2024
1 parent e47b503 commit c4276a4
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 231 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ gradlePlugin {
tasks.register<JavaExec>("scanDelvelin") {
classpath = sourceSets["main"].runtimeClasspath
mainClass.set("io.github.hangga.delvelin.Delvelin")
args("format_html")
// args("format_json")
// args("format_html")
args("format_json")
}
128 changes: 5 additions & 123 deletions src/main/java/io/github/hangga/delvelin/utils/Reports.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ public static void generateHtmlReport() {
}
buildBarChart(htmlBuffer, cweCounts, priorities);
buildPieChart(htmlBuffer, cweCounts, priorities);
// buildBarChart(htmlBuffer, cweCounts, priorities);

appendFooter(htmlBuffer);

Expand All @@ -304,35 +303,6 @@ private static void buildHtmlHeader(StringBuffer htmlBuffer) {
}
}

// private static void buildFileStatsBarChart(StringBuffer htmlBuffer, Map<String, Long> fileStats) {
// // Persiapan data untuk labels dan data
// String fileLabels = fileStats.keySet()
// .stream()
// .map(ext -> "\"" + ext + "\"")
// .collect(Collectors.joining(","));
// String fileData = fileStats.values()
// .stream()
// .map(String::valueOf)
// .collect(Collectors.joining(","));
//
// // Warna default jika tidak ada prioritas
// String chartColors = "[\"#4CAF50\", \"#FFC107\", \"#F44336\", \"#2196F3\", \"#9C27B0\"]"; // Kamu bisa tambahkan logika warna jika dibutuhkan
//
// try {
// String template = loadResource("html/filestats-bar-chart.html");
//
// // Mengganti placeholder dengan data aktual
// String populatedHtml = template.replace("${STAT_LABELS}", fileLabels)
// .replace("${STAT_DATA}", fileData)
// .replace("${STAT_CHART_COLORS}", chartColors);
//
// // Menambahkan hasil ke htmlBuffer
// htmlBuffer.append(populatedHtml);
// } catch (IOException e) {
// throw new RuntimeException("Failed to load or process bar chart template", e);
// }
// }

private static void buildFileStatsBarChart(StringBuffer htmlBuffer, Map<String, Long> fileStats) {
// Hitung total nilai
long totalFiles = fileStats.values()
Expand Down Expand Up @@ -552,98 +522,6 @@ static String getDirName() {
return path.substring(path.lastIndexOf(SourceSet.SEP) + 1);
}

// String getDirName(){
// String path = String.valueOf(FileUtil.getBasePath());
// String[] end = path.split(SourceSet.SEP);
// return end[end.length - 1];
// }

// public static void generateJson() {
// if (itemReports.isEmpty()) {
// return;
// }
//
// // Grouping reports by CWE Code
// Map<String, List<ItemReport>> groupedReports = itemReports.stream()
// .collect(Collectors.groupingBy(ItemReport::getCweCode));
//
// StringBuilder jsonBuilder = new StringBuilder();
// jsonBuilder.append("{");
//
// String dateReport = formattedDate();
// jsonBuilder.append("\"date\": \"")
// .append(dateReport)
// .append("\",");
//
// jsonBuilder.append("\"projectRoot\": \"")
// .append(getDirName())
// .append("\",");
//
// jsonBuilder.append("\"vulnerabilities\": [");
//
// boolean isFirstCwe = true;
//
// for (Map.Entry<String, List<ItemReport>> entry : groupedReports.entrySet()) {
// if (!isFirstCwe) {
// jsonBuilder.append(",");
// }
//
// String cweCode = entry.getKey();
// List<ItemReport> reports = entry.getValue();
//
// String vulnerabilityName = reports.get(0)
// .getVulnerabilityName();
//
// String priority = reports.get(0)
// .getPriority();
//
// jsonBuilder.append("{");
// jsonBuilder.append("\"cweCode\": \"")
// .append(cweCode)
// .append("\",");
// jsonBuilder.append("\"vulnerabilityName\": \"")
// .append(vulnerabilityName)
// .append("\",");
// jsonBuilder.append("\"priority\": \"")
// .append(priority)
// .append("\",");
// jsonBuilder.append("\"issues\": [");
//
// boolean isFirstFinding = true;
// for (ItemReport item : reports) {
// if (!isFirstFinding) {
// jsonBuilder.append(",");
// }
//
// jsonBuilder.append("{");
// jsonBuilder.append("\"issues\": \"")
// .append(escapeJson(item.getFinding()))
// .append("\",");
// jsonBuilder.append("\"message\": \"")
// .append(escapeJson(item.getMessage()))
// .append("\",");
// jsonBuilder.append("\"location\": \"")
// .append(escapeJson(item.getSpecificLocation()))
// .append("\"");
// jsonBuilder.append("}");
// isFirstFinding = false;
// }
//
// jsonBuilder.append("]");
// jsonBuilder.append("}");
// isFirstCwe = false;
// }
//
// jsonBuilder.append("]");
// jsonBuilder.append("}");
//
// if (Config.isShowSaveDialog) {
// FileUtil.saveOutputCustom(jsonBuilder.toString(), ".json");
// } else {
// FileUtil.saveOutputFile(jsonBuilder.toString(), ".json");
// }
// }

public static void generateJson() {
if (itemReports.isEmpty()) {
return;
Expand All @@ -665,6 +543,10 @@ public static void generateJson() {
.append(getDirName())
.append("\",\n");

jsonBuilder.append("\"projectPath\": \"")
.append(FileUtil.getBasePath())
.append("\",\n");

// Adding file extension statistics
Map<String, Long> fileStats = countFilesByExtensionFromReports();
jsonBuilder.append("\"fileExtensions\": {\n");
Expand Down Expand Up @@ -718,7 +600,7 @@ public static void generateJson() {
}

jsonBuilder.append("{\n");
jsonBuilder.append("\"issues\": \"")
jsonBuilder.append("\"issue\": \"")
.append(escapeJson(item.getFinding()))
.append("\",\n");
jsonBuilder.append("\"message\": \"")
Expand Down
63 changes: 2 additions & 61 deletions vulnerability-report.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,38 +149,6 @@ <h2>Vulnerability Report</h2>
</div>
<br/>

<!--<script>-->
<!-- const fileStats = ${STAT_DATA_OBJECT}; // Format: {"extension": value}-->
<!-- const totalFiles = Object.values(fileStats).reduce((sum, count) => sum + count, 0);-->

<!-- const barContainer = document.querySelector("ul");-->

<!-- Object.entries(fileStats).forEach(([ext, count]) => {-->
<!-- const percentage = ((count / totalFiles) * 100).toFixed(1);-->
<!-- const barItem = `-->
<!-- <li style="margin-bottom: 8px; display: flex; align-items: center;">-->
<!-- <span style="width: 80px; text-align: right; padding-right: 10px; font-weight: bold;">${ext}</span>-->
<!-- <div style="flex: 1; height: 18px; background-color: #ddd; border-radius: 4px; overflow: hidden; margin: 0 10px;">-->
<!-- <div style="width: ${percentage}%; height: 100%; background-color: ${getBarColor(ext)}; border-radius: 4px;"></div>-->
<!-- </div>-->
<!-- <span style="width: 50px; text-align: left;">${percentage}%</span>-->
<!-- </li>-->
<!-- `;-->
<!-- barContainer.insertAdjacentHTML("beforeend", barItem);-->
<!-- });-->

<!-- function getBarColor(ext) {-->
<!-- const colors = {-->
<!-- ".java": "#4CAF50",-->
<!-- ".kt": "#FFC107",-->
<!-- ".xml": "#F44336",-->
<!-- ".properties": "#2196F3",-->
<!-- ".json": "#9C27B0",-->
<!-- };-->
<!-- return colors[ext] || "#757575"; // Default color-->
<!-- }-->
<!--</script>-->

<style>
details summary:hover {
background-color: #9694FF; /* Warna saat hover */
Expand Down Expand Up @@ -1936,39 +1904,12 @@ <h2>Vulnerability Report</h2>

</table>
</details>
<!--<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>-->
<!--<script>-->
<!-- const barCtx = document.getElementById('findingsBarChart').getContext('2d');-->
<!-- new Chart(barCtx, {-->
<!-- type: 'bar',-->
<!-- data: {-->
<!-- labels: [${CWE_LABELS}],-->
<!-- datasets: [{-->
<!-- label: 'Issues',-->
<!-- data: [${CWE_DATA}],-->
<!-- backgroundColor: ${CHART_COLORS},-->
<!-- borderWidth: 1-->
<!-- }]-->
<!-- },-->
<!-- options: {-->
<!-- indexAxis: 'y', // Membuat grafik horizontal-->
<!-- scales: {-->
<!-- x: { beginAtZero: true }-->
<!-- },-->
<!-- plugins: {-->
<!-- legend: { display: false }-->
<!-- }-->
<!-- }-->
<!-- });-->
<!--</script>-->
<h3 style="text-align: center; font-family: Arial, sans-serif;">CWE Issues Distribution</h3>
<div
style="display: flex; justify-content: space-between; align-items: center; height: 400px; border: 1px solid #9694FF; border-radius: 8px;">

<!-- <canvas id="findingsBarChart" style="flex: 1; margin: 0 10px;"></canvas>-->
<div
style="width:50%; padding: 10px;">

<ul
style="list-style: none; padding: 10; margin: 0; font-family: Arial, sans-serif; font-size: 14px;">
${BAR_ITEMS_BAR}
Expand Down Expand Up @@ -2039,7 +1980,7 @@ <h3 style="text-align: center; font-family: Arial, sans-serif;">CWE Issues Distr
<footer style="margin-top: 40px; text-align: center; font-size: 12px; color: #666;">
<hr style="border: none; border-top: 1px solid #ccc; margin: 20px 0;">
<div>Generated by <strong>Delveline</strong> v0.1.1-beta</div>
<div>2024-12-07 06:43:14</div>
<div>For more information, visit: <a href="https://github.com/hangga/delvelin" target="_blank">https://github.com/hangga/delvelin</a></div>
<div>2024-12-07 06:50:41</div>
<div>For more information, visit: <a href="https://delvelin.github.io" target="_blank">https://delvelin.github.io</a></div>
<div>© 2024 Delveline Team. All Rights Reserved.</div>
</footer>
Loading

0 comments on commit c4276a4

Please sign in to comment.