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 67e9a108a..d67f1c2f1 100644 --- a/src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala @@ -96,39 +96,38 @@ object RpmPlugin extends AutoPlugin { rpmDaemonLogFile := s"${(packageName in Linux).value}.log", daemonStdoutLogFile in Rpm := Some((rpmDaemonLogFile).value), // override the linux sourceDirectory setting - sourceDirectory in Rpm <<= sourceDirectory - ) ++ inConfig(Rpm)(Seq( - packageArchitecture := "noarch", - rpmMetadata <<= - (packageName, version, rpmRelease, rpmPrefix, packageArchitecture, rpmVendor, rpmOs, packageSummary, packageDescription, rpmAutoprov, rpmAutoreq) apply RpmMetadata, - rpmDescription <<= - (rpmLicense, rpmDistribution, rpmUrl, rpmGroup, rpmPackager, rpmIcon, rpmChangelogFile) apply RpmDescription, - rpmDependencies <<= - (rpmProvides, rpmRequirements, rpmPrerequisites, rpmObsoletes, rpmConflicts) apply RpmDependencies, - maintainerScripts := { - val scripts = maintainerScripts.value - if (rpmBrpJavaRepackJars.value) { - val pre = scripts.getOrElse(Names.Pre, Nil) - val scriptBits = IO.readStream(RpmPlugin.osPostInstallMacro.openStream, Charset forName "UTF-8") - scripts + (Names.Pre -> (pre :+ scriptBits)) - } else { - scripts - } - }, - rpmScripts := RpmScripts.fromMaintainerScripts(maintainerScripts.value, linuxScriptReplacements.value), - rpmSpecConfig <<= - (rpmMetadata, rpmDescription, rpmDependencies, rpmSetarch, rpmScripts, linuxPackageMappings, linuxPackageSymlinks, defaultLinuxInstallLocation) map RpmSpec, - packageBin <<= (rpmSpecConfig, target, streams) map { (spec, dir, s) => - spec.validate(s.log) - RpmHelper.buildRpm(spec, dir, s.log) - }, - rpmLint <<= (packageBin, streams) map { (rpm, s) => - (Process(Seq("rpmlint", "-v", rpm.getAbsolutePath)) ! s.log) match { - case 0 => () - case x => sys.error("Failed to run rpmlint, exit status: " + x) - } + sourceDirectory in Rpm <<= sourceDirectory, + packageArchitecture in Rpm := "noarch", + rpmMetadata <<= + (packageName in Rpm, version in Rpm, rpmRelease, rpmPrefix, packageArchitecture in Rpm, rpmVendor, rpmOs, packageSummary in Rpm, packageDescription in Rpm, rpmAutoprov, rpmAutoreq) apply RpmMetadata, + rpmDescription <<= + (rpmLicense, rpmDistribution, rpmUrl, rpmGroup, rpmPackager, rpmIcon, rpmChangelogFile) apply RpmDescription, + rpmDependencies <<= + (rpmProvides, rpmRequirements, rpmPrerequisites, rpmObsoletes, rpmConflicts) apply RpmDependencies, + maintainerScripts in Rpm := { + val scripts = (maintainerScripts in Rpm).value + if (rpmBrpJavaRepackJars.value) { + val pre = scripts.getOrElse(Names.Pre, Nil) + val scriptBits = IO.readStream(RpmPlugin.osPostInstallMacro.openStream, Charset forName "UTF-8") + scripts + (Names.Pre -> (pre :+ scriptBits)) + } else { + scripts } - )) + }, + rpmScripts := RpmScripts.fromMaintainerScripts((maintainerScripts in Rpm).value, (linuxScriptReplacements in Rpm).value), + rpmSpecConfig <<= + (rpmMetadata, rpmDescription, rpmDependencies, rpmSetarch, rpmScripts, linuxPackageMappings in Rpm, linuxPackageSymlinks in Rpm, defaultLinuxInstallLocation in Rpm) map RpmSpec, + packageBin in Rpm <<= (rpmSpecConfig, target in Rpm, streams) map { (spec, dir, s) => + spec.validate(s.log) + RpmHelper.buildRpm(spec, dir, s.log) + }, + rpmLint <<= (packageBin in Rpm, streams) map { (rpm, s) => + (Process(Seq("rpmlint", "-v", rpm.getAbsolutePath)) ! s.log) match { + case 0 => () + case x => sys.error("Failed to run rpmlint, exit status: " + x) + } + } + ) } object RpmDeployPlugin extends AutoPlugin { diff --git a/src/sbt-test/rpm/simple-rpm/build.sbt b/src/sbt-test/rpm/simple-rpm/build.sbt index f3f339cac..0d953ef6d 100644 --- a/src/sbt-test/rpm/simple-rpm/build.sbt +++ b/src/sbt-test/rpm/simple-rpm/build.sbt @@ -1,3 +1,5 @@ +import com.typesafe.sbt.packager.linux._ + enablePlugins(RpmPlugin) name := "rpm-test" @@ -19,4 +21,57 @@ rpmUrl := Some("http://github.com/sbt/sbt-native-packager") rpmLicense := Some("BSD") +packageArchitecture in Rpm := "x86_64" + +linuxPackageMappings in Rpm := { + val mapping1 = ((baseDirectory.value / "test"), "tmp/test") + val mapping2 = ((baseDirectory.value / "build.sbt"), "/tmp/build.sbt") + Seq(LinuxPackageMapping(Seq(mapping1, mapping2))) +} + +linuxPackageSymlinks in Rpm := Seq( + LinuxSymlink("/etc/link1", "destination1"), + LinuxSymlink("link2", "destination2") +) + +defaultLinuxInstallLocation in Rpm := "/opt/foo" + +TaskKey[Unit]("unzip") <<= (packageBin in Rpm, streams) map { (rpmFile, streams) => + val rpmPath = Seq(rpmFile.getAbsolutePath) + Process("rpm2cpio" , rpmPath) #| Process("cpio -i --make-directories") ! streams.log +} + +TaskKey[Unit]("checkSpecFile") <<= (target, streams) map { (target, out) => + val spec = IO.read(target / "rpm" / "SPECS" / "rpm-test.spec") + assert(spec contains "Name: rpm-test", "Contains project name") + assert(spec contains "Version: 0.1.0", "Contains project version") + assert(spec contains "Release: 1", "Contains project release") + assert(spec contains "Summary: Test rpm package", "Contains project summary") + assert(spec contains "License: BSD", "Contains project license") + assert(spec contains "Vendor: typesafe", "Contains project vendor") + assert(spec contains "URL: http://github.com/sbt/sbt-native-packager", "Contains project url") + assert(spec contains "BuildArch: x86_64", "Contains project package architecture") + + assert(spec contains + "%description\nA fun package description of our software,\n with multiple lines.", + "Contains project description" + ) + + assert(spec contains + "%files\n%attr(755,root,root) /tmp/test\n%attr(755,root,root) /tmp/build.sbt", + "Contains package mappings" + ) + + assert(spec contains + "ln -s $(relocateLink destination1 /opt/foo/rpm-test rpm-test $RPM_INSTALL_PREFIX) $(relocateLink /etc/link1 /opt/foo/rpm-test rpm-test $RPM_INSTALL_PREFIX)", + "Contains package symlink link (1)" + ) + + assert(spec contains + "ln -s $(relocateLink destination2 /opt/foo/rpm-test rpm-test $RPM_INSTALL_PREFIX) $(relocateLink link2 /opt/foo/rpm-test rpm-test $RPM_INSTALL_PREFIX)", + "Contains package symlink link (2)" + ) + out.log.success("Successfully tested rpm test file") + () +} diff --git a/src/sbt-test/rpm/simple-rpm/test b/src/sbt-test/rpm/simple-rpm/test index dcad9b056..e6620db76 100644 --- a/src/sbt-test/rpm/simple-rpm/test +++ b/src/sbt-test/rpm/simple-rpm/test @@ -1,3 +1,7 @@ # Run the debian packaging. > rpm:package-bin -$ exists target/rpm/RPMS/noarch/rpm-test-0.1.0-1.noarch.rpm +$ exists target/rpm/RPMS/x86_64/rpm-test-0.1.0-1.x86_64.rpm + +> unzip + +> checkSpecFile \ No newline at end of file