diff --git a/src/main/scala/software/purpledragon/sbt/lock/DependencyLockPlugin.scala b/src/main/scala/software/purpledragon/sbt/lock/DependencyLockPlugin.scala index 289d170..2852fd8 100644 --- a/src/main/scala/software/purpledragon/sbt/lock/DependencyLockPlugin.scala +++ b/src/main/scala/software/purpledragon/sbt/lock/DependencyLockPlugin.scala @@ -18,6 +18,8 @@ package software.purpledragon.sbt.lock import sbt.Keys._ import sbt._ +import sbt.internal.util.ManagedLogger +import software.purpledragon.sbt.lock.DependencyLockUpdateMode._ import software.purpledragon.sbt.lock.model.{DependencyLockFile, LockFileMatches} object DependencyLockPlugin extends AutoPlugin { @@ -29,12 +31,20 @@ object DependencyLockPlugin extends AutoPlugin { val dependencyLockRead = taskKey[Option[DependencyLockFile]]("read dependencies from lock file") val dependencyLockCheck = taskKey[Unit]("check if dependency lock is up to date") + + val DependencyLockUpdateMode: software.purpledragon.sbt.lock.DependencyLockUpdateMode.type = + software.purpledragon.sbt.lock.DependencyLockUpdateMode + val dependencyLockAutoCheck = settingKey[DependencyLockUpdateMode]("automatically check lock file after update") } import autoImport._ + // task names to skip auto-check if we're inside of + private val PluginTasks = Seq("dependencyLockWrite", "dependencyLockCheck", "dependencyLockRead") + override def projectSettings: Seq[Def.Setting[_]] = Seq( dependencyLockFile := baseDirectory.value / "build.sbt.lock", + dependencyLockAutoCheck := DependencyLockUpdateMode.WarnOnError, dependencyLockWrite := { val dest = dependencyLockFile.value val updateReport = update.value @@ -49,8 +59,8 @@ object DependencyLockPlugin extends AutoPlugin { deps }, dependencyLockCheck := { - val logger = streams.value.log - val updateReport = update.value + val logger: ManagedLogger = streams.value.log + val updateReport: UpdateReport = update.value val currentFile = dependencyLockRead.value.getOrElse(sys.error("no lock file")) val updatedFile = DependencyUtils.resolve(updateReport, thisProject.value.configurations.map(_.toConfigRef)) @@ -63,6 +73,47 @@ object DependencyLockPlugin extends AutoPlugin { logger.warn(changes.toShortReport) sys.error(changes.toLongReport) } - } + }, + update := Def.taskDyn { + val report = update.value + val logger = streams.value.log + + + // check to see if the current command/task is one of our internal ones + val skipCheck = state.value.currentCommand.map(_.commandLine).exists(PluginTasks.contains) + val checkMode = dependencyLockAutoCheck.value + + if (checkMode != DependencyLockUpdateMode.CheckDisabled && !skipCheck) { + logger.debug("Automatically checking lockfile") + + dependencyLockRead.value match { + case Some(currentFile) => + val updatedFile = DependencyUtils.resolve(report, thisProject.value.configurations.map(_.toConfigRef)) + + val changes = currentFile.findChanges(updatedFile) + + (changes, checkMode) match { + case (LockFileMatches, _) => + // check passed + case (_, WarnOnError) => + logger.warn("Dependency lock file is outdated - please run `dependencyLockCheck` for details") + case (_, FailOnError) => + logger.error("Dependency lock file is outdated") + sys.error(changes.toLongReport) + + case _ => + // scenario shouldn't happen - failed check, but we're not checking... + } + + case None => + logger.warn("no lockfile found - please run dependencyLockWrite") + } + } + + // return the original report + Def.task { + report + } + }.value ) } diff --git a/src/main/scala/software/purpledragon/sbt/lock/DependencyLockUpdateMode.scala b/src/main/scala/software/purpledragon/sbt/lock/DependencyLockUpdateMode.scala new file mode 100644 index 0000000..3922eb6 --- /dev/null +++ b/src/main/scala/software/purpledragon/sbt/lock/DependencyLockUpdateMode.scala @@ -0,0 +1,23 @@ +/* + * Copyright 2019 Michael Stringer + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package software.purpledragon.sbt.lock + +object DependencyLockUpdateMode extends Enumeration { + type DependencyLockUpdateMode = Value + + val CheckDisabled, WarnOnError, FailOnError = Value +} diff --git a/src/sbt-test/sbt-dependency-lock/check-fail/build.sbt b/src/sbt-test/dependencyLockCheck/fail-differences/build.sbt similarity index 100% rename from src/sbt-test/sbt-dependency-lock/check-fail/build.sbt rename to src/sbt-test/dependencyLockCheck/fail-differences/build.sbt diff --git a/src/sbt-test/sbt-dependency-lock/check-fail/build.sbt.lock b/src/sbt-test/dependencyLockCheck/fail-differences/build.sbt.lock similarity index 100% rename from src/sbt-test/sbt-dependency-lock/check-fail/build.sbt.lock rename to src/sbt-test/dependencyLockCheck/fail-differences/build.sbt.lock diff --git a/src/sbt-test/sbt-dependency-lock/check-different-order/project/plugins.sbt b/src/sbt-test/dependencyLockCheck/fail-differences/project/plugins.sbt similarity index 100% rename from src/sbt-test/sbt-dependency-lock/check-different-order/project/plugins.sbt rename to src/sbt-test/dependencyLockCheck/fail-differences/project/plugins.sbt diff --git a/src/sbt-test/sbt-dependency-lock/check-fail/test b/src/sbt-test/dependencyLockCheck/fail-differences/test similarity index 100% rename from src/sbt-test/sbt-dependency-lock/check-fail/test rename to src/sbt-test/dependencyLockCheck/fail-differences/test diff --git a/src/sbt-test/sbt-dependency-lock/check-different-order/build.sbt b/src/sbt-test/dependencyLockCheck/fail-missing-file/build.sbt similarity index 100% rename from src/sbt-test/sbt-dependency-lock/check-different-order/build.sbt rename to src/sbt-test/dependencyLockCheck/fail-missing-file/build.sbt diff --git a/src/sbt-test/sbt-dependency-lock/check-fail/project/plugins.sbt b/src/sbt-test/dependencyLockCheck/fail-missing-file/project/plugins.sbt similarity index 100% rename from src/sbt-test/sbt-dependency-lock/check-fail/project/plugins.sbt rename to src/sbt-test/dependencyLockCheck/fail-missing-file/project/plugins.sbt diff --git a/src/sbt-test/sbt-dependency-lock/check-missing/test b/src/sbt-test/dependencyLockCheck/fail-missing-file/test similarity index 100% rename from src/sbt-test/sbt-dependency-lock/check-missing/test rename to src/sbt-test/dependencyLockCheck/fail-missing-file/test diff --git a/src/sbt-test/sbt-dependency-lock/check-missing/build.sbt b/src/sbt-test/dependencyLockCheck/pass-different-order/build.sbt similarity index 100% rename from src/sbt-test/sbt-dependency-lock/check-missing/build.sbt rename to src/sbt-test/dependencyLockCheck/pass-different-order/build.sbt diff --git a/src/sbt-test/sbt-dependency-lock/check-different-order/build.sbt.lock b/src/sbt-test/dependencyLockCheck/pass-different-order/build.sbt.lock similarity index 100% rename from src/sbt-test/sbt-dependency-lock/check-different-order/build.sbt.lock rename to src/sbt-test/dependencyLockCheck/pass-different-order/build.sbt.lock diff --git a/src/sbt-test/sbt-dependency-lock/check-missing/project/plugins.sbt b/src/sbt-test/dependencyLockCheck/pass-different-order/project/plugins.sbt similarity index 100% rename from src/sbt-test/sbt-dependency-lock/check-missing/project/plugins.sbt rename to src/sbt-test/dependencyLockCheck/pass-different-order/project/plugins.sbt diff --git a/src/sbt-test/sbt-dependency-lock/check-different-order/test b/src/sbt-test/dependencyLockCheck/pass-different-order/test similarity index 100% rename from src/sbt-test/sbt-dependency-lock/check-different-order/test rename to src/sbt-test/dependencyLockCheck/pass-different-order/test diff --git a/src/sbt-test/sbt-dependency-lock/check-pass/build.sbt b/src/sbt-test/dependencyLockCheck/pass/build.sbt similarity index 100% rename from src/sbt-test/sbt-dependency-lock/check-pass/build.sbt rename to src/sbt-test/dependencyLockCheck/pass/build.sbt diff --git a/src/sbt-test/sbt-dependency-lock/check-pass/build.sbt.lock b/src/sbt-test/dependencyLockCheck/pass/build.sbt.lock similarity index 100% rename from src/sbt-test/sbt-dependency-lock/check-pass/build.sbt.lock rename to src/sbt-test/dependencyLockCheck/pass/build.sbt.lock diff --git a/src/sbt-test/sbt-dependency-lock/check-pass/project/plugins.sbt b/src/sbt-test/dependencyLockCheck/pass/project/plugins.sbt similarity index 100% rename from src/sbt-test/sbt-dependency-lock/check-pass/project/plugins.sbt rename to src/sbt-test/dependencyLockCheck/pass/project/plugins.sbt diff --git a/src/sbt-test/sbt-dependency-lock/check-pass/test b/src/sbt-test/dependencyLockCheck/pass/test similarity index 100% rename from src/sbt-test/sbt-dependency-lock/check-pass/test rename to src/sbt-test/dependencyLockCheck/pass/test diff --git a/src/sbt-test/update/disabled-differences/build.sbt b/src/sbt-test/update/disabled-differences/build.sbt new file mode 100644 index 0000000..5abbcb3 --- /dev/null +++ b/src/sbt-test/update/disabled-differences/build.sbt @@ -0,0 +1,9 @@ +scalaVersion := "2.12.10" + +libraryDependencies ++= Seq( + "org.apache.commons" % "commons-lang3" % "3.9", + // lock file has 3.0.8 + "org.scalatest" %% "scalatest" % "3.0.7" % Test, +) + +dependencyLockAutoCheck := DependencyLockUpdateMode.CheckDisabled \ No newline at end of file diff --git a/src/sbt-test/update/disabled-differences/build.sbt.lock b/src/sbt-test/update/disabled-differences/build.sbt.lock new file mode 100644 index 0000000..cae2104 --- /dev/null +++ b/src/sbt-test/update/disabled-differences/build.sbt.lock @@ -0,0 +1,101 @@ +{ + "lockVersion" : 1, + "timestamp" : "2019-11-21T18:42:01.200Z", + "configurations" : [ + "compile", + "optional", + "provided", + "runtime", + "test" + ], + "dependencies" : [ + { + "org" : "org.apache.commons", + "name" : "commons-lang3", + "version" : "3.9", + "artifacts" : [ + { + "name" : "commons-lang3.jar", + "hash" : "sha1:0122c7cee69b53ed4a7681c03d4ee4c0e2765da5" + } + ], + "configurations" : [ + "test", + "compile", + "runtime" + ] + }, + { + "org" : "org.scala-lang", + "name" : "scala-library", + "version" : "2.12.10", + "artifacts" : [ + { + "name" : "scala-library.jar", + "hash" : "sha1:3509860bc2e5b3da001ed45aca94ffbe5694dbda" + } + ], + "configurations" : [ + "test", + "compile", + "runtime" + ] + }, + { + "org" : "org.scala-lang", + "name" : "scala-reflect", + "version" : "2.12.10", + "artifacts" : [ + { + "name" : "scala-reflect.jar", + "hash" : "sha1:14cb7beb516cd8e07716133668c427792122c926" + } + ], + "configurations" : [ + "test" + ] + }, + { + "org" : "org.scala-lang.modules", + "name" : "scala-xml_2.12", + "version" : "1.2.0", + "artifacts" : [ + { + "name" : "scala-xml_2.12.jar", + "hash" : "sha1:5d38ac30beb8420dd395c0af447ba412158965e6" + } + ], + "configurations" : [ + "test" + ] + }, + { + "org" : "org.scalactic", + "name" : "scalactic_2.12", + "version" : "3.0.8", + "artifacts" : [ + { + "name" : "scalactic_2.12.jar", + "hash" : "sha1:b50559dfc4a691c1089f9c8812e1d6fd17f80277" + } + ], + "configurations" : [ + "test" + ] + }, + { + "org" : "org.scalatest", + "name" : "scalatest_2.12", + "version" : "3.0.8", + "artifacts" : [ + { + "name" : "scalatest_2.12.jar", + "hash" : "sha1:8493ffa579676977b810a7a9fdc23af9d3c8af7f" + } + ], + "configurations" : [ + "test" + ] + } + ] +} \ No newline at end of file diff --git a/src/sbt-test/update/disabled-differences/project/plugins.sbt b/src/sbt-test/update/disabled-differences/project/plugins.sbt new file mode 100644 index 0000000..85547d6 --- /dev/null +++ b/src/sbt-test/update/disabled-differences/project/plugins.sbt @@ -0,0 +1,7 @@ +{ + val pluginVersion = System.getProperty("plugin.version") + if (pluginVersion == null) + throw new RuntimeException("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) + else addSbtPlugin("software.purpledragon" % "sbt-dependency-lock" % pluginVersion) +} diff --git a/src/sbt-test/update/disabled-differences/test b/src/sbt-test/update/disabled-differences/test new file mode 100644 index 0000000..edf1fbd --- /dev/null +++ b/src/sbt-test/update/disabled-differences/test @@ -0,0 +1 @@ +> update \ No newline at end of file diff --git a/src/sbt-test/update/disabled-same/build.sbt b/src/sbt-test/update/disabled-same/build.sbt new file mode 100644 index 0000000..54d14d9 --- /dev/null +++ b/src/sbt-test/update/disabled-same/build.sbt @@ -0,0 +1,19 @@ +scalaVersion := "2.12.10" + +libraryDependencies ++= Seq( + "org.apache.commons" % "commons-lang3" % "3.9", + "org.scalatest" %% "scalatest" % "3.0.8" % Test, +) + +dependencyLockAutoCheck := DependencyLockUpdateMode.CheckDisabled + +val checkLog = taskKey[Unit]("checks the contents of the log") + +checkLog := { + val lastLog = BuiltinCommands.lastLogFile(state.value).get + val last = IO.read(lastLog) + + if (last.contains("Dependency lock file is outdated")) { + sys.error("check contained warning") + } +} \ No newline at end of file diff --git a/src/sbt-test/update/disabled-same/build.sbt.lock b/src/sbt-test/update/disabled-same/build.sbt.lock new file mode 100644 index 0000000..cae2104 --- /dev/null +++ b/src/sbt-test/update/disabled-same/build.sbt.lock @@ -0,0 +1,101 @@ +{ + "lockVersion" : 1, + "timestamp" : "2019-11-21T18:42:01.200Z", + "configurations" : [ + "compile", + "optional", + "provided", + "runtime", + "test" + ], + "dependencies" : [ + { + "org" : "org.apache.commons", + "name" : "commons-lang3", + "version" : "3.9", + "artifacts" : [ + { + "name" : "commons-lang3.jar", + "hash" : "sha1:0122c7cee69b53ed4a7681c03d4ee4c0e2765da5" + } + ], + "configurations" : [ + "test", + "compile", + "runtime" + ] + }, + { + "org" : "org.scala-lang", + "name" : "scala-library", + "version" : "2.12.10", + "artifacts" : [ + { + "name" : "scala-library.jar", + "hash" : "sha1:3509860bc2e5b3da001ed45aca94ffbe5694dbda" + } + ], + "configurations" : [ + "test", + "compile", + "runtime" + ] + }, + { + "org" : "org.scala-lang", + "name" : "scala-reflect", + "version" : "2.12.10", + "artifacts" : [ + { + "name" : "scala-reflect.jar", + "hash" : "sha1:14cb7beb516cd8e07716133668c427792122c926" + } + ], + "configurations" : [ + "test" + ] + }, + { + "org" : "org.scala-lang.modules", + "name" : "scala-xml_2.12", + "version" : "1.2.0", + "artifacts" : [ + { + "name" : "scala-xml_2.12.jar", + "hash" : "sha1:5d38ac30beb8420dd395c0af447ba412158965e6" + } + ], + "configurations" : [ + "test" + ] + }, + { + "org" : "org.scalactic", + "name" : "scalactic_2.12", + "version" : "3.0.8", + "artifacts" : [ + { + "name" : "scalactic_2.12.jar", + "hash" : "sha1:b50559dfc4a691c1089f9c8812e1d6fd17f80277" + } + ], + "configurations" : [ + "test" + ] + }, + { + "org" : "org.scalatest", + "name" : "scalatest_2.12", + "version" : "3.0.8", + "artifacts" : [ + { + "name" : "scalatest_2.12.jar", + "hash" : "sha1:8493ffa579676977b810a7a9fdc23af9d3c8af7f" + } + ], + "configurations" : [ + "test" + ] + } + ] +} \ No newline at end of file diff --git a/src/sbt-test/update/disabled-same/project/plugins.sbt b/src/sbt-test/update/disabled-same/project/plugins.sbt new file mode 100644 index 0000000..85547d6 --- /dev/null +++ b/src/sbt-test/update/disabled-same/project/plugins.sbt @@ -0,0 +1,7 @@ +{ + val pluginVersion = System.getProperty("plugin.version") + if (pluginVersion == null) + throw new RuntimeException("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) + else addSbtPlugin("software.purpledragon" % "sbt-dependency-lock" % pluginVersion) +} diff --git a/src/sbt-test/update/disabled-same/test b/src/sbt-test/update/disabled-same/test new file mode 100644 index 0000000..e211012 --- /dev/null +++ b/src/sbt-test/update/disabled-same/test @@ -0,0 +1,2 @@ +> update +> checkLog diff --git a/src/sbt-test/update/fail-differences/build.sbt b/src/sbt-test/update/fail-differences/build.sbt new file mode 100644 index 0000000..e0e9153 --- /dev/null +++ b/src/sbt-test/update/fail-differences/build.sbt @@ -0,0 +1,9 @@ +scalaVersion := "2.12.10" + +libraryDependencies ++= Seq( + "org.apache.commons" % "commons-lang3" % "3.9", + // lock file has 3.0.8 + "org.scalatest" %% "scalatest" % "3.0.7" % Test, +) + +dependencyLockAutoCheck := DependencyLockUpdateMode.FailOnError \ No newline at end of file diff --git a/src/sbt-test/update/fail-differences/build.sbt.lock b/src/sbt-test/update/fail-differences/build.sbt.lock new file mode 100644 index 0000000..cae2104 --- /dev/null +++ b/src/sbt-test/update/fail-differences/build.sbt.lock @@ -0,0 +1,101 @@ +{ + "lockVersion" : 1, + "timestamp" : "2019-11-21T18:42:01.200Z", + "configurations" : [ + "compile", + "optional", + "provided", + "runtime", + "test" + ], + "dependencies" : [ + { + "org" : "org.apache.commons", + "name" : "commons-lang3", + "version" : "3.9", + "artifacts" : [ + { + "name" : "commons-lang3.jar", + "hash" : "sha1:0122c7cee69b53ed4a7681c03d4ee4c0e2765da5" + } + ], + "configurations" : [ + "test", + "compile", + "runtime" + ] + }, + { + "org" : "org.scala-lang", + "name" : "scala-library", + "version" : "2.12.10", + "artifacts" : [ + { + "name" : "scala-library.jar", + "hash" : "sha1:3509860bc2e5b3da001ed45aca94ffbe5694dbda" + } + ], + "configurations" : [ + "test", + "compile", + "runtime" + ] + }, + { + "org" : "org.scala-lang", + "name" : "scala-reflect", + "version" : "2.12.10", + "artifacts" : [ + { + "name" : "scala-reflect.jar", + "hash" : "sha1:14cb7beb516cd8e07716133668c427792122c926" + } + ], + "configurations" : [ + "test" + ] + }, + { + "org" : "org.scala-lang.modules", + "name" : "scala-xml_2.12", + "version" : "1.2.0", + "artifacts" : [ + { + "name" : "scala-xml_2.12.jar", + "hash" : "sha1:5d38ac30beb8420dd395c0af447ba412158965e6" + } + ], + "configurations" : [ + "test" + ] + }, + { + "org" : "org.scalactic", + "name" : "scalactic_2.12", + "version" : "3.0.8", + "artifacts" : [ + { + "name" : "scalactic_2.12.jar", + "hash" : "sha1:b50559dfc4a691c1089f9c8812e1d6fd17f80277" + } + ], + "configurations" : [ + "test" + ] + }, + { + "org" : "org.scalatest", + "name" : "scalatest_2.12", + "version" : "3.0.8", + "artifacts" : [ + { + "name" : "scalatest_2.12.jar", + "hash" : "sha1:8493ffa579676977b810a7a9fdc23af9d3c8af7f" + } + ], + "configurations" : [ + "test" + ] + } + ] +} \ No newline at end of file diff --git a/src/sbt-test/update/fail-differences/project/plugins.sbt b/src/sbt-test/update/fail-differences/project/plugins.sbt new file mode 100644 index 0000000..85547d6 --- /dev/null +++ b/src/sbt-test/update/fail-differences/project/plugins.sbt @@ -0,0 +1,7 @@ +{ + val pluginVersion = System.getProperty("plugin.version") + if (pluginVersion == null) + throw new RuntimeException("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) + else addSbtPlugin("software.purpledragon" % "sbt-dependency-lock" % pluginVersion) +} diff --git a/src/sbt-test/update/fail-differences/test b/src/sbt-test/update/fail-differences/test new file mode 100644 index 0000000..85240ac --- /dev/null +++ b/src/sbt-test/update/fail-differences/test @@ -0,0 +1 @@ +-> update \ No newline at end of file diff --git a/src/sbt-test/update/fail-same/build.sbt b/src/sbt-test/update/fail-same/build.sbt new file mode 100644 index 0000000..9a22113 --- /dev/null +++ b/src/sbt-test/update/fail-same/build.sbt @@ -0,0 +1,19 @@ +scalaVersion := "2.12.10" + +libraryDependencies ++= Seq( + "org.apache.commons" % "commons-lang3" % "3.9", + "org.scalatest" %% "scalatest" % "3.0.8" % Test, +) + +dependencyLockAutoCheck := DependencyLockUpdateMode.FailOnError + +val checkLog = taskKey[Unit]("checks the contents of the log") + +checkLog := { + val lastLog = BuiltinCommands.lastLogFile(state.value).get + val last = IO.read(lastLog) + + if (last.contains("Dependency lock file is outdated")) { + sys.error("check contained warning") + } +} \ No newline at end of file diff --git a/src/sbt-test/update/fail-same/build.sbt.lock b/src/sbt-test/update/fail-same/build.sbt.lock new file mode 100644 index 0000000..cae2104 --- /dev/null +++ b/src/sbt-test/update/fail-same/build.sbt.lock @@ -0,0 +1,101 @@ +{ + "lockVersion" : 1, + "timestamp" : "2019-11-21T18:42:01.200Z", + "configurations" : [ + "compile", + "optional", + "provided", + "runtime", + "test" + ], + "dependencies" : [ + { + "org" : "org.apache.commons", + "name" : "commons-lang3", + "version" : "3.9", + "artifacts" : [ + { + "name" : "commons-lang3.jar", + "hash" : "sha1:0122c7cee69b53ed4a7681c03d4ee4c0e2765da5" + } + ], + "configurations" : [ + "test", + "compile", + "runtime" + ] + }, + { + "org" : "org.scala-lang", + "name" : "scala-library", + "version" : "2.12.10", + "artifacts" : [ + { + "name" : "scala-library.jar", + "hash" : "sha1:3509860bc2e5b3da001ed45aca94ffbe5694dbda" + } + ], + "configurations" : [ + "test", + "compile", + "runtime" + ] + }, + { + "org" : "org.scala-lang", + "name" : "scala-reflect", + "version" : "2.12.10", + "artifacts" : [ + { + "name" : "scala-reflect.jar", + "hash" : "sha1:14cb7beb516cd8e07716133668c427792122c926" + } + ], + "configurations" : [ + "test" + ] + }, + { + "org" : "org.scala-lang.modules", + "name" : "scala-xml_2.12", + "version" : "1.2.0", + "artifacts" : [ + { + "name" : "scala-xml_2.12.jar", + "hash" : "sha1:5d38ac30beb8420dd395c0af447ba412158965e6" + } + ], + "configurations" : [ + "test" + ] + }, + { + "org" : "org.scalactic", + "name" : "scalactic_2.12", + "version" : "3.0.8", + "artifacts" : [ + { + "name" : "scalactic_2.12.jar", + "hash" : "sha1:b50559dfc4a691c1089f9c8812e1d6fd17f80277" + } + ], + "configurations" : [ + "test" + ] + }, + { + "org" : "org.scalatest", + "name" : "scalatest_2.12", + "version" : "3.0.8", + "artifacts" : [ + { + "name" : "scalatest_2.12.jar", + "hash" : "sha1:8493ffa579676977b810a7a9fdc23af9d3c8af7f" + } + ], + "configurations" : [ + "test" + ] + } + ] +} \ No newline at end of file diff --git a/src/sbt-test/update/fail-same/project/plugins.sbt b/src/sbt-test/update/fail-same/project/plugins.sbt new file mode 100644 index 0000000..85547d6 --- /dev/null +++ b/src/sbt-test/update/fail-same/project/plugins.sbt @@ -0,0 +1,7 @@ +{ + val pluginVersion = System.getProperty("plugin.version") + if (pluginVersion == null) + throw new RuntimeException("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) + else addSbtPlugin("software.purpledragon" % "sbt-dependency-lock" % pluginVersion) +} diff --git a/src/sbt-test/update/fail-same/test b/src/sbt-test/update/fail-same/test new file mode 100644 index 0000000..e211012 --- /dev/null +++ b/src/sbt-test/update/fail-same/test @@ -0,0 +1,2 @@ +> update +> checkLog diff --git a/src/sbt-test/update/warn-differences/build.sbt b/src/sbt-test/update/warn-differences/build.sbt new file mode 100644 index 0000000..51af6ee --- /dev/null +++ b/src/sbt-test/update/warn-differences/build.sbt @@ -0,0 +1,20 @@ +scalaVersion := "2.12.10" + +libraryDependencies ++= Seq( + "org.apache.commons" % "commons-lang3" % "3.9", + // lock file has 3.0.8 + "org.scalatest" %% "scalatest" % "3.0.7" % Test, +) + +dependencyLockAutoCheck := DependencyLockUpdateMode.WarnOnError + +val checkLog = taskKey[Unit]("checks the contents of the log") + +checkLog := { + val lastLog = BuiltinCommands.lastLogFile(state.value).get + val last = IO.read(lastLog) + + if (!last.contains("Dependency lock file is outdated")) { + sys.error("check did not contain error") + } +} \ No newline at end of file diff --git a/src/sbt-test/update/warn-differences/build.sbt.lock b/src/sbt-test/update/warn-differences/build.sbt.lock new file mode 100644 index 0000000..cae2104 --- /dev/null +++ b/src/sbt-test/update/warn-differences/build.sbt.lock @@ -0,0 +1,101 @@ +{ + "lockVersion" : 1, + "timestamp" : "2019-11-21T18:42:01.200Z", + "configurations" : [ + "compile", + "optional", + "provided", + "runtime", + "test" + ], + "dependencies" : [ + { + "org" : "org.apache.commons", + "name" : "commons-lang3", + "version" : "3.9", + "artifacts" : [ + { + "name" : "commons-lang3.jar", + "hash" : "sha1:0122c7cee69b53ed4a7681c03d4ee4c0e2765da5" + } + ], + "configurations" : [ + "test", + "compile", + "runtime" + ] + }, + { + "org" : "org.scala-lang", + "name" : "scala-library", + "version" : "2.12.10", + "artifacts" : [ + { + "name" : "scala-library.jar", + "hash" : "sha1:3509860bc2e5b3da001ed45aca94ffbe5694dbda" + } + ], + "configurations" : [ + "test", + "compile", + "runtime" + ] + }, + { + "org" : "org.scala-lang", + "name" : "scala-reflect", + "version" : "2.12.10", + "artifacts" : [ + { + "name" : "scala-reflect.jar", + "hash" : "sha1:14cb7beb516cd8e07716133668c427792122c926" + } + ], + "configurations" : [ + "test" + ] + }, + { + "org" : "org.scala-lang.modules", + "name" : "scala-xml_2.12", + "version" : "1.2.0", + "artifacts" : [ + { + "name" : "scala-xml_2.12.jar", + "hash" : "sha1:5d38ac30beb8420dd395c0af447ba412158965e6" + } + ], + "configurations" : [ + "test" + ] + }, + { + "org" : "org.scalactic", + "name" : "scalactic_2.12", + "version" : "3.0.8", + "artifacts" : [ + { + "name" : "scalactic_2.12.jar", + "hash" : "sha1:b50559dfc4a691c1089f9c8812e1d6fd17f80277" + } + ], + "configurations" : [ + "test" + ] + }, + { + "org" : "org.scalatest", + "name" : "scalatest_2.12", + "version" : "3.0.8", + "artifacts" : [ + { + "name" : "scalatest_2.12.jar", + "hash" : "sha1:8493ffa579676977b810a7a9fdc23af9d3c8af7f" + } + ], + "configurations" : [ + "test" + ] + } + ] +} \ No newline at end of file diff --git a/src/sbt-test/update/warn-differences/project/plugins.sbt b/src/sbt-test/update/warn-differences/project/plugins.sbt new file mode 100644 index 0000000..85547d6 --- /dev/null +++ b/src/sbt-test/update/warn-differences/project/plugins.sbt @@ -0,0 +1,7 @@ +{ + val pluginVersion = System.getProperty("plugin.version") + if (pluginVersion == null) + throw new RuntimeException("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) + else addSbtPlugin("software.purpledragon" % "sbt-dependency-lock" % pluginVersion) +} diff --git a/src/sbt-test/update/warn-differences/test b/src/sbt-test/update/warn-differences/test new file mode 100644 index 0000000..2019427 --- /dev/null +++ b/src/sbt-test/update/warn-differences/test @@ -0,0 +1,2 @@ +> update +> checkLog \ No newline at end of file diff --git a/src/sbt-test/update/warn-same/build.sbt b/src/sbt-test/update/warn-same/build.sbt new file mode 100644 index 0000000..38237b1 --- /dev/null +++ b/src/sbt-test/update/warn-same/build.sbt @@ -0,0 +1,19 @@ +scalaVersion := "2.12.10" + +libraryDependencies ++= Seq( + "org.apache.commons" % "commons-lang3" % "3.9", + "org.scalatest" %% "scalatest" % "3.0.8" % Test, +) + +dependencyLockAutoCheck := DependencyLockUpdateMode.WarnOnError + +val checkLog = taskKey[Unit]("checks the contents of the log") + +checkLog := { + val lastLog = BuiltinCommands.lastLogFile(state.value).get + val last = IO.read(lastLog) + + if (last.contains("Dependency lock file is outdated")) { + sys.error("check contained warning") + } +} \ No newline at end of file diff --git a/src/sbt-test/update/warn-same/build.sbt.lock b/src/sbt-test/update/warn-same/build.sbt.lock new file mode 100644 index 0000000..cae2104 --- /dev/null +++ b/src/sbt-test/update/warn-same/build.sbt.lock @@ -0,0 +1,101 @@ +{ + "lockVersion" : 1, + "timestamp" : "2019-11-21T18:42:01.200Z", + "configurations" : [ + "compile", + "optional", + "provided", + "runtime", + "test" + ], + "dependencies" : [ + { + "org" : "org.apache.commons", + "name" : "commons-lang3", + "version" : "3.9", + "artifacts" : [ + { + "name" : "commons-lang3.jar", + "hash" : "sha1:0122c7cee69b53ed4a7681c03d4ee4c0e2765da5" + } + ], + "configurations" : [ + "test", + "compile", + "runtime" + ] + }, + { + "org" : "org.scala-lang", + "name" : "scala-library", + "version" : "2.12.10", + "artifacts" : [ + { + "name" : "scala-library.jar", + "hash" : "sha1:3509860bc2e5b3da001ed45aca94ffbe5694dbda" + } + ], + "configurations" : [ + "test", + "compile", + "runtime" + ] + }, + { + "org" : "org.scala-lang", + "name" : "scala-reflect", + "version" : "2.12.10", + "artifacts" : [ + { + "name" : "scala-reflect.jar", + "hash" : "sha1:14cb7beb516cd8e07716133668c427792122c926" + } + ], + "configurations" : [ + "test" + ] + }, + { + "org" : "org.scala-lang.modules", + "name" : "scala-xml_2.12", + "version" : "1.2.0", + "artifacts" : [ + { + "name" : "scala-xml_2.12.jar", + "hash" : "sha1:5d38ac30beb8420dd395c0af447ba412158965e6" + } + ], + "configurations" : [ + "test" + ] + }, + { + "org" : "org.scalactic", + "name" : "scalactic_2.12", + "version" : "3.0.8", + "artifacts" : [ + { + "name" : "scalactic_2.12.jar", + "hash" : "sha1:b50559dfc4a691c1089f9c8812e1d6fd17f80277" + } + ], + "configurations" : [ + "test" + ] + }, + { + "org" : "org.scalatest", + "name" : "scalatest_2.12", + "version" : "3.0.8", + "artifacts" : [ + { + "name" : "scalatest_2.12.jar", + "hash" : "sha1:8493ffa579676977b810a7a9fdc23af9d3c8af7f" + } + ], + "configurations" : [ + "test" + ] + } + ] +} \ No newline at end of file diff --git a/src/sbt-test/update/warn-same/project/plugins.sbt b/src/sbt-test/update/warn-same/project/plugins.sbt new file mode 100644 index 0000000..85547d6 --- /dev/null +++ b/src/sbt-test/update/warn-same/project/plugins.sbt @@ -0,0 +1,7 @@ +{ + val pluginVersion = System.getProperty("plugin.version") + if (pluginVersion == null) + throw new RuntimeException("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) + else addSbtPlugin("software.purpledragon" % "sbt-dependency-lock" % pluginVersion) +} diff --git a/src/sbt-test/update/warn-same/test b/src/sbt-test/update/warn-same/test new file mode 100644 index 0000000..e211012 --- /dev/null +++ b/src/sbt-test/update/warn-same/test @@ -0,0 +1,2 @@ +> update +> checkLog