Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce RPM / packageBin / artifactPath setting. #1299

Merged
merged 7 commits into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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