Skip to content

Commit

Permalink
Introduce RPM / packageBin / artifactPath setting. (#1299)
Browse files Browse the repository at this point in the history
* Introduce RPM / packageBin / artifactPath setting. Closes #1287

* Fix setting cannot depend on a task.

* Proper fix.

* Now without breaking mima.

* Add a little bit of documentation. And a sbt-test.

* Fix test

Co-authored-by: Nepomuk Seiler <muuki88@users.noreply.github.com>
  • Loading branch information
Lasering and muuki88 committed Jan 30, 2020
1 parent 30b5366 commit 42f17fb
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/main/scala/com/typesafe/sbt/packager/rpm/RpmHelper.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.typesafe.sbt.packager.rpm

import sbt._
import com.typesafe.sbt.packager.Compat._
import com.typesafe.sbt.packager.linux.LinuxSymlink

object RpmHelper {
Expand All @@ -26,6 +25,9 @@ object RpmHelper {
workArea
}

private[rpm] def defaultRpmArtifactPath(stagingArea: File, meta: RpmMetadata): File =
stagingArea / "RPMS" / meta.arch / s"${meta.name}-${meta.version}-${meta.release}.${meta.arch}.rpm"

/**
* Build the rpm package
*
Expand All @@ -36,9 +38,7 @@ object RpmHelper {
*/
def buildRpm(spec: RpmSpec, stagingArea: File, log: sbt.Logger): File = {
buildPackage(stagingArea, spec, log)
// We should probably return the File that was created.
val rpmname = "%s-%s-%s.%s.rpm" format (spec.meta.name, spec.meta.version, spec.meta.release, spec.meta.arch)
stagingArea / "RPMS" / spec.meta.arch / rpmname
defaultRpmArtifactPath(stagingArea, spec.meta)
}

private[this] def copyFiles(spec: RpmSpec, workArea: File, log: sbt.Logger): Unit = {
Expand Down
10 changes: 9 additions & 1 deletion src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,15 @@ object RpmPlugin extends AutoPlugin {
(defaultLinuxInstallLocation in Rpm).value
),
stage in Rpm := RpmHelper.stage(rpmSpecConfig.value, (target in Rpm).value, streams.value.log),
packageBin in Rpm := RpmHelper.buildRpm(rpmSpecConfig.value, (stage in Rpm).value, streams.value.log),
artifactPath in (Rpm, packageBin) := RpmHelper.defaultRpmArtifactPath((target in Rpm).value, rpmMetadata.value),
packageBin in Rpm := {
val defaultPath = RpmHelper.buildRpm(rpmSpecConfig.value, (stage in Rpm).value, streams.value.log)
// `file` points to where buildRpm created the rpm. However we want it to be at `artifactPath`.
// If `artifactPath` is not the default value then we need to copy the file.
val path = (artifactPath in (Rpm, packageBin)).value
if (path.getCanonicalFile != defaultPath.getCanonicalFile) IO.copyFile(defaultPath, path)
path
},
rpmLint := {
sys.process.Process(Seq("rpmlint", "-v", (packageBin in Rpm).value.getAbsolutePath)) ! streams.value.log match {
case 0 => ()
Expand Down
45 changes: 45 additions & 0 deletions src/sbt-test/rpm/test-artifactPath/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
enablePlugins(JavaServerAppPackaging, SystemVPlugin)

name := "rpm-test"

version := "0.1.0"

maintainer := "Josh Suereth <joshua.suereth@typesafe.com>"

packageSummary := "Test rpm package"

packageName in Linux := "rpm-package"

artifactPath in (Rpm, packageBin) := target.value / s"${(packageName in Rpm).value}-${(version in Rpm).value}.rpm"

packageDescription := """A fun package description of our software,
with multiple lines."""

rpmRelease := "1"

rpmVendor := "typesafe"

rpmUrl := Some("http://github.com/sbt/sbt-native-packager")

rpmLicense := Some("BSD")

TaskKey[Unit]("checkSpecFile") := {
val spec = IO.read(target.value / "rpm" / "SPECS" / "rpm-package.spec")
streams.value.log.success(spec)
assert(
spec contains "%attr(0644,root,root) /usr/share/rpm-package/lib/rpm-test.rpm-test-0.1.0.jar",
"Wrong installation path\n" + spec
)
assert(spec contains "%attr(0755,root,root) /etc/init.d/rpm-package", "Wrong /etc/init.d path\n" + spec)
assert(spec contains "%config %attr(644,root,root) /etc/default/rpm-package", "Wrong /etc default file\n" + spec)
assert(
spec contains "%dir %attr(755,rpm-package,rpm-package) /var/log/rpm-package",
"Wrong logging dir path\n" + spec
)
assert(
spec contains "%dir %attr(755,rpm-package,rpm-package) /var/run/rpm-package",
"Wrong /var/run dir path\n" + spec
)
streams.value.log.success("Successfully tested rpm-package file")
()
}
1 change: 1 addition & 0 deletions src/sbt-test/rpm/test-artifactPath/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"))
8 changes: 8 additions & 0 deletions src/sbt-test/rpm/test-artifactPath/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Run the debian packaging.
> rpm:packageBin
$ exists target/rpm-package-0.1.0.rpm
$ exists target/rpm/RPMS/noarch/rpm-package-0.1.0-1.noarch.rpm
$ exists target/rpm/SPECS/rpm-package.spec

# Check files for defaults
> checkSpecFile
3 changes: 3 additions & 0 deletions src/sphinx/formats/rpm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ Informational Settings
used, and in the event of a tie it will fall back to comparing the version and
release.

``artifactPath in (Rpm, packageBin)``
The location of the generated RPM.

Dependency Settings
~~~~~~~~~~~~~~~~~~~

Expand Down

0 comments on commit 42f17fb

Please sign in to comment.