From b2586c60f56196a0528d8f02de18dfffe04a6373 Mon Sep 17 00:00:00 2001 From: colin-passiv Date: Thu, 29 Jun 2017 15:36:39 +0100 Subject: [PATCH] strip snapshot suffix safely (#1004) --- .../typesafe/sbt/packager/rpm/RpmPlugin.scala | 7 +---- .../rpm/snapshot-override-rpm/build.sbt | 26 +++++++++++++++++++ .../snapshot-override-rpm/project/plugins.sbt | 1 + .../src/universal/conf/test | 1 + src/sbt-test/rpm/snapshot-override-rpm/test | 6 +++++ 5 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 src/sbt-test/rpm/snapshot-override-rpm/build.sbt create mode 100644 src/sbt-test/rpm/snapshot-override-rpm/project/plugins.sbt create mode 100644 src/sbt-test/rpm/snapshot-override-rpm/src/universal/conf/test create mode 100644 src/sbt-test/rpm/snapshot-override-rpm/test diff --git a/src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala index 0e2d3051a..21d233530 100644 --- a/src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala @@ -105,7 +105,7 @@ object RpmPlugin extends AutoPlugin { packageArchitecture in Rpm := "noarch", rpmMetadata := RpmMetadata( (packageName in Rpm).value, - if (isSnapshot.value) stripSnapshot((version in Rpm).value) else (version in Rpm).value, + (version in Rpm).value.stripSuffix("-SNAPSHOT"), rpmRelease.value, rpmPrefix.value, (packageArchitecture in Rpm).value, @@ -163,11 +163,6 @@ object RpmPlugin extends AutoPlugin { } } ) - - def stripSnapshot(version: String): String = { - val suffixPosition = version.indexOf("-SNAPSHOT") - version.slice(0, suffixPosition) - } } object RpmDeployPlugin extends AutoPlugin { diff --git a/src/sbt-test/rpm/snapshot-override-rpm/build.sbt b/src/sbt-test/rpm/snapshot-override-rpm/build.sbt new file mode 100644 index 000000000..9eed1209e --- /dev/null +++ b/src/sbt-test/rpm/snapshot-override-rpm/build.sbt @@ -0,0 +1,26 @@ +enablePlugins(RpmPlugin) + +name := "rpm-test" + +version := "0.1.0-SNAPSHOT" + +maintainer := "Keir Lawson " + +packageSummary := "Snapshot test rpm package" + +packageDescription := """A fun package description of our software, + with multiple lines.""" + +rpmVendor := "typesafe" + +rpmUrl := Some("http://github.com/sbt/sbt-native-packager") + +rpmLicense := Some("BSD") + +version in Rpm := "1" + +TaskKey[Unit]("check-snapshot") := { + assert(rpmRelease.value == "SNAPSHOT", s"RPM has incorrect value ${rpmRelease.value}") + assert(rpmMetadata.value.version == "1", s"RPM has incorrect value ${rpmMetadata.value.version}") + assert((version in Rpm).value == "1", s"RPM has incorrect value ${(version in Rpm).value}") +} diff --git a/src/sbt-test/rpm/snapshot-override-rpm/project/plugins.sbt b/src/sbt-test/rpm/snapshot-override-rpm/project/plugins.sbt new file mode 100644 index 000000000..b53de154c --- /dev/null +++ b/src/sbt-test/rpm/snapshot-override-rpm/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version")) diff --git a/src/sbt-test/rpm/snapshot-override-rpm/src/universal/conf/test b/src/sbt-test/rpm/snapshot-override-rpm/src/universal/conf/test new file mode 100644 index 000000000..92e38dfb2 --- /dev/null +++ b/src/sbt-test/rpm/snapshot-override-rpm/src/universal/conf/test @@ -0,0 +1 @@ +# Test configuration file! diff --git a/src/sbt-test/rpm/snapshot-override-rpm/test b/src/sbt-test/rpm/snapshot-override-rpm/test new file mode 100644 index 000000000..dbd83ee21 --- /dev/null +++ b/src/sbt-test/rpm/snapshot-override-rpm/test @@ -0,0 +1,6 @@ +# Run the debian packaging. +> rpm:package-bin +$ exists target/rpm/RPMS/noarch/rpm-test-1-SNAPSHOT.noarch.rpm + +#Check release and version configured correctly +> check-snapshot