Skip to content

Commit

Permalink
FIX #676 adding configuration scopes to project configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
muuki88 committed Mar 20, 2016
1 parent 1fb9724 commit d55169e
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 33 deletions.
54 changes: 28 additions & 26 deletions src/main/scala/com/typesafe/sbt/packager/debian/DebianPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {

val CHOWN_REPLACEMENT = "chown-paths"

override def projectConfigurations: Seq[Configuration] = Seq(Debian)

// TODO maybe we can put settings/debiansettings together
/**
* Enables native packaging by default
Expand Down Expand Up @@ -107,36 +109,36 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {
maintainerScripts in Debian := {
val replacements = (linuxScriptReplacements in Debian).value
val scripts = Map(
Names.Prerm -> defaultMaintainerScript(Names.Prerm).toSeq.flatten,
Names.Preinst -> defaultMaintainerScript(Names.Preinst).toSeq.flatten,
Names.Postinst -> defaultMaintainerScript(Names.Postinst).toSeq.flatten,
Names.Postrm -> defaultMaintainerScript(Names.Postrm).toSeq.flatten
Names.Prerm -> defaultMaintainerScript(Names.Prerm).toSeq.flatten,
Names.Preinst -> defaultMaintainerScript(Names.Preinst).toSeq.flatten,
Names.Postinst -> defaultMaintainerScript(Names.Postinst).toSeq.flatten,
Names.Postrm -> defaultMaintainerScript(Names.Postrm).toSeq.flatten
)

// this is for legacy purposes to keep old behaviour
// --- legacy starts
def readContent(scriptFiles: Seq[(File, String)]): Map[String, Seq[String]] = scriptFiles.map {
case (scriptFile, scriptName) => scriptName -> IO.readLines(scriptFile)
case (scriptFile, scriptName) => scriptName -> IO.readLines(scriptFile)
}.toMap

val userProvided = readContent(Seq(
debianMakePreinstScript.value.map(script => script -> Names.Preinst),
debianMakePostinstScript.value.map(script => script -> Names.Postinst),
debianMakePrermScript.value.map(script => script -> Names.Prerm),
debianMakePostrmScript.value.map(script => script -> Names.Postrm)
debianMakePreinstScript.value.map(script => script -> Names.Preinst),
debianMakePostinstScript.value.map(script => script -> Names.Postinst),
debianMakePrermScript.value.map(script => script -> Names.Prerm),
debianMakePostrmScript.value.map(script => script -> Names.Postrm)
).flatten)

// these things get appended. Don't check for nonexisting keys as they are already in the default scripts map
val appendedScripts = scripts.map {
case (scriptName, content) => scriptName -> (content ++ userProvided.getOrElse(scriptName, Nil))
case (scriptName, content) => scriptName -> (content ++ userProvided.getOrElse(scriptName, Nil))
}
// override and merge with the user defined scripts. Will change in the future
val controlScriptsDir = debianControlScriptsDirectory.value
val overridenScripts = scripts ++ readContent(Seq(
scriptMapping(Names.Prerm, debianMakePrermScript.value, controlScriptsDir),
scriptMapping(Names.Preinst, debianMakePreinstScript.value, controlScriptsDir),
scriptMapping(Names.Postinst, debianMakePostinstScript.value, controlScriptsDir),
scriptMapping(Names.Postrm, debianMakePostrmScript.value, controlScriptsDir)
scriptMapping(Names.Prerm, debianMakePrermScript.value, controlScriptsDir),
scriptMapping(Names.Preinst, debianMakePreinstScript.value, controlScriptsDir),
scriptMapping(Names.Postinst, debianMakePostinstScript.value, controlScriptsDir),
scriptMapping(Names.Postrm, debianMakePostrmScript.value, controlScriptsDir)
).flatten)
// --- legacy ends

Expand All @@ -145,7 +147,7 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {

// apply all replacements
content.mapValues { lines =>
TemplateWriter.generateScriptFromLines(lines, replacements)
TemplateWriter.generateScriptFromLines(lines, replacements)
}
},
debianMaintainerScripts := generateDebianMaintainerScripts(
Expand Down Expand Up @@ -182,14 +184,14 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {
packageDescription in Debian := "My package Description""""
)
}
val cfile = dir / Names.DebianMaintainerScripts / Names.Control
val cfile = dir / Names.DebianMaintainerScripts / Names.Control
IO.write(cfile, data.makeContent(size), java.nio.charset.Charset.defaultCharset)
chmod(cfile, "0644")
cfile
},
debianConffilesFile <<= (linuxPackageMappings, target) map {
(mappings, dir) =>
val cfile = dir / Names.DebianMaintainerScripts / Names.Conffiles
val cfile = dir / Names.DebianMaintainerScripts / Names.Conffiles
val conffiles = for {
LinuxPackageMapping(files, meta, _) <- mappings
if meta.config != "false"
Expand All @@ -202,11 +204,11 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {
},
debianMD5sumsFile <<= (debianExplodedPackage, target) map {
(mappings, dir) =>
val md5file = dir / Names.DebianMaintainerScripts / "md5sums"
val md5file = dir / Names.DebianMaintainerScripts / "md5sums"
val md5sums = for {
(file, name) <- (dir.*** --- dir pair relativeTo(dir))
if file.isFile
if !(name startsWith Names.DebianMaintainerScripts)
if !(name startsWith Names.DebianMaintainerScripts)
if !(name contains "debian-binary")
// TODO - detect symlinks with Java7 (when we can) rather than hackery...
if file.getCanonicalPath == file.getAbsolutePath
Expand All @@ -219,7 +221,7 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {
debianMakeChownReplacements <<= (linuxPackageMappings, streams) map makeChownReplacements,
debianExplodedPackage <<= (linuxPackageMappings, debianControlFile, debianMaintainerScripts, debianConffilesFile, debianChangelog,
linuxScriptReplacements, debianMakeChownReplacements, linuxPackageSymlinks, target, streams)
map { (mappings, _, maintScripts, _, changelog, replacements, chown, symlinks, t, streams) =>
map { (mappings, _, maintScripts, _, changelog, replacements, chown, symlinks, t, streams) =>

// Create files and directories
mappings foreach {
Expand All @@ -244,7 +246,7 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {
// Put the maintainer files in `dir / "DEBIAN"` named as specified.
// Valid values for the name are preinst,postinst,prerm,postrm
for ((file, name) <- maintScripts) {
val targetFile = t / Names.DebianMaintainerScripts / name
val targetFile = t / Names.DebianMaintainerScripts / name
copyAndFixPerms(file, targetFile, LinuxFileMetaData())
filterAndFixPerms(targetFile, chown +: replacements, LinuxFileMetaData())
}
Expand Down Expand Up @@ -281,10 +283,10 @@ trait DebianPluginLike {

scripts.map {
case (scriptName, content) =>
val scriptBits = TemplateWriter.generateScriptFromLines(content, replacements)
val script = tmpDir / "tmp" / "debian" / scriptName
IO.write(script, scriptBits mkString "\n")
script -> scriptName
val scriptBits = TemplateWriter.generateScriptFromLines(content, replacements)
val script = tmpDir / "tmp" / "debian" / scriptName
IO.write(script, scriptBits mkString "\n")
script -> scriptName
}.toList
}

Expand Down Expand Up @@ -350,7 +352,7 @@ trait DebianPluginLike {
(script, controlDir) match {
// check if user defined script exists
case (_, dir) if (dir / scriptName).exists =>
Some(file((dir / scriptName).getAbsolutePath) -> scriptName)
Some(file((dir / scriptName).getAbsolutePath) -> scriptName)
// create mappings for generated script
case (scr, _) => scr.map(_ -> scriptName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ object DockerPlugin extends AutoPlugin {

override def requires = universal.UniversalPlugin

override def projectConfigurations: Seq[Configuration] = Seq(Docker)

override lazy val projectSettings = Seq(
dockerBaseImage := "java:latest",
dockerExposedPorts := Seq(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ object JDKPackagerPlugin extends AutoPlugin {
override def requires = JavaAppPackaging && LauncherJarPlugin
private val dirname = JDKPackager.name.toLowerCase

override def projectConfigurations: Seq[Configuration] = Seq(JDKPackager)

override lazy val projectSettings = Seq(
jdkAppIcon := None,
jdkPackagerType := "installer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ object LinuxPlugin extends AutoPlugin {

import autoImport._

override def projectConfigurations: Seq[Configuration] = Seq(Linux)

/** default users available for */
object Users {
val Root = "root"
Expand Down
16 changes: 9 additions & 7 deletions src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ object RpmPlugin extends AutoPlugin {

}

override def projectConfigurations: Seq[Configuration] = Seq(Rpm)

override lazy val projectSettings = Seq(
rpmOs := "Linux", // TODO - default to something else?
rpmRelease := "1",
Expand Down Expand Up @@ -105,14 +107,14 @@ object RpmPlugin extends AutoPlugin {
rpmDependencies <<=
(rpmProvides, rpmRequirements, rpmPrerequisites, rpmObsoletes, rpmConflicts) apply RpmDependencies,
maintainerScripts := {
val scripts = maintainerScripts.value
if (rpmBrpJavaRepackJars.value) {
val pre = scripts.getOrElse(Names.Pre, Nil)
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
}
scripts + (Names.Pre -> (pre :+ scriptBits))
} else {
scripts
}
},
rpmScripts := RpmScripts.fromMaintainerScripts(maintainerScripts.value),
rpmSpecConfig <<=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ object UniversalPlugin extends AutoPlugin {

override def requires = SbtNativePackager

override def projectConfigurations: Seq[Configuration] = Seq(Universal, UniversalDocs, UniversalSrc)

/** The basic settings for the various packaging types. */
override lazy val projectSettings = Seq[Setting[_]](
// For now, we provide delegates from dist/stage to universal...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ object WindowsPlugin extends AutoPlugin {
override lazy val projectSettings = windowsSettings ++ mapGenericFilesToWindows
override def requires = universal.UniversalPlugin

override def projectConfigurations: Seq[Configuration] = Seq(Windows)

/**
* default windows settings
*/
Expand Down

0 comments on commit d55169e

Please sign in to comment.