2024-05-11 10:51:11 +03:00
|
|
|
import sbt.Keys._
|
|
|
|
import sbt._
|
|
|
|
import complete.DefaultParsers._
|
2020-10-19 11:50:12 +03:00
|
|
|
import org.apache.ivy.core.resolve.IvyNode
|
2020-10-09 17:19:58 +03:00
|
|
|
import src.main.scala.licenses.backend.{
|
|
|
|
CombinedBackend,
|
|
|
|
GatherCopyrights,
|
|
|
|
GatherNotices,
|
|
|
|
GithubHeuristic
|
|
|
|
}
|
|
|
|
import src.main.scala.licenses.frontend.SbtLicenses
|
2024-05-11 10:51:11 +03:00
|
|
|
import src.main.scala.licenses.report._
|
Add AWS SSO JARs to the `Standard.AWS` library (#9782)
As reported by our users, when using the AWS SSO, our code was failing with:
```
Execution finished with an error: To use Sso related properties in the 'xyz' profile, the 'sso' service module must be on the class path.
```
This PR adds the missing JARs to fix that.
Additionally it improves the license review tool UX a bit (parts of #9122):
- sorting the report by amount of problems, so that dependencies with unresolved problems appear at the top,
- semi-automatic helper button to rename package configurations after a version bump,
- button to remove stale entries from config (files or copyrights that disappeared after update),
- button to add custom copyright notice text straight from the report UI,
- button to set a file as the license for the project (creating the `custom-license` file automatically)
- ability to filter processed projects - e.g. `openLegalReviewReport AWS` will only run on the AWS subproject - saving time processing unchanged dependencies,
- updated the license search heuristic, fixing a problem with duplicates:
- if we had dependencies `netty-http` and `netty-http2`, because of a prefix-check logic, the notices for `netty-http` would also appear again for `netty-http2`, which is not valid. I have improved the heuristic to avoid these false positives and removed them from the current report.
- WIP: button to mark a license type as reviewed (not finished in this PR).
2024-04-25 21:44:51 +03:00
|
|
|
import src.main.scala.licenses.{
|
|
|
|
DependencySummary,
|
|
|
|
DistributionDescription,
|
|
|
|
ReviewedSummary
|
|
|
|
}
|
2020-10-09 17:19:58 +03:00
|
|
|
|
2024-05-11 10:51:11 +03:00
|
|
|
import scala.collection.JavaConverters._
|
|
|
|
import scala.sys.process._
|
2020-10-09 17:19:58 +03:00
|
|
|
|
2020-10-22 17:12:28 +03:00
|
|
|
/** The task and configuration for automatically gathering license information.
|
2020-10-09 17:19:58 +03:00
|
|
|
*/
|
|
|
|
object GatherLicenses {
|
|
|
|
val distributions = taskKey[Seq[DistributionDescription]](
|
|
|
|
"Defines descriptions of distributions."
|
|
|
|
)
|
|
|
|
val configurationRoot = settingKey[File]("Path to review configuration.")
|
|
|
|
val licenseConfigurations =
|
|
|
|
settingKey[Set[String]]("The ivy configurations we consider in the review.")
|
2020-10-19 11:50:12 +03:00
|
|
|
private val stateFileName = "report-state"
|
2020-10-09 17:19:58 +03:00
|
|
|
|
2020-10-30 14:31:31 +03:00
|
|
|
/** The task that performs the whole license gathering process. */
|
Add AWS SSO JARs to the `Standard.AWS` library (#9782)
As reported by our users, when using the AWS SSO, our code was failing with:
```
Execution finished with an error: To use Sso related properties in the 'xyz' profile, the 'sso' service module must be on the class path.
```
This PR adds the missing JARs to fix that.
Additionally it improves the license review tool UX a bit (parts of #9122):
- sorting the report by amount of problems, so that dependencies with unresolved problems appear at the top,
- semi-automatic helper button to rename package configurations after a version bump,
- button to remove stale entries from config (files or copyrights that disappeared after update),
- button to add custom copyright notice text straight from the report UI,
- button to set a file as the license for the project (creating the `custom-license` file automatically)
- ability to filter processed projects - e.g. `openLegalReviewReport AWS` will only run on the AWS subproject - saving time processing unchanged dependencies,
- updated the license search heuristic, fixing a problem with duplicates:
- if we had dependencies `netty-http` and `netty-http2`, because of a prefix-check logic, the notices for `netty-http` would also appear again for `netty-http2`, which is not valid. I have improved the heuristic to avoid these false positives and removed them from the current report.
- WIP: button to mark a license type as reviewed (not finished in this PR).
2024-04-25 21:44:51 +03:00
|
|
|
def run = Def.inputTask {
|
|
|
|
val names: Seq[String] = spaceDelimited("<arg>").parsed
|
|
|
|
val log = state.value.log
|
|
|
|
val targetRoot = target.value
|
2020-10-09 17:19:58 +03:00
|
|
|
log.info(
|
|
|
|
"Gathering license files and copyright notices. " +
|
|
|
|
"This task may take a long time."
|
|
|
|
)
|
|
|
|
|
|
|
|
val configRoot = configurationRoot.value
|
|
|
|
|
Add AWS SSO JARs to the `Standard.AWS` library (#9782)
As reported by our users, when using the AWS SSO, our code was failing with:
```
Execution finished with an error: To use Sso related properties in the 'xyz' profile, the 'sso' service module must be on the class path.
```
This PR adds the missing JARs to fix that.
Additionally it improves the license review tool UX a bit (parts of #9122):
- sorting the report by amount of problems, so that dependencies with unresolved problems appear at the top,
- semi-automatic helper button to rename package configurations after a version bump,
- button to remove stale entries from config (files or copyrights that disappeared after update),
- button to add custom copyright notice text straight from the report UI,
- button to set a file as the license for the project (creating the `custom-license` file automatically)
- ability to filter processed projects - e.g. `openLegalReviewReport AWS` will only run on the AWS subproject - saving time processing unchanged dependencies,
- updated the license search heuristic, fixing a problem with duplicates:
- if we had dependencies `netty-http` and `netty-http2`, because of a prefix-check logic, the notices for `netty-http` would also appear again for `netty-http2`, which is not valid. I have improved the heuristic to avoid these false positives and removed them from the current report.
- WIP: button to mark a license type as reviewed (not finished in this PR).
2024-04-25 21:44:51 +03:00
|
|
|
val namesToProcess: Set[String] = names.toSet
|
|
|
|
val knownDistributions = distributions.value
|
|
|
|
val distributionsToProcess =
|
|
|
|
if (names.isEmpty) knownDistributions
|
|
|
|
else
|
|
|
|
knownDistributions.filter(distribution =>
|
|
|
|
namesToProcess.contains(distribution.artifactName)
|
|
|
|
)
|
|
|
|
|
|
|
|
val unrecognizedDistributions =
|
|
|
|
namesToProcess -- distributionsToProcess.map(_.artifactName).toSet
|
|
|
|
if (unrecognizedDistributions.nonEmpty) {
|
|
|
|
val message =
|
|
|
|
s"Unrecognized distribution names: $unrecognizedDistributions."
|
|
|
|
log.error(message)
|
|
|
|
throw new IllegalArgumentException(message)
|
|
|
|
}
|
|
|
|
log.info(
|
|
|
|
s"Found following distributions to process: ${distributionsToProcess.map(_.artifactName)}"
|
|
|
|
)
|
|
|
|
|
|
|
|
val reports = distributionsToProcess.map { distribution =>
|
2020-10-09 17:19:58 +03:00
|
|
|
log.info(s"Processing the ${distribution.artifactName} distribution")
|
|
|
|
val projectNames = distribution.sbtComponents.map(_.name)
|
|
|
|
log.info(
|
|
|
|
s"It consists of the following sbt project roots:" +
|
|
|
|
s" ${projectNames.mkString(", ")}"
|
|
|
|
)
|
2024-02-27 19:32:08 +03:00
|
|
|
val (sbtInfo, sbtDiagnostics) =
|
2020-10-09 17:19:58 +03:00
|
|
|
SbtLicenses.analyze(distribution.sbtComponents, log)
|
|
|
|
|
|
|
|
val allInfo = sbtInfo // TODO [RW] add Rust frontend result here (#1187)
|
|
|
|
|
|
|
|
log.info(s"${allInfo.size} unique dependencies discovered")
|
|
|
|
val defaultBackend = CombinedBackend(GatherNotices, GatherCopyrights)
|
|
|
|
|
|
|
|
val processed = allInfo.map { dependency =>
|
|
|
|
log.debug(
|
|
|
|
s"Processing ${dependency.moduleInfo} (${dependency.license}) -> " +
|
|
|
|
s"${dependency.url}"
|
|
|
|
)
|
|
|
|
val defaultAttachments = defaultBackend.run(dependency.sources)
|
2024-02-27 19:32:08 +03:00
|
|
|
val WithDiagnostics(attachments, attachmentDiagnostics) =
|
|
|
|
if (defaultAttachments.nonEmpty) WithDiagnostics(defaultAttachments)
|
2020-10-09 17:19:58 +03:00
|
|
|
else GithubHeuristic(dependency, log).run()
|
2024-02-27 19:32:08 +03:00
|
|
|
(dependency, attachments, attachmentDiagnostics)
|
2020-10-09 17:19:58 +03:00
|
|
|
}
|
|
|
|
|
2024-02-27 19:32:08 +03:00
|
|
|
val forSummary = processed.map(t => (t._1, t._2))
|
|
|
|
val processingDiagnostics = processed.flatMap(_._3)
|
|
|
|
val summary = DependencySummary(forSummary)
|
|
|
|
val distributionRoot = configRoot / distribution.artifactName
|
|
|
|
val WithDiagnostics(processedSummary, summaryDiagnostics) =
|
2020-10-19 11:50:12 +03:00
|
|
|
Review(distributionRoot, summary).run()
|
2024-02-27 19:32:08 +03:00
|
|
|
val allDiagnostics =
|
|
|
|
sbtDiagnostics ++ processingDiagnostics ++ summaryDiagnostics
|
2020-10-09 17:19:58 +03:00
|
|
|
val reportDestination =
|
|
|
|
targetRoot / s"${distribution.artifactName}-report.html"
|
|
|
|
|
2024-02-27 19:32:08 +03:00
|
|
|
val (warnings: Seq[Diagnostic.Warning], errors: Seq[Diagnostic.Error]) =
|
|
|
|
Diagnostic.partition(allDiagnostics)
|
|
|
|
|
|
|
|
if (warnings.nonEmpty) {
|
|
|
|
log.warn(s"Found ${warnings.size} non-fatal warnings in the report:")
|
|
|
|
warnings.foreach(notice => log.warn(notice.message))
|
|
|
|
}
|
|
|
|
|
|
|
|
if (errors.isEmpty) {
|
|
|
|
log.info("No fatal errors found in the report.")
|
|
|
|
} else {
|
|
|
|
log.error(s"Found ${errors.size} fatal errors in the report:")
|
|
|
|
errors.foreach(problem => log.error(problem.message))
|
|
|
|
}
|
2020-10-09 17:19:58 +03:00
|
|
|
|
|
|
|
Report.writeHTML(
|
|
|
|
distribution,
|
|
|
|
processedSummary,
|
2024-02-27 19:32:08 +03:00
|
|
|
allDiagnostics,
|
2020-10-09 17:19:58 +03:00
|
|
|
reportDestination
|
|
|
|
)
|
|
|
|
log.info(
|
2020-10-19 11:50:12 +03:00
|
|
|
s"Written the report for the ${distribution.artifactName} to " +
|
|
|
|
s"`$reportDestination`."
|
2020-10-09 17:19:58 +03:00
|
|
|
)
|
|
|
|
val packagePath = distribution.packageDestination
|
|
|
|
PackageNotices.create(distribution, processedSummary, packagePath)
|
2020-10-30 14:31:31 +03:00
|
|
|
ReportState.write(
|
2020-10-19 11:50:12 +03:00
|
|
|
distributionRoot / stateFileName,
|
|
|
|
distribution,
|
2024-02-27 19:32:08 +03:00
|
|
|
errors.size
|
2020-10-19 11:50:12 +03:00
|
|
|
)
|
2020-10-09 17:19:58 +03:00
|
|
|
log.info(s"Re-generated distribution notices at `$packagePath`.")
|
2024-02-27 19:32:08 +03:00
|
|
|
if (errors.nonEmpty) {
|
2020-10-09 17:19:58 +03:00
|
|
|
log.warn(
|
|
|
|
"The distribution notices were regenerated, but there are " +
|
|
|
|
"not-reviewed issues within the report. The notices are probably " +
|
|
|
|
"incomplete."
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
(distribution, processedSummary)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.warn(
|
|
|
|
"Finished gathering license information. " +
|
|
|
|
"This is an automated process, make sure that its output is reviewed " +
|
|
|
|
"by a human to ensure that all licensing requirements are met."
|
|
|
|
)
|
|
|
|
|
|
|
|
reports
|
|
|
|
}
|
|
|
|
|
2020-12-09 16:58:11 +03:00
|
|
|
private def verifyReportStatus(
|
|
|
|
log: Logger,
|
|
|
|
targetRoot: File,
|
|
|
|
distributionDescription: DistributionDescription,
|
|
|
|
distributionConfig: File
|
|
|
|
): Unit = {
|
|
|
|
val name = distributionDescription.artifactName
|
2020-12-02 18:56:47 +03:00
|
|
|
|
2020-10-19 11:50:12 +03:00
|
|
|
def warnAndThrow(exceptionMessage: String): Nothing = {
|
|
|
|
log.error(exceptionMessage)
|
|
|
|
log.warn(
|
|
|
|
"Please make sure to run `enso / gatherLicenses` " +
|
2020-12-02 18:56:47 +03:00
|
|
|
s"and review the reports generated at $targetRoot, " +
|
|
|
|
"ensuring that the legal review is complete and there are no warnings."
|
|
|
|
)
|
|
|
|
log.warn(
|
2021-02-25 16:48:18 +03:00
|
|
|
"See docs/distribution/licenses.md#review-process for a more detailed " +
|
2020-12-02 18:56:47 +03:00
|
|
|
"explanation."
|
2020-10-19 11:50:12 +03:00
|
|
|
)
|
|
|
|
throw LegalReviewException(exceptionMessage)
|
|
|
|
}
|
|
|
|
|
2020-12-09 16:58:11 +03:00
|
|
|
ReportState.read(distributionConfig / stateFileName, log) match {
|
|
|
|
case Some(reviewState) =>
|
|
|
|
val currentInputHash =
|
|
|
|
ReportState.computeInputHash(distributionDescription)
|
|
|
|
if (currentInputHash != reviewState.inputHash) {
|
2022-06-13 17:09:08 +03:00
|
|
|
log.info("Input hash computed from build.sbt: " + currentInputHash)
|
|
|
|
log.info("Input hash stored in metadata: " + reviewState.inputHash)
|
2020-12-09 16:58:11 +03:00
|
|
|
warnAndThrow(
|
|
|
|
s"Report for the $name is not up to date - " +
|
|
|
|
s"it seems that some dependencies were added or removed."
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reviewState.warningsCount > 0) {
|
|
|
|
warnAndThrow(
|
|
|
|
s"Report for the $name has ${reviewState.warningsCount} warnings."
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.info(s"Report for $name is reviewed.")
|
|
|
|
case None =>
|
|
|
|
warnAndThrow(s"Report for $name has not been generated.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private def verifyPackage(
|
|
|
|
log: Logger,
|
|
|
|
distributionConfig: File,
|
|
|
|
packageDestination: File
|
|
|
|
): Unit = {
|
|
|
|
val reportState = ReportState
|
|
|
|
.read(distributionConfig / stateFileName, log)
|
|
|
|
.getOrElse(
|
|
|
|
throw LegalReviewException(
|
|
|
|
s"Report at $distributionConfig is not available. " +
|
2024-02-27 19:32:08 +03:00
|
|
|
s"Make sure to run `enso/gatherLicenses` or `openLegalReviewReport`."
|
2020-12-09 16:58:11 +03:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
val currentOutputHash = ReportState.computeOutputHash(packageDestination)
|
|
|
|
if (currentOutputHash != reportState.outputHash) {
|
2022-06-13 17:09:08 +03:00
|
|
|
log.info("Output hash computed from build.sbt: " + currentOutputHash)
|
|
|
|
log.info("Output hash stored in metadata: " + reportState.outputHash)
|
2020-12-09 16:58:11 +03:00
|
|
|
log.error(
|
|
|
|
s"Generated package at $packageDestination seems to be not up-to-date."
|
|
|
|
)
|
|
|
|
log.warn(
|
|
|
|
"Re-run `enso/gatherLicenses` and make sure that all files " +
|
|
|
|
"from the notice package are committed, no unexpected files " +
|
|
|
|
"have been added and the package is created in a consistent way."
|
|
|
|
)
|
|
|
|
throw LegalReviewException(
|
|
|
|
s"Package $packageDestination has different content than expected."
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
log.info(s"Package $packageDestination is up-to-date.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** The task that verifies if the report has been generated and is up-to-date.
|
|
|
|
*/
|
|
|
|
lazy val verifyReports = Def.task {
|
|
|
|
val configRoot = configurationRoot.value
|
|
|
|
val log = streams.value.log
|
|
|
|
val targetRoot = target.value
|
|
|
|
|
2020-10-19 11:50:12 +03:00
|
|
|
for (distribution <- distributions.value) {
|
2020-12-09 16:58:11 +03:00
|
|
|
val distributionConfig = configRoot / distribution.artifactName
|
|
|
|
verifyReportStatus(
|
|
|
|
log = log,
|
|
|
|
targetRoot = targetRoot,
|
|
|
|
distributionDescription = distribution,
|
|
|
|
distributionConfig = distributionConfig
|
|
|
|
)
|
|
|
|
verifyPackage(
|
|
|
|
log = log,
|
|
|
|
distributionConfig = distributionConfig,
|
|
|
|
packageDestination = distribution.packageDestination
|
|
|
|
)
|
2020-10-19 11:50:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-09 16:58:11 +03:00
|
|
|
/** A task that verifies if contents of the provided package directory are
|
|
|
|
* up-to-date with the review state.
|
|
|
|
*
|
|
|
|
* It takes two arguments:
|
|
|
|
* - an artifact name identifying the distribution
|
|
|
|
* - a path to the generated packages.
|
|
|
|
*/
|
|
|
|
lazy val verifyGeneratedPackage = Def.inputTask {
|
|
|
|
val configRoot = configurationRoot.value
|
|
|
|
val log = streams.value.log
|
|
|
|
val args: Seq[String] = spaceDelimited("<arg>").parsed
|
|
|
|
val (distributionName, packagePathString) = args match {
|
|
|
|
case Seq(distribution, path) => (distribution, path)
|
|
|
|
case _ =>
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
"The task expects exactly 2 arguments."
|
|
|
|
)
|
|
|
|
}
|
|
|
|
val packageDestination = file(packagePathString)
|
|
|
|
verifyPackage(
|
|
|
|
log = log,
|
|
|
|
distributionConfig = configRoot / distributionName,
|
|
|
|
packageDestination = packageDestination
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-10-19 11:50:12 +03:00
|
|
|
case class LegalReviewException(string: String)
|
|
|
|
extends RuntimeException(string)
|
|
|
|
|
2020-10-22 17:12:28 +03:00
|
|
|
/** Launches a server that allows to easily review the generated report.
|
2020-10-09 17:19:58 +03:00
|
|
|
*
|
|
|
|
* Requires `npm` to be on the system PATH.
|
|
|
|
*/
|
|
|
|
def runReportServer(): Unit = {
|
|
|
|
Seq("npm", "install").!
|
|
|
|
Process(Seq("npm", "start"), file("tools/legal-review-helper"))
|
|
|
|
.run(connectInput = true)
|
|
|
|
.exitValue()
|
|
|
|
}
|
|
|
|
|
2020-10-22 17:12:28 +03:00
|
|
|
/** A task that prints which sub-projects use a dependency and what
|
2020-10-19 11:50:12 +03:00
|
|
|
* dependencies use it (so that one can track where dependencies come from).
|
|
|
|
*/
|
|
|
|
lazy val analyzeDependency = Def.inputTask {
|
|
|
|
val args: Seq[String] = spaceDelimited("<arg>").parsed
|
|
|
|
val evaluatedDistributions = distributions.value
|
|
|
|
val log = streams.value.log
|
|
|
|
for (arg <- args) {
|
|
|
|
for (distribution <- evaluatedDistributions) {
|
|
|
|
for (sbtComponent <- distribution.sbtComponents) {
|
|
|
|
val ivyDeps =
|
|
|
|
sbtComponent.licenseReport.orig.getDependencies.asScala
|
|
|
|
.map(_.asInstanceOf[IvyNode])
|
|
|
|
for (dep <- sbtComponent.licenseReport.licenses) {
|
|
|
|
if (dep.module.name.contains(arg)) {
|
|
|
|
val module = dep.module
|
|
|
|
log.info(
|
|
|
|
s"${distribution.artifactName} distribution, project ${sbtComponent.name} " +
|
|
|
|
s"contains $module"
|
|
|
|
)
|
|
|
|
val node = ivyDeps.find(n =>
|
|
|
|
SbtLicenses.safeModuleInfo(n) == Some(dep.module)
|
|
|
|
)
|
|
|
|
node match {
|
|
|
|
case None =>
|
|
|
|
log.warn(s"IvyNode for $module not found.")
|
|
|
|
case Some(ivyNode) =>
|
|
|
|
val callers =
|
|
|
|
ivyNode.getAllCallers.toSeq.map(_.toString).distinct
|
|
|
|
log.info(s"Callers: $callers")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-09 17:19:58 +03:00
|
|
|
}
|