From 9fa3951e37d08ec419ff9152db5d2736687cce95 Mon Sep 17 00:00:00 2001 From: Nepomuk Seiler Date: Wed, 25 Jan 2017 22:02:24 +0100 Subject: [PATCH] Wip/remove symbolic operators (#931) * FIX 919 Remove symbol operators from Archetypes * FIX 919 Remove symbol operators in Debian * FIX 919 Remove symbol operators in Docker * FIX 919 Fix warnings in classpath and launcher jar * FIX 919 Fix warnings in jdkpackager plugin * FIX 919 Remove symbol operators in Linux * FIX 919 Remove symbol operators in Rpm * FIX 919 Remove symbol operators in Universal * FIX 919 Remove symbol operators * FIX 919 Fix compile error * FIX 919 Fix bashScriptConfigLocation * FIX 919 Use correct version in windows --- .../sbt/packager/SettingsHelper.scala | 58 +++--- .../{JavaApp.scala => JavaAppPackaging.scala} | 96 +++++----- .../archetypes/JavaServerApplication.scala | 62 ++++--- .../archetypes/JavaServerBashScript.scala | 3 +- .../scripts/BashStartScriptPlugin.scala | 42 +++-- ...ging.scala => DebianNativePackaging.scala} | 13 +- .../sbt/packager/debian/DebianPlugin.scala | 73 ++++---- .../sbt/packager/debian/JDebPackaging.scala | 30 +-- .../sbt/packager/docker/DockerPlugin.scala | 125 ++++++------- .../docker/DockerSpotifyClientPlugin.scala | 28 ++- .../sbt/packager/jar/ClasspathJarPlugin.scala | 10 +- .../sbt/packager/jar/LauncherJarPlugin.scala | 10 +- .../jdkpackager/JDKPackagerKeys.scala | 30 +-- .../jdkpackager/JDKPackagerPlugin.scala | 6 +- .../sbt/packager/linux/LinuxPlugin.scala | 86 ++++----- .../typesafe/sbt/packager/rpm/RpmPlugin.scala | 100 +++++----- .../packager/universal/UniversalPlugin.scala | 74 ++++---- .../sbt/packager/windows/WindowsPlugin.scala | 172 +++++++++--------- .../project/Build.scala | 68 ++++--- .../project/Build.scala | 56 +++--- test-project-simple/build.sbt | 2 +- 21 files changed, 567 insertions(+), 577 deletions(-) rename src/main/scala/com/typesafe/sbt/packager/archetypes/{JavaApp.scala => JavaAppPackaging.scala} (71%) rename src/main/scala/com/typesafe/sbt/packager/debian/{NativePackaging.scala => DebianNativePackaging.scala} (94%) diff --git a/src/main/scala/com/typesafe/sbt/packager/SettingsHelper.scala b/src/main/scala/com/typesafe/sbt/packager/SettingsHelper.scala index 635c749c7..e9258e7ab 100644 --- a/src/main/scala/com/typesafe/sbt/packager/SettingsHelper.scala +++ b/src/main/scala/com/typesafe/sbt/packager/SettingsHelper.scala @@ -26,44 +26,34 @@ object SettingsHelper { ) def makeDeploymentSettings(config: Configuration, packageTask: TaskKey[File], extension: String): Seq[Setting[_]] = - (inConfig(config)(Classpaths.publishSettings)) ++ inConfig(config)( + inConfig(config)(Classpaths.publishSettings) ++ inConfig(config)( Seq( artifacts := Seq.empty, packagedArtifacts := Map.empty, - projectID <<= (organization, name, version) apply { (o, n, v) => - ModuleID(o, n, v) + projectID := ModuleID(organization.value, name.value, version.value), + moduleSettings := InlineConfiguration(projectID.value, projectInfo.value, Seq.empty), + ivyModule := { + val ivy = ivySbt.value + new ivy.Module(moduleSettings.value) }, - moduleSettings <<= (projectID, projectInfo) map { (pid, pinfo) => - InlineConfiguration(pid, pinfo, Seq.empty) - }, - ivyModule <<= (ivySbt, moduleSettings) map { (i, s) => - new i.Module(s) - }, - 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, - resolverName = Classpaths.getPublishTo(publishTo).name, - artifacts = as, - checksums = checks, - logging = UpdateLogging.DownloadOnly, - overwrite = isSnap - ) - }, - publishLocalConfiguration <<= (packagedArtifacts, checksums, isSnapshot) map { (as, checks, isSnap) => - new PublishConfiguration( - ivyFile = None, - resolverName = "local", - artifacts = as, - checksums = checks, - logging = UpdateLogging.DownloadOnly, - overwrite = isSnap - ) - } + deliverLocalConfiguration := Classpaths.deliverConfig(crossTarget.value, logging = ivyLoggingLevel.value), + deliverConfiguration := deliverLocalConfiguration.value, + publishConfiguration := new PublishConfiguration( + ivyFile = None, + resolverName = Classpaths.getPublishTo(publishTo.value).name, + artifacts = packagedArtifacts.value, + checksums = checksums.value, + logging = UpdateLogging.DownloadOnly, + overwrite = isSnapshot.value + ), + publishLocalConfiguration := new PublishConfiguration( + ivyFile = None, + resolverName = "local", + artifacts = packagedArtifacts.value, + checksums = checksums.value, + logging = UpdateLogging.DownloadOnly, + overwrite = isSnapshot.value + ) ) ) ++ addPackage(config, packageTask, extension) } diff --git a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaApp.scala b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppPackaging.scala similarity index 71% rename from src/main/scala/com/typesafe/sbt/packager/archetypes/JavaApp.scala rename to src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppPackaging.scala index e2434eeea..72d042444 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaApp.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppPackaging.scala @@ -1,13 +1,12 @@ -package com.typesafe.sbt -package packager -package archetypes +package com.typesafe.sbt.packager.archetypes import sbt._ -import sbt.Keys.{javaOptions, mainClass, mappings, name, sourceDirectory, streams, target} -import packager.Keys.{executableScriptName, packageName} -import linux.{LinuxFileMetaData, LinuxPackageMapping} -import linux.LinuxPlugin.autoImport.{defaultLinuxInstallLocation, linuxPackageMappings} -import SbtNativePackager.{Debian, Universal} +import sbt.Keys._ +import com.typesafe.sbt.SbtNativePackager.{Debian, Universal} +import com.typesafe.sbt.packager._ +import com.typesafe.sbt.packager.Keys.packageName +import com.typesafe.sbt.packager.linux.{LinuxFileMetaData, LinuxPackageMapping} +import com.typesafe.sbt.packager.linux.LinuxPlugin.autoImport.{defaultLinuxInstallLocation, linuxPackageMappings} /** * == Java Application == @@ -38,39 +37,45 @@ object JavaAppPackaging extends AutoPlugin { import JavaAppPackaging.autoImport._ - override def requires = + override def requires: Plugins = debian.DebianPlugin && rpm.RpmPlugin && docker.DockerPlugin && windows.WindowsPlugin - // format: off override def projectSettings = Seq( javaOptions in Universal := Nil, // Here we record the classpath as it's added to the mappings separately, so // we can use its order to generate the bash/bat scripts. scriptClasspathOrdering := Nil, // Note: This is sometimes on the classpath via dependencyClasspath in Runtime. - // We need to figure out why sometimes the Attributed[File] is corrrectly configured + // We need to figure out why sometimes the Attributed[File] is correctly configured // and sometimes not. - scriptClasspathOrdering <+= (Keys.packageBin in Compile, Keys.projectID, Keys.artifact in Compile in Keys.packageBin) map { (jar, id, art) => + scriptClasspathOrdering += { + val jar = (packageBin in Compile).value + val id = projectID.value + val art = (artifact in Compile in packageBin).value jar -> ("lib/" + makeJarName(id.organization, id.name, id.revision, art.name, art.classifier)) }, - projectDependencyArtifacts <<= findProjectDependencyArtifacts, - scriptClasspathOrdering <++= (Keys.dependencyClasspath in Runtime, projectDependencyArtifacts) map universalDepMappings, - scriptClasspathOrdering <<= scriptClasspathOrdering map { _.distinct }, - mappings in Universal <++= scriptClasspathOrdering, - scriptClasspath <<= scriptClasspathOrdering map makeRelativeClasspathNames, - linuxPackageMappings in Debian <+= (packageName in Debian, defaultLinuxInstallLocation, target in Debian) map { - (name, installLocation, target) => - // create empty var/log directory - val d = target / installLocation - d.mkdirs() - LinuxPackageMapping(Seq(d -> (installLocation + "/" + name)), LinuxFileMetaData()) + projectDependencyArtifacts := findProjectDependencyArtifacts.value, + scriptClasspathOrdering ++= universalDepMappings( + (dependencyClasspath in Runtime).value, + projectDependencyArtifacts.value + ), + scriptClasspathOrdering := scriptClasspathOrdering.value.distinct, + mappings in Universal ++= scriptClasspathOrdering.value, + scriptClasspath := makeRelativeClasspathNames(scriptClasspathOrdering.value), + linuxPackageMappings in Debian += { + val name = (packageName in Debian).value + val installLocation = defaultLinuxInstallLocation.value + val targetDir = (target in Debian).value + // create empty var/log directory + val d = targetDir / installLocation + d.mkdirs() + LinuxPackageMapping(Seq(d -> (installLocation + "/" + name)), LinuxFileMetaData()) } ) - // format: on private def makeRelativeClasspathNames(mappings: Seq[(File, String)]): Seq[String] = for { - (file, name) <- mappings + (_, name) <- mappings } yield { // Here we want the name relative to the lib/ folder... // For now we just cheat... @@ -107,30 +112,6 @@ object JavaAppPackaging extends AutoPlugin { private def dependencyProjectRefs(build: sbt.BuildDependencies, thisProject: ProjectRef): Seq[ProjectRef] = build.classpathTransitive.getOrElse(thisProject, Nil) - private def filterArtifacts(artifacts: Seq[(Artifact, File)], config: Option[String]): Seq[(Artifact, File)] = - for { - (art, file) <- artifacts - // TODO - Default to compile or default? - if art.configurations.exists(_.name == config.getOrElse("default")) - } yield art -> file - - private def extractArtifacts(stateTask: Task[State], ref: ProjectRef): Task[Seq[Attributed[File]]] = - stateTask flatMap { state => - val extracted = Project extract state - // TODO - Is this correct? - val module = extracted.get(sbt.Keys.projectID in ref) - val artifactTask = extracted get (sbt.Keys.packagedArtifacts in ref) - for { - arts <- artifactTask - } yield { - for { - (art, file) <- arts.toSeq // TODO -Filter! - } yield { - sbt.Attributed.blank(file).put(sbt.Keys.moduleID.key, module).put(sbt.Keys.artifact.key, art) - } - } - } - // TODO - Should we pull in more than just JARs? How do native packages come in? private def isRuntimeArtifact(dep: Attributed[File]): Boolean = dep.get(sbt.Keys.artifact.key).map(_.`type` == "jar").getOrElse { @@ -139,7 +120,7 @@ object JavaAppPackaging extends AutoPlugin { } private def findProjectDependencyArtifacts: Def.Initialize[Task[Seq[Attributed[File]]]] = - (sbt.Keys.buildDependencies, sbt.Keys.thisProjectRef, sbt.Keys.state) apply { (build, thisProject, stateTask) => + (buildDependencies, thisProjectRef, state).apply { (build, thisProject, stateTask) => val refs = thisProject +: dependencyProjectRefs(build, thisProject) // Dynamic lookup of dependencies... val artTasks = refs map { ref => @@ -155,6 +136,21 @@ object JavaAppPackaging extends AutoPlugin { allArtifactsTask } + private def extractArtifacts(stateTask: Task[State], ref: ProjectRef): Task[Seq[Attributed[File]]] = + stateTask.flatMap { state => + val extracted = Project.extract(state) + // TODO - Is this correct? + val module = extracted.get(projectID in ref) + val artifactTask = extracted.get(packagedArtifacts in ref) + for { + arts <- artifactTask + } yield { + for { + (art, file) <- arts.toSeq // TODO -Filter! + } yield Attributed.blank(file).put(moduleID.key, module).put(artifact.key, art) + } + } + private def findRealDep(dep: Attributed[File], projectArts: Seq[Attributed[File]]): Option[Attributed[File]] = if (dep.data.isFile) Some(dep) else { diff --git a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala index 8daa04e10..c551614ea 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala @@ -48,17 +48,20 @@ object JavaServerAppPackaging extends AutoPlugin { * - config directory */ def linuxSettings: Seq[Setting[_]] = Seq( - javaOptions in Linux <<= javaOptions in Universal, + javaOptions in Linux := (javaOptions in Universal).value, // === logging directory mapping === - linuxPackageMappings <+= (packageName in Linux, - defaultLinuxLogsLocation, - daemonUser in Linux, - daemonGroup in Linux) map { (name, logsDir, user, group) => - packageTemplateMapping(logsDir + "/" + name)() withUser user withGroup group withPerms "755" + linuxPackageMappings += { + packageTemplateMapping(defaultLinuxLogsLocation.value + "/" + (packageName in Linux).value)() + .withUser((daemonUser in Linux).value) + .withGroup((daemonGroup in Linux).value) + .withPerms("755") }, - linuxPackageSymlinks <+= (packageName in Linux, defaultLinuxInstallLocation, defaultLinuxLogsLocation) map { - (name, install, logsDir) => - LinuxSymlink(install + "/" + name + "/logs", logsDir + "/" + name) + linuxPackageSymlinks += { + val name = (packageName in Linux).value + LinuxSymlink( + defaultLinuxInstallLocation.value + "/" + name + "/logs", + defaultLinuxLogsLocation.value + "/" + name + ) }, // === etc config mapping === bashScriptEnvConfigLocation := Some("/etc/default/" + (packageName in Linux).value), @@ -104,15 +107,14 @@ object JavaServerAppPackaging extends AutoPlugin { ) ) ++ Seq( // === Daemon User and Group === - daemonUser in Debian <<= daemonUser in Linux, - daemonUserUid in Debian <<= daemonUserUid in Linux, - daemonGroup in Debian <<= daemonGroup in Linux, - daemonGroupGid in Debian <<= daemonGroupGid in Linux + daemonUser in Debian := (daemonUser in Linux).value, + daemonUserUid in Debian := (daemonUserUid in Linux).value, + daemonGroup in Debian := (daemonGroup in Linux).value, + daemonGroupGid in Debian := (daemonGroupGid in Linux).value ) } - def rpmSettings: Seq[Setting[_]] = { - import RpmPlugin.Names.{Post, Postun, Pre, Preun} + def rpmSettings: Seq[Setting[_]] = inConfig(Rpm)(etcDefaultConfig) ++ inConfig(Rpm)( Seq( @@ -120,16 +122,19 @@ object JavaServerAppPackaging extends AutoPlugin { linuxScriptReplacements ++= bashScriptEnvConfigLocation.value.map(ENV_CONFIG_REPLACEMENT -> _).toSeq, linuxScriptReplacements += Names.DaemonStdoutLogFileReplacement -> daemonStdoutLogFile.value.getOrElse(""), // === /var/run/app pid folder === - linuxPackageMappings <+= (packageName, daemonUser, daemonGroup) map { (name, user, group) => - packageTemplateMapping("/var/run/" + name)() withUser user withGroup group withPerms "755" + linuxPackageMappings += { + packageTemplateMapping("/var/run/" + packageName.value)() + .withUser(daemonUser.value) + .withGroup(daemonGroup.value) + .withPerms("755") } ) ) ++ Seq( // === Daemon User and Group === - daemonUser in Rpm <<= daemonUser in Linux, - daemonUserUid in Rpm <<= daemonUserUid in Linux, - daemonGroup in Rpm <<= daemonGroup in Linux, - daemonGroupGid in Rpm <<= daemonGroupGid in Linux, + daemonUser in Rpm := (daemonUser in Linux).value, + daemonUserUid in Rpm := (daemonUserUid in Linux).value, + daemonGroup in Rpm := (daemonGroup in Linux).value, + daemonGroupGid in Rpm := (daemonGroupGid in Linux).value, // == Maintainer scripts === maintainerScripts in Rpm := rpmScriptletContents( rpmScriptsDirectory.value, @@ -137,7 +142,6 @@ object JavaServerAppPackaging extends AutoPlugin { (linuxScriptReplacements in Rpm).value ) ) - } /* ========================================== */ /* ============ Helper Methods ============== */ @@ -154,12 +158,14 @@ object JavaServerAppPackaging extends AutoPlugin { */ private[this] def getEtcTemplateSource(sourceDirectory: File, loader: Option[ServerLoader]): java.net.URL = { val defaultTemplate = getClass.getResource(ETC_DEFAULT + "-template") - val (suffix, default) = loader.map { - case Upstart => ("-upstart", defaultTemplate) - case SystemV => ("-systemv", defaultTemplate) - case Systemd => - ("-systemd", getClass.getResource(ETC_DEFAULT + "-systemd-template")) - }.getOrElse(("", defaultTemplate)) + val (suffix, default) = loader + .map { + case Upstart => ("-upstart", defaultTemplate) + case SystemV => ("-systemv", defaultTemplate) + case Systemd => + ("-systemd", getClass.getResource(ETC_DEFAULT + "-systemd-template")) + } + .getOrElse(("", defaultTemplate)) val overrides = List[File](sourceDirectory / "templates" / (ETC_DEFAULT + suffix), sourceDirectory / "templates" / ETC_DEFAULT) diff --git a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerBashScript.scala b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerBashScript.scala index 5a7971250..780f98831 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerBashScript.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerBashScript.scala @@ -61,7 +61,7 @@ object JavaServerLoaderScript { case file if file.exists => Some(file.toURI.toURL) case _ => Option(getClass getResource templatePath(script, loader, archetype)) - } getOrElse (sys.error(s"Could not find init [$script] for system [$loader] in archetype [$archetype]")) + } getOrElse sys.error(s"Could not find init [$script] for system [$loader] in archetype [$archetype]") /** * Loads the [[com.typesafe.sbt.packager.archetypes.systemloader.ServerLoader]] specific "functions" resource, @@ -70,7 +70,6 @@ object JavaServerLoaderScript { * The functions script resides in "[archetype]/[loader]/functions" * * @param loader - Upstart, SystemV, SystemD - * @param replacements - tuple of name->replacement * @param script - default is "functions" * @return functions - addService/stopService with resolved variables */ diff --git a/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BashStartScriptPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BashStartScriptPlugin.scala index fcbd6a30e..3c6cb6874 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BashStartScriptPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BashStartScriptPlugin.scala @@ -55,8 +55,8 @@ object BashStartScriptPlugin extends AutoPlugin { bashScriptDefines ++= bashScriptExtraDefines.value, bashScriptReplacements := generateScriptReplacements(bashScriptDefines.value), // Create a bashConfigLocation if options are set in build.sbt - bashScriptConfigLocation <<= bashScriptConfigLocation ?? Some(appIniLocation), - bashScriptEnvConfigLocation <<= bashScriptEnvConfigLocation ?? None, + bashScriptConfigLocation := (bashScriptConfigLocation ?? Some(appIniLocation)).value, + bashScriptEnvConfigLocation := (bashScriptEnvConfigLocation ?? None).value, // Generating the application configuration mappings in Universal := generateApplicationIni( (mappings in Universal).value, @@ -90,24 +90,26 @@ object BashStartScriptPlugin extends AutoPlugin { bashScriptConfigLocation: Option[String], tmpDir: File, log: Logger): Seq[(File, String)] = - bashScriptConfigLocation.collect { - case location if javaOptions.nonEmpty => - val configFile = tmpDir / "tmp" / "conf" / "application.ini" - //Do not use writeLines here because of issue #637 - IO.write(configFile, ("# options from build" +: javaOptions).mkString("\n")) - val filteredMappings = universalMappings.filter { - case (file, path) => path != appIniLocation - } - // Warn the user if he tries to specify options - if (filteredMappings.size < universalMappings.size) { - log.warn("--------!!! JVM Options are defined twice !!!-----------") - log.warn( - "application.ini is already present in output package. Will be overridden by 'javaOptions in Universal'" - ) - } - (configFile -> cleanApplicationIniPath(location)) +: filteredMappings - - }.getOrElse(universalMappings) + bashScriptConfigLocation + .collect { + case location if javaOptions.nonEmpty => + val configFile = tmpDir / "tmp" / "conf" / "application.ini" + //Do not use writeLines here because of issue #637 + IO.write(configFile, ("# options from build" +: javaOptions).mkString("\n")) + val filteredMappings = universalMappings.filter { + case (file, path) => path != appIniLocation + } + // Warn the user if he tries to specify options + if (filteredMappings.size < universalMappings.size) { + log.warn("--------!!! JVM Options are defined twice !!!-----------") + log.warn( + "application.ini is already present in output package. Will be overridden by 'javaOptions in Universal'" + ) + } + (configFile -> cleanApplicationIniPath(location)) +: filteredMappings + + } + .getOrElse(universalMappings) private[this] def generateStartScripts(config: BashScriptConfig, mainClass: Option[String], diff --git a/src/main/scala/com/typesafe/sbt/packager/debian/NativePackaging.scala b/src/main/scala/com/typesafe/sbt/packager/debian/DebianNativePackaging.scala similarity index 94% rename from src/main/scala/com/typesafe/sbt/packager/debian/NativePackaging.scala rename to src/main/scala/com/typesafe/sbt/packager/debian/DebianNativePackaging.scala index 3498b8971..39b013f9c 100644 --- a/src/main/scala/com/typesafe/sbt/packager/debian/NativePackaging.scala +++ b/src/main/scala/com/typesafe/sbt/packager/debian/DebianNativePackaging.scala @@ -45,15 +45,19 @@ trait DebianNativePackaging extends DebianPluginLike { debianPackageMetadata.value, target.value ), - debianSign <<= (packageBin, debianSignRole, streams) map { (deb, role, s) => - Process(Seq("dpkg-sig", "-s", role, deb.getAbsolutePath), Some(deb.getParentFile())) ! s.log match { + debianSign := { + val deb = packageBin.value + val role = debianSignRole.value + val log = streams.value.log + Process(Seq("dpkg-sig", "-s", role, deb.getAbsolutePath), Some(deb.getParentFile)) ! log match { case 0 => () case x => sys.error("Failed to sign debian package! exit code: " + x) } deb }, - lintian <<= packageBin map { file => + lintian := { + val file = packageBin.value Process(Seq("lintian", "-c", "-v", file.getName), Some(file.getParentFile)).! }, /** Implementation of the actual packaging */ @@ -73,7 +77,7 @@ trait DebianNativePackaging extends DebianPluginLike { changelog match { case None => sys.error("Cannot generate .changes file without a changelog") - case Some(chlog) => { + case Some(chlog) => // dpkg-genchanges needs a debian "source" directory, different from the DEBIAN "binary" directory val debSrc = targetDir / "../tmp" / Names.DebianSource debSrc.mkdirs() @@ -92,7 +96,6 @@ trait DebianNativePackaging extends DebianPluginLike { sys.error("Failure generating changes file." + e.getStackTraceString) } changesFile - } } } diff --git a/src/main/scala/com/typesafe/sbt/packager/debian/DebianPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/debian/DebianPlugin.scala index 2a862255d..72e890d48 100644 --- a/src/main/scala/com/typesafe/sbt/packager/debian/DebianPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/debian/DebianPlugin.scala @@ -33,7 +33,7 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging { override def requires = LinuxPlugin object autoImport extends DebianKeys { - val Debian = config("debian") extend Linux + val Debian: Configuration = config("debian") extend Linux val DebianConstants = Names } @@ -65,7 +65,7 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging { /** * Enables native packaging by default */ - override lazy val projectSettings = settings ++ debianSettings ++ debianNativeSettings + override lazy val projectSettings: Seq[Setting[_]] = settings ++ debianSettings ++ debianNativeSettings /** * the default debian settings for the debian namespaced settings @@ -79,21 +79,20 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging { debianPackageProvides := Seq.empty, debianPackageRecommends := Seq.empty, 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), - version in Debian <<= (version in Linux), - linuxPackageMappings in Debian <<= linuxPackageMappings, - packageDescription in Debian <<= packageDescription in Linux, - packageSummary in Debian <<= packageSummary in Linux, - maintainer in Debian <<= maintainer in Linux, + target in Debian := target.value / ((name in Debian).value + "-" + (version in Debian).value), + name in Debian := (name in Linux).value, + maintainerScripts in Debian := (maintainerScripts in Linux).value, + packageName in Debian := (packageName in Linux).value, + executableScriptName in Debian := (executableScriptName in Linux).value, + version in Debian := (version in Linux).value, + linuxPackageMappings in Debian := linuxPackageMappings.value, + packageDescription in Debian := (packageDescription in Linux).value, + packageSummary in Debian := (packageSummary in Linux).value, + maintainer in Debian := (maintainer in Linux).value, // override the linux sourceDirectory setting - sourceDirectory in Debian <<= sourceDirectory, + sourceDirectory in Debian := sourceDirectory.value, /* ==== Debian configuration settings ==== */ - debianControlScriptsDirectory <<= (sourceDirectory) apply (_ / "debian" / Names.DebianMaintainerScripts), + debianControlScriptsDirectory := (sourceDirectory.value / "debian" / Names.DebianMaintainerScripts), debianMaintainerScripts := Seq.empty, debianMakePreinstScript := None, debianMakePrermScript := None, @@ -240,7 +239,7 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging { private[this] def createMD5SumFile(stageDir: File): File = { val md5file = stageDir / Names.DebianMaintainerScripts / "md5sums" val md5sums = for { - (file, name) <- (stageDir.*** --- stageDir pair relativeTo(stageDir)) + (file, name) <- stageDir.*** --- stageDir pair relativeTo(stageDir) if file.isFile if !(name startsWith Names.DebianMaintainerScripts) if !(name contains "debian-binary") @@ -271,17 +270,17 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging { case LinuxPackageMapping(paths, perms, zipped) => val (dirs, files) = paths.partition(_._1.isDirectory) dirs map { - case (_, name) => targetDir / name + case (_, dirName) => targetDir / dirName } foreach { targetDir => targetDir mkdirs () chmod(targetDir, perms.permissions) } files map { - case (file, name) => (file, targetDir / name) + case (file, fileName) => (file, targetDir / fileName) } foreach { - case (source, target) => - copyAndFixPerms(source, target, perms, zipped) + case (source, destination) => + copyAndFixPerms(source, destination, perms, zipped) } } @@ -430,21 +429,25 @@ trait DebianPluginLike { val header = "# Chown definitions created by SBT Native Packager\n" // Check for non root user/group and create chown commands // filter all root mappings, map to (user,group) key, group by, append everything - val chowns = mappings filter { - case LinuxPackageMapping(_, LinuxFileMetaData(Users.Root, Users.Root, _, _, _), _) => - false - case _ => true - } map { - case LinuxPackageMapping(paths, meta, _) => - (meta.user, meta.group) -> paths - } groupBy (_._1) map { - case ((user, group), pathList) => - validateUserGroupNames(user, streams) - validateUserGroupNames(group, streams) - val chown = chownCmd(user, group) _ - // remove key, flatten it and then use mapping path (_.2) to create chown command - pathList.map(_._2).flatten map (m => chown(m._2)) - } + val chowns = mappings + .filter { + case LinuxPackageMapping(_, LinuxFileMetaData(Users.Root, Users.Root, _, _, _), _) => + false + case _ => true + } + .map { + case LinuxPackageMapping(paths, meta, _) => + (meta.user, meta.group) -> paths + } + .groupBy(_._1) + .map { + case ((user, group), pathList) => + validateUserGroupNames(user, streams) + validateUserGroupNames(group, streams) + val chown = chownCmd(user, group) _ + // remove key, flatten it and then use mapping path (_.2) to create chown command + pathList.flatMap(_._2).map(m => chown(m._2)) + } val replacement = header :: chowns.flatten.toList mkString "\n" DebianPlugin.CHOWN_REPLACEMENT -> replacement } diff --git a/src/main/scala/com/typesafe/sbt/packager/debian/JDebPackaging.scala b/src/main/scala/com/typesafe/sbt/packager/debian/JDebPackaging.scala index 244923dc4..ac7da2b55 100644 --- a/src/main/scala/com/typesafe/sbt/packager/debian/JDebPackaging.scala +++ b/src/main/scala/com/typesafe/sbt/packager/debian/JDebPackaging.scala @@ -38,7 +38,7 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike { override def requires = DebianPlugin - override lazy val projectSettings = inConfig(Debian)(jdebSettings) + override lazy val projectSettings: Seq[Setting[_]] = inConfig(Debian)(jdebSettings) def jdebSettings = Seq( // FIXME do nothing. Java7 posix needed @@ -46,12 +46,14 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike { target.value / Names.DebianMaintainerScripts / Names.Conffiles }, // FIXME copied from the debian plugin. Java7 posix needed - debianControlFile <<= (debianPackageMetadata, debianPackageInstallSize, target) map { (data, size, dir) => + debianControlFile := { + val data = debianPackageMetadata.value + val size = debianPackageInstallSize.value if (data.info.description == null || data.info.description.isEmpty) { sys.error("""packageDescription in Debian cannot be empty. Use packageDescription in Debian := "My package Description"""") } - val cfile = dir / Names.DebianMaintainerScripts / Names.Control + val cfile = target.value / Names.DebianMaintainerScripts / Names.Control IO.write(cfile, data.makeContent(size), java.nio.charset.Charset.defaultCharset) cfile }, @@ -67,7 +69,7 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike { // unused, but needed as dependency val controlDir = targetDir / Names.DebianMaintainerScripts - val control = debianControlFile.value + val _ = debianControlFile.value val conffile = debianConffilesFile.value val replacements = debianMakeChownReplacements.value +: linuxScriptReplacements.value @@ -109,9 +111,9 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike { val tmp = dir / from.getName IO.copyFile(from, tmp) val zipped = Archives.gzip(tmp) - IO.copyFile(zipped, to, true) + IO.copyFile(zipped, to, preserveLastModified = true) } - } else IO.copyFile(from, to, true) + } else IO.copyFile(from, to, preserveLastModified = true) /** * The same as [[DebianPluginLike.filterAndFixPerms]] except chmod invocation (for windows compatibility). @@ -135,9 +137,9 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike { * This will be an performance improvement (reducing IO) */ private[debian] def fileAndDirectoryProducers(mappings: Seq[LinuxPackageMapping], target: File): Seq[DataProducer] = - mappings.map { + mappings.flatMap { case LinuxPackageMapping(paths, perms, zipped) => - paths map { + paths.map { // Directories need to be created so jdeb can pick them up case (path, name) if path.isDirectory => val permMapper = new PermMapper(-1, -1, perms.user, perms.group, null, perms.permissions, -1, null) @@ -148,7 +150,7 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike { case (path, name) => new DataProducerFile(path, cleanPath(name), null, null, Array(filePermissions(perms))) } - }.flatten + } /** * Creating link producers for symlinks. @@ -164,8 +166,8 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike { private[debian] def conffileProducers(linuxMappings: Seq[LinuxPackageMapping], target: File): Seq[DataProducer] = { val producers = linuxMappings map { - case mapping @ LinuxPackageMapping(mappings, perms, _) if perms.config == "true" => - mappings collect { + case LinuxPackageMapping(concretMappings, perms, _) if perms.config == "true" => + concretMappings collect { case (path, name) if path.isFile => val permMapper = filePermissions(perms.withPerms("0644")) new DataProducerFile(path, cleanPath(name), null, null, Array(permMapper)) @@ -190,9 +192,9 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike { */ class JDebConsole(log: Logger) extends org.vafer.jdeb.Console { - def debug(message: String) = log debug message + def debug(message: String): Unit = log debug message - def info(message: String) = log info message + def info(message: String): Unit = log info message - def warn(message: String) = log warn message + def warn(message: String): Unit = log warn message } diff --git a/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala index 047a128cc..1e9893861 100644 --- a/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala @@ -54,7 +54,7 @@ import SbtNativePackager.{Linux, Universal} object DockerPlugin extends AutoPlugin { object autoImport extends DockerKeys { - val Docker = config("docker") + val Docker: Configuration = config("docker") val DockerAlias = com.typesafe.sbt.packager.docker.DockerAlias } @@ -71,26 +71,25 @@ object DockerPlugin extends AutoPlugin { override def projectConfigurations: Seq[Configuration] = Seq(Docker) - // format: off - override lazy val projectSettings = Seq( - dockerBaseImage := "openjdk:latest", - dockerExposedPorts := Seq(), - dockerExposedUdpPorts := Seq(), - dockerExposedVolumes := Seq(), - dockerRepository := None, - dockerAlias := DockerAlias(dockerRepository.value, None, packageName.value, Some((version in Docker).value)), - dockerUpdateLatest := false, - dockerEntrypoint := Seq("bin/%s" format executableScriptName.value), - dockerCmd := Seq(), - dockerExecCommand := Seq("docker"), - dockerBuildOptions := Seq("--force-rm") ++ Seq("-t", dockerAlias.value.versioned) ++ ( - if (dockerUpdateLatest.value) - Seq("-t", dockerAlias.value.latest) - else - Seq() - ), - dockerBuildCommand := dockerExecCommand.value ++ Seq("build") ++ dockerBuildOptions.value ++ Seq("."), - dockerCommands := { + override lazy val projectSettings: Seq[Setting[_]] = Seq( + dockerBaseImage := "openjdk:latest", + dockerExposedPorts := Seq(), + dockerExposedUdpPorts := Seq(), + dockerExposedVolumes := Seq(), + dockerRepository := None, + dockerAlias := DockerAlias(dockerRepository.value, None, packageName.value, Some((version in Docker).value)), + dockerUpdateLatest := false, + dockerEntrypoint := Seq("bin/%s" format executableScriptName.value), + dockerCmd := Seq(), + dockerExecCommand := Seq("docker"), + dockerBuildOptions := Seq("--force-rm") ++ Seq("-t", dockerAlias.value.versioned) ++ ( + if (dockerUpdateLatest.value) + Seq("-t", dockerAlias.value.latest) + else + Seq() + ), + dockerBuildCommand := dockerExecCommand.value ++ Seq("build") ++ dockerBuildOptions.value ++ Seq("."), + dockerCommands := { val dockerBaseDirectory = (defaultLinuxInstallLocation in Docker).value val user = (daemonUser in Docker).value val group = (daemonGroup in Docker).value @@ -104,47 +103,41 @@ object DockerPlugin extends AutoPlugin { ) ++ makeExposePorts(dockerExposedPorts.value, dockerExposedUdpPorts.value) ++ makeVolumes(dockerExposedVolumes.value, user, group) ++ - Seq( - makeUser(user), - makeEntrypoint(dockerEntrypoint.value), - makeCmd(dockerCmd.value) - ) + Seq(makeUser(user), makeEntrypoint(dockerEntrypoint.value), makeCmd(dockerCmd.value)) } - - ) ++ mapGenericFilesToDocker ++ inConfig(Docker)(Seq( - executableScriptName := executableScriptName.value, - mappings ++= dockerPackageMappings.value, - mappings ++= Seq(dockerGenerateConfig.value) pair relativeTo(target.value), - name := name.value, - packageName := packageName.value, - publishLocal <<= (stage, dockerAlias, dockerBuildCommand, streams) map { - (context, alias, buildCommand, s) => - publishLocalDocker(context, buildCommand, s.log) - s.log.info(s"Built image $alias") - }, - publish <<= (publishLocal, dockerAlias, dockerUpdateLatest, dockerExecCommand, streams) map { - (_, alias, updateLatest, dockerExecCommand, s) => - publishDocker(dockerExecCommand ,alias.versioned, s.log) - if (updateLatest) { - publishDocker(dockerExecCommand, alias.latest, s.log) - } + ) ++ mapGenericFilesToDocker ++ inConfig(Docker)( + Seq( + executableScriptName := executableScriptName.value, + mappings ++= dockerPackageMappings.value, + mappings ++= Seq(dockerGenerateConfig.value) pair relativeTo(target.value), + name := name.value, + packageName := packageName.value, + publishLocal := { + val log = streams.value.log + publishLocalDocker(stage.value, dockerBuildCommand.value, log) + log.info(s"Built image ${dockerAlias.value}") }, - sourceDirectory := sourceDirectory.value / "docker", - stage <<= (streams, stagingDirectory, mappings) map Stager.stage(Docker.name), - stagingDirectory := (target in Docker).value / "stage", - target := target.value / "docker", - - daemonUser := "daemon", - daemonGroup := daemonUser.value, - defaultLinuxInstallLocation := "/opt/docker", - - dockerPackageMappings <<= sourceDirectory map { dir => - MappingsHelper contentOf dir + publish := { + val _ = publishLocal.value + val alias = dockerAlias.value + val log = streams.value.log + publishDocker(dockerExecCommand.value, alias.versioned, log) + if (dockerUpdateLatest.value) { + publishDocker(dockerExecCommand.value, alias.latest, log) + } }, - dockerGenerateConfig <<= (dockerCommands, target) map generateDockerConfig - )) - // format: on + sourceDirectory := sourceDirectory.value / "docker", + stage := Stager.stage(Docker.name)(streams.value, stagingDirectory.value, mappings.value), + stagingDirectory := (target in Docker).value / "stage", + target := target.value / "docker", + daemonUser := "daemon", + daemonGroup := daemonUser.value, + defaultLinuxInstallLocation := "/opt/docker", + dockerPackageMappings := MappingsHelper.contentOf(sourceDirectory.value), + dockerGenerateConfig := generateDockerConfig(dockerCommands.value, target.value) + ) + ) /** * @param maintainer (optional) @@ -276,14 +269,12 @@ object DockerPlugin extends AutoPlugin { newPath = "%s/%s" format (dest, path) } yield (f, newPath) - inConfig(Docker)(Seq(mappings <<= (mappings in Universal, defaultLinuxInstallLocation) map { (mappings, dest) => - renameDests(mappings, dest) - })) + inConfig(Docker)(Seq(mappings := renameDests((mappings in Universal).value, defaultLinuxInstallLocation.value))) } private[docker] def publishLocalLogger(log: Logger) = new ProcessLogger { - def error(err: => String) = + def error(err: => String): Unit = err match { case s if s.startsWith("Uploading context") => log.debug(s) // pre-1.0 @@ -293,12 +284,12 @@ object DockerPlugin extends AutoPlugin { case s => } - def info(inf: => String) = inf match { + def info(inf: => String): Unit = inf match { case s if !s.trim.isEmpty => log.info(s) case s => } - def buffer[T](f: => T) = f + def buffer[T](f: => T): T = f } def publishLocalDocker(context: File, buildCommand: Seq[String], log: Logger): Unit = { @@ -317,12 +308,12 @@ object DockerPlugin extends AutoPlugin { def publishLogger(log: Logger) = new ProcessLogger { - def error(err: => String) = err match { + def error(err: => String): Unit = err match { case s if !s.trim.isEmpty => log.error(s) case s => } - def info(inf: => String) = + def info(inf: => String): Unit = inf match { case s if s.startsWith("Please login") => loginRequired.compareAndSet(false, true) @@ -330,7 +321,7 @@ object DockerPlugin extends AutoPlugin { case s => } - def buffer[T](f: => T) = f + def buffer[T](f: => T): T = f } val cmd = execCommand ++ Seq("push", tag) diff --git a/src/main/scala/com/typesafe/sbt/packager/docker/DockerSpotifyClientPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/docker/DockerSpotifyClientPlugin.scala index 7260113f6..fb0b08b28 100644 --- a/src/main/scala/com/typesafe/sbt/packager/docker/DockerSpotifyClientPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/docker/DockerSpotifyClientPlugin.scala @@ -1,6 +1,4 @@ -package com.typesafe.sbt -package packager -package docker +package com.typesafe.sbt.packager.docker import java.nio.file.Paths @@ -9,8 +7,7 @@ import com.spotify.docker.client.{DefaultDockerClient, DockerClient, ProgressHan import com.spotify.docker.client.DockerClient.BuildParam import sbt._ import sbt.Keys._ -import packager.Keys._ -import universal.UniversalPlugin.autoImport.stage +import com.typesafe.sbt.packager.universal.UniversalPlugin.autoImport.stage /** * == DockerSpotifyClientPlugin Plugin == @@ -51,15 +48,15 @@ import universal.UniversalPlugin.autoImport.stage */ object DockerSpotifyClientPlugin extends AutoPlugin { - override def requires = DockerPlugin + override def requires: Plugins = DockerPlugin import DockerPlugin.autoImport._ - override lazy val projectSettings = inConfig(Docker)(clientSettings) + override lazy val projectSettings: Seq[Setting[_]] = inConfig(Docker)(clientSettings) def clientSettings = Seq(publishLocal := publishLocalDocker.value) - def publishLocalDocker = Def.task { + def publishLocalDocker: Def.Initialize[Task[Unit]] = Def.task { val context = stage.value val tag = dockerAlias.value.versioned val latest = dockerUpdateLatest.value @@ -70,14 +67,13 @@ object DockerSpotifyClientPlugin extends AutoPlugin { log.info(s"PublishLocal using Docker API ${docker.version().apiVersion()}") - val id = - docker.build(Paths.get(dockerDirectory), tag, new ProgressHandler() { - def progress(message: ProgressMessage) = - Option(message.error()) match { - case Some(error) if error.nonEmpty => log.error(message.error()) - case _ => Option(message.stream()) foreach (v => log.info(v)) - } - }, BuildParam.forceRm()) + docker.build(Paths.get(dockerDirectory), tag, new ProgressHandler() { + def progress(message: ProgressMessage): Unit = + Option(message.error()) match { + case Some(error) if error.nonEmpty => log.error(message.error()) + case _ => Option(message.stream()) foreach (v => log.info(v)) + } + }, BuildParam.forceRm()) if (latest) { val name = tag.substring(0, tag.lastIndexOf(":")) + ":latest" diff --git a/src/main/scala/com/typesafe/sbt/packager/jar/ClasspathJarPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/jar/ClasspathJarPlugin.scala index e68e6936f..134726a49 100644 --- a/src/main/scala/com/typesafe/sbt/packager/jar/ClasspathJarPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/jar/ClasspathJarPlugin.scala @@ -1,5 +1,4 @@ -package com.typesafe.sbt.packager -package archetypes.jar +package com.typesafe.sbt.packager.archetypes.jar import java.io.File import java.util.jar.Attributes @@ -9,20 +8,21 @@ import sbt._ import sbt.Keys._ import com.typesafe.sbt.packager.Keys._ import com.typesafe.sbt.SbtNativePackager.Universal +import com.typesafe.sbt.packager.archetypes.JavaAppPackaging object ClasspathJarPlugin extends AutoPlugin { object autoImport { - val packageJavaClasspathJar = TaskKey[File]( + val packageJavaClasspathJar: TaskKey[File] = TaskKey[File]( "packageJavaClasspathJar", "Creates a Java classpath jar that specifies the classpath in its manifest" ) } import autoImport._ - override def requires = archetypes.JavaAppPackaging + override def requires = JavaAppPackaging - override lazy val projectSettings = Defaults + override lazy val projectSettings: Seq[Setting[_]] = Defaults .packageTaskSettings(packageJavaClasspathJar, mappings in packageJavaClasspathJar) ++ Seq( mappings in packageJavaClasspathJar := Nil, artifactClassifier in packageJavaClasspathJar := Option("classpath"), diff --git a/src/main/scala/com/typesafe/sbt/packager/jar/LauncherJarPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/jar/LauncherJarPlugin.scala index f808c977f..edd244b9b 100644 --- a/src/main/scala/com/typesafe/sbt/packager/jar/LauncherJarPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/jar/LauncherJarPlugin.scala @@ -1,5 +1,4 @@ -package com.typesafe.sbt.packager -package archetypes.jar +package com.typesafe.sbt.packager.archetypes.jar import java.io.File import java.util.jar.Attributes @@ -9,11 +8,12 @@ import sbt._ import sbt.Keys._ import com.typesafe.sbt.packager.Keys._ import com.typesafe.sbt.SbtNativePackager.Universal +import com.typesafe.sbt.packager.archetypes.JavaAppPackaging object LauncherJarPlugin extends AutoPlugin { object autoImport { - val packageJavaLauncherJar = TaskKey[File]( + val packageJavaLauncherJar: TaskKey[File] = TaskKey[File]( "packageJavaLauncherJar", "Creates a Java launcher jar that specifies the main class and classpath in its manifest" ) @@ -21,9 +21,9 @@ object LauncherJarPlugin extends AutoPlugin { import autoImport._ - override def requires = archetypes.JavaAppPackaging + override def requires = JavaAppPackaging - override lazy val projectSettings = Defaults + override lazy val projectSettings: Seq[Setting[_]] = Defaults .packageTaskSettings(packageJavaLauncherJar, mappings in packageJavaLauncherJar) ++ Seq( mappings in packageJavaLauncherJar := Nil, artifactClassifier in packageJavaLauncherJar := Option("launcher"), diff --git a/src/main/scala/com/typesafe/sbt/packager/jdkpackager/JDKPackagerKeys.scala b/src/main/scala/com/typesafe/sbt/packager/jdkpackager/JDKPackagerKeys.scala index fe4bd404b..910cc66cb 100644 --- a/src/main/scala/com/typesafe/sbt/packager/jdkpackager/JDKPackagerKeys.scala +++ b/src/main/scala/com/typesafe/sbt/packager/jdkpackager/JDKPackagerKeys.scala @@ -4,6 +4,8 @@ import com.typesafe.sbt.SbtNativePackager import com.typesafe.sbt.packager.jdkpackager.JDKPackagerPlugin.autoImport._ import sbt._ +import scala.xml.Node + /** * Keys specific to deployment via the `javapackger` tool. * @@ -12,9 +14,10 @@ import sbt._ */ trait JDKPackagerKeys { - val jdkPackagerBasename = settingKey[String]("Filename sans extension for generated installer package.") + val jdkPackagerBasename: SettingKey[String] = + settingKey[String]("Filename sans extension for generated installer package.") - val jdkPackagerType = settingKey[String]( + val jdkPackagerType: SettingKey[String] = settingKey[String]( """Value passed as the `native` attribute to `fx:deploy` task. |Per `javapackager` documentation, this may be one of the following: | @@ -37,10 +40,10 @@ trait JDKPackagerKeys { """.stripMargin ) - val jdkPackagerToolkit = + val jdkPackagerToolkit: SettingKey[JDKPackagerToolkit] = settingKey[JDKPackagerToolkit]("GUI toolkit used in app. Either `JavaFXToolkit` (default) or `SwingToolkit`") - val jdkPackagerJVMArgs = settingKey[Seq[String]]( + val jdkPackagerJVMArgs: SettingKey[Seq[String]] = settingKey[Seq[String]]( """Sequence of arguments to pass to the JVM. |Default: `Seq("-Xmx768m")`. |Details: @@ -48,7 +51,7 @@ trait JDKPackagerKeys { """.stripMargin ) - val jdkPackagerAppArgs = settingKey[Seq[String]]( + val jdkPackagerAppArgs: SettingKey[Seq[String]] = settingKey[Seq[String]]( """List of command line arguments to pass to the application on launch. |Default: `Seq.empty` |Details: @@ -57,7 +60,7 @@ trait JDKPackagerKeys { """.stripMargin ) - val jdkPackagerProperties = settingKey[Map[String, String]]( + val jdkPackagerProperties: SettingKey[Map[String, String]] = settingKey[Map[String, String]]( """Map of `System` properties to define in application. |Default: `Map.empty` |Details: @@ -65,7 +68,7 @@ trait JDKPackagerKeys { """.stripMargin ) - val jdkAppIcon = settingKey[Option[File]]("""Path to platform-specific application icon: + val jdkAppIcon: SettingKey[Option[File]] = settingKey[Option[File]]("""Path to platform-specific application icon: | * `icns`: MacOS | * `ico`: Windows | * `png`: Linux @@ -73,7 +76,7 @@ trait JDKPackagerKeys { | Defaults to generic Java icon. """.stripMargin) - val jdkPackagerAssociations = settingKey[Seq[FileAssociation]]( + val jdkPackagerAssociations: SettingKey[Seq[FileAssociation]] = settingKey[Seq[FileAssociation]]( """Set of application file associations to register for the application. |Example: `jdkPackagerAssociations := Seq(FileAssociation("foo", "application/x-foo", Foo Data File", iconPath)) |Default: `Seq.empty` @@ -84,21 +87,22 @@ trait JDKPackagerKeys { ) /** Config for scoping keys outside of Global . */ - val JDKPackager = config("jdkPackager") extend SbtNativePackager.Universal + val JDKPackager: Configuration = config("jdkPackager") extend SbtNativePackager.Universal // ------------------------------------------ // Keys to be defined in JDKPackager config. // ------------------------------------------ - val antPackagerTasks = settingKey[Option[File]]( + val antPackagerTasks: SettingKey[Option[File]] = settingKey[Option[File]]( "Path to `ant-javafx.jar` library in JDK. By plugin attempts to find location based on `java.home` property. Specifying `JAVA_HOME` or `JDK_HOME` can help." ) - val antBuildDefn = + val antBuildDefn: TaskKey[Node] = taskKey[xml.Node]("Generates a Ant XML DOM defining package generating build for JDK provided Ant task.") - val writeAntBuild = taskKey[File]("Write the Ant `build.xml` file to the jdkpackager target directory") + val writeAntBuild: TaskKey[File] = + taskKey[File]("Write the Ant `build.xml` file to the jdkpackager target directory") - val antExtraClasspath = + val antExtraClasspath: SettingKey[Seq[File]] = settingKey[Seq[File]]("Additional classpath entries for the JavaFX Ant task beyond `antPackagerTasks`") } diff --git a/src/main/scala/com/typesafe/sbt/packager/jdkpackager/JDKPackagerPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/jdkpackager/JDKPackagerPlugin.scala index 060e97db8..856573178 100644 --- a/src/main/scala/com/typesafe/sbt/packager/jdkpackager/JDKPackagerPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/jdkpackager/JDKPackagerPlugin.scala @@ -27,12 +27,12 @@ object JDKPackagerPlugin extends AutoPlugin { } import autoImport._ - override def requires = JavaAppPackaging && LauncherJarPlugin + override def requires: Plugins = JavaAppPackaging && LauncherJarPlugin private val dirname = JDKPackager.name.toLowerCase override def projectConfigurations: Seq[Configuration] = Seq(JDKPackager) - override lazy val projectSettings = Seq( + override lazy val projectSettings: Seq[Setting[_]] = Seq( jdkAppIcon := None, jdkPackagerType := "installer", jdkPackagerBasename := packageName.value + "-pkg", @@ -94,6 +94,6 @@ object JDKPackagerDeployPlugin extends AutoPlugin { import JDKPackagerPlugin.autoImport._ override def requires = JDKPackagerPlugin - override def projectSettings = + override def projectSettings: Seq[Setting[_]] = SettingsHelper.makeDeploymentSettings(JDKPackager, packageBin in JDKPackager, "jdkPackager") } diff --git a/src/main/scala/com/typesafe/sbt/packager/linux/LinuxPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/linux/LinuxPlugin.scala index 37b46c976..3e13655d0 100644 --- a/src/main/scala/com/typesafe/sbt/packager/linux/LinuxPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/linux/LinuxPlugin.scala @@ -1,14 +1,12 @@ package com.typesafe.sbt.packager.linux import sbt._ -import sbt.Keys.{mappings, name, normalizedName, sourceDirectory} +import sbt.Keys.{mappings, name, sourceDirectory, streams} import com.typesafe.sbt.SbtNativePackager.Universal import com.typesafe.sbt.packager.MappingsHelper import com.typesafe.sbt.packager.Keys._ import com.typesafe.sbt.packager.universal.UniversalPlugin -import com.typesafe.sbt.packager.archetypes.{TemplateWriter} -import com.typesafe.sbt.packager.archetypes.systemloader.ServerLoader -import LinuxPlugin.Users +import com.typesafe.sbt.packager.archetypes.TemplateWriter /** * Plugin containing all the generic values used for @@ -48,22 +46,23 @@ object LinuxPlugin extends AutoPlugin { def linuxSettings: Seq[Setting[_]] = Seq( linuxPackageMappings := Seq.empty, linuxPackageSymlinks := Seq.empty, - sourceDirectory in Linux <<= sourceDirectory apply (_ / "linux"), - generateManPages <<= (sourceDirectory in Linux, sbt.Keys.streams) map { (dir, s) => - for (file <- (dir / "usr/share/man/man1" ** "*.1").get) { + sourceDirectory in Linux := sourceDirectory.value / "linux", + generateManPages := { + val log = streams.value.log + for (file <- ((sourceDirectory in Linux).value / "usr/share/man/man1" ** "*.1").get) { val man = makeMan(file) - s.log.info("Generated man page for[" + file + "] =") - s.log.info(man) + log.info("Generated man page for[" + file + "] =") + log.info(man) } }, - packageSummary in Linux <<= packageSummary, - packageDescription in Linux <<= packageDescription, - name in Linux <<= name, - packageName in Linux <<= packageName, - executableScriptName in Linux <<= executableScriptName, - daemonUser in Linux <<= packageName in Linux, + packageSummary in Linux := packageSummary.value, + packageDescription in Linux := packageDescription.value, + name in Linux := name.value, + packageName in Linux := packageName.value, + executableScriptName in Linux := executableScriptName.value, + daemonUser in Linux := (packageName in Linux).value, daemonUserUid in Linux := None, - daemonGroup in Linux <<= daemonUser in Linux, + daemonGroup in Linux := (daemonUser in Linux).value, daemonGroupGid in Linux := None, daemonShell in Linux := "/bin/false", defaultLinuxInstallLocation := "/usr/share", @@ -114,30 +113,35 @@ object LinuxPlugin extends AutoPlugin { (mappings in Universal).value ), // Now we generate symlinks. - linuxPackageSymlinks <++= (packageName in Linux, mappings in Universal, defaultLinuxInstallLocation) map { - (pkg, mappings, installLocation) => - for { - (file, name) <- mappings - if !file.isDirectory - if name startsWith "bin/" - if !(name endsWith ".bat") // IGNORE windows-y things. - } yield LinuxSymlink("/usr/" + name, installLocation + "/" + pkg + "/" + name) + linuxPackageSymlinks ++= { + val installLocation = defaultLinuxInstallLocation.value + val linuxPackageName = (packageName in Linux).value + for { + (file, name) <- (mappings in Universal).value + if !file.isDirectory + if name startsWith "bin/" + if !(name endsWith ".bat") // IGNORE windows-y things. + } yield LinuxSymlink("/usr/" + name, installLocation + "/" + linuxPackageName + "/" + name) }, // Map configuration files - linuxPackageSymlinks <++= (packageName in Linux, - mappings in Universal, - defaultLinuxInstallLocation, - defaultLinuxConfigLocation) - map { (pkg, mappings, installLocation, configLocation) => - val needsConfLink = - mappings exists { - case (file, name) => - (name startsWith "conf/") && !file.isDirectory - } - if (needsConfLink) - Seq(LinuxSymlink(link = configLocation + "/" + pkg, destination = installLocation + "/" + pkg + "/conf")) - else Seq.empty - } + linuxPackageSymlinks ++= { + val linuxPackageName = (packageName in Linux).value + val installLocation = defaultLinuxInstallLocation.value + val configLocation = defaultLinuxConfigLocation.value + val needsConfLink = + (mappings in Universal).value exists { + case (file, destination) => + (destination startsWith "conf/") && !file.isDirectory + } + if (needsConfLink) + Seq( + LinuxSymlink( + link = configLocation + "/" + linuxPackageName, + destination = installLocation + "/" + linuxPackageName + "/conf" + ) + ) + else Seq.empty + } ) def makeReplacements(author: String, @@ -207,13 +211,13 @@ object LinuxPlugin extends AutoPlugin { val (directories, nondirectories) = mappings.partition(_._1.isDirectory) val (binaries, nonbinaries) = nondirectories.partition(_._1.canExecute) val (manPages, nonManPages) = nonbinaries partition { - case (file, name) => (name contains "man/") && (name endsWith ".1") + case (_, destination) => (destination contains "man/") && (destination endsWith ".1") } val compressedManPages = for ((file, name) <- manPages) yield file -> (name + ".gz") val (configFiles, remaining) = nonManPages partition { - case (file, name) => (name contains "etc/") || (name contains "conf/") + case (_, destination) => (destination contains "etc/") || (destination contains "conf/") } def packageMappingWithRename(mappings: (File, String)*): LinuxPackageMapping = { val renamed = @@ -223,7 +227,7 @@ object LinuxPlugin extends AutoPlugin { } Seq( - packageMappingWithRename((binaries ++ directories): _*) withUser user withGroup group withPerms "0755", + packageMappingWithRename(binaries ++ directories: _*) withUser user withGroup group withPerms "0755", packageMappingWithRename(compressedManPages: _*).gzipped withUser user withGroup group withPerms "0644", packageMappingWithRename(configFiles: _*) withConfig () withUser user withGroup group withPerms "0644", packageMappingWithRename(remaining: _*) withUser user withGroup group withPerms "0644" 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 d2521a5a4..53b0a0c37 100644 --- a/src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala @@ -22,7 +22,7 @@ object RpmPlugin extends AutoPlugin { override def requires = LinuxPlugin object autoImport extends RpmKeys { - val Rpm = config("rpm") extend Linux + val Rpm: Configuration = config("rpm") extend Linux val RpmConstants = Names } @@ -89,36 +89,49 @@ object RpmPlugin extends AutoPlugin { rpmPosttrans := None, rpmPreun := None, rpmPostun := None, - rpmScriptsDirectory <<= sourceDirectory apply (_ / "rpm" / Names.Scriptlets), + rpmScriptsDirectory := sourceDirectory.value / "rpm" / Names.Scriptlets, // Explicitly defer default settings to generic Linux Settings. - maintainerScripts in Rpm <<= maintainerScripts in Linux, - packageSummary in Rpm <<= packageSummary in Linux, - packageDescription in Rpm <<= packageDescription in Linux, - target in Rpm <<= target(_ / "rpm"), - name in Rpm <<= name in Linux, - packageName in Rpm <<= packageName in Linux, - executableScriptName in Rpm <<= executableScriptName in Linux, + maintainerScripts in Rpm := (maintainerScripts in Linux).value, + packageSummary in Rpm := (packageSummary in Linux).value, + packageDescription in Rpm := (packageDescription in Linux).value, + target in Rpm := target.value / "rpm", + name in Rpm := (name in Linux).value, + packageName in Rpm := (packageName in Linux).value, + executableScriptName in Rpm := (executableScriptName in Linux).value, rpmDaemonLogFile := s"${(packageName in Linux).value}.log", - daemonStdoutLogFile in Rpm := Some((rpmDaemonLogFile).value), + daemonStdoutLogFile in Rpm := Some(rpmDaemonLogFile.value), // override the linux sourceDirectory setting - sourceDirectory in Rpm <<= sourceDirectory, + sourceDirectory in Rpm := sourceDirectory.value, 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, + rpmMetadata := RpmMetadata( + (packageName in Rpm).value, + (version in Rpm).value, + rpmRelease.value, + rpmPrefix.value, + (packageArchitecture in Rpm).value, + rpmVendor.value, + rpmOs.value, + (packageSummary in Rpm).value, + (packageDescription in Rpm).value, + rpmAutoprov.value, + rpmAutoreq.value + ), + rpmDescription := RpmDescription( + rpmLicense.value, + rpmDistribution.value, + rpmUrl.value, + rpmGroup.value, + rpmPackager.value, + rpmIcon.value, + rpmChangelogFile.value + ), + rpmDependencies := RpmDependencies( + rpmProvides.value, + rpmRequirements.value, + rpmPrerequisites.value, + rpmObsoletes.value, + rpmConflicts.value + ), maintainerScripts in Rpm := { val scripts = (maintainerScripts in Rpm).value if (!rpmBrpJavaRepackJars.value) { @@ -131,21 +144,24 @@ object RpmPlugin extends AutoPlugin { }, 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) + rpmSpecConfig := RpmSpec( + rpmMetadata.value, + rpmDescription.value, + rpmDependencies.value, + rpmSetarch.value, + rpmScripts.value, + (linuxPackageMappings in Rpm).value, + (linuxPackageSymlinks in Rpm).value, + (defaultLinuxInstallLocation in Rpm).value + ), + packageBin in Rpm := { + val log = streams.value.log + val spec = rpmSpecConfig.value + spec.validate(log) + RpmHelper.buildRpm(spec, (target in Rpm).value, log) }, - rpmLint <<= (packageBin in Rpm, streams) map { (rpm, s) => - (Process(Seq("rpmlint", "-v", rpm.getAbsolutePath)) ! s.log) match { + rpmLint := { + Process(Seq("rpmlint", "-v", (packageBin in Rpm).value.getAbsolutePath)) ! streams.value.log match { case 0 => () case x => sys.error("Failed to run rpmlint, exit status: " + x) } @@ -159,6 +175,6 @@ object RpmDeployPlugin extends AutoPlugin { override def requires = RpmPlugin - override def projectSettings = + override def projectSettings: Seq[Setting[_]] = SettingsHelper.makeDeploymentSettings(Rpm, packageBin in Rpm, "rpm") } diff --git a/src/main/scala/com/typesafe/sbt/packager/universal/UniversalPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/universal/UniversalPlugin.scala index 3ed9b00af..9e821297f 100644 --- a/src/main/scala/com/typesafe/sbt/packager/universal/UniversalPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/universal/UniversalPlugin.scala @@ -1,23 +1,11 @@ -package com.typesafe.sbt -package packager -package universal +package com.typesafe.sbt.packager.universal import sbt._ -import sbt.Keys.{ - cacheDirectory, - mappings, - name, - normalizedName, - packageBin, - packageDoc, - packageSrc, - sourceDirectory, - streams, - target, - version -} -import packager.Keys._ +import sbt.Keys._ import Archives._ +import com.typesafe.sbt.SbtNativePackager +import com.typesafe.sbt.packager.Keys._ +import com.typesafe.sbt.packager.{SettingsHelper, Stager} import sbt.Keys.TaskStreams /** @@ -37,9 +25,9 @@ import sbt.Keys.TaskStreams object UniversalPlugin extends AutoPlugin { object autoImport extends UniversalKeys { - val Universal = config("universal") - val UniversalDocs = config("universal-docs") - val UniversalSrc = config("universal-src") + val Universal: Configuration = config("universal") + val UniversalDocs: Configuration = config("universal-docs") + val UniversalSrc: Configuration = config("universal-src") /** * Use native zipping instead of java based zipping @@ -58,18 +46,18 @@ object UniversalPlugin extends AutoPlugin { Seq(Universal, UniversalDocs, UniversalSrc) /** The basic settings for the various packaging types. */ - override lazy val projectSettings = Seq[Setting[_]]( + override lazy val projectSettings: Seq[Setting[_]] = Seq[Setting[_]]( // For now, we provide delegates from dist/stage to universal... - dist <<= dist in Universal, - stage <<= stage in Universal, + dist := (dist in Universal).value, + stage := (stage in Universal).value, // TODO - New default to naming, is this right? // TODO - We may need to do this for UniversalSrcs + UnviersalDocs - name in Universal <<= name, - name in UniversalDocs <<= name in Universal, - name in UniversalSrc <<= name in Universal, - packageName in Universal <<= packageName, + name in Universal := name.value, + name in UniversalDocs := (name in Universal).value, + name in UniversalSrc := (name in Universal).value, + packageName in Universal := packageName.value, topLevelDirectory := Some((packageName in Universal).value), - executableScriptName in Universal <<= executableScriptName + executableScriptName in Universal := executableScriptName.value ) ++ makePackageSettingsForConfig(Universal) ++ makePackageSettingsForConfig(UniversalDocs) ++ @@ -84,15 +72,15 @@ object UniversalPlugin extends AutoPlugin { makePackageSettings(packageXzTarball, config)(makeTxz) ++ inConfig(config)( Seq( - packageName <<= (packageName, version) apply (_ + "-" + _), - mappings <<= sourceDirectory map findSources, - dist <<= (packageBin, streams) map printDist, - stagingDirectory <<= target apply (_ / "stage"), - stage <<= (streams, stagingDirectory, mappings) map Stager.stage(config.name) + packageName := (packageName.value + "-" + version.value), + mappings := findSources(sourceDirectory.value), + dist := printDist(packageBin.value, streams.value), + stagingDirectory := target.value / "stage", + stage := Stager.stage(config.name)(streams.value, stagingDirectory.value, mappings.value) ) ) ++ Seq( - sourceDirectory in config <<= sourceDirectory apply (_ / config.name), - target in config <<= target apply (_ / config.name) + sourceDirectory in config := sourceDirectory.value / config.name, + target in config := target.value / config.name ) private[this] def defaultUniversalArchiveOptions: Seq[Setting[_]] = Seq( @@ -119,12 +107,14 @@ object UniversalPlugin extends AutoPlugin { inConfig(config)( Seq( universalArchiveOptions in packageKey := Nil, - mappings in packageKey <<= mappings map checkMappings, - packageKey <<= (target, - packageName, - mappings in packageKey, - topLevelDirectory, - universalArchiveOptions in packageKey) map packager + mappings in packageKey := checkMappings(mappings.value), + packageKey := packager( + target.value, + packageName.value, + (mappings in packageKey).value, + topLevelDirectory.value, + (universalArchiveOptions in packageKey).value + ) ) ) @@ -148,7 +138,7 @@ object UniversalDeployPlugin extends AutoPlugin { override def requires = UniversalPlugin - override def projectSettings = + override def projectSettings: Seq[Setting[_]] = SettingsHelper.makeDeploymentSettings(Universal, packageBin in Universal, "zip") ++ SettingsHelper.addPackage(Universal, packageZipTarball in Universal, "tgz") ++ SettingsHelper.makeDeploymentSettings(UniversalDocs, packageBin in UniversalDocs, "zip") ++ diff --git a/src/main/scala/com/typesafe/sbt/packager/windows/WindowsPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/windows/WindowsPlugin.scala index 1c8a151c7..e264fb908 100644 --- a/src/main/scala/com/typesafe/sbt/packager/windows/WindowsPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/windows/WindowsPlugin.scala @@ -31,110 +31,105 @@ import SbtNativePackager.Universal object WindowsPlugin extends AutoPlugin { object autoImport extends WindowsKeys { - val Windows = config("windows") + val Windows: Configuration = config("windows") } import autoImport._ - override lazy val projectSettings = windowsSettings ++ mapGenericFilesToWindows + override lazy val projectSettings: Seq[Setting[_]] = windowsSettings ++ mapGenericFilesToWindows override def requires = universal.UniversalPlugin override def projectConfigurations: Seq[Configuration] = Seq(Windows) - // format: off /** * default windows settings */ - def windowsSettings: Seq[Setting[_]] = Seq( - sourceDirectory in Windows <<= sourceDirectory(_ / "windows"), - target in Windows <<= target apply (_ / "windows"), - // TODO - Should this use normalized name like the linux guys? - name in Windows <<= name, - packageName in Windows <<= packageName, - // Defaults so that our simplified building works - candleOptions := Seq("-ext", "WixUtilExtension"), - lightOptions := Seq("-ext", "WixUIExtension", - "-ext", "WixUtilExtension", - "-cultures:en-us"), - wixProductId := WixHelper.makeGUID, - wixProductUpgradeId := WixHelper.makeGUID, - wixMajorVersion := 3, - maintainer in Windows <<= maintainer, - packageSummary in Windows <<= packageSummary, - packageDescription in Windows <<= packageDescription, - wixProductLicense <<= (sourceDirectory in Windows) map { dir => - // TODO - document this default. - val default = dir / "License.rtf" - if (default.exists) Some(default) - else None - }, - wixPackageInfo <<= ( - wixProductId, - wixProductUpgradeId, - version in Windows, - maintainer in Windows, - packageSummary in Windows, - packageDescription in Windows - ) apply { (id, uid, version, mtr, title, desc) => - WindowsProductInfo( - id = id, - title = title, - version = version, - maintainer = mtr, - description = desc, - upgradeId = uid, - comments = "TODO - we need comments." // TODO - allow comments - ) + def windowsSettings: Seq[Setting[_]] = + Seq( + sourceDirectory in Windows := sourceDirectory.value / "windows", + target in Windows := target.value / "windows", + // TODO - Should this use normalized name like the linux guys? + name in Windows := name.value, + packageName in Windows := packageName.value, + // Defaults so that our simplified building works + candleOptions := Seq("-ext", "WixUtilExtension"), + lightOptions := Seq("-ext", "WixUIExtension", "-ext", "WixUtilExtension", "-cultures:en-us"), + wixProductId := WixHelper.makeGUID, + wixProductUpgradeId := WixHelper.makeGUID, + wixMajorVersion := 3, + maintainer in Windows := maintainer.value, + packageSummary in Windows := packageSummary.value, + packageDescription in Windows := packageDescription.value, + wixProductLicense := { + // TODO - document this default. + val default = (sourceDirectory in Windows).value / "License.rtf" + if (default.exists) Some(default) + else None }, - wixFeatures := Seq.empty, - wixProductConfig <<= (name in Windows, wixPackageInfo, wixFeatures, wixProductLicense) map { (name, product, features, license) => - WixHelper.makeWixProductConfig(name, product, features, license) - }, - wixConfig <<= (name in Windows, wixPackageInfo, wixMajorVersion, wixProductConfig) map { (name, product, wmv, nested) => - val namespaceDefinitions = WixHelper.getNameSpaceDefinitions(wmv) - WixHelper.makeWixConfig(name, product, namespaceDefinitions, nested) - }, - wixConfig in Windows <<= wixConfig, - wixProductConfig in Windows <<= wixProductConfig, - wixFile <<= (wixConfig in Windows, name in Windows, target in Windows) map { (c, n, t) => - val f = t / (n + ".wxs") - IO.write(f, c.toString) - f - } - ) ++ inConfig(Windows)(Seq( - packageBin <<= (mappings, wixFile, name, target, candleOptions, lightOptions, streams) map { (m, f, n, t, co, lo, s) => - val msi = t / (n + ".msi") - // First we have to move everything (including the wix file) to our target directory. - val wix = t / (n + ".wix") - if (f.getAbsolutePath != wix.getAbsolutePath) IO.copyFile(f, wix) - IO.copy(for ((f, to) <- m) yield (f, t / to)) - // Now compile WIX - val wixdir = Option(System.getenv("WIX")) getOrElse sys.error("WIX environment not found. Please ensure WIX is installed on this computer.") - val candleCmd = Seq(wixdir + "\\bin\\candle.exe", wix.getAbsolutePath) ++ co - s.log.debug(candleCmd mkString " ") - Process(candleCmd, Some(t)) ! s.log match { - case 0 => () - case x => sys.error("Unable to run WIX compilation to wixobj...") - } - // Now create MSI - val wixobj = t / (n + ".wixobj") - val lightCmd = Seq(wixdir + "\\bin\\light.exe", wixobj.getAbsolutePath) ++ lo - s.log.debug(lightCmd mkString " ") - Process(lightCmd, Some(t)) ! s.log match { - case 0 => () - case x => sys.error("Unable to run build msi...") - } - msi + wixPackageInfo := WindowsProductInfo( + id = wixProductId.value, + title = (packageSummary in Windows).value, + version = (version in Windows).value, + maintainer = (maintainer in Windows).value, + description = (packageDescription in Windows).value, + upgradeId = wixProductUpgradeId.value, + comments = "TODO - we need comments." // TODO - allow comments + ), + wixFeatures := Seq.empty, + wixProductConfig := WixHelper.makeWixProductConfig( + (name in Windows).value, + wixPackageInfo.value, + wixFeatures.value, + wixProductLicense.value + ), + wixConfig := WixHelper.makeWixConfig( + (name in Windows).value, + wixPackageInfo.value, + WixHelper.getNameSpaceDefinitions(wixMajorVersion.value), + wixProductConfig.value + ), + wixConfig in Windows := wixConfig.value, + wixProductConfig in Windows := wixProductConfig.value, + wixFile := { + val config = (wixConfig in Windows).value + val wixConfigFile = (target in Windows).value / ((name in Windows).value + ".wxs") + IO.write(wixConfigFile, config.toString) + wixConfigFile + } + ) ++ inConfig(Windows)(Seq(packageBin := { + val wixFileValue = wixFile.value + val msi = target.value / (name.value + ".msi") + // First we have to move everything (including the wix file) to our target directory. + val wix = target.value / (name.value + ".wix") + if (wixFileValue.getAbsolutePath != wix.getAbsolutePath) IO.copyFile(wixFileValue, wix) + IO.copy(for ((f, to) <- mappings.value) yield (f, target.value / to)) + // Now compile WIX + val wixdir = Option(System.getenv("WIX")) getOrElse sys.error( + "WIX environment not found. Please ensure WIX is installed on this computer." + ) + val candleCmd = Seq(wixdir + "\\bin\\candle.exe", wix.getAbsolutePath) ++ candleOptions.value + streams.value.log.debug(candleCmd mkString " ") + Process(candleCmd, Some(target.value)) ! streams.value.log match { + case 0 => () + case exitCode => sys.error(s"Unable to run WIX compilation to wixobj. Exited with ${exitCode}") + } + // Now create MSI + val wixobj = target.value / (name.value + ".wixobj") + val lightCmd = Seq(wixdir + "\\bin\\light.exe", wixobj.getAbsolutePath) ++ lightOptions.value + streams.value.log.debug(lightCmd mkString " ") + Process(lightCmd, Some(target.value)) ! streams.value.log match { + case 0 => () + case exitCode => sys.error(s"Unable to run build msi. Exited with ${exitCode}") } - )) - // format: on + msi + })) /** * set the `mappings in Windows` and the `wixFeatures` */ def mapGenericFilesToWindows: Seq[Setting[_]] = Seq( - mappings in Windows <<= mappings in Universal, - wixFeatures <<= (packageName in Windows, mappings in Windows) map makeWindowsFeatures + mappings in Windows := (mappings in Universal).value, + wixFeatures := makeWindowsFeatures((packageName in Windows).value, (mappings in Windows).value) ) /** @@ -146,13 +141,12 @@ object WindowsPlugin extends AutoPlugin { */ def makeWindowsFeatures(name: String, mappings: Seq[(File, String)]): Seq[windows.WindowsFeature] = { // TODO select main script! Filter Config links! - import windows._ val files = for { (file, name) <- mappings if !file.isDirectory - } yield ComponentFile(name, editable = (name startsWith "conf")) + } yield ComponentFile(name, editable = name startsWith "conf") val corePackage = WindowsFeature( id = WixHelper.cleanStringForId(name + "_core").takeRight(38), // Must be no longer @@ -193,6 +187,6 @@ object WindowsDeployPlugin extends AutoPlugin { override def requires = WindowsPlugin - override def projectSettings = + override def projectSettings: Seq[Setting[_]] = SettingsHelper.makeDeploymentSettings(Windows, packageBin in Windows, "msi") } diff --git a/src/sbt-test/universal/multiproject-classifiers/project/Build.scala b/src/sbt-test/universal/multiproject-classifiers/project/Build.scala index 7e2ae497f..7dd296f0e 100644 --- a/src/sbt-test/universal/multiproject-classifiers/project/Build.scala +++ b/src/sbt-test/universal/multiproject-classifiers/project/Build.scala @@ -3,53 +3,51 @@ import Keys._ import com.typesafe.sbt.SbtNativePackager._ import com.typesafe.sbt.packager.Keys._ +// FIXME replace Build with AutoPlugin object MutliBuild extends Build { - + val appVersion = "1.0" - + val mySettings: Seq[Setting[_]] = packageArchetype.java_application ++ - Seq( - organization := "org.test", - version := appVersion, - TaskKey[Unit]("show-files") <<= (name, target, streams) map { (n, t, s) => + Seq(organization := "org.test", version := appVersion, TaskKey[Unit]("show-files") := { System.out.synchronized { - println("Files in ["+n+"]") - val files = (t / "universal/stage").***.get + println("Files in [" + name.value + "]") + val files = (target.value / "universal/stage").***.get files foreach println } - } - ) + }) val assets = config("assets") lazy val sub = ( - Project("sub", file("sub")) - settings(mySettings:_*) - settings( - ivyConfigurations += assets, - artifact in assets := artifact.value.copy(classifier = Some("assets")), - packagedArtifacts += { - val file = target.value / "assets.jar" - val assetsDir = baseDirectory.value / "src" / "main" / "assets" - val sources = assetsDir.***.filter(_.isFile) pair relativeTo(assetsDir) - IO.zip(sources, file) - (artifact in assets).value -> file - }, - exportedProducts in assets := { - Seq( - Attributed.blank(baseDirectory.value / "src" / "main" / "assets") - .put(artifact.key, (artifact in assets).value) - .put(AttributeKey[ModuleID]("module-id"), projectID.value) - ) - } + Project("sub", file("sub")) + settings (mySettings: _*) + settings ( + ivyConfigurations += assets, + artifact in assets := artifact.value.copy(classifier = Some("assets")), + packagedArtifacts += { + val file = target.value / "assets.jar" + val assetsDir = baseDirectory.value / "src" / "main" / "assets" + val sources = assetsDir.***.filter(_.isFile) pair relativeTo(assetsDir) + IO.zip(sources, file) + (artifact in assets).value -> file + }, + exportedProducts in assets := { + Seq( + Attributed + .blank(baseDirectory.value / "src" / "main" / "assets") + .put(artifact.key, (artifact in assets).value) + .put(AttributeKey[ModuleID]("module-id"), projectID.value) + ) + } + ) ) - ) - + lazy val root = ( - Project("root", file(".")) - settings(mySettings:_*) - dependsOn(sub % "compile->compile;compile->assets") - ) + Project("root", file(".")) + settings (mySettings: _*) + dependsOn (sub % "compile->compile;compile->assets") + ) } diff --git a/src/sbt-test/universal/multiproject-java-app-archetype/project/Build.scala b/src/sbt-test/universal/multiproject-java-app-archetype/project/Build.scala index 2fe3357f6..87aa52f41 100644 --- a/src/sbt-test/universal/multiproject-java-app-archetype/project/Build.scala +++ b/src/sbt-test/universal/multiproject-java-app-archetype/project/Build.scala @@ -2,48 +2,44 @@ import sbt._ import Keys._ import com.typesafe.sbt.SbtNativePackager._ +// FIXME replace Build with AutoPlugin object MutliBuild extends Build { - + val appName = "play-bug-1499" val appVersion = "1.0" - + val mySettings: Seq[Setting[_]] = packageArchetype.java_application ++ - Seq( - organization := "org.test", - version := appVersion, - TaskKey[Unit]("show-files") <<= (name, target, streams) map { (n, t, s) => + Seq(organization := "org.test", version := appVersion, TaskKey[Unit]("show-files") := { System.out.synchronized { - println("Files in ["+n+"]") - val files = (t / "universal/stage").***.get + println("Files in [" + name.value + "]") + val files = (target.value / "universal/stage").***.get files foreach println } - } - ) - - + }) + lazy val common = ( - Project(appName + "-common", file("module/common")) - settings(mySettings:_*) - ) - + Project(appName + "-common", file("module/common")) + settings (mySettings: _*) + ) + lazy val foo = ( - Project(appName + "-foo", file("module/foo")) - settings(mySettings:_*) - dependsOn(common) - ) + Project(appName + "-foo", file("module/foo")) + settings (mySettings: _*) + dependsOn (common) + ) lazy val bar = ( - Project(appName + "-bar", file("module/bar")) - settings(mySettings:_*) - dependsOn(common) - ) + Project(appName + "-bar", file("module/bar")) + settings (mySettings: _*) + dependsOn (common) + ) lazy val aaMain = ( - Project(appName + "-main", file(".")) - settings(mySettings:_*) - dependsOn(common,foo,bar) - aggregate(foo,bar) - ) + Project(appName + "-main", file(".")) + settings (mySettings: _*) + dependsOn (common, foo, bar) + aggregate (foo, bar) + ) -} \ No newline at end of file +} diff --git a/test-project-simple/build.sbt b/test-project-simple/build.sbt index 10658a219..5e3d2d622 100644 --- a/test-project-simple/build.sbt +++ b/test-project-simple/build.sbt @@ -4,7 +4,7 @@ libraryDependencies ++= Seq("com.typesafe" % "config" % "1.2.1") mainClass in Compile := Some("ExampleApp") -enablePlugins(JavaServerAppPackaging, JDebPackaging, SystemdPlugin) +enablePlugins(JavaServerAppPackaging, UpstartPlugin) maintainer := "Josh Suereth " packageSummary := "Minimal Native Packager"