Skip to content

Commit

Permalink
Forwarder script is added to AshScriptPlugin (#1557)
Browse files Browse the repository at this point in the history
* [Issue#1392] Forwarder script is added to AshScriptPlugin

* [Issue#1392] Excluded all problems by add them to MIMA filters file (as suggested)

* [Issue#1392] corrected typo and renamed local variable

---------

Co-authored-by: Muki Seiler <[email protected]>
  • Loading branch information
Seetaramayya and muuki88 authored Jul 30, 2024
1 parent b3a8720 commit 6ccddfc
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 10 deletions.
11 changes: 11 additions & 0 deletions src/main/mima-filters/1.3.15.backward.excludes
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,14 @@ ProblemFilters.exclude[DirectMissingMethodProblem]("com.typesafe.sbt.packager.li

ProblemFilters.exclude[ReversedMissingMethodProblem]("com.typesafe.sbt.packager.docker.DockerKeys.dockerBuildEnvVars")
ProblemFilters.exclude[ReversedMissingMethodProblem]("com.typesafe.sbt.packager.docker.DockerKeys.com$typesafe$sbt$packager$docker$DockerKeys$_setter_$dockerBuildEnvVars_=")

# added via #1557
ProblemFilters.exclude[ReversedMissingMethodProblem]("com.typesafe.sbt.packager.archetypes.scripts.BashStartScriptKeys.com$typesafe$sbt$packager$archetypes$scripts$BashStartScriptKeys$_setter_$bashForwarderTemplateLocation_=")
ProblemFilters.exclude[ReversedMissingMethodProblem]("com.typesafe.sbt.packager.archetypes.scripts.BashStartScriptKeys.bashForwarderTemplateLocation")
ProblemFilters.exclude[DirectMissingMethodProblem]("com.typesafe.sbt.packager.archetypes.scripts.BashStartScriptPlugin#BashScriptConfig.copy")
ProblemFilters.exclude[DirectMissingMethodProblem]("com.typesafe.sbt.packager.archetypes.scripts.BashStartScriptPlugin#BashScriptConfig.this")
ProblemFilters.exclude[MissingTypesProblem]("com.typesafe.sbt.packager.archetypes.scripts.BashStartScriptPlugin$BashScriptConfig$")
ProblemFilters.exclude[DirectMissingMethodProblem]("com.typesafe.sbt.packager.archetypes.scripts.BashStartScriptPlugin#BashScriptConfig.apply")
ProblemFilters.exclude[ReversedMissingMethodProblem]("com.typesafe.sbt.packager.archetypes.scripts.BatStartScriptKeys.com$typesafe$sbt$packager$archetypes$scripts$BatStartScriptKeys$_setter_$batForwarderTemplateLocation_=")
ProblemFilters.exclude[ReversedMissingMethodProblem]("com.typesafe.sbt.packager.archetypes.scripts.BatStartScriptKeys.batForwarderTemplateLocation")
ProblemFilters.exclude[ReversedMissingMethodProblem]("com.typesafe.sbt.packager.archetypes.scripts.CommonStartScriptGenerator#ScriptConfig.forwarderTemplateLocation")
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/sh

# Absolute path to this script
# macOS doesn't support "readlink -f"
realpath () {
TARGET_FILE="$1"
CHECK_CYGWIN="$2"

cd "$(dirname "$TARGET_FILE")"
TARGET_FILE=$(basename "$TARGET_FILE")

COUNT=0
while [ -L "$TARGET_FILE" -a $COUNT -lt 100 ]
do
TARGET_FILE=$(readlink "$TARGET_FILE")
cd "$(dirname "$TARGET_FILE")"
TARGET_FILE=$(basename "$TARGET_FILE")
COUNT=$(($COUNT + 1))
done

if [ "$TARGET_FILE" == "." -o "$TARGET_FILE" == ".." ]; then
cd "$TARGET_FILE"
TARGET_FILEPATH=
else
TARGET_FILEPATH=/$TARGET_FILE
fi

# make sure we grab the actual windows path, instead of cygwin's path.
if [[ "x$CHECK_CYGWIN" == "x" ]]; then
echo "$(pwd -P)/$TARGET_FILE"
else
echo $(cygwinpath "$(pwd -P)/$TARGET_FILE")
fi
}

# Uses uname to detect if we're in the odd cygwin environment.
is_cygwin() {
local os=$(uname -s)
case "$os" in
CYGWIN*) return 0 ;;
*) return 1 ;;
esac
}

# This can fix cygwin style /cygdrive paths so we get the
# windows style paths.
cygwinpath() {
local file="$1"
if is_cygwin; then
echo $(cygpath -w $file)
else
echo $file
fi
}

# get the absolute path for the current script
SCRIPT=$(realpath "$0")
SCRIPTPATH=$(dirname "$SCRIPT")

# execute the main start script
$SCRIPTPATH/${{startScript}} -main ${{qualifiedClassName}} "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ object AshScriptPlugin extends AutoPlugin {
override def requires = JavaAppPackaging && BashStartScriptPlugin

val ashTemplate = "ash-template"
val ashForwarderTemplate = "ash-forwarder-template"

override def projectSettings =
Seq(
bashScriptTemplateLocation := (sourceDirectory.value / "templates" / ashTemplate),
bashForwarderTemplateLocation := Some(sourceDirectory.value / "templates" / ashForwarderTemplate),
bashScriptDefines := Defines(
(scriptClasspath in bashScriptDefines).value,
bashScriptConfigLocation.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ trait BashStartScriptKeys {
"bashScriptConfigLocation",
"The location where the bash script will load default argument configuration from."
)

val bashForwarderTemplateLocation =
TaskKey[Option[File]]("bashForwarderTemplateLocation", "The location of the bash forwarder template")
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ object BashStartScriptPlugin extends AutoPlugin with ApplicationIniGenerator wit
override val executableScriptName: String,
override val scriptClasspath: Seq[String],
override val replacements: Seq[(String, String)],
override val templateLocation: File
override val templateLocation: File,
override val forwarderTemplateLocation: Option[File]
) extends ScriptConfig {
override def withScriptName(scriptName: String): BashScriptConfig = copy(executableScriptName = scriptName)
}
Expand All @@ -55,6 +56,7 @@ object BashStartScriptPlugin extends AutoPlugin with ApplicationIniGenerator wit
override def projectSettings: Seq[Setting[_]] =
Seq(
bashScriptTemplateLocation := (sourceDirectory.value / "templates" / bashTemplate),
bashForwarderTemplateLocation := Some(sourceDirectory.value / "templates" / forwarderTemplateName),
bashScriptExtraDefines := Nil,
bashScriptDefines := Defines(
(scriptClasspath in bashScriptDefines).value,
Expand All @@ -79,7 +81,8 @@ object BashStartScriptPlugin extends AutoPlugin with ApplicationIniGenerator wit
executableScriptName = executableScriptName.value,
scriptClasspath = (scriptClasspath in bashScriptDefines).value,
replacements = bashScriptReplacements.value,
templateLocation = bashScriptTemplateLocation.value
templateLocation = bashScriptTemplateLocation.value,
forwarderTemplateLocation = bashForwarderTemplateLocation.value
),
(mainClass in (Compile, bashScriptDefines)).value,
(discoveredMainClasses in Compile).value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ trait BatStartScriptKeys {
val makeBatScripts = TaskKey[Seq[(File, String)]]("makeBatScripts", "Creates start scripts for this project.")
val batScriptTemplateLocation =
TaskKey[File]("batScriptTemplateLocation", "The location of the bat script template.")

val batForwarderTemplateLocation =
TaskKey[Option[File]]("batForwarderTemplateLocation", "The location of the bat forwarder script template.")

val batScriptReplacements = TaskKey[Seq[(String, String)]](
"batScriptReplacements",
"""|Replacements of template parameters used in the windows bat script.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ object BatStartScriptPlugin extends AutoPlugin with ApplicationIniGenerator with
extraDefines: Seq[String],
override val replacements: Seq[(String, String)],
override val templateLocation: File,
bundledJvmLocation: Option[String]
bundledJvmLocation: Option[String],
override val forwarderTemplateLocation: Option[File]
) extends ScriptConfig {

@deprecated("1.3.21", "")
Expand All @@ -62,7 +63,16 @@ object BatStartScriptPlugin extends AutoPlugin with ApplicationIniGenerator with
replacements: Seq[(String, String)],
templateLocation: File
) =
this(executableScriptName, scriptClasspath, configLocation, extraDefines, replacements, templateLocation, None)
this(
executableScriptName,
scriptClasspath,
configLocation,
extraDefines,
replacements,
templateLocation,
None,
None
)

@deprecated("1.3.21", "")
def copy(
Expand All @@ -80,7 +90,8 @@ object BatStartScriptPlugin extends AutoPlugin with ApplicationIniGenerator with
extraDefines,
replacements,
templateLocation,
bundledJvmLocation
bundledJvmLocation,
forwarderTemplateLocation
)

override def withScriptName(scriptName: String): BatScriptConfig = copy(executableScriptName = scriptName)
Expand All @@ -107,6 +118,7 @@ object BatStartScriptPlugin extends AutoPlugin with ApplicationIniGenerator with
extraDefines,
replacements,
templateLocation,
None,
None
)

Expand All @@ -117,6 +129,7 @@ object BatStartScriptPlugin extends AutoPlugin with ApplicationIniGenerator with
override def projectSettings: Seq[Setting[_]] =
Seq(
batScriptTemplateLocation := (sourceDirectory.value / "templates" / batTemplate),
batForwarderTemplateLocation := Some(sourceDirectory.value / "templates" / forwarderTemplateName),
batScriptConfigLocation := (batScriptConfigLocation ?? Some(appIniLocation)).value,
batScriptExtraDefines := Nil,
batScriptReplacements := Replacements(executableScriptName.value),
Expand All @@ -136,7 +149,8 @@ object BatStartScriptPlugin extends AutoPlugin with ApplicationIniGenerator with
extraDefines = batScriptExtraDefines.value,
replacements = batScriptReplacements.value,
templateLocation = batScriptTemplateLocation.value,
bundledJvmLocation = bundledJvmLocation.value
bundledJvmLocation = bundledJvmLocation.value,
forwarderTemplateLocation = batForwarderTemplateLocation.value
),
(mainClass in (Compile, batScriptReplacements)).value,
(discoveredMainClasses in Compile).value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ trait CommonStartScriptGenerator {
val scriptClasspath: Seq[String]
val replacements: Seq[(String, String)]
val templateLocation: File
val forwarderTemplateLocation: Option[File]

def withScriptName(scriptName: String): SpecializedScriptConfig
}
Expand Down Expand Up @@ -135,9 +136,9 @@ trait CommonStartScriptGenerator {
script -> s"$scriptTargetFolder/$scriptNameWithSuffix"
}

private[this] def resolveTemplate(defaultTemplateLocation: File): URL =
if (defaultTemplateLocation.exists) defaultTemplateLocation.toURI.toURL
else getClass.getResource(defaultTemplateLocation.getName)
private[this] def resolveTemplate(templateLocation: File): URL =
if (templateLocation.exists) templateLocation.toURI.toURL
else getClass.getResource(templateLocation.getName)

private[this] def createForwarderScripts(
executableScriptName: String,
Expand All @@ -147,7 +148,8 @@ trait CommonStartScriptGenerator {
log: sbt.Logger
): Seq[(File, String)] = {
val tmp = targetDir / scriptTargetFolder
val forwarderTemplate = getClass.getResource(forwarderTemplateName)
val forwarderTemplate =
config.forwarderTemplateLocation.map(resolveTemplate).getOrElse(getClass.getResource(forwarderTemplateName))
val classAndScriptNames = ScriptUtils.createScriptNames(discoveredMainClasses)
ScriptUtils.warnOnScriptNameCollision(classAndScriptNames :+ ("<main script>" -> mainScriptName(config)), log)
classAndScriptNames.map { case (qualifiedClassName, scriptNameWithoutSuffix) =>
Expand Down

0 comments on commit 6ccddfc

Please sign in to comment.