forked from pantsbuild/pants
-
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.
Filter zinc compilation warnings at the Reporter level
The existing impl did not include the severity in its match, so it's possible that errors could be filtered. - Only filter non-errors - Filter zinc compilation at the Reporter level, rather than in the logger - Split between message filters and filename filters Testing Done: Used: ./pants --config-override=pants.ini.isolated publish.jar --no-dryrun --local=~/.m2/repository --named-snapshot=$USER-`date +%s` src/scala/org/pantsbuild/zinc:: ...to do a local publish, then tested that: ./pants --config-override=pants.ini.isolated compile testprojects/src/java/org/pantsbuild/testproject/dummies:: properly applied both `-msg-filter` and `-file-filter`. ---- Can add a pants integration test once this release goes out. Reviewed at https://rbcommons.com/s/twitter/r/2656/
- Loading branch information
Showing
6 changed files
with
76 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright (C) 2015 Pants project contributors (see CONTRIBUTORS.md). | ||
* Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
*/ | ||
|
||
package org.pantsbuild.zinc.logging | ||
|
||
import xsbti.{ Position, Reporter, Severity } | ||
import sbt.{ Logger, LoggerReporter } | ||
|
||
import scala.util.matching.Regex | ||
|
||
object Reporters { | ||
def create( | ||
log: Logger, | ||
fileFilters: Seq[Regex], | ||
msgFilters: Seq[Regex], | ||
maximumErrors: Int = 100 | ||
): Reporter = | ||
if (fileFilters.isEmpty && msgFilters.isEmpty) { | ||
new LoggerReporter(maximumErrors, log) | ||
} else { | ||
new RegexFilterReporter(fileFilters, msgFilters, maximumErrors, log) | ||
} | ||
} | ||
|
||
/** | ||
* Extends LoggerReporter to filter compile warnings that match various patterns. | ||
*/ | ||
class RegexFilterReporter( | ||
fileFilters: Seq[Regex], | ||
msgFilters: Seq[Regex], | ||
maximumErrors: Int, | ||
log: Logger | ||
) extends LoggerReporter( | ||
maximumErrors, | ||
log | ||
) { | ||
|
||
private final def isFiltered(filters: Seq[Regex], str: String): Boolean = | ||
filters.exists(_.findFirstIn(str).isDefined) | ||
|
||
private final def isFiltered(pos: Position, msg: String, severity: Severity): Boolean = | ||
severity != Severity.Error && ( | ||
(!pos.sourceFile.isEmpty && isFiltered(fileFilters, pos.sourceFile.get.getPath)) || ( | ||
isFiltered(msgFilters, msg) | ||
) | ||
) | ||
|
||
override def display(pos: Position, msg: String, severity: Severity): Unit = | ||
if (isFiltered(pos, msg, severity)) { | ||
// the only side-effecting operation in the superclass | ||
inc(severity) | ||
} else { | ||
super.display(pos, msg, severity) | ||
} | ||
} |
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