Skip to content

Commit

Permalink
Merge pull request #757 from sbt/wip/ivy-configurations
Browse files Browse the repository at this point in the history
FIX #676 adding configuration scopes to project configurations
  • Loading branch information
muuki88 committed Mar 28, 2016
2 parents 5bd92bd + 8a82e40 commit 66dd482
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ object JavaServerAppPackaging extends AutoPlugin {
sourceDirectory.value,
serverLoading.value),
makeEtcDefault := makeEtcDefaultScript(
(packageName in Linux).value,
packageName.value,
(target in Universal).value,
linuxEtcDefaultTemplate.value,
linuxScriptReplacements.value),
Expand Down
58 changes: 32 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 All @@ -85,6 +87,7 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {
debianSignRole := "builder",
target in Debian <<= (target, name in Debian, version in Debian) apply ((t, n, v) => t / (n + "-" + v)),
name in Debian <<= (name in Linux),
// TODO maybe we can remove this, with the projectConfigurations
maintainerScripts in Debian <<= (maintainerScripts in Linux),
packageName in Debian <<= (packageName in Linux),
executableScriptName in Debian <<= (executableScriptName in Linux),
Expand All @@ -94,6 +97,9 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {
packageSummary in Debian <<= packageSummary in Linux,
maintainer in Debian <<= maintainer in Linux,

// override the linux sourceDirectory setting
sourceDirectory in Debian <<= sourceDirectory,

/* ==== Debian configuration settings ==== */
debianControlScriptsDirectory <<= (sourceDirectory) apply (_ / "debian" / Names.DebianMaintainerScripts),
debianMaintainerScripts := Seq.empty,
Expand All @@ -107,36 +113,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 +151,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 +188,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 +208,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 +225,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 +250,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 +287,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 +356,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
20 changes: 12 additions & 8 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 @@ -95,7 +97,9 @@ object RpmPlugin extends AutoPlugin {
name in Rpm <<= name in Linux,
packageName in Rpm <<= packageName in Linux,
executableScriptName in Rpm <<= executableScriptName in Linux,
rpmDaemonLogFile := s"${(packageName in Linux).value}.log"
rpmDaemonLogFile := s"${(packageName in Linux).value}.log",
// override the linux sourceDirectory setting
sourceDirectory in Rpm <<= sourceDirectory
) ++ inConfig(Rpm)(Seq(
packageArchitecture := "noarch",
rpmMetadata <<=
Expand All @@ -105,14 +109,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
1 change: 1 addition & 0 deletions test-project-simple/src/templates/etc-default-template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# right etc-default template
2 changes: 0 additions & 2 deletions test-project-simple/src/templates/etc-default.bak

This file was deleted.

0 comments on commit 66dd482

Please sign in to comment.