Better minification

This commit is contained in:
Alexandre Archambault 2015-06-25 00:18:52 +01:00
parent 07278edd6d
commit 5dc17a5bb3
2 changed files with 39 additions and 13 deletions

View File

@ -8,7 +8,7 @@ object Exclusions {
.partition{case (org, name) => org == "*" || name == "*" }
val all = wildCards
.contains(("*", "*"))
.contains(one.head)
val excludeByOrg = wildCards
.collect{case (org, "*") if org != "*" => org }
@ -35,7 +35,7 @@ object Exclusions {
val (all, excludeByOrg, excludeByName, remaining) = partition(exclusions)
if (all) Set(("*", "*"))
if (all) one
else {
val filteredRemaining = remaining
.filter{case (org, name) =>
@ -49,5 +49,39 @@ object Exclusions {
}
}
val zero = Set.empty[(String, String)]
val one = Set(("*", "*"))
def join(x: Set[(String, String)], y: Set[(String, String)]): Set[(String, String)] =
minimize(x ++ y)
def meet(x: Set[(String, String)], y: Set[(String, String)]): Set[(String, String)] = {
val ((xAll, xExcludeByOrg, xExcludeByName, xRemaining), (yAll, yExcludeByOrg, yExcludeByName, yRemaining)) =
(partition(x), partition(y))
val all = xAll && yAll
if (all) one
else {
val excludeByOrg =
if (xAll) yExcludeByOrg
else if (yAll) xExcludeByOrg
else xExcludeByOrg intersect yExcludeByOrg
val excludeByName =
if (xAll) yExcludeByName
else if (yAll) xExcludeByName
else xExcludeByName intersect yExcludeByName
val remaining =
xRemaining.filter{case (org, name) => yAll || yExcludeByOrg(org) || yExcludeByName(name)} ++
yRemaining.filter{case (org, name) => xAll || xExcludeByOrg(org) || xExcludeByName(name)} ++
(xRemaining intersect yRemaining)
excludeByOrg.map((_, "*")) ++
excludeByName.map(("*", _)) ++
remaining
}
}
}

View File

@ -105,23 +105,15 @@ object Orders {
def minDependenciesUnsafe(dependencies: Set[Dependency]): Set[Dependency] = {
val groupedDependencies = dependencies
.groupBy(dep => (dep.optional, dep.scope))
.mapValues(deps => deps.head.copy(exclusions = deps.foldLeft(Exclusions.one)((acc, dep) => Exclusions.meet(acc, dep.exclusions))))
.toList
/*
* Iterates over all pairs (xDep, yDep) from `dependencies`.
* If xDep < yDep (all that yDep brings is already brought by xDep), remove yDep.
*
* The (partial) order on dependencies is made of the ones on scope, optional, and exclusions.
*/
val remove =
for {
List(((xOpt, xScope), xDeps), ((yOpt, yScope), yDeps)) <- groupedDependencies.combinations(2)
List(((xOpt, xScope), xDep), ((yOpt, yScope), yDep)) <- groupedDependencies.combinations(2)
optCmp <- optionalPartialOrder.cmp(xOpt, yOpt).iterator
scopeCmp <- mavenScopePartialOrder.cmp(xScope, yScope).iterator
if optCmp*scopeCmp >= 0
xDep <- xDeps.iterator
yDep <- yDeps.iterator
exclCmp <- exclusionsPartialOrder.cmp(xDep.exclusions, yDep.exclusions).iterator
if optCmp*exclCmp >= 0
if scopeCmp*exclCmp >= 0
@ -130,7 +122,7 @@ object Orders {
if xIsMin || yIsMin // should be always true, unless xDep == yDep, which shouldn't happen
} yield if (xIsMin) yDep else xDep
dependencies -- remove
groupedDependencies.map(_._2).toSet -- remove
}
/**