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

Debian scripts are now picked up from default folder #35 #57

Merged
merged 4 commits into from
Oct 31, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 16 additions & 16 deletions src/main/scala/com/typesafe/sbt/packager/debian/DebianPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import linux.LinuxSymlink
import linux.LinuxFileMetaData
import com.typesafe.sbt.packager.Hashing
import com.typesafe.sbt.packager.linux.LinuxSymlink
import java.io.{ File => JFile }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to do this. sbt.File == java.io.File.

It's done like so:

package object sbt {
  type File = java.io.File
}


trait DebianPlugin extends Plugin with linux.LinuxPlugin {
val Debian = config("debian") extend Linux
Expand All @@ -30,6 +31,15 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin {
// TODO - Can we do anything about user/group ownership?
}

private[this] def scriptMapping(scriptName: String)(script: Option[JFile], controlDir: JFile): Seq[(File, String)] = {
(script, controlDir) match {
case (Some(script), _) => Seq(script -> scriptName)
case (None, dir) =>
val script = dir / scriptName
if (script exists) Seq(file(script getAbsolutePath) -> scriptName) else Seq.empty
}
}

def debianSettings: Seq[Setting[_]] = Seq(
debianPriority := "optional",
debianSection := "java",
Expand All @@ -43,28 +53,18 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin {
packageDescription in Debian <<= packageDescription in Linux,
packageSummary in Debian <<= packageSummary in Linux,
maintainer in Debian <<= maintainer in Linux,
debianControlScriptsDirectory := (sourceDirectory.value / "debian" / "DEBIAN"),
debianMaintainerScripts := Seq.empty,
debianMakePreinstScript := None,
debianMakePrermScript := None,
debianMakePostinstScript := None,
debianMakePostrmScript := None,

// TODO - We should make sure there isn't one already specified...
debianMaintainerScripts <++= debianMakePreinstScript map {
case Some(script) => Seq(script -> "preinst")
case None => Seq.empty
},
debianMaintainerScripts <++= debianMakePrermScript map {
case Some(script) => Seq(script -> "prerm")
case None => Seq.empty
},
debianMaintainerScripts <++= debianMakePostinstScript map {
case Some(script) => Seq(script -> "postinst")
case None => Seq.empty
},
debianMaintainerScripts <++= debianMakePostrmScript map {
case Some(script) => Seq(script -> "postrm")
case None => Seq.empty
}) ++ inConfig(Debian)(Seq(
debianMaintainerScripts <++= (debianMakePrermScript, debianControlScriptsDirectory) map scriptMapping("prerm"),
debianMaintainerScripts <++= (debianMakePreinstScript, debianControlScriptsDirectory) map scriptMapping("preinst"),
debianMaintainerScripts <++= (debianMakePostinstScript, debianControlScriptsDirectory) map scriptMapping("postinst"),
debianMaintainerScripts <++= (debianMakePostrmScript, debianControlScriptsDirectory) map scriptMapping("postrm")) ++ inConfig(Debian)(Seq(
packageArchitecture := "all",
debianPackageInfo <<=
(name, version, maintainer, packageSummary, packageDescription) apply PackageInfo,
Expand Down
6 changes: 5 additions & 1 deletion src/main/scala/com/typesafe/sbt/packager/debian/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ trait DebianKeys {
val debianSign = TaskKey[File]("debian-sign", "runs the dpkg-sig command to sign the generated deb file.")
val debianSignRole = SettingKey[String]("debian-sign-role", "The role to use when signing a debian file (defaults to 'builder').")

val debianControlScriptsDirectory = SettingKey[File]("""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a bug here. YOu probably want the triple " to be the second argument....

val debianControlScriptsDirectory = SettingKey[File]("debian-control-scripts-directory",
  """Directory where all debian control scripts reside.
      Default is 'src/debian/DEBIAN'""".stripMargin)

debian-control-scripts-directory", "Directory where all debian control scripts reside.
Default is 'src/debian/DEBIAN'
""".stripMargin)
val debianMakePreinstScript = TaskKey[Option[File]]("makePreinstScript", "Creates or discovers the preinst script used by this project")
val debianMakePrermScript = TaskKey[Option[File]]("makePrermScript", "Creates or discovers the prerm script used by this project")
val debianMakePostinstScript = TaskKey[Option[File]]("makePostInstScript", "Creates or discovers the postinst script used by this project")
Expand All @@ -45,7 +49,7 @@ trait DebianKeys {
""".stripMargin)
}

/** Keys used for RPM specific settings. */
/** Keys used for Debian specific settings. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch :) Can you tell I copy-paste a lot?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure that xD

object Keys extends DebianKeys {
// Metadata keys
def name = sbt.Keys.name
Expand Down
3 changes: 3 additions & 0 deletions test-project/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ debianPackageDependencies in Debian ++= Seq("java2-runtime", "bash (>= 2.05a-11)

debianPackageRecommends in Debian += "git"

//debianMakePrermScript := Some(sourceDirectory.value / "deb" / "control" / "prerm") //change defaults


TaskKey[Unit]("check-script") <<= (NativePackagerKeys.stagingDirectory in Universal, name, streams) map { (dir, name, streams) =>
val script = dir / "bin" / name
Expand All @@ -45,3 +47,4 @@ TaskKey[Unit]("check-script") <<= (NativePackagerKeys.stagingDirectory in Univer
val expected = "SUCCESS!"
assert(output contains expected, "Failed to correctly run the main script!. Found ["+output+"] wanted ["+expected+"]")
}

1 change: 1 addition & 0 deletions test-project/src/debian/DEBIAN/preinst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo "installing ${name}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm... wish we could somehow actually install in the integration test.... probably can't but thanks for creating this :)

1 change: 1 addition & 0 deletions test-project/src/debian/DEBIAN/prerm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo "prepare remove of ${name}"