-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PomFilter to filter out "scoverage" and "silencer"
Motivation: - "provided" does not remove dependencies from a pom.xml - use a snippet from #739 to exclude undesired dependencies - apply PomFilter to exlude scoverage too.
- Loading branch information
Showing
3 changed files
with
53 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import scala.util.matching.Regex | ||
import scala.xml.Elem | ||
import scala.xml.transform.{RewriteRule, RuleTransformer} | ||
import sbt.Keys.pomPostProcess | ||
|
||
object PomFilter { | ||
|
||
/** | ||
* Filter out dependencies from the generated `pom.xml`. | ||
* | ||
* E.g. to exclude Scoverage: | ||
* {{{ | ||
* filterOutDependencyFromGeneratedPomXml("groupId" -> "org\\.scoverage".r) | ||
* }}} | ||
* | ||
* Or to exclude based on both `groupId` and `artifactId`: | ||
* {{{ | ||
* filterOutDependencyFromGeneratedPomXml("groupId" -> "io\\.estatico".r, "artifactId" -> "newtype".r) | ||
* }}} | ||
*/ | ||
def filterOutDependencyFromGeneratedPomXml(conditions: (String, Regex)*) = { | ||
def shouldExclude(e: Elem) = | ||
e.label == "dependency" && { | ||
conditions.forall { | ||
case (key, regex) => | ||
e.child.exists(child => child.label == key && regex.findFirstIn(child.text).isDefined) | ||
} | ||
} | ||
|
||
if (conditions.isEmpty) Nil | ||
else { | ||
Seq( | ||
pomPostProcess := { (node: xml.Node) => | ||
new RuleTransformer(new RewriteRule { | ||
override def transform(node: xml.Node): Seq[xml.Node] = node match { | ||
case e: Elem if shouldExclude(e) => Nil | ||
case _ => Seq(node) | ||
} | ||
}).transform(node).head | ||
} | ||
) | ||
} | ||
} | ||
} |