Skip to content

Commit

Permalink
Run scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
NeQuissimus authored and muuki88 committed Apr 13, 2017
1 parent 6dcd123 commit 3b1adc4
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,12 @@ 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 @@ -90,26 +90,24 @@ 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
34 changes: 15 additions & 19 deletions src/main/scala/com/typesafe/sbt/packager/debian/DebianPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -429,25 +429,21 @@ 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.flatMap(_._2).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
}
Expand Down
40 changes: 20 additions & 20 deletions src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ object DockerPlugin extends AutoPlugin {
dockerExposedVolumes := Seq(),
dockerLabels := Map(),
dockerRepository := None,
dockerAlias := DockerAlias(dockerRepository.value, None, (packageName in Docker).value, Some((version in Docker).value)),
dockerAlias := DockerAlias(
dockerRepository.value,
None,
(packageName in Docker).value,
Some((version in Docker).value)
),
dockerUpdateLatest := false,
dockerEntrypoint := Seq("bin/%s" format executableScriptName.value),
dockerCmd := Seq(),
Expand All @@ -91,23 +96,19 @@ object DockerPlugin extends AutoPlugin {
),
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

val generalCommands = makeFrom(dockerBaseImage.value) +: makeMaintainer((maintainer in Docker).value).toSeq

generalCommands ++
Seq(
makeWorkdir(dockerBaseDirectory),
makeAdd(dockerBaseDirectory),
makeChown(user, group, "." :: Nil)
) ++
dockerLabels.value.map(makeLabel) ++
makeExposePorts(dockerExposedPorts.value, dockerExposedUdpPorts.value) ++
makeVolumes(dockerExposedVolumes.value, user, group) ++
Seq(makeUser(user), makeEntrypoint(dockerEntrypoint.value), makeCmd(dockerCmd.value))
}
val dockerBaseDirectory = (defaultLinuxInstallLocation in Docker).value
val user = (daemonUser in Docker).value
val group = (daemonGroup in Docker).value

val generalCommands = makeFrom(dockerBaseImage.value) +: makeMaintainer((maintainer in Docker).value).toSeq

generalCommands ++
Seq(makeWorkdir(dockerBaseDirectory), makeAdd(dockerBaseDirectory), makeChown(user, group, "." :: Nil)) ++
dockerLabels.value.map(makeLabel) ++
makeExposePorts(dockerExposedPorts.value, dockerExposedUdpPorts.value) ++
makeVolumes(dockerExposedVolumes.value, user, group) ++
Seq(makeUser(user), makeEntrypoint(dockerEntrypoint.value), makeCmd(dockerCmd.value))
}
) ++ mapGenericFilesToDocker ++ inConfig(Docker)(
Seq(
executableScriptName := executableScriptName.value,
Expand Down Expand Up @@ -160,8 +161,7 @@ object DockerPlugin extends AutoPlugin {
* @return LABEL command
*/
private final def makeLabel(label: Tuple2[String, String]): CmdLike = {
val variable = label._1
val value = label._2
val (variable, value) = label
Cmd("LABEL", s"${variable}=${value}")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ object WixHelper {
* 72) so we can safely add a few later.
*/
def cleanStringForId(n: String) = {
val x = n.replaceAll("[^0-9a-zA-Z_]", "_").takeRight(59) + (math.abs(n.hashCode).toString + "xxxxxxxxx").substring(0, 9)
val x = n.replaceAll("[^0-9a-zA-Z_]", "_").takeRight(59) + (math.abs(n.hashCode).toString + "xxxxxxxxx")
.substring(0, 9)
if (x startsWith "_") x
else "_" + x
}
Expand Down
5 changes: 1 addition & 4 deletions src/sbt-test/ash/memory-settings/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ name := "simple-app"

version := "0.1.0"

bashScriptExtraDefines ++= Seq(
"""addJava "-Xms64m"""",
"""addJava "-Xmx64m""""
)
bashScriptExtraDefines ++= Seq("""addJava "-Xms64m"""", """addJava "-Xmx64m"""")

TaskKey[Unit]("script-check") := {
val startScript = (stagingDirectory in Universal).value / "bin" / executableScriptName.value
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/debian/override-loader-functions/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TaskKey[Unit]("check-loader-functions") <<= (target, streams) map { (target, out
Seq("dpkg-deb", "-e", (target / "debian-test_0.1.0_all.deb").absolutePath, extracted.absolutePath).!

val script = IO.read(extracted / "postinst")

assert(script.contains("# right systemd template"), s"override script wasn't picked, script is\n$script")
assert(!script.contains("wrong systemd start template"), s"script contained wrong template, script is\n$script")
()
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/rpm/override-loader-functions/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ rpmLicense := Some("BSD")
rpmGroup := Some("test-group")

TaskKey[Unit]("check-loader-script") <<= (target, streams) map { (target, out) =>
val path = target / "rpm"/ "RPMS" / "noarch" / "rpm-test-0.1.0-1.noarch.rpm"
val path = target / "rpm" / "RPMS" / "noarch" / "rpm-test-0.1.0-1.noarch.rpm"
val scripts = s"rpm -qp --scripts ${path.absolutePath}".!!

assert(scripts.contains("# right systemd template"), s"override script wasn't picked, scripts are\n$scripts")
Expand Down
1 change: 0 additions & 1 deletion src/sbt-test/rpm/scriplets-no-javarepack-rpm/build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

enablePlugins(JavaServerAppPackaging)

name := "rpm-test-no-repack"
Expand Down
1 change: 0 additions & 1 deletion src/sbt-test/rpm/scriplets-use-javarepack-rpm/build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

enablePlugins(JavaServerAppPackaging)

name := "rpm-test-with-repack"
Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "1.2.0-SNAPSHOT"
version in ThisBuild := "1.2.0-SNAPSHOT"

0 comments on commit 3b1adc4

Please sign in to comment.