Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #11 from havocp/havocp-print-project-name

Allow missing previous-artifact, print project name in logs
  • Loading branch information...
commit 07d9abab1b5607dd8871e2904db215c694b77bce 2 parents e19ea6f + d274a2d
@jsuereth jsuereth authored
View
8 sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/Keys.scala
@@ -5,12 +5,12 @@ import sbt._
object MimaKeys {
val failOnProblem = SettingKey[Boolean]("mima-fail-on-problem", "if true, fail the build on binary incompatibility detection.")
-
+
val previousArtifact = SettingKey[Option[ModuleID]]("mima-previous-artifact", "Previous released artifact used to test binary compatibility.")
- val previousClassfiles = TaskKey[File]("mima-previous-classfiles", "Directory or jar containing the previous class files used to test compatibility.")
+ val previousClassfiles = TaskKey[Option[File]]("mima-previous-classfiles", "Directory or jar containing the previous class files used to test compatibility.")
val currentClassfiles = TaskKey[File]("mima-current-classfiles", "Directory or jar containing the current class files used to test compatibility.")
// TODO - Create a task to make a MiMaLib, is that a good idea?
val findBinaryIssues = TaskKey[List[core.Problem]]("mima-find-binary-issues", "A list of all binary incompatibilities between two files.")
val reportBinaryIssues = TaskKey[Unit]("mima-report-binary-issues", "Logs all binary incompatibilities to the sbt console/logs.")
-
-}
+
+}
View
23 sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/MimaPlugin.scala
@@ -2,17 +2,25 @@ package com.typesafe.tools.mima
package plugin
import sbt._
-import sbt.Keys.{fullClasspath, streams, classDirectory, ivySbt}
+import sbt.Keys.{fullClasspath, streams, classDirectory, ivySbt, name}
/** Sbt plugin for using MiMa. */
object MimaPlugin extends Plugin {
import MimaKeys._
/** Just configures MiMa to compare previous/current classfiles.*/
def mimaReportSettings: Seq[Setting[_]] = Seq(
- findBinaryIssues <<= (previousClassfiles, currentClassfiles,
- fullClasspath in findBinaryIssues, streams
- ) map SbtMima.runMima,
- reportBinaryIssues <<= (findBinaryIssues, failOnProblem, streams) map SbtMima.reportErrors
+ findBinaryIssues <<= (previousClassfiles, currentClassfiles,
+ fullClasspath in findBinaryIssues, streams, name
+ ) map { (prevOption, curr, cp, s, name) =>
+ prevOption match {
+ case Some(prev) =>
+ SbtMima.runMima(prev, curr, cp, s)
+ case None =>
+ s.log.info(name + ": previous-artifact not set, not analyzing binary compatibility")
+ Nil
+ }
+ },
+ reportBinaryIssues <<= (findBinaryIssues, failOnProblem, streams, name) map SbtMima.reportErrors
)
/** Setup mima with default settings, applicable for most projects. */
def mimaDefaultSettings: Seq[Setting[_]] = Seq(
@@ -20,9 +28,8 @@ object MimaPlugin extends Plugin {
previousArtifact := None,
currentClassfiles <<= classDirectory in Compile map identity,
previousClassfiles <<= (ivySbt, previousArtifact, streams) map { (i, optArt, s) =>
- val art = optArt getOrElse sys.error("No previous-artifact defined. Cannot check binary compatibility.")
- SbtMima.getPreviousArttifact(art, i, s)
+ optArt map { art => SbtMima.getPreviousArtifact(art, i, s) }
},
fullClasspath in findBinaryIssues <<= fullClasspath in Compile
) ++ mimaReportSettings
-}
+}
View
20 sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/SbtMima.scala
@@ -17,7 +17,7 @@ class SbtLogger(s: TaskStreams) extends Logging {
object SbtMima {
val x = sbt.Keys.fullClasspath
-
+
/** Creates a new MiMaLib object to run analysis. */
private def makeMima(cp: sbt.Keys.Classpath, s: TaskStreams): lib.MiMaLib = {
// TODO: Fix MiMa so we don't have to hack this bit in.
@@ -26,28 +26,28 @@ object SbtMima {
val classpath = new JavaClassPath(DefaultJavaContext.classesInPath(cpstring).toIndexedSeq, DefaultJavaContext)
new lib.MiMaLib(classpath, new SbtLogger(s))
}
-
+
/** Runs MiMa and returns a list of potential binary incompatibilities. */
- def runMima(prev: File, curr: File, cp: sbt.Keys.Classpath, s: TaskStreams): List[core.Problem] =
+ def runMima(prev: File, curr: File, cp: sbt.Keys.Classpath, s: TaskStreams): List[core.Problem] =
makeMima(cp, s).collectProblems(prev.getAbsolutePath, curr.getAbsolutePath)
/** Reports binary compatibility errors.
* @param failOnProblem if true, fails the build on binary compatibility errors.
*/
- def reportErrors(errors: List[core.Problem], failOnProblem: Boolean, s: TaskStreams): Unit = {
- // TODO - Line wrapping an other magikz
+ def reportErrors(errors: List[core.Problem], failOnProblem: Boolean, s: TaskStreams, projectName: String): Unit = {
+ // TODO - Line wrapping an other magikz
def prettyPrint(p: core.Problem): String = " * " + p.description
- s.log.info("Found " + errors.size + " potential binary incompatibilities")
+ s.log.info(projectName + ": found " + errors.size + " potential binary incompatibilities")
errors map prettyPrint foreach { p =>
if(failOnProblem) s.log.error(p)
else s.log.warn(p)
}
- if(failOnProblem && !errors.isEmpty) sys.error("Binary compatibility check failed!")
+ if(failOnProblem && !errors.isEmpty) sys.error(projectName + ": Binary compatibility check failed!")
}
/** Resolves an artifact representing the previous abstract binary interface
* for testing.
*/
- def getPreviousArttifact(m: ModuleID, ivy: IvySbt, s: TaskStreams): File = {
+ def getPreviousArtifact(m: ModuleID, ivy: IvySbt, s: TaskStreams): File = {
val moduleSettings = InlineConfiguration(
"dummy" % "test" % "version",
ModuleInfo("dummy-test-project-for-resolving"),
@@ -57,10 +57,10 @@ object SbtMima {
val report = IvyActions.update(
module,
new UpdateConfiguration(
- retrieve = None,
+ retrieve = None,
missingOk = false,
logging = UpdateLogging.DownloadOnly),
- s.log
+ s.log
)
val optFile = (for {
config <- report.configurations
Please sign in to comment.
Something went wrong with that request. Please try again.