From 1fa500d30170aad497575fab2285341c26d80319 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Tue, 30 Jun 2020 20:59:27 +0100 Subject: [PATCH] Fix tagPrefix/vTagPrefix coherence I thought I'd gotten the defaults right with the coherence checking, but I never wrote a test for it so, inevitably, it wasn't.. Fixed by not giving `dynverTagPrefix` a default value so it's possible to tell if a user set it or not. Now this sets the tagPrefix to "" if vTagPrefix was set to false. If both keys are set, to incoherent values, it will throw. --- project/plugins.sbt | 2 +- src/main/scala/sbtdynver/DynVerPlugin.scala | 5 ++--- src/sbt-test/dynver/no-v-tag-prefix/build.sbt | 1 + src/sbt-test/dynver/no-v-tag-prefix/project/plugins.sbt | 5 +++++ src/sbt-test/dynver/no-v-tag-prefix/test | 1 + 5 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 src/sbt-test/dynver/no-v-tag-prefix/build.sbt create mode 100644 src/sbt-test/dynver/no-v-tag-prefix/project/plugins.sbt create mode 100644 src/sbt-test/dynver/no-v-tag-prefix/test diff --git a/project/plugins.sbt b/project/plugins.sbt index 4f04499..1e5ee74 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,3 +1,3 @@ -addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.0.0") +addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.0") addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.7.0") addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.6") diff --git a/src/main/scala/sbtdynver/DynVerPlugin.scala b/src/main/scala/sbtdynver/DynVerPlugin.scala index cb920c9..a8769ad 100644 --- a/src/main/scala/sbtdynver/DynVerPlugin.scala +++ b/src/main/scala/sbtdynver/DynVerPlugin.scala @@ -55,8 +55,8 @@ object DynVerPlugin extends AutoPlugin { previousStableVersion := dynverGitPreviousStableVersion.value.previousVersion, dynverInstance := { - val tagPrefix = dynverTagPrefix.value val vTagPrefix = dynverVTagPrefix.value + val tagPrefix = dynverTagPrefix.?.value.getOrElse(if (vTagPrefix) "v" else "") assert(vTagPrefix ^ tagPrefix != "v", s"Incoherence: dynverTagPrefix=$tagPrefix vs dynverVTagPrefix=$vTagPrefix") DynVer(Some(buildBase.value), dynverSeparator.value, tagPrefix) }, @@ -66,8 +66,7 @@ object DynVerPlugin extends AutoPlugin { dynverSonatypeSnapshots := false, dynverGitPreviousStableVersion := dynverInstance.value.getGitPreviousStableTag, dynverSeparator := DynVer.separator, - dynverTagPrefix := DynVer.tagPrefix, - dynverVTagPrefix := dynverTagPrefix.value == "v", + dynverVTagPrefix := dynverTagPrefix.??(DynVer.tagPrefix).value == "v", dynver := { val dynver = dynverInstance.value diff --git a/src/sbt-test/dynver/no-v-tag-prefix/build.sbt b/src/sbt-test/dynver/no-v-tag-prefix/build.sbt new file mode 100644 index 0000000..3159fa2 --- /dev/null +++ b/src/sbt-test/dynver/no-v-tag-prefix/build.sbt @@ -0,0 +1 @@ +dynverVTagPrefix in ThisBuild := false diff --git a/src/sbt-test/dynver/no-v-tag-prefix/project/plugins.sbt b/src/sbt-test/dynver/no-v-tag-prefix/project/plugins.sbt new file mode 100644 index 0000000..66ad543 --- /dev/null +++ b/src/sbt-test/dynver/no-v-tag-prefix/project/plugins.sbt @@ -0,0 +1,5 @@ +sys.props.get("plugin.version") match { + case Some(x) => addSbtPlugin("com.dwijnand" % "sbt-dynver" % x) + case _ => sys.error("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) +} diff --git a/src/sbt-test/dynver/no-v-tag-prefix/test b/src/sbt-test/dynver/no-v-tag-prefix/test new file mode 100644 index 0000000..4e3db81 --- /dev/null +++ b/src/sbt-test/dynver/no-v-tag-prefix/test @@ -0,0 +1 @@ +> about