Skip to content

Commit

Permalink
Wip/remove symbolic operators (#931)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
muuki88 authored Jan 25, 2017
1 parent e793228 commit 9fa3951
Show file tree
Hide file tree
Showing 21 changed files with 567 additions and 577 deletions.
58 changes: 24 additions & 34 deletions src/main/scala/com/typesafe/sbt/packager/SettingsHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
@@ -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 ==
Expand Down Expand Up @@ -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...
Expand Down Expand Up @@ -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 {
Expand All @@ -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 =>
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -104,40 +107,41 @@ 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(
// === Extra replacements ===
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,
(maintainerScripts in Rpm).value,
(linuxScriptReplacements in Rpm).value
)
)
}

/* ========================================== */
/* ============ Helper Methods ============== */
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand Down
Loading

0 comments on commit 9fa3951

Please sign in to comment.