Skip to content

Commit

Permalink
Merge pull request #25 from rocketlawyer/feature/csvTargetLanguage
Browse files Browse the repository at this point in the history
Add CSV target language
  • Loading branch information
eed3si9n committed Feb 25, 2016
2 parents 744a645 + 8d6c6ed commit f905fa1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/main/scala/com/typesafe/sbt/SbtLicenseReport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ object SbtLicenseReport extends AutoPlugin {
def LicenseReportConfiguration = com.typesafe.sbt.license.LicenseReportConfiguration
def Html = com.typesafe.sbt.license.Html
def MarkDown = com.typesafe.sbt.license.MarkDown
def Csv = com.typesafe.sbt.license.Csv

// Keys
val updateLicenses = taskKey[LicenseReport]("Construct a report of used licenses in a project.")
Expand Down Expand Up @@ -59,11 +60,11 @@ object SbtLicenseReport extends AutoPlugin {
// TODO - Maybe we need a general purpose reporting directory
licenseReportDir := target.value / "license-reports",
licenseReportStyleRules := None,
licenseReportTypes := Seq(MarkDown, Html),
licenseReportTypes := Seq(MarkDown, Html, Csv),
licenseReportConfigurations := {
val dir = licenseReportDir.value
val styleRules = licenseReportStyleRules.value
// TODO - Configurable language (markdown/html) rather than both always
// TODO - Configurable language (markdown/html/csv) rather than all always
val reportTypes = licenseReportTypes.value
val notesLookup = licenseReportNotes.value.lift
val config = LicenseReportConfiguration(licenseReportTitle.value, reportTypes, licenseReportMakeHeader.value, notesLookup, licenseFilter.value, dir, styleRules)
Expand Down
21 changes: 17 additions & 4 deletions src/main/scala/com/typesafe/sbt/license/TargetLanguage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ sealed trait TargetLanguage {
def blankLine(): String
/** Creates something equivalent to an html <h1> tag. */
def header1(msg: String): String
/** Creates something equivalent to an html <h4> tag. */
def header4(msg: String): String
/** The syntax for the header of a table. */
def tableHeader(firstColumn: String, secondColumn: String, thirdColumn: String, fourthColumn: String): String
/** The syntax for a row of a table. */
Expand All @@ -32,7 +30,6 @@ case object MarkDown extends TargetLanguage {
def createHyperLink(link: String, content: String): String =
s"[$content]($link)"
def blankLine(): String = "\n"
def header4(msg: String): String = s"#### $msg\n"
def header1(msg: String): String = s"# $msg\n"
def tableHeader(firstColumn: String, secondColumn: String, thirdColumn: String, fourthColumn: String): String =
s"""
Expand Down Expand Up @@ -66,7 +63,6 @@ case object Html extends TargetLanguage {
s"""<a href="$link">$content</a>"""
def blankLine(): String = "<p>&nbsp;</p>"
def header1(msg: String): String = s"<h1>$msg</h1>"
def header4(msg: String): String = s"<h4>$msg</h4>"
def tableHeader(firstColumn: String, secondColumn: String, thirdColumn: String, fourthColumn: String): String =
s"""<table border="0" cellspacing="0" cellpading="1">
<thead><tr><th>$firstColumn</th><th>$secondColumn</th><th>$thirdColumn</th><th>$fourthColumn</th></tr></thead>
Expand All @@ -77,3 +73,20 @@ case object Html extends TargetLanguage {

def htmlEncode(s: String) = org.apache.commons.lang3.StringEscapeUtils.escapeHtml4(s)
}

case object Csv extends TargetLanguage {
val ext = "csv"
def documentStart(title: String, reportStyleRules: Option[String]): String = ""
def documentEnd(): String = ""
def createHyperLink(link: String, content: String): String = {
if (link != null && !link.trim().isEmpty()) s"$content ($link)" else s"$content"
}
def blankLine(): String = ""
def header1(msg: String): String = ""
def tableHeader(firstColumn: String, secondColumn: String, thirdColumn: String, fourthColumn: String): String =
tableRow(firstColumn, secondColumn, thirdColumn, fourthColumn)
def tableRow(firstColumn: String, secondColumn: String, thirdColumn: String, fourthColumn: String): String =
s"""${csvEncode(firstColumn)},${csvEncode(secondColumn)},${csvEncode(thirdColumn)},${csvEncode(fourthColumn)}\n"""
def tableEnd: String = ""
def csvEncode(s: String): String = org.apache.commons.lang3.StringEscapeUtils.escapeCsv(s)
}
3 changes: 2 additions & 1 deletion src/sbt-test/dumpLicenseReport/custom-report/test
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
> dumpLicenseReport
$ exists target/license-reports/lreport.md
> check
$ exists target/license-reports/test-config.html
$ exists target/license-reports/test-config.html
-$ exists target/license-reports/lreport.csv
1 change: 1 addition & 0 deletions src/sbt-test/dumpLicenseReport/default-report/test
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
> dumpLicenseReport
$ exists target/license-reports/example-licenses.md
$ exists target/license-reports/example-licenses.html
$ exists target/license-reports/example-licenses.csv
> check

0 comments on commit f905fa1

Please sign in to comment.