Skip to content

Commit

Permalink
Use SNAPSHOT for release when snapshot version
Browse files Browse the repository at this point in the history
  • Loading branch information
keirlawson committed Jun 6, 2017
1 parent f7e7b08 commit dbe1fa5
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.typesafe.sbt.packager.rpm

import sbt._
import sbt.Keys.{name, packageBin, sourceDirectory, streams, target, version}
import sbt.Keys.{name, packageBin, sourceDirectory, streams, target, version, isSnapshot}
import java.nio.charset.Charset

import com.typesafe.sbt.SbtNativePackager.Linux
Expand Down Expand Up @@ -63,7 +63,7 @@ object RpmPlugin extends AutoPlugin {

override lazy val projectSettings = Seq(
rpmOs := "Linux", // TODO - default to something else?
rpmRelease := "1",
rpmRelease := (if (isSnapshot.value) "SNAPSHOT" else "1"),
rpmPrefix := None,
rpmVendor := "", // TODO - Maybe pull in organization?
rpmLicense := None,
Expand Down Expand Up @@ -105,7 +105,7 @@ object RpmPlugin extends AutoPlugin {
packageArchitecture in Rpm := "noarch",
rpmMetadata := RpmMetadata(
(packageName in Rpm).value,
(version in Rpm).value,
if (isSnapshot.value) stripSnapshot((version in Rpm).value) else (version in Rpm).value,
rpmRelease.value,
rpmPrefix.value,
(packageArchitecture in Rpm).value,
Expand Down Expand Up @@ -163,6 +163,11 @@ object RpmPlugin extends AutoPlugin {
}
}
)

def stripSnapshot(version: String): String = {
val suffixPosition = version.indexOf("-SNAPSHOT")
version.slice(0, suffixPosition)
}
}

object RpmDeployPlugin extends AutoPlugin {
Expand Down
24 changes: 24 additions & 0 deletions src/sbt-test/rpm/snapshot-rpm/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
enablePlugins(RpmPlugin)

name := "rpm-test"

version := "0.1.0-SNAPSHOT"

maintainer := "Keir Lawson <[email protected]>"

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")

TaskKey[Unit]("check-snapshot") := {
assert(rpmRelease.value == "SNAPSHOT", s"RPM has incorrect value ${rpmRelease.value}")
assert(rpmMetadata.value.version == "0.1.0", s"RPM has incorrect value ${rpmMetadata.value.version}")
}

1 change: 1 addition & 0 deletions src/sbt-test/rpm/snapshot-rpm/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))
1 change: 1 addition & 0 deletions src/sbt-test/rpm/snapshot-rpm/src/universal/conf/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Test configuration file!
6 changes: 6 additions & 0 deletions src/sbt-test/rpm/snapshot-rpm/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Run the debian packaging.
> rpm:package-bin
$ exists target/rpm/RPMS/noarch/rpm-test-0.1.0-SNAPSHOT.noarch.rpm

#Check release and version configured correctly
> check-snapshot

0 comments on commit dbe1fa5

Please sign in to comment.