Skip to content

Commit 9fa3951

Browse files
authored
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
1 parent e793228 commit 9fa3951

21 files changed

+567
-577
lines changed

src/main/scala/com/typesafe/sbt/packager/SettingsHelper.scala

+24-34
Original file line numberDiff line numberDiff line change
@@ -26,44 +26,34 @@ object SettingsHelper {
2626
)
2727

2828
def makeDeploymentSettings(config: Configuration, packageTask: TaskKey[File], extension: String): Seq[Setting[_]] =
29-
(inConfig(config)(Classpaths.publishSettings)) ++ inConfig(config)(
29+
inConfig(config)(Classpaths.publishSettings) ++ inConfig(config)(
3030
Seq(
3131
artifacts := Seq.empty,
3232
packagedArtifacts := Map.empty,
33-
projectID <<= (organization, name, version) apply { (o, n, v) =>
34-
ModuleID(o, n, v)
33+
projectID := ModuleID(organization.value, name.value, version.value),
34+
moduleSettings := InlineConfiguration(projectID.value, projectInfo.value, Seq.empty),
35+
ivyModule := {
36+
val ivy = ivySbt.value
37+
new ivy.Module(moduleSettings.value)
3538
},
36-
moduleSettings <<= (projectID, projectInfo) map { (pid, pinfo) =>
37-
InlineConfiguration(pid, pinfo, Seq.empty)
38-
},
39-
ivyModule <<= (ivySbt, moduleSettings) map { (i, s) =>
40-
new i.Module(s)
41-
},
42-
deliverLocalConfiguration <<= (crossTarget, ivyLoggingLevel) map { (outDir, level) =>
43-
Classpaths.deliverConfig(outDir, logging = level)
44-
},
45-
deliverConfiguration <<= deliverLocalConfiguration,
46-
publishConfiguration <<= (packagedArtifacts, checksums, publishTo, isSnapshot) map {
47-
(as, checks, publishTo, isSnap) =>
48-
new PublishConfiguration(
49-
ivyFile = None,
50-
resolverName = Classpaths.getPublishTo(publishTo).name,
51-
artifacts = as,
52-
checksums = checks,
53-
logging = UpdateLogging.DownloadOnly,
54-
overwrite = isSnap
55-
)
56-
},
57-
publishLocalConfiguration <<= (packagedArtifacts, checksums, isSnapshot) map { (as, checks, isSnap) =>
58-
new PublishConfiguration(
59-
ivyFile = None,
60-
resolverName = "local",
61-
artifacts = as,
62-
checksums = checks,
63-
logging = UpdateLogging.DownloadOnly,
64-
overwrite = isSnap
65-
)
66-
}
39+
deliverLocalConfiguration := Classpaths.deliverConfig(crossTarget.value, logging = ivyLoggingLevel.value),
40+
deliverConfiguration := deliverLocalConfiguration.value,
41+
publishConfiguration := new PublishConfiguration(
42+
ivyFile = None,
43+
resolverName = Classpaths.getPublishTo(publishTo.value).name,
44+
artifacts = packagedArtifacts.value,
45+
checksums = checksums.value,
46+
logging = UpdateLogging.DownloadOnly,
47+
overwrite = isSnapshot.value
48+
),
49+
publishLocalConfiguration := new PublishConfiguration(
50+
ivyFile = None,
51+
resolverName = "local",
52+
artifacts = packagedArtifacts.value,
53+
checksums = checksums.value,
54+
logging = UpdateLogging.DownloadOnly,
55+
overwrite = isSnapshot.value
56+
)
6757
)
6858
) ++ addPackage(config, packageTask, extension)
6959
}

src/main/scala/com/typesafe/sbt/packager/archetypes/JavaApp.scala src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppPackaging.scala

+46-50
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
package com.typesafe.sbt
2-
package packager
3-
package archetypes
1+
package com.typesafe.sbt.packager.archetypes
42

53
import sbt._
6-
import sbt.Keys.{javaOptions, mainClass, mappings, name, sourceDirectory, streams, target}
7-
import packager.Keys.{executableScriptName, packageName}
8-
import linux.{LinuxFileMetaData, LinuxPackageMapping}
9-
import linux.LinuxPlugin.autoImport.{defaultLinuxInstallLocation, linuxPackageMappings}
10-
import SbtNativePackager.{Debian, Universal}
4+
import sbt.Keys._
5+
import com.typesafe.sbt.SbtNativePackager.{Debian, Universal}
6+
import com.typesafe.sbt.packager._
7+
import com.typesafe.sbt.packager.Keys.packageName
8+
import com.typesafe.sbt.packager.linux.{LinuxFileMetaData, LinuxPackageMapping}
9+
import com.typesafe.sbt.packager.linux.LinuxPlugin.autoImport.{defaultLinuxInstallLocation, linuxPackageMappings}
1110

1211
/**
1312
* == Java Application ==
@@ -38,39 +37,45 @@ object JavaAppPackaging extends AutoPlugin {
3837

3938
import JavaAppPackaging.autoImport._
4039

41-
override def requires =
40+
override def requires: Plugins =
4241
debian.DebianPlugin && rpm.RpmPlugin && docker.DockerPlugin && windows.WindowsPlugin
4342

44-
// format: off
4543
override def projectSettings = Seq(
4644
javaOptions in Universal := Nil,
4745
// Here we record the classpath as it's added to the mappings separately, so
4846
// we can use its order to generate the bash/bat scripts.
4947
scriptClasspathOrdering := Nil,
5048
// Note: This is sometimes on the classpath via dependencyClasspath in Runtime.
51-
// We need to figure out why sometimes the Attributed[File] is corrrectly configured
49+
// We need to figure out why sometimes the Attributed[File] is correctly configured
5250
// and sometimes not.
53-
scriptClasspathOrdering <+= (Keys.packageBin in Compile, Keys.projectID, Keys.artifact in Compile in Keys.packageBin) map { (jar, id, art) =>
51+
scriptClasspathOrdering += {
52+
val jar = (packageBin in Compile).value
53+
val id = projectID.value
54+
val art = (artifact in Compile in packageBin).value
5455
jar -> ("lib/" + makeJarName(id.organization, id.name, id.revision, art.name, art.classifier))
5556
},
56-
projectDependencyArtifacts <<= findProjectDependencyArtifacts,
57-
scriptClasspathOrdering <++= (Keys.dependencyClasspath in Runtime, projectDependencyArtifacts) map universalDepMappings,
58-
scriptClasspathOrdering <<= scriptClasspathOrdering map { _.distinct },
59-
mappings in Universal <++= scriptClasspathOrdering,
60-
scriptClasspath <<= scriptClasspathOrdering map makeRelativeClasspathNames,
61-
linuxPackageMappings in Debian <+= (packageName in Debian, defaultLinuxInstallLocation, target in Debian) map {
62-
(name, installLocation, target) =>
63-
// create empty var/log directory
64-
val d = target / installLocation
65-
d.mkdirs()
66-
LinuxPackageMapping(Seq(d -> (installLocation + "/" + name)), LinuxFileMetaData())
57+
projectDependencyArtifacts := findProjectDependencyArtifacts.value,
58+
scriptClasspathOrdering ++= universalDepMappings(
59+
(dependencyClasspath in Runtime).value,
60+
projectDependencyArtifacts.value
61+
),
62+
scriptClasspathOrdering := scriptClasspathOrdering.value.distinct,
63+
mappings in Universal ++= scriptClasspathOrdering.value,
64+
scriptClasspath := makeRelativeClasspathNames(scriptClasspathOrdering.value),
65+
linuxPackageMappings in Debian += {
66+
val name = (packageName in Debian).value
67+
val installLocation = defaultLinuxInstallLocation.value
68+
val targetDir = (target in Debian).value
69+
// create empty var/log directory
70+
val d = targetDir / installLocation
71+
d.mkdirs()
72+
LinuxPackageMapping(Seq(d -> (installLocation + "/" + name)), LinuxFileMetaData())
6773
}
6874
)
69-
// format: on
7075

7176
private def makeRelativeClasspathNames(mappings: Seq[(File, String)]): Seq[String] =
7277
for {
73-
(file, name) <- mappings
78+
(_, name) <- mappings
7479
} yield {
7580
// Here we want the name relative to the lib/ folder...
7681
// For now we just cheat...
@@ -107,30 +112,6 @@ object JavaAppPackaging extends AutoPlugin {
107112
private def dependencyProjectRefs(build: sbt.BuildDependencies, thisProject: ProjectRef): Seq[ProjectRef] =
108113
build.classpathTransitive.getOrElse(thisProject, Nil)
109114

110-
private def filterArtifacts(artifacts: Seq[(Artifact, File)], config: Option[String]): Seq[(Artifact, File)] =
111-
for {
112-
(art, file) <- artifacts
113-
// TODO - Default to compile or default?
114-
if art.configurations.exists(_.name == config.getOrElse("default"))
115-
} yield art -> file
116-
117-
private def extractArtifacts(stateTask: Task[State], ref: ProjectRef): Task[Seq[Attributed[File]]] =
118-
stateTask flatMap { state =>
119-
val extracted = Project extract state
120-
// TODO - Is this correct?
121-
val module = extracted.get(sbt.Keys.projectID in ref)
122-
val artifactTask = extracted get (sbt.Keys.packagedArtifacts in ref)
123-
for {
124-
arts <- artifactTask
125-
} yield {
126-
for {
127-
(art, file) <- arts.toSeq // TODO -Filter!
128-
} yield {
129-
sbt.Attributed.blank(file).put(sbt.Keys.moduleID.key, module).put(sbt.Keys.artifact.key, art)
130-
}
131-
}
132-
}
133-
134115
// TODO - Should we pull in more than just JARs? How do native packages come in?
135116
private def isRuntimeArtifact(dep: Attributed[File]): Boolean =
136117
dep.get(sbt.Keys.artifact.key).map(_.`type` == "jar").getOrElse {
@@ -139,7 +120,7 @@ object JavaAppPackaging extends AutoPlugin {
139120
}
140121

141122
private def findProjectDependencyArtifacts: Def.Initialize[Task[Seq[Attributed[File]]]] =
142-
(sbt.Keys.buildDependencies, sbt.Keys.thisProjectRef, sbt.Keys.state) apply { (build, thisProject, stateTask) =>
123+
(buildDependencies, thisProjectRef, state).apply { (build, thisProject, stateTask) =>
143124
val refs = thisProject +: dependencyProjectRefs(build, thisProject)
144125
// Dynamic lookup of dependencies...
145126
val artTasks = refs map { ref =>
@@ -155,6 +136,21 @@ object JavaAppPackaging extends AutoPlugin {
155136
allArtifactsTask
156137
}
157138

139+
private def extractArtifacts(stateTask: Task[State], ref: ProjectRef): Task[Seq[Attributed[File]]] =
140+
stateTask.flatMap { state =>
141+
val extracted = Project.extract(state)
142+
// TODO - Is this correct?
143+
val module = extracted.get(projectID in ref)
144+
val artifactTask = extracted.get(packagedArtifacts in ref)
145+
for {
146+
arts <- artifactTask
147+
} yield {
148+
for {
149+
(art, file) <- arts.toSeq // TODO -Filter!
150+
} yield Attributed.blank(file).put(moduleID.key, module).put(artifact.key, art)
151+
}
152+
}
153+
158154
private def findRealDep(dep: Attributed[File], projectArts: Seq[Attributed[File]]): Option[Attributed[File]] =
159155
if (dep.data.isFile) Some(dep)
160156
else {

src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala

+34-28
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,20 @@ object JavaServerAppPackaging extends AutoPlugin {
4848
* - config directory
4949
*/
5050
def linuxSettings: Seq[Setting[_]] = Seq(
51-
javaOptions in Linux <<= javaOptions in Universal,
51+
javaOptions in Linux := (javaOptions in Universal).value,
5252
// === logging directory mapping ===
53-
linuxPackageMappings <+= (packageName in Linux,
54-
defaultLinuxLogsLocation,
55-
daemonUser in Linux,
56-
daemonGroup in Linux) map { (name, logsDir, user, group) =>
57-
packageTemplateMapping(logsDir + "/" + name)() withUser user withGroup group withPerms "755"
53+
linuxPackageMappings += {
54+
packageTemplateMapping(defaultLinuxLogsLocation.value + "/" + (packageName in Linux).value)()
55+
.withUser((daemonUser in Linux).value)
56+
.withGroup((daemonGroup in Linux).value)
57+
.withPerms("755")
5858
},
59-
linuxPackageSymlinks <+= (packageName in Linux, defaultLinuxInstallLocation, defaultLinuxLogsLocation) map {
60-
(name, install, logsDir) =>
61-
LinuxSymlink(install + "/" + name + "/logs", logsDir + "/" + name)
59+
linuxPackageSymlinks += {
60+
val name = (packageName in Linux).value
61+
LinuxSymlink(
62+
defaultLinuxInstallLocation.value + "/" + name + "/logs",
63+
defaultLinuxLogsLocation.value + "/" + name
64+
)
6265
},
6366
// === etc config mapping ===
6467
bashScriptEnvConfigLocation := Some("/etc/default/" + (packageName in Linux).value),
@@ -104,40 +107,41 @@ object JavaServerAppPackaging extends AutoPlugin {
104107
)
105108
) ++ Seq(
106109
// === Daemon User and Group ===
107-
daemonUser in Debian <<= daemonUser in Linux,
108-
daemonUserUid in Debian <<= daemonUserUid in Linux,
109-
daemonGroup in Debian <<= daemonGroup in Linux,
110-
daemonGroupGid in Debian <<= daemonGroupGid in Linux
110+
daemonUser in Debian := (daemonUser in Linux).value,
111+
daemonUserUid in Debian := (daemonUserUid in Linux).value,
112+
daemonGroup in Debian := (daemonGroup in Linux).value,
113+
daemonGroupGid in Debian := (daemonGroupGid in Linux).value
111114
)
112115
}
113116

114-
def rpmSettings: Seq[Setting[_]] = {
115-
import RpmPlugin.Names.{Post, Postun, Pre, Preun}
117+
def rpmSettings: Seq[Setting[_]] =
116118
inConfig(Rpm)(etcDefaultConfig) ++
117119
inConfig(Rpm)(
118120
Seq(
119121
// === Extra replacements ===
120122
linuxScriptReplacements ++= bashScriptEnvConfigLocation.value.map(ENV_CONFIG_REPLACEMENT -> _).toSeq,
121123
linuxScriptReplacements += Names.DaemonStdoutLogFileReplacement -> daemonStdoutLogFile.value.getOrElse(""),
122124
// === /var/run/app pid folder ===
123-
linuxPackageMappings <+= (packageName, daemonUser, daemonGroup) map { (name, user, group) =>
124-
packageTemplateMapping("/var/run/" + name)() withUser user withGroup group withPerms "755"
125+
linuxPackageMappings += {
126+
packageTemplateMapping("/var/run/" + packageName.value)()
127+
.withUser(daemonUser.value)
128+
.withGroup(daemonGroup.value)
129+
.withPerms("755")
125130
}
126131
)
127132
) ++ Seq(
128133
// === Daemon User and Group ===
129-
daemonUser in Rpm <<= daemonUser in Linux,
130-
daemonUserUid in Rpm <<= daemonUserUid in Linux,
131-
daemonGroup in Rpm <<= daemonGroup in Linux,
132-
daemonGroupGid in Rpm <<= daemonGroupGid in Linux,
134+
daemonUser in Rpm := (daemonUser in Linux).value,
135+
daemonUserUid in Rpm := (daemonUserUid in Linux).value,
136+
daemonGroup in Rpm := (daemonGroup in Linux).value,
137+
daemonGroupGid in Rpm := (daemonGroupGid in Linux).value,
133138
// == Maintainer scripts ===
134139
maintainerScripts in Rpm := rpmScriptletContents(
135140
rpmScriptsDirectory.value,
136141
(maintainerScripts in Rpm).value,
137142
(linuxScriptReplacements in Rpm).value
138143
)
139144
)
140-
}
141145

142146
/* ========================================== */
143147
/* ============ Helper Methods ============== */
@@ -154,12 +158,14 @@ object JavaServerAppPackaging extends AutoPlugin {
154158
*/
155159
private[this] def getEtcTemplateSource(sourceDirectory: File, loader: Option[ServerLoader]): java.net.URL = {
156160
val defaultTemplate = getClass.getResource(ETC_DEFAULT + "-template")
157-
val (suffix, default) = loader.map {
158-
case Upstart => ("-upstart", defaultTemplate)
159-
case SystemV => ("-systemv", defaultTemplate)
160-
case Systemd =>
161-
("-systemd", getClass.getResource(ETC_DEFAULT + "-systemd-template"))
162-
}.getOrElse(("", defaultTemplate))
161+
val (suffix, default) = loader
162+
.map {
163+
case Upstart => ("-upstart", defaultTemplate)
164+
case SystemV => ("-systemv", defaultTemplate)
165+
case Systemd =>
166+
("-systemd", getClass.getResource(ETC_DEFAULT + "-systemd-template"))
167+
}
168+
.getOrElse(("", defaultTemplate))
163169

164170
val overrides =
165171
List[File](sourceDirectory / "templates" / (ETC_DEFAULT + suffix), sourceDirectory / "templates" / ETC_DEFAULT)

src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerBashScript.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ object JavaServerLoaderScript {
6161
case file if file.exists => Some(file.toURI.toURL)
6262
case _ =>
6363
Option(getClass getResource templatePath(script, loader, archetype))
64-
} getOrElse (sys.error(s"Could not find init [$script] for system [$loader] in archetype [$archetype]"))
64+
} getOrElse sys.error(s"Could not find init [$script] for system [$loader] in archetype [$archetype]")
6565

6666
/**
6767
* Loads the [[com.typesafe.sbt.packager.archetypes.systemloader.ServerLoader]] specific "functions" resource,
@@ -70,7 +70,6 @@ object JavaServerLoaderScript {
7070
* The functions script resides in "[archetype]/[loader]/functions"
7171
*
7272
* @param loader - Upstart, SystemV, SystemD
73-
* @param replacements - tuple of name->replacement
7473
* @param script - default is "functions"
7574
* @return functions - addService/stopService with resolved variables
7675
*/

src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BashStartScriptPlugin.scala

+22-20
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ object BashStartScriptPlugin extends AutoPlugin {
5555
bashScriptDefines ++= bashScriptExtraDefines.value,
5656
bashScriptReplacements := generateScriptReplacements(bashScriptDefines.value),
5757
// Create a bashConfigLocation if options are set in build.sbt
58-
bashScriptConfigLocation <<= bashScriptConfigLocation ?? Some(appIniLocation),
59-
bashScriptEnvConfigLocation <<= bashScriptEnvConfigLocation ?? None,
58+
bashScriptConfigLocation := (bashScriptConfigLocation ?? Some(appIniLocation)).value,
59+
bashScriptEnvConfigLocation := (bashScriptEnvConfigLocation ?? None).value,
6060
// Generating the application configuration
6161
mappings in Universal := generateApplicationIni(
6262
(mappings in Universal).value,
@@ -90,24 +90,26 @@ object BashStartScriptPlugin extends AutoPlugin {
9090
bashScriptConfigLocation: Option[String],
9191
tmpDir: File,
9292
log: Logger): Seq[(File, String)] =
93-
bashScriptConfigLocation.collect {
94-
case location if javaOptions.nonEmpty =>
95-
val configFile = tmpDir / "tmp" / "conf" / "application.ini"
96-
//Do not use writeLines here because of issue #637
97-
IO.write(configFile, ("# options from build" +: javaOptions).mkString("\n"))
98-
val filteredMappings = universalMappings.filter {
99-
case (file, path) => path != appIniLocation
100-
}
101-
// Warn the user if he tries to specify options
102-
if (filteredMappings.size < universalMappings.size) {
103-
log.warn("--------!!! JVM Options are defined twice !!!-----------")
104-
log.warn(
105-
"application.ini is already present in output package. Will be overridden by 'javaOptions in Universal'"
106-
)
107-
}
108-
(configFile -> cleanApplicationIniPath(location)) +: filteredMappings
109-
110-
}.getOrElse(universalMappings)
93+
bashScriptConfigLocation
94+
.collect {
95+
case location if javaOptions.nonEmpty =>
96+
val configFile = tmpDir / "tmp" / "conf" / "application.ini"
97+
//Do not use writeLines here because of issue #637
98+
IO.write(configFile, ("# options from build" +: javaOptions).mkString("\n"))
99+
val filteredMappings = universalMappings.filter {
100+
case (file, path) => path != appIniLocation
101+
}
102+
// Warn the user if he tries to specify options
103+
if (filteredMappings.size < universalMappings.size) {
104+
log.warn("--------!!! JVM Options are defined twice !!!-----------")
105+
log.warn(
106+
"application.ini is already present in output package. Will be overridden by 'javaOptions in Universal'"
107+
)
108+
}
109+
(configFile -> cleanApplicationIniPath(location)) +: filteredMappings
110+
111+
}
112+
.getOrElse(universalMappings)
111113

112114
private[this] def generateStartScripts(config: BashScriptConfig,
113115
mainClass: Option[String],

0 commit comments

Comments
 (0)