Skip to content

Commit

Permalink
Merge branch 'main' into parse-cddlgplclasspath
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n authored Oct 23, 2024
2 parents ce1e0b2 + af486cb commit a4c31de
Show file tree
Hide file tree
Showing 22 changed files with 135 additions and 48 deletions.
25 changes: 17 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
scala: [2.12.18]
scala: [2.12.19]
java: [temurin@8, temurin@11, temurin@17, temurin@21]
exclude:
- java: temurin@8
os: macos-latest
runs-on: ${{ matrix.os }}
steps:
- name: Ignore line ending differences in git
Expand All @@ -34,7 +37,7 @@ jobs:

- name: Configure pagefile for Windows
if: contains(runner.os, 'windows')
uses: al-cheb/configure-pagefile-action@v1.3
uses: al-cheb/configure-pagefile-action@v1.4
with:
minimum-size: 2GB
maximum-size: 8GB
Expand Down Expand Up @@ -77,12 +80,15 @@ jobs:
java-version: 21
cache: sbt

- name: Setup sbt
uses: sbt/setup-sbt@v1

- name: Check that workflows are up to date
shell: bash
run: sbt '++ ${{ matrix.scala }}' githubWorkflowCheck

- shell: bash
run: sbt '++ ${{ matrix.scala }}' test scripted
run: sbt '++ ${{ matrix.scala }}' '+ testAll'

- name: Compress target directories
shell: bash
Expand All @@ -101,7 +107,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.18]
scala: [2.12.19]
java: [temurin@8]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -111,7 +117,7 @@ jobs:

- name: Configure pagefile for Windows
if: contains(runner.os, 'windows')
uses: al-cheb/configure-pagefile-action@v1.3
uses: al-cheb/configure-pagefile-action@v1.4
with:
minimum-size: 2GB
maximum-size: 8GB
Expand Down Expand Up @@ -154,12 +160,15 @@ jobs:
java-version: 21
cache: sbt

- name: Download target directories (2.12.18)
- name: Setup sbt
uses: sbt/setup-sbt@v1

- name: Download target directories (2.12.19)
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-2.12.18-${{ matrix.java }}
name: target-${{ matrix.os }}-2.12.19-${{ matrix.java }}

- name: Inflate target directories (2.12.18)
- name: Inflate target directories (2.12.19)
run: |
tar xf targets.tar
rm targets.tar
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
persist-credentials: false

- name: Check project is formatted
uses: jrouly/scalafmt-native-action@v3
uses: jrouly/scalafmt-native-action@v4
with:
arguments: '--list --mode diff-ref=origin/main'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ project/plugins/project/

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

.bsp/
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.7.17
version = 3.8.1
runner.dialect = scala212
maxColumn = 120
project.git = true
Expand Down
43 changes: 39 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,16 +1,49 @@
lazy val lang3 = "org.apache.commons" % "commons-lang3" % "3.14.0"
lazy val lang3 = "org.apache.commons" % "commons-text" % "1.12.0"
lazy val repoSlug = "sbt/sbt-license-report"

val scala212 = "2.12.18"
val scala212 = "2.12.19"
val scala3 = "3.3.3"

pluginCrossBuild / sbtVersion := {
scalaBinaryVersion.value match {
case "2.12" =>
(pluginCrossBuild / sbtVersion).value
case _ =>
"2.0.0-M2"
}
}

ThisBuild / scalaVersion := scala212
ThisBuild / crossScalaVersions := Seq(scala212)
ThisBuild / crossScalaVersions := Seq(scala212, scala3)
organization := "com.github.sbt"
name := "sbt-license-report"
enablePlugins(SbtPlugin)
libraryDependencies += lang3
scriptedLaunchOpts += s"-Dplugin.version=${version.value}"

ThisBuild / githubWorkflowScalaVersions := Seq(scalaVersion.value)

TaskKey[Unit]("testAll") := {
if (scalaBinaryVersion.value == "3") {
Def
.sequential(
Test / test,
Def.task(
// TODO enable test
streams.value.log.warn("skip sbt 2.x scripted tests")
)
)
.value
} else {
Def
.sequential(
Test / test,
scripted.toTask("")
)
.value
}
}

// publishing info
licenses := Seq("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.html"))
scmInfo := Some(
Expand Down Expand Up @@ -54,7 +87,7 @@ scalacOptions ++= {
} else Nil
}

ThisBuild / githubWorkflowBuild := Seq(WorkflowStep.Sbt(List("test", "scripted")))
ThisBuild / githubWorkflowBuild := Seq(WorkflowStep.Sbt(List("+ testAll")))

ThisBuild / githubWorkflowTargetTags ++= Seq("v*")
ThisBuild / githubWorkflowPublishTargetBranches :=
Expand Down Expand Up @@ -83,3 +116,5 @@ ThisBuild / githubWorkflowJavaVersions := Seq(
JavaSpec.temurin("17"),
JavaSpec.temurin("21")
)

ThisBuild / githubWorkflowBuildMatrixExclusions += MatrixExclude(Map("java" -> "temurin@8", "os" -> "macos-latest"))
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.8
sbt.version=1.10.3
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.9.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("com.github.sbt" % "sbt-github-actions" % "0.22.0")
addSbtPlugin("com.github.sbt" % "sbt-github-actions" % "0.24.0")
2 changes: 1 addition & 1 deletion src/main/scala/sbtlicensereport/SbtLicenseReport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ object SbtLicenseReport extends AutoPlugin {
licenseReportNotes := PartialFunction.empty,
licenseOverrides := PartialFunction.empty,
licenseDepExclusions := PartialFunction.empty,
licenseFilter := TypeFunctions.const(true),
licenseFilter := Function.const(true),
licenseReportStyleRules := None,
licenseReportTypes := Seq(MarkDown, Html, Csv),
licenseReportColumns := Seq(Column.Category, Column.License, Column.Dependency),
Expand Down
8 changes: 5 additions & 3 deletions src/main/scala/sbtlicensereport/license/LicenseCategory.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package sbtlicensereport
package license

import java.util.Locale

// TODO - What do we mean by viral?
case class LicenseCategory(name: String, synonyms: Seq[String] = Nil) {
def unapply(license: String): Boolean = {
val names = name +: synonyms
names exists { n =>
license.toLowerCase contains n.toLowerCase
license.toLowerCase(Locale.ROOT) contains n.toLowerCase(Locale.ROOT)
}
}

Expand All @@ -17,14 +19,14 @@ object LicenseCategory {
val LGPL = LicenseCategory("LGPL", Seq("lesser general public license"))
object GPLClasspath extends LicenseCategory("GPL with Classpath Extension") {
override def unapply(license: String): Boolean = {
val name = license.toLowerCase
val name = license.toLowerCase(Locale.ROOT)
(name.contains("gpl") || name.contains("general public license")) &&
name.contains("classpath")
}
}
object CDDLPlusGPLClasspath extends LicenseCategory("CDDL + GPLv2 with classpath exception") {
override def unapply(license: String): Boolean = {
val name = license.toLowerCase
val name = license.toLowerCase(Locale.ROOT)
(name.contains("gpl") || name.contains("general public license")) &&
(name.contains("cddl") || name.contains("common development and distribution license")) &&
name.contains("classpath")
Expand Down
31 changes: 17 additions & 14 deletions src/main/scala/sbtlicensereport/license/LicenseReport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ object LicenseReport {
print(language.tableRow(notes, rest: _*))
}
print(language.tableEnd)
print(language.documentEnd)
print(language.documentEnd())
}
}
}
Expand Down Expand Up @@ -147,20 +147,23 @@ object LicenseReport {
// Even though the url is optional this field seems to always exist
val licensesWithUrls = licenses.collect { case (name, Some(url)) => (name, url) }
if (licensesWithUrls.isEmpty) {
return LicenseInfo(LicenseCategory.NoneSpecified, "", "")
}
// We look for a license matching the category in the order they are defined.
// i.e. the user selects the licenses they prefer to use, in order, if an artifact is dual-licensed (or more)
for (category <- categories) {
for (license <- licensesWithUrls) {
val (name, url) = license
if (category.unapply(name)) {
return LicenseInfo(category, name, url)
LicenseInfo(LicenseCategory.NoneSpecified, "", "")
} else {
// We look for a license matching the category in the order they are defined.
// i.e. the user selects the licenses they prefer to use, in order, if an artifact is dual-licensed (or more)
categories
.flatMap(category =>
licensesWithUrls.collectFirst {
case (name, url) if category.unapply(name) =>
LicenseInfo(category, name, url)
}
)
.headOption
.getOrElse {
val license = licensesWithUrls(0)
LicenseInfo(LicenseCategory.Unrecognized, license._1, license._2)
}
}
}
val license = licensesWithUrls(0)
LicenseInfo(LicenseCategory.Unrecognized, license._1, license._2)
}

/** Picks a single license (or none) for this dependency. */
Expand All @@ -177,7 +180,7 @@ object LicenseReport {
None
else {
val licenses = dep.licenses
val homepage = dep.homepage.map(string => new URL(string))
val homepage = dep.homepage.map(string => new URI(string).toURL)
Some(
DepLicense(
getModuleInfo(dep),
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/sbtlicensereport/license/TargetLanguage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ case object Html extends TargetLanguage {
}
def tableEnd: String = "</tbody></table>"

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

case object Csv extends TargetLanguage {
Expand All @@ -114,7 +114,7 @@ case object Csv extends TargetLanguage {
}

def tableEnd: String = ""
def csvEncode(s: String): String = org.apache.commons.lang3.StringEscapeUtils.escapeCsv(s)
def csvEncode(s: String): String = org.apache.commons.text.StringEscapeUtils.escapeCsv(s)
}

case object ConfluenceWikiMarkup extends TargetLanguage {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
addSbtPlugin("com.github.sbt" % "sbt-license-report" % sys.props("plugin.version"))
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.github.sbt" % "sbt-license-report" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
6 changes: 5 additions & 1 deletion src/sbt-test/checkLicense/default-check/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
addSbtPlugin("com.github.sbt" % "sbt-license-report" % sys.props("plugin.version"))
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.github.sbt" % "sbt-license-report" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
6 changes: 5 additions & 1 deletion src/sbt-test/checkLicense/failing-check/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
addSbtPlugin("com.github.sbt" % "sbt-license-report" % sys.props("plugin.version"))
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.github.sbt" % "sbt-license-report" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "example"

excludeDependencies in ThisBuild += "org.scala-lang"
ThisBuild / excludeDependencies += "org.scala-lang"

lazy val one = project
.in(file("one"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
addSbtPlugin("com.github.sbt" % "sbt-license-report" % sys.props("plugin.version"))
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.github.sbt" % "sbt-license-report" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "example"

excludeDependencies in ThisBuild += "org.scala-lang"
ThisBuild / excludeDependencies += "org.scala-lang"

lazy val one = project
.in(file("one"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
addSbtPlugin("com.github.sbt" % "sbt-license-report" % sys.props("plugin.version"))
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.github.sbt" % "sbt-license-report" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
addSbtPlugin("com.github.sbt" % "sbt-license-report" % sys.props("plugin.version"))
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.github.sbt" % "sbt-license-report" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
addSbtPlugin("com.github.sbt" % "sbt-license-report" % sys.props("plugin.version"))
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.github.sbt" % "sbt-license-report" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
addSbtPlugin("com.github.sbt" % "sbt-license-report" % sys.props("plugin.version"))
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.github.sbt" % "sbt-license-report" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
addSbtPlugin("com.github.sbt" % "sbt-license-report" % sys.props("plugin.version"))
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.github.sbt" % "sbt-license-report" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}

0 comments on commit a4c31de

Please sign in to comment.