Skip to content

Commit

Permalink
Merge pull request #6 from scala-steward/update/scalafmt-core-3.7.17
Browse files Browse the repository at this point in the history
Update scalafmt-core to 3.7.17
  • Loading branch information
hoangmaihuy committed Jan 15, 2024
2 parents 73d6d98 + 3b9c995 commit e2abe74
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 159 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Scala Steward: Reformat with scalafmt 3.7.17
926b562eec20232bee38b866f4093520ed349e3d
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.7.14"
version = "3.7.17"
runner.dialect = scala213

project.git = true
Expand Down
1 change: 0 additions & 1 deletion itest/src/example/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import io.github.hoangmaihuy.mill.packager.archetypes._

object example extends RootModule with ScalaModule with JavaAppPackagingModule {


override def artifactName = "example"

override def scalaVersion = "3.3.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ import java.nio.file.attribute.{PosixFilePermission, PosixFilePermissions}

import scala.util.Try

/**
* Setting the file permissions
/** Setting the file permissions
*/
object chmod {

/**
* Using java 7 nio API to set the permissions.
/** 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 @@ -36,17 +35,17 @@ object chmod {
sys.error("Error setting permissions " + perms + " on " + file.getAbsolutePath + ": " + e.getMessage)
}
}

}

/**
* 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,43 @@ package io.github.hoangmaihuy.mill.packager.archetypes
import scala.annotation.unused
import scala.io.{Codec, Source}

/**
* This object provides methods to generate scripts from templates. This involves
/** This object provides methods to generate scripts from templates. This involves
*
* <ol>
* <li>procesing - replacing a placeholders with actual values</li>
* <li>TODO: validating - check the script if there are no remaining placeholders</li>
* </ol>
* <ol> <li>procesing - replacing a placeholders with actual values</li> <li>TODO: validating - check the script if
* there are no remaining placeholders</li> </ol>
*
* @example a bash script can be generated like this
* {{{
* @example
* a bash script can be generated like this
* {{{
* val template = getClass getResource "template-your-bashscript"
* val replacements = Seq("name" -> "your-app", "custom" -> "1")
* TemplateWriter.generateScript(template, replacements)
* }}}
* }}}
*
* @example a bat script can be generated like this
* {{{
* @example
* a bat script can be generated like this
* {{{
* val template = getClass getResource "template-your-batscript"
* val replacements = Seq("name" -> "your-app", "custom" -> "1")
* TemplateWriter.generateScript(template, replacements, "\r\n", TemplateWriter.batFriendlyKeySurround)
* }}}
* }}}
*
* TODO move out of archetypes package
*/
object TemplateWriter {

def defaultCharset: java.nio.charset.Charset =
java.nio.charset.Charset.forName("UTF-8")

def bashFriendlyKeySurround(key: String) =
"\\$\\{\\{" + key + "\\}\\}"

def batFriendlyKeySurround(key: String) =
"@@" + key + "@@"

private def replace(line: String, replacements: Seq[(String, String)], keySurround: String => String): String =
replacements.foldLeft(line) {
case (line, (key, value)) =>
keySurround(key).r.replaceAllIn(line, java.util.regex.Matcher.quoteReplacement(value))
replacements.foldLeft(line) { case (line, (key, value)) =>
keySurround(key).r.replaceAllIn(line, java.util.regex.Matcher.quoteReplacement(value))
}

private def replaceValues(
Expand Down Expand Up @@ -83,11 +83,12 @@ object TemplateWriter {
): String =
replaceValues(source.split(eol).toSeq, replacements, eol, keySurround)

/**
* @param lines
/** @param lines
* @param replacements
* @param keySurround defaults to bashFriendlyKeySurround
* @param charset defaults to UTF-8
* @param keySurround
* defaults to bashFriendlyKeySurround
* @param charset
* defaults to UTF-8
*/
def generateScriptFromLines(
lines: Seq[String],
Expand All @@ -96,4 +97,5 @@ object TemplateWriter {
@unused charset: java.nio.charset.Charset = defaultCharset
): Seq[String] =
replaceValues(lines, replacements, keySurround)

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import mill._
import io.github.hoangmaihuy.mill.packager.archetypes.{JavaAppPackagingModule, TemplateWriter}
import io.github.hoangmaihuy.mill.packager._

/** == Bash StartScript Plugin ==
/** ==Bash StartScript Plugin==
*
* This plugins creates a start bash script to run an application built with the
* [[io.github.hoangmaihuy.mill.packager.archetypes.JavaAppPackagingModule]].
Expand Down Expand Up @@ -86,9 +86,10 @@ trait BashStartScriptModule extends Module with CommonStartScriptGenerator { sel

/** Creates the block of defines for a script.
*
* @param appClasspath A sequence of relative-locations (to the lib/ folder) of jars
* to include on the classpath.
* @param configFile An (optional) filename from which the script will read arguments.
* @param appClasspath
* A sequence of relative-locations (to the lib/ folder) of jars to include on the classpath.
* @param configFile
* An (optional) filename from which the script will read arguments.
*/
def apply(appClasspath: Seq[String], configFile: Option[String], bundledJvm: Option[String]): Seq[String] =
(configFile map configFileDefine).toSeq ++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ trait CommonStartScriptGenerator {
protected[this] val keySurround: String => String

/** Set executable bit of the generated scripts to this value
* @todo Does it work when building archives on hosts that do not support such permission?
* @todo
* Does it work when building archives on hosts that do not support such permission?
*/
protected[this] val executableBitValue: Boolean

Expand All @@ -49,9 +50,8 @@ trait CommonStartScriptGenerator {
def withScriptName(scriptName: String): SpecializedScriptConfig
}

/** The type of specialized ScriptConfig.
* This enables callback methods of the concrete plugin implementations
* to use fields of config that only exist in their ScriptConfig specialization.
/** The type of specialized ScriptConfig. This enables callback methods of the concrete plugin implementations to use
* fields of config that only exist in their ScriptConfig specialization.
*/
protected[this] type SpecializedScriptConfig <: ScriptConfig

Expand Down Expand Up @@ -129,10 +129,14 @@ trait CommonStartScriptGenerator {
private[this] def mainScriptName(config: ScriptConfig): String =
config.executableScriptName + scriptSuffix

/** @param mainClass - Main class added to the java command
* @param config - Config data for this script
* @param targetDir - Target directory for this script
* @return File pointing to the created main script
/** @param mainClass
* \- Main class added to the java command
* @param config
* \- Config data for this script
* @param targetDir
* \- Target directory for this script
* @return
* File pointing to the created main script
*/
private[this] def createMainScript(
mainClass: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ object ScriptUtils {
}

/** Generates launcher script names for the specified main class names.
* @param discoveredMainClasses discovered qualified main class names
* @return sequence of tuples: (passed in class name) -> (generated script name)
* @note may introduce name collisions in some corner cases
* @param discoveredMainClasses
* discovered qualified main class names
* @return
* sequence of tuples: (passed in class name) -> (generated script name)
* @note
* may introduce name collisions in some corner cases
*/
def createScriptNames(discoveredMainClasses: Seq[String]): Seq[(String, String)] = {
val mainClasses = discoveredMainClasses.map { fullyQualifiedClassName =>
Expand Down Expand Up @@ -63,12 +66,14 @@ object ScriptUtils {
)
}

/** Converts class name to lower case, applying some heuristics
* to guess the word splitting.
* @param qualifiedClassName a class name
* @return lower cased name with '-' between words. Dots ('.') are left as is.
* @note This function can still introduce name collisions sometimes: for example,
* both Test1Class and Test1class (note the capitalization) will end up test-1-class.
/** Converts class name to lower case, applying some heuristics to guess the word splitting.
* @param qualifiedClassName
* a class name
* @return
* lower cased name with '-' between words. Dots ('.') are left as is.
* @note
* This function can still introduce name collisions sometimes: for example, both Test1Class and Test1class (note
* the capitalization) will end up test-1-class.
*/
def toLowerCase(qualifiedClassName: String): String = {
// suppose list is not very huge, so no need in tail recursion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
package io.github.hoangmaihuy.mill.packager.archetypes.scripts

/**
* Models the main script configuration for the given project.
/** Models the main script configuration for the given project.
*/
sealed trait StartScriptMainClassConfig

/**
* The project has no main class.
/** The project has no main class.
*/
case object NoMain extends StartScriptMainClassConfig

/**
* The project has a single defined main class.
/** The project has a single defined main class.
*
* @param mainClass project main entrypoint
* @param mainClass
* project main entrypoint
*/
case class SingleMain(mainClass: String) extends StartScriptMainClassConfig

/**
* The project has multiple main classes, but no explicit configured main entrypoint.
/** The project has multiple main classes, but no explicit configured main entrypoint.
*
* @param mainClasses A non-empty list of main classes
* @param mainClasses
* A non-empty list of main classes
*/
case class MultipleMains(mainClasses: Seq[String]) extends StartScriptMainClassConfig

/**
* The project has multiple main classes and a defined main entrypoint.
/** The project has multiple main classes and a defined main entrypoint.
*
* @param mainClass Explicitly defined main class
* @param additional Other discovered main classes without the explicit main class
* @param mainClass
* Explicitly defined main class
* @param additional
* Other discovered main classes without the explicit main class
*/
case class ExplicitMainWithAdditional(mainClass: String, additional: Seq[String]) extends StartScriptMainClassConfig

object StartScriptMainClassConfig {

/**
* @param mainClass optional main class, e.g. from (mainClass in Compile).value
* @param discoveredMainClasses all discovered main classes, e.g. from (discoveredMainClasses in Compile).value
* @return A start script configuration
/** @param mainClass
* optional main class, e.g. from (mainClass in Compile).value
* @param discoveredMainClasses
* all discovered main classes, e.g. from (discoveredMainClasses in Compile).value
* @return
* A start script configuration
*/
def from(mainClass: Option[String], discoveredMainClasses: Seq[String]): StartScriptMainClassConfig = {
val additionalMainClasses = discoveredMainClasses.filterNot(mainClass == Some(_))
Expand Down
Loading

0 comments on commit e2abe74

Please sign in to comment.