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

Better Entrypoint Support #411

Merged
merged 3 commits into from
Nov 26, 2014
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
15 changes: 10 additions & 5 deletions src/main/scala/com/typesafe/sbt/packager/SettingsHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,24 @@ object SettingsHelper {
deliverLocalConfiguration <<= (crossTarget, ivyLoggingLevel) map { (outDir, level) => Classpaths.deliverConfig(outDir, logging = level) },
deliverConfiguration <<= deliverLocalConfiguration,
publishConfiguration <<= (packagedArtifacts, checksums, publishTo, isSnapshot) map { (as, checks, publishTo, isSnap) =>
new PublishConfiguration(ivyFile = None,
new PublishConfiguration(
ivyFile = None,
resolverName = Classpaths.getPublishTo(publishTo).name,
artifacts = as,
checksums = checks,
logging = UpdateLogging.DownloadOnly,
overwrite = isSnap)
overwrite = isSnap
)
},
publishLocalConfiguration <<= (packagedArtifacts, checksums, isSnapshot) map { (as, checks, isSnap) =>
new PublishConfiguration(ivyFile = None,
new PublishConfiguration(
ivyFile = None,
resolverName = "local",
artifacts = as,
checksums = checks,
logging = UpdateLogging.DownloadOnly,
overwrite = isSnap)
})) ++ addPackage(config, packageTask, extension)
overwrite = isSnap
)
}
)) ++ addPackage(config, packageTask, extension)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import sbt._
import sbt.Keys.{ mappings, target, name, mainClass, sourceDirectory }
import packager.Keys.{ packageName, executableScriptName }
import linux.{ LinuxFileMetaData, LinuxPackageMapping }
import linux.LinuxPlugin.autoImport.{linuxPackageMappings, defaultLinuxInstallLocation}
import linux.LinuxPlugin.autoImport.{ linuxPackageMappings, defaultLinuxInstallLocation }
import SbtNativePackager.{ Universal, Debian }

/**
Expand Down Expand Up @@ -39,7 +39,7 @@ object JavaAppPackaging extends AutoPlugin with JavaAppStartScript {
*/
val batTemplate = "bat-template"

object autoImport extends JavaAppKeys
object autoImport extends JavaAppKeys

import JavaAppPackaging.autoImport._

Expand Down Expand Up @@ -95,7 +95,8 @@ object JavaAppPackaging extends AutoPlugin with JavaAppStartScript {
val d = target / installLocation
d.mkdirs()
LinuxPackageMapping(Seq(d -> (installLocation + "/" + name)), LinuxFileMetaData())
})
}
)

private def makeRelativeClasspathNames(mappings: Seq[(File, String)]): Seq[String] =
for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ object JavaAppBashScript {
mainClass: String,
appClasspath: Seq[String] = Seq("*"),
configFile: Option[String] = None,
extras: Seq[String] = Nil): Seq[String] =
extras: Seq[String] = Nil
): Seq[String] =
Seq(mainClassDefine(mainClass)) ++
(configFile map configFileDefine).toSeq ++
Seq(makeClasspathDefine(appClasspath)) ++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ object JavaAppBatScript {
name: String,
mainClass: String,
appClasspath: Seq[String] = Seq("*"),
extras: Seq[String] = Nil): Seq[(String, String)] = {
extras: Seq[String] = Nil
): Seq[(String, String)] = {
val replacements = Seq(
"APP_NAME" -> name,
"APP_ENV_NAME" -> makeEnvFriendlyName(name)
Expand All @@ -50,7 +51,8 @@ object JavaAppBatScript {
}

def generateScript(
replacements: Seq[(String, String)], template: java.net.URL = bashTemplateSource): String =
replacements: Seq[(String, String)], template: java.net.URL = bashTemplateSource
): String =
TemplateWriter.generateScript(template, replacements, "\r\n", TemplateWriter.batFriendlyKeySurround)

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ trait JavaAppKeys {
val projectDependencyArtifacts = TaskKey[Seq[Attributed[File]]]("projectDependencyArtifacts", "The set of exported artifacts from our dependent projects.")
val scriptClasspath = TaskKey[Seq[String]]("scriptClasspath", "A list of relative filenames (to the lib/ folder in the distribution) of what to include on the classpath.")
val makeBatScript = TaskKey[Option[File]]("makeBatScript", "Creates or discovers the bat script used by this project.")
val batScriptReplacements = TaskKey[Seq[(String, String)]]("batScriptReplacements",
val batScriptReplacements = TaskKey[Seq[(String, String)]](
"batScriptReplacements",
"""|Replacements of template parameters used in the windows bat script.
| Default supported templates:
| APP_ENV_NAME - the name of the application for defining <name>_HOME variables
| APP_NAME - the name of the app
| APP_DEFINES - the defines to go into the app
| """.stripMargin)
| """.stripMargin
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ object JavaServerAppPackaging extends AutoPlugin {
debianMakePreinstScript <<= (target in Universal, serverLoading in Debian, linuxScriptReplacements) map makeMaintainerScript(Preinst),
debianMakePostinstScript <<= (target in Universal, serverLoading in Debian, linuxScriptReplacements) map makeMaintainerScript(Postinst),
debianMakePrermScript <<= (target in Universal, serverLoading in Debian, linuxScriptReplacements) map makeMaintainerScript(Prerm),
debianMakePostrmScript <<= (target in Universal, serverLoading in Debian, linuxScriptReplacements) map makeMaintainerScript(Postrm))
debianMakePostrmScript <<= (target in Universal, serverLoading in Debian, linuxScriptReplacements) map makeMaintainerScript(Postrm)
)
}

def rpmSettings: Seq[Setting[_]] = {
Expand Down Expand Up @@ -173,7 +174,8 @@ object JavaServerAppPackaging extends AutoPlugin {
requiredStopFacilities: Option[String],
startRunlevels: Option[String],
stopRunlevels: Option[String],
loader: ServerLoader): Seq[(String, String)] = {
loader: ServerLoader
): Seq[(String, String)] = {

// Upstart cannot handle empty values
val (startOn, stopOn) = loader match {
Expand Down Expand Up @@ -238,9 +240,12 @@ object JavaServerAppPackaging extends AutoPlugin {
Some(script)
}

protected def makeMaintainerScript(scriptName: String,
template: Option[URL] = None, archetype: String = ARCHETYPE, config: Configuration = Debian)(
tmpDir: File, loader: ServerLoader, replacements: Seq[(String, String)]): Option[File] = {
protected def makeMaintainerScript(
scriptName: String,
template: Option[URL] = None, archetype: String = ARCHETYPE, config: Configuration = Debian
)(
tmpDir: File, loader: ServerLoader, replacements: Seq[(String, String)]
): Option[File] = {
val scriptBits = JavaServerBashScript(scriptName, archetype, config, replacements, template) getOrElse {
sys.error(s"Couldn't load [$scriptName] for config [${config.name}] in archetype [$archetype]")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ object JavaServerBashScript {
archetype: String,
config: Configuration,
replacements: Seq[(String, String)],
template: Option[URL] = None): Option[String] = {
template: Option[URL] = None
): Option[String] = {
// use template or else search for a default
val url = template orElse {
Option(getClass getResource s"$archetype/${config.name}/$script-template")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,20 @@ object TemplateWriter {
private def replace(
line: String,
replacements: Seq[(String, String)],
keySurround: String => String): String = {
keySurround: String => String
): String = {
replacements.foldLeft(line) {
case (line, (key, value)) =>
keySurround(key).r.replaceAllIn(line, java.util.regex.Matcher.quoteReplacement(value))
}
}

private def replaceValues(lines: Seq[String],
private def replaceValues(
lines: Seq[String],
replacements: Seq[(String, String)],
eol: String,
keySurround: String => String): String = {
keySurround: String => String
): String = {
val sb = new StringBuilder
for (line <- lines) {
sb append replace(line, replacements, keySurround)
Expand All @@ -57,7 +60,8 @@ object TemplateWriter {
replacements: Seq[(String, String)],
eol: String = "\n",
keySurround: String => String = bashFriendlyKeySurround,
charset: java.nio.charset.Charset = defaultCharset): String = {
charset: java.nio.charset.Charset = defaultCharset
): String = {
val lines = sbt.IO.readLinesURL(source, charset)
replaceValues(lines, replacements, eol, keySurround)
}
Expand All @@ -67,7 +71,8 @@ object TemplateWriter {
replacements: Seq[(String, String)],
eol: String = "\n",
keySurround: String => String = bashFriendlyKeySurround,
charset: java.nio.charset.Charset = defaultCharset): String = {
charset: java.nio.charset.Charset = defaultCharset
): String = {
replaceValues(source split eol, replacements, eol, keySurround)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ case class PackageInfo(
version: String,
maintainer: String,
summary: String,
description: String)
description: String
)

/** Represents package meta used by debian when constructing packages. */
case class PackageMetaData(
Expand All @@ -16,7 +17,8 @@ case class PackageMetaData(
architecture: String = "all",
section: String = "java",
depends: Seq[String] = Seq.empty,
recommends: Seq[String] = Seq.empty) {
recommends: Seq[String] = Seq.empty
) {
def makeContent(installSizeEstimate: Long = 0L): String = {
// TODO: Pretty print with line wrap.
val sb = new StringBuilder
Expand Down Expand Up @@ -64,7 +66,8 @@ case class DebianControlScriptReplacements(
author: String,
descr: String,
name: String,
version: String) {
version: String
) {

/**
* Generates the replacement sequence for the debian
Expand All @@ -74,5 +77,6 @@ case class DebianControlScriptReplacements(
"author" -> author,
"descr" -> descr,
"name" -> name,
"version" -> version)
"version" -> version
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {

// TODO maybe we can put settings/debiansettings together
/**
* Enables native packaging by default
* Enables native packaging by default
*/
override lazy val projectSettings = settings ++ inConfig(Debian)(debianSettings) ++ debianNativeSettings

Expand Down Expand Up @@ -115,12 +115,13 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {
debianMaintainerScripts <++= (debianMakePrermScript, debianControlScriptsDirectory) map scriptMapping(Names.Prerm),
debianMaintainerScripts <++= (debianMakePreinstScript, debianControlScriptsDirectory) map scriptMapping(Names.Preinst),
debianMaintainerScripts <++= (debianMakePostinstScript, debianControlScriptsDirectory) map scriptMapping(Names.Postinst),
debianMaintainerScripts <++= (debianMakePostrmScript, debianControlScriptsDirectory) map scriptMapping(Names.Postrm))
debianMaintainerScripts <++= (debianMakePostrmScript, debianControlScriptsDirectory) map scriptMapping(Names.Postrm)
)

/**
* == Debian scoped settings ==
* Everything used inside the debian scope
*
*
*/
private def debianSettings: Seq[Setting[_]] = inConfig(Debian)(
Seq(
Expand All @@ -141,7 +142,8 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {
if (data.info.description == null || data.info.description.isEmpty) {
sys.error(
"""packageDescription in Debian cannot be empty. Use
packageDescription in Debian := "My package Description"""")
packageDescription in Debian := "My package Description""""
)
}
val cfile = dir / Names.Debian / Names.Control
IO.write(cfile, data.makeContent(size), java.nio.charset.Charset.defaultCharset)
Expand Down Expand Up @@ -215,7 +217,8 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {
linuxScriptReplacements += ("header" -> "#!/bin/sh\nset -e")

// Adding package specific implementation settings
))
)
)

}

Expand Down Expand Up @@ -350,4 +353,4 @@ object DebianDeployPlugin extends AutoPlugin {
override def projectSettings =
SettingsHelper.makeDeploymentSettings(Debian, packageBin in Debian, "deb") ++
SettingsHelper.makeDeploymentSettings(Debian, genChanges in Debian, "changes")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.typesafe.sbt
package packager
package debian


import com.typesafe.sbt.packager.archetypes.TemplateWriter
import com.typesafe.sbt.packager.universal.Archives
import sbt._
Expand Down Expand Up @@ -49,7 +48,8 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike {
if (data.info.description == null || data.info.description.isEmpty) {
sys.error(
"""packageDescription in Debian cannot be empty. Use
packageDescription in Debian := "My package Description"""")
packageDescription in Debian := "My package Description""""
)
}
val cfile = dir / Names.Debian / Names.Control
IO.write(cfile, data.makeContent(size), java.nio.charset.Charset.defaultCharset)
Expand Down Expand Up @@ -83,7 +83,8 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike {
val console = new JDebConsole(log)
val archive = archiveFilename(normalizedName.value, version.value, packageArchitecture.value)
val debianFile = targetDir.getParentFile / archive
val debMaker = new DebMaker(console,
val debMaker = new DebMaker(
console,
fileAndDirectoryProducers(mappings, targetDir) ++ linkProducers(symlinks),
conffileProducers(mappings, targetDir)
)
Expand All @@ -95,8 +96,8 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike {
debMaker validate ()
debMaker makeDeb ()
debianFile
})

}
)

/**
* The same as [[DebianPluginLike.copyAndFixPerms]] except chmod invocation (for windows compatibility).
Expand All @@ -113,7 +114,6 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike {
} else IO.copyFile(from, to, true)
}


/**
* The same as [[DebianPluginLike.filterAndFixPerms]] except chmod invocation (for windows compatibility).
* Permissions will be handled by jDeb packager itself.
Expand All @@ -125,7 +125,6 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike {
script
}


/**
* Creating file and directory producers. These "produce" the
* files for the debian packaging.
Expand Down
6 changes: 4 additions & 2 deletions src/main/scala/com/typesafe/sbt/packager/debian/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ trait DebianKeys {
val genChanges = TaskKey[File]("gen-changes", "runs the dpkg-genchanges command to generate the .changes file.")

// Debian control scripts
val debianControlScriptsDirectory = SettingKey[File]("debian-control-scripts-directory",
"Directory where all debian control scripts reside. Default is 'src/debian/DEBIAN'")
val debianControlScriptsDirectory = SettingKey[File](
"debian-control-scripts-directory",
"Directory where all debian control scripts reside. Default is 'src/debian/DEBIAN'"
)
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 Down
Loading