-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* FIX #1026 Add validatePackageConfiguration task This is an initial draft to provide helpful feedback to users during their configuration phase with sbt-native-packager. The intention is to give a short explanation why a warning or error is triggerd and a detailed description how to fix the issue. This is an initial draft to provide helpful feedback to users during their configuration phase with sbt-native-packager. The intention is to give a short explanation why a warning or error is triggerd and a detailed description how to fix the issue. * FIX #1026 Valiate mappings from linuxPackageMappings * Add scripted tests to check basic validation * Remove trailing comma
- Loading branch information
Showing
15 changed files
with
290 additions
and
17 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
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
73 changes: 73 additions & 0 deletions
73
src/main/scala/com/typesafe/sbt/packager/validation/Validation.scala
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,73 @@ | ||
package com.typesafe.sbt.packager.validation | ||
|
||
import sbt.Logger | ||
|
||
/** | ||
* Validation result. | ||
* | ||
* @param errors all errors that were found during the validation | ||
* @param warnings all warnings that were found during the validation | ||
*/ | ||
final case class Validation(errors: List[ValidationError], warnings: List[ValidationWarning]) | ||
|
||
object Validation { | ||
|
||
/** | ||
* A validator is a function that returns a list of validation results. | ||
* | ||
* | ||
* @example Usually a validator is a function that captures some setting or task value, e.g. | ||
* {{{ | ||
* validatePackageValidators += { | ||
* val universalMappings = (mappings in Universal).value | ||
* () => { | ||
* if (universalMappings.isEmpty) List(ValidationError(...)) else List.empt | ||
* } | ||
* } | ||
* }}} | ||
* | ||
* The `validation` package object contains various standard validators. | ||
* | ||
*/ | ||
type Validator = () => List[ValidationResult] | ||
|
||
/** | ||
* | ||
* @param validators a list of validators that produce a `Validation` result | ||
* @return aggregated result of all validator function | ||
*/ | ||
def apply(validators: Seq[Validator]): Validation = validators.flatMap(_.apply()).foldLeft(Validation(Nil, Nil)) { | ||
case (validation, error: ValidationError) => validation.copy(errors = validation.errors :+ error) | ||
case (validation, warning: ValidationWarning) => validation.copy(warnings = validation.warnings :+ warning) | ||
} | ||
|
||
/** | ||
* Runs a list of validators and throws an exception after printing all | ||
* errors and warnings with the provided logger. | ||
* | ||
* @param validators a list of validators that produce the validation result | ||
* @param log used to print errors and warnings | ||
*/ | ||
def runAndThrow(validators: Seq[Validator], log: Logger): Unit = { | ||
val Validation(errors, warnings) = apply(validators) | ||
|
||
warnings.zipWithIndex.foreach { | ||
case (warning, i) => | ||
log.warn(s"[${i + 1}] ${warning.description}") | ||
log.warn(warning.howToFix) | ||
} | ||
|
||
errors.zipWithIndex.foreach { | ||
case (error, i) => | ||
log.error(s"[${i + 1}] ${error.description}") | ||
log.error(error.howToFix) | ||
} | ||
|
||
if (errors.nonEmpty) { | ||
sys.error(s"${errors.length} error(s) found") | ||
} | ||
|
||
log.success("All package validations passed") | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/main/scala/com/typesafe/sbt/packager/validation/ValidationKeys.scala
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,22 @@ | ||
package com.typesafe.sbt.packager.validation | ||
|
||
import sbt._ | ||
|
||
trait ValidationKeys { | ||
|
||
/** | ||
* A task that implements various validations for a format. | ||
* Example usage: | ||
* - `sbt universal:packageBin::validatePackage` | ||
* - `sbt debian:packageBin::validatePackage` | ||
* | ||
* | ||
* Each format should implement it's own validate. | ||
* Implemented in #1026 | ||
*/ | ||
val validatePackage = taskKey[Unit]("validates the package configuration") | ||
|
||
val validatePackageValidators = taskKey[Seq[Validation.Validator]]("validator functions") | ||
} | ||
|
||
object ValidationKeys extends ValidationKeys |
18 changes: 18 additions & 0 deletions
18
src/main/scala/com/typesafe/sbt/packager/validation/ValidationResult.scala
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,18 @@ | ||
package com.typesafe.sbt.packager.validation | ||
|
||
sealed trait ValidationResult { | ||
|
||
/** | ||
* Human readable and understandable description of the validation result. | ||
*/ | ||
val description: String | ||
|
||
/** | ||
* Help text on how to fix the issue. | ||
*/ | ||
val howToFix: String | ||
|
||
} | ||
|
||
final case class ValidationError(description: String, howToFix: String) extends ValidationResult | ||
final case class ValidationWarning(description: String, howToFix: String) extends ValidationResult |
Oops, something went wrong.