Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to latest sbt-scalafmt and scalafmt #1596

Merged
merged 3 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Version https://scalameta.org/scalafmt/docs/configuration.html#version
version = 3.8.1
# Dialect https://scalameta.org/scalafmt/docs/configuration.html#scala-dialects
runner.dialect = scala212

style = IntelliJ
maxColumn = 120
rewrite.rules = [SortImports, RedundantBraces]
rewrite.rules = [SortImports, RedundantBraces]
docstrings.blankFirstLine = yes

project.excludePaths = [
# [error] (Compile / scalafmt) org.scalafmt.sbt.ScalafmtSbtReporter$ScalafmtSbtError: scalafmt:
# WixHelper.scala:105: error: Unable to format file due to bug in scalafmt
"glob:**/src/main/scala/com/typesafe/sbt/packager/windows/WixHelper.scala"
]
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
libraryDependencies += "jline" % "jline" % "2.14.6"

// For code formatting
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")

// binary compatibility checks
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.3")
Expand Down
13 changes: 7 additions & 6 deletions src/main/scala-sbt-1.0/com/typesafe/sbt/packager/Compat.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.typesafe.sbt.packager

import sbt.{PathFinder, librarymanagement => lm}
import sbt.{librarymanagement => lm, PathFinder}
import sbt.internal.{librarymanagement => ilm, BuildDependencies => InternalBuildDependencies}
import sbt.util.CacheStore

Expand All @@ -14,7 +14,7 @@ object Compat {

/**
* Used in
* - [[com.typesafe.sbt.packager.archetypes.JavaAppPackaging]]
* - [[com.typesafe.sbt.packager.archetypes.JavaAppPackaging]]
*/
type BuildDependencies = InternalBuildDependencies

Expand All @@ -24,15 +24,16 @@ object Compat {

/**
* Used in
* - [[com.typesafe.sbt.packager.docker.DockerPlugin]]
* - [[com.typesafe.sbt.packager.docker.DockerPlugin]]
*/
type ProcessLogger = sys.process.ProcessLogger

/**
* Used in
* - [[com.typesafe.sbt.packager.Stager]]
* Used in
* - [[com.typesafe.sbt.packager.Stager]]
* @param file
* @return a CacheStore
* @return
* a CacheStore
*/
implicit def fileToCacheStore(file: java.io.File): CacheStore = CacheStore(file)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ object MappingsHelper extends Mapper {
* It lightens the build file if one wants to give a string instead of file.
*
* @example
* {{{
* {{{
* mappings in Universal ++= directory("extra")
* }}}
* }}}
*
* @param sourceDir
* @return mappings
* @return
* mappings
*/
def directory(sourceDir: String): Seq[(File, String)] =
directory(file(sourceDir))
Expand All @@ -24,50 +25,57 @@ object MappingsHelper extends Mapper {
* It lightens the build file if one wants to give a string instead of file.
*
* @example
* {{{
* {{{
* mappings in Universal ++= contentOf("extra")
* }}}
* }}}
*
* @param sourceDir as string representation
* @return mappings
* @param sourceDir
* as string representation
* @return
* mappings
*/
def contentOf(sourceDir: String): Seq[(File, String)] =
contentOf(file(sourceDir))

/**
* Create mappings from your classpath. For example if you want to add additional
* dependencies, like test or model.
* Create mappings from your classpath. For example if you want to add additional dependencies, like test or model.
*
* @example Add all test artifacts to a separated test folder
* {{{
* @example
* Add all test artifacts to a separated test folder
* {{{
* mappings in Universal ++= fromClasspath((managedClasspath in Test).value, target = "test")
* }}}
* }}}
*
* @param entries
* @param target
* @return a list of mappings
* @return
* a list of mappings
*/
def fromClasspath(entries: Seq[Attributed[File]], target: String): Seq[(File, String)] =
fromClasspath(entries, target, _ => true)

/**
* Create mappings from your classpath. For example if you want to add additional
* dependencies, like test or model. You can also filter the artifacts that should
* be mapped to mappings.
* Create mappings from your classpath. For example if you want to add additional dependencies, like test or model.
* You can also filter the artifacts that should be mapped to mappings.
*
* @example Filter all osgi bundles
* {{{
* @example
* Filter all osgi bundles
* {{{
* mappings in Universal ++= fromClasspath(
* (managedClasspath in Runtime).value,
* "osgi",
* artifact => artifact.`type` == "bundle"
* )
* }}}
* }}}
*
* @param entries from where mappings should be created from
* @param target folder, e.g. `model`. Must not end with a slash
* @param includeArtifact function to determine if an artifact should result in a mapping
* @param includeOnNoArtifact default is false. When there's no Artifact meta data remove it
* @param entries
* from where mappings should be created from
* @param target
* folder, e.g. `model`. Must not end with a slash
* @param includeArtifact
* function to determine if an artifact should result in a mapping
* @param includeOnNoArtifact
* default is false. When there's no Artifact meta data remove it
*/
def fromClasspath(
entries: Seq[Attributed[File]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import sbt.librarymanagement.{IvyFileConfiguration, PublishConfiguration}
import com.typesafe.sbt.packager.Compat._

/**
* TODO write tests for the SettingsHelper
* TODO document methods properly
* TODO document the sbt internal stuff that is used
* - TODO write tests for the SettingsHelper
* - TODO document methods properly
* - TODO document the sbt internal stuff that is used
*/
object SettingsHelper {

Expand Down Expand Up @@ -78,8 +78,8 @@ object SettingsHelper {
) ++ addPackage(config, packageTask, extension, classifier) ++ addResolver(config)

/**
* SBT looks in the `otherResolvers` setting for resolvers defined in `publishTo`.
* If a user scopes a `publishTo`, e.g.
* SBT looks in the `otherResolvers` setting for resolvers defined in `publishTo`. If a user scopes a `publishTo`,
* e.g.
*
* {{{
* // publish the rpm to the target folder
Expand All @@ -88,7 +88,8 @@ object SettingsHelper {
*
* then the resolver must also be present in the `otherResolvers`
*
* @param config the ivy configuration to look for resolvers
* @param config
* the ivy configuration to look for resolvers
*/
private def addResolver(config: Configuration): Seq[Setting[_]] =
Seq(otherResolvers ++= (publishTo in config).value.toSeq)
Expand Down
37 changes: 17 additions & 20 deletions src/main/scala/com/typesafe/sbt/PackagerPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@ import sbt._
import sbt.Keys.{name, normalizedName, packageBin, streams}

/**
* == SBT Native Packager Plugin ==
* ==SBT Native Packager Plugin==
*
* This is the top level plugin for the sbt native packager.
* You don't have to enable this by yourself, instead we recommend
* using an archetype for this.
* This is the top level plugin for the sbt native packager. You don't have to enable this by yourself, instead we
* recommend using an archetype for this.
*
* Currently you can choose between
*
* <ul>
* <li>JavaAppPackaging</li>
* <li>JavaServerPackaging</li>
* <li>AkkaAppPackging</li>
* </ul>
* - JavaAppPackaging
* - JavaServerPackaging
* - AkkaAppPackging
*
* == Configuration ==
* ==Configuration==
*
* The are a few settings you should set if you want to build package
* no matter what format.
* The are a few settings you should set if you want to build package no matter what format.
*
* {{{
* maintainer := "Your name <[email protected]>"
Expand All @@ -34,10 +30,11 @@ import sbt.Keys.{name, normalizedName, packageBin, streams}
*
* For all other general settings take a look at [[com.typesafe.sbt.packager.NativePackagerKeys]]
*
* @example Enable the plugin in the `build.sbt`
* {{{
* @example
* Enable the plugin in the `build.sbt`
* {{{
* enablePlugins(SbtNativePackager)
* }}}
* }}}
*/
object SbtNativePackager extends AutoPlugin {

Expand All @@ -56,16 +53,16 @@ object SbtNativePackager extends AutoPlugin {
/**
* imports all [[com.typesafe.sbt.packager.NativePackagerKeys]] and two objects:
*
* === NativePackagerKeys ===
* ===NativePackagerKeys===
*
* This inclues ''all'' available keys provided by the sbt-native-packager.
* Used it if a setting/task key is not in scope.
* This inclues ''all'' available keys provided by the sbt-native-packager. Used it if a setting/task key is not in
* scope.
*
* {{{
* NativePackagerKeys.notAutomaticallyImported := "cool!"
* }}}
*
* === NativePackagerHelper ===
* ===NativePackagerHelper===
*
* This object contains a set of helper methods for working with mappings.
*/
Expand Down Expand Up @@ -106,7 +103,7 @@ object SbtNativePackager extends AutoPlugin {
object packageArchetype {

/**
* == Recommended usage ==
* ==Recommended usage==
*
* {{{
* enablePlugins(JavaAppPackaging)
Expand Down
20 changes: 11 additions & 9 deletions src/main/scala/com/typesafe/sbt/packager/FileUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ object chmod {
* Using java 7 nio API to set the permissions.
*
* @param file
* @param perms in octal format
* @param perms
* in octal format
*/
def apply(file: File, perms: String): Unit = {
val posix = permissions(perms)
Expand All @@ -41,14 +42,15 @@ object chmod {
}

/**
* Converts a octal unix permission representation into
* a java `PosiFilePermissions` compatible string.
* Converts a octal unix permission representation into a java `PosiFilePermissions` compatible string.
*/
object permissions {

/**
* @param perms in octal format
* @return java 7 posix file permissions
* @param perms
* in octal format
* @return
* java 7 posix file permissions
*/
def apply(perms: String): java.util.Set[PosixFilePermission] =
PosixFilePermissions fromString convert(perms)
Expand Down Expand Up @@ -86,10 +88,10 @@ object permissions {
object sourceDateEpoch {

/**
* If the SOURCE_DATE_EPOCH environment variable is defined, change the mtime of the file (and
* all children recursively) to the epoch value. This is useful when trying to create
* reproducible builds since some packaging tools (e.g. tar, gzip) embed last modified times
* in the package. If the environment variable is not defined, this does nothing.
* If the SOURCE_DATE_EPOCH environment variable is defined, change the mtime of the file (and all children
* recursively) to the epoch value. This is useful when trying to create reproducible builds since some packaging
* tools (e.g. tar, gzip) embed last modified times in the package. If the environment variable is not defined, this
* does nothing.
*/
def apply(file: File): Unit =
sys.env.get("SOURCE_DATE_EPOCH").foreach { epoch =>
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/typesafe/sbt/packager/Hashing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object Hashing {
}

def convertToHex(data: Array[Byte]): String = {
//TODO - use java.lang.Integer.toHexString() ?
// TODO - use java.lang.Integer.toHexString() ?
val buf = new StringBuffer
def byteToHex(b: Int) =
if ((0 <= b) && (b <= 9)) ('0' + b).toChar
Expand Down
10 changes: 4 additions & 6 deletions src/main/scala/com/typesafe/sbt/packager/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,18 @@ trait NativePackagerKeys {

/**
* This Keys object can be used for
* <ul>
* <li>non autoplugin builds</li>
* <li>import single keys, which are not inside the autoImport</li>
* </ul>
* - non autoplugin builds
* - import single keys, which are not inside the autoImport
*
* == Non autoplugin builds ==
* ==Non autoplugin builds==
*
* {{{
* import com.typesafe.sbt.packager.Keys._
*
* packageName := ""
* }}}
*
* == autoplugin builds ==
* ==autoplugin builds==
*
* {{{
* NativePackagerKeys.packageName := ""
Expand Down
23 changes: 12 additions & 11 deletions src/main/scala/com/typesafe/sbt/packager/Stager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ object Stager {
/**
* create a cache and sync files if needed
*
* @param config - create a configuration specific cache directory
* @param cacheDirectory - e.g. streams.value.cacheDirectory
* @param stageDirectory - staging directory
* @param mappings - staging content
*
* @example {{{
*
* }}}
* @param config
* create a configuration specific cache directory
* @param cacheDirectory
* e.g. streams.value.cacheDirectory
* @param stageDirectory
* staging directory
* @param mappings
* staging content
*/
def stageFiles(config: String)(cacheDirectory: File, stageDirectory: File, mappings: Seq[(File, String)]): File = {
val cache = cacheDirectory / ("packager-mappings-" + config)
val copies = mappings map {
case (file, path) => file -> (stageDirectory / path)
val copies = mappings map { case (file, path) =>
file -> (stageDirectory / path)
}
Sync(cache, FileInfo.hash, FileInfo.exists)(copies)
// Now set scripts to executable using Java's lack of understanding of permissions.
Expand All @@ -38,7 +38,8 @@ object Stager {
}

/**
* @see stageFiles
* @see
* stageFiles
*/
def stage(config: String)(streams: TaskStreams, stageDirectory: File, mappings: Seq[(File, String)]): File =
stageFiles(config)(streams.cacheDirectory, stageDirectory, mappings)
Expand Down
Loading
Loading