Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort project group order in HTML report using license keys #433

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class HtmlReport(private val projects: List<Model>) : Report {
override fun report(): String = if (projects.isEmpty()) emptyReport() else fullReport()

override fun fullReport(): String {
val projectsMap = hashMapOf<String?, List<Model>>()
val projectsMap = hashMapOf<String, List<Model>>()
val licenseMap = LicenseHelper.licenseMap

// Store packages by licenses: build a composite key of all the licenses, sorted in the (probably vain)
Expand All @@ -66,6 +66,13 @@ class HtmlReport(private val projects: List<Model>) : Report {
(projectsMap[key] as MutableList).add(project)
}

val sortedProjectsList =
projectsMap.entries.map { (key, projects) ->
Pair(key, projects.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.name }))
}.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.first })

sortedProjectsList.forEach { (key, _) -> println(key) }

return buildString {
appendLine(DOCTYPE) // createHTMLDocument() add doctype and meta
appendHTML()
Expand All @@ -83,20 +90,14 @@ class HtmlReport(private val projects: List<Model>) : Report {
h3 {
+NOTICE_LIBRARIES
}

projectsMap.entries.forEach { entry ->
sortedProjectsList.forEach { (key, sortedProjects) ->
var currentProject: Model? = null
var currentLicense: Int? = null

ul {
val sortedProjects =
entry.value.sortedWith(
compareBy(String.CASE_INSENSITIVE_ORDER) { it.name },
)

sortedProjects.forEach { project ->
currentProject = project
currentLicense = entry.key.hashCode()
currentLicense = key.hashCode()

// Display libraries
li {
Expand Down Expand Up @@ -142,7 +143,7 @@ class HtmlReport(private val projects: List<Model>) : Report {
val sortedKeysAndLicenses =
licenses.map { license ->
Pair(getLicenseKey(license), license)
}.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { (key, license) -> key })
}.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.first })

sortedKeysAndLicenses.forEach { (key, license) ->
if (key.isNotEmpty() && licenseMap.values.contains(key)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ final class HtmlReportSpec extends Specification {
</head>
<body>
<h3>Notice for packages:</h3>
<ul>
<li>
<a href="#0">name (1.2.3)</a>
<dl>
<dt>Copyright &copy; 20xx name</dt>
<dd></dd>
<dt>Copyright &copy; 20xx name</dt>
<dd></dd>
</dl>
</li>
</ul>
<a id="0"></a>
<pre>No license found</pre>
<hr>
<ul>
<li>
<a href="#87638953">name (1.2.3)</a>
Expand All @@ -105,20 +119,6 @@ final class HtmlReportSpec extends Specification {
<a href="url">url</a></pre>
<br>
<hr>
<ul>
<li>
<a href="#0">name (1.2.3)</a>
<dl>
<dt>Copyright &copy; 20xx name</dt>
<dd></dd>
<dt>Copyright &copy; 20xx name</dt>
<dd></dd>
</dl>
</li>
</ul>
<a id="0"></a>
<pre>No license found</pre>
<hr>
</body>
</html>
"""
Expand Down