forked from sbt/sbt-sbom
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* json format * cleanup and tests * fix formatting * update README.md * reduce diff * fixed tests
- Loading branch information
Showing
24 changed files
with
2,101 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.github.sbt.sbom | ||
|
||
import com.github.sbt.sbom.PluginConstants.supportedVersions | ||
import org.cyclonedx.Version | ||
|
||
sealed abstract class BomFormat(val string: String) | ||
|
||
object BomFormat { | ||
case object Json extends BomFormat("json") | ||
case object Xml extends BomFormat("xml") | ||
|
||
def fromSettings(bomFormat: Option[String], bomFileName: Option[String], schemaVersion: String): BomFormat = { | ||
bomFormat | ||
.collect { | ||
case Json.string => Json | ||
case Xml.string => Xml | ||
case format => | ||
throw new BomError(s"Unsupported format ${format}") | ||
} | ||
.orElse { | ||
bomFileName.map(_.toLowerCase).collect { | ||
case ext if ext.endsWith(".json") => Json | ||
case ext if ext.endsWith(".xml") => Xml | ||
} | ||
} | ||
.orElse { | ||
supportedVersions.find(_.getVersionString == schemaVersion).collect { | ||
case foundVersion if foundVersion.getVersion > Version.VERSION_11.getVersion => Json | ||
} | ||
} | ||
.getOrElse { | ||
Xml | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
> clean | ||
> compile | ||
> makeBom | ||
$ exists target/exists-0.1.bom.xml | ||
$ exists target/exists-0.1.bom.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import scala.xml.XML | ||
|
||
lazy val root = (project in file(".")) | ||
.settings( | ||
name := "dependencies", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import scala.xml.XML | ||
|
||
lazy val root = (project in file(".")) | ||
.settings( | ||
name := "dependencies", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import scala.xml.XML | ||
|
||
lazy val root = (project in file(".")) | ||
.settings( | ||
name := "dependencies", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
lazy val root = (project in file(".")) | ||
.settings( | ||
name := "dependencies", | ||
version := "0.1", | ||
libraryDependencies ++= Dependencies.library, | ||
bomFileName := "bom.json", | ||
includeBomToolVersion := false, | ||
enableBomSha3Hashes := false, | ||
scalaVersion := "2.12.20", | ||
check := Def | ||
.sequential( | ||
Compile / clean, | ||
Compile / compile, | ||
checkTask | ||
) | ||
.value | ||
) | ||
|
||
lazy val check = taskKey[Unit]("check") | ||
lazy val checkTask = Def.task { | ||
val s: TaskStreams = streams.value | ||
s.log.info("Verifying bom content...") | ||
makeBom.value | ||
import scala.sys.process._ | ||
require(Seq("diff", "-w", "target/bom.json", s"${thisProject.value.base}/etc/bom.json").! == 0) | ||
} |
Oops, something went wrong.