Skip to content

Commit

Permalink
Fix HTML report structure (closes #715) (#723)
Browse files Browse the repository at this point in the history
* Fix and cleanup HtmlReporter generated HTML structure

* Bump version to 0.45.0

* Lowercase missed tag
  • Loading branch information
marcinfigiel authored Jan 31, 2023
1 parent 3274580 commit 7b8c8e0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,36 @@ class HtmlReporter(
override val gradleReleaseChannel: String,
) : AbstractReporter(project, revision, gradleReleaseChannel) {
override fun write(printStream: OutputStream, result: Result) {
printStream.println("<!doctype html>")
printStream.println("<html lang=\"en\">")
writeHeader(printStream)
writeBody(printStream, result)
printStream.println("</html>")
}

private fun writeHeader(printStream: OutputStream) {
printStream.println(header.trimMargin())
}

private fun writeBody(printStream: OutputStream, result: Result) {
printStream.println("<body>")
if (result.count == 0) {
printStream.println("<P>No dependencies found.</P>")
printStream.println("<p>No dependencies found.</p>")
} else {
writeUpToDate(printStream, result)
writeExceedLatestFound(printStream, result)
writeUpgrades(printStream, result)
writeUndeclared(printStream, result)
writeUnresolved(printStream, result)
}

writeGradleUpdates(printStream, result)
}

private fun writeHeader(printStream: OutputStream) {
printStream.println(header.trimMargin())
printStream.println("</body>")
}

private fun writeUpToDate(printStream: OutputStream, result: Result) {
val versions = result.current.dependencies
if (versions.isNotEmpty()) {
printStream.println("<H2>Current dependencies</H2>")
printStream.println("<h2>Current dependencies</h2>")
printStream
.println("<p>The following dependencies are using the latest $revision version:<p>")
printStream.println("<table class=\"currentInfo\">")
Expand All @@ -56,7 +63,7 @@ class HtmlReporter(
if (versions.isNotEmpty()) {
// The following dependencies exceed the version found at the "
// + revision + " revision level:
printStream.println("<H2>Exceeded dependencies</H2>")
printStream.println("<h2>Exceeded dependencies</h2>")
printStream.println(
"<p>The following dependencies exceed the version found at the $revision revision level:<p>"
)
Expand All @@ -72,7 +79,7 @@ class HtmlReporter(
private fun writeUpgrades(printStream: OutputStream, result: Result) {
val versions = result.outdated.dependencies
if (versions.isNotEmpty()) {
printStream.println("<H2>Later dependencies</H2>")
printStream.println("<h2>Later dependencies</h2>")
printStream.println("<p>The following dependencies have later $revision versions:<p>")
printStream.println("<table class=\"warningInfo\">")
for (it in getUpgradesRows(result)) {
Expand All @@ -86,7 +93,7 @@ class HtmlReporter(
private fun writeUndeclared(printStream: OutputStream, result: Result) {
val versions = result.undeclared.dependencies
if (versions.isNotEmpty()) {
printStream.println("<H2>Undeclared dependencies</H2>")
printStream.println("<h2>Undeclared dependencies</h2>")
printStream.println(
"<p>Failed to compare versions for the following dependencies because they were declared without version:<p>"
)
Expand All @@ -102,7 +109,7 @@ class HtmlReporter(
private fun writeUnresolved(printStream: OutputStream, result: Result) {
val versions = result.unresolved.dependencies
if (versions.isNotEmpty()) {
printStream.println("<H2>Unresolved dependencies</H2>")
printStream.println("<h2>Unresolved dependencies</h2>")
printStream
.println("<p>Failed to determine the latest version for the following dependencies:<p>")
printStream.println("<table class=\"warningInfo\">")
Expand All @@ -118,32 +125,29 @@ class HtmlReporter(
if (!result.gradle.enabled) {
return
}

printStream.println("<H2>Gradle $gradleReleaseChannel updates</H2>")

printStream.println("<h2>Gradle $gradleReleaseChannel updates</h2>")
printStream.println("Gradle $gradleReleaseChannel updates:")
// Log Gradle update checking failures.
if (result.gradle.current.isFailure) {
printStream.println(
"<P>[ERROR] [release channel: ${CURRENT.id}] " + result.gradle.current.reason + "</P>"
"<p>[ERROR] [release channel: ${CURRENT.id}] " + result.gradle.current.reason + "</p>"
)
}
if ((gradleReleaseChannel == RELEASE_CANDIDATE.id || gradleReleaseChannel == NIGHTLY.id) &&
result.gradle.releaseCandidate.isFailure
) {
printStream.println(
"<P>[ERROR] [release channel: ${RELEASE_CANDIDATE.id}] " + result
.gradle.releaseCandidate.reason + "</P>"
"<p>[ERROR] [release channel: ${RELEASE_CANDIDATE.id}] " + result.gradle.releaseCandidate.reason + "</p>"
)
}
if (gradleReleaseChannel == NIGHTLY.id && result.gradle.nightly.isFailure) {
printStream.println(
"<P>[ERROR] [release channel: ${NIGHTLY.id}] " + result.gradle.nightly.reason + "</P>"
"<p>[ERROR] [release channel: ${NIGHTLY.id}] " + result.gradle.nightly.reason + "</p>"
)
}

// print Gradle updates in breadcrumb format
printStream.print("<P>Gradle: [" + getGradleVersionUrl(result.gradle.running.version))
printStream.print("<p>Gradle: [" + getGradleVersionUrl(result.gradle.running.version))
var updatePrinted = false
if (result.gradle.current.isUpdateAvailable && result.gradle.current > result.gradle.running) {
updatePrinted = true
Expand All @@ -168,7 +172,7 @@ class HtmlReporter(
if (!updatePrinted) {
printStream.print(": UP-TO-DATE")
}
printStream.println("]<P>")
printStream.println("]</p>")
printStream.println(getGradleUrl())
}

Expand Down Expand Up @@ -216,13 +220,13 @@ class HtmlReporter(

companion object {
private const val header = """
<!DOCTYPE html>
<HEAD><TITLE>Project Dependency Updates Report</TITLE></HEAD>
<style type=\"text/css\">
<head>
<title>Project Dependency Updates Report</title>
<style>
.body {
font:100% verdana, arial, sans-serif;
background-color:#fff
}
font:100% verdana, arial, sans-serif;
background-color:#fff
}
.currentInfo {
border-collapse: collapse;
}
Expand All @@ -241,11 +245,10 @@ class HtmlReporter(
border-collapse: collapse;
}
.currentInfo tr:nth-child(odd) {
background-color: #EFFFD2;
background-color: #EFFFD2;
padding: 12px 15px;
border-collapse: collapse;
}
.warningInfo {
border-collapse: collapse;
}
Expand All @@ -264,27 +267,25 @@ class HtmlReporter(
border-collapse: collapse;
}
.warningInfo tr:nth-child(odd) {
background-color: #FFFFCC;
background-color: #FFFFCC;
padding: 12px 15px;
border-collapse: collapse;
}
</style>
<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js\"></script>
<script type="text/javascript">
\$(document).ready(function(){
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
/* set current to collapsed initially */
\$('#currentId').nextUntil('tr.header').slideToggle(100, function(){});
$('#currentId').nextUntil('tr.header').slideToggle(100, function(){});
/* click callback to toggle tables */
\$('tr.header').click(function(){
\$(this).find('span').text(function(_, value){return value=='(Click to collapse)'?'(Click to expand)':'(Click to collapse)'});
\$(this).nextUntil('tr.header').slideToggle(100, function(){
$('tr.header').click(function(){
$(this).find('span').text(function(_, value){return value=='(Click to collapse)'?'(Click to expand)':'(Click to collapse)'});
$(this).nextUntil('tr.header').slideToggle(100, function(){
});
});
});
});
</script>
</head>
"""

private fun getCurrentRows(result: Result): List<String> {
Expand Down Expand Up @@ -389,7 +390,7 @@ class HtmlReporter(
}

private fun getGradleUrl(): String {
return "<P>For information about Gradle releases click <a target=\"_blank\" href=\"https://gradle.org/releases/\">here</a>."
return "<p>For information about Gradle releases click <a target=\"_blank\" href=\"https://gradle.org/releases/\">here</a>.</p>"
}

private fun getGradleVersionUrl(version: String?): String {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GROUP=com.github.ben-manes
VERSION_NAME=0.44.0
VERSION_NAME=0.45.0

POM_INCEPTION_YEAR=2012
POM_PACKAGING=jar
Expand Down

0 comments on commit 7b8c8e0

Please sign in to comment.