Skip to content

Commit 6ccddfc

Browse files
Forwarder script is added to AshScriptPlugin (#1557)
* [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 <muuki88@users.noreply.github.com>
1 parent b3a8720 commit 6ccddfc

8 files changed

Lines changed: 110 additions & 10 deletions

File tree

src/main/mima-filters/1.3.15.backward.excludes

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,14 @@ ProblemFilters.exclude[DirectMissingMethodProblem]("com.typesafe.sbt.packager.li
8282

8383
ProblemFilters.exclude[ReversedMissingMethodProblem]("com.typesafe.sbt.packager.docker.DockerKeys.dockerBuildEnvVars")
8484
ProblemFilters.exclude[ReversedMissingMethodProblem]("com.typesafe.sbt.packager.docker.DockerKeys.com$typesafe$sbt$packager$docker$DockerKeys$_setter_$dockerBuildEnvVars_=")
85+
86+
# added via #1557
87+
ProblemFilters.exclude[ReversedMissingMethodProblem]("com.typesafe.sbt.packager.archetypes.scripts.BashStartScriptKeys.com$typesafe$sbt$packager$archetypes$scripts$BashStartScriptKeys$_setter_$bashForwarderTemplateLocation_=")
88+
ProblemFilters.exclude[ReversedMissingMethodProblem]("com.typesafe.sbt.packager.archetypes.scripts.BashStartScriptKeys.bashForwarderTemplateLocation")
89+
ProblemFilters.exclude[DirectMissingMethodProblem]("com.typesafe.sbt.packager.archetypes.scripts.BashStartScriptPlugin#BashScriptConfig.copy")
90+
ProblemFilters.exclude[DirectMissingMethodProblem]("com.typesafe.sbt.packager.archetypes.scripts.BashStartScriptPlugin#BashScriptConfig.this")
91+
ProblemFilters.exclude[MissingTypesProblem]("com.typesafe.sbt.packager.archetypes.scripts.BashStartScriptPlugin$BashScriptConfig$")
92+
ProblemFilters.exclude[DirectMissingMethodProblem]("com.typesafe.sbt.packager.archetypes.scripts.BashStartScriptPlugin#BashScriptConfig.apply")
93+
ProblemFilters.exclude[ReversedMissingMethodProblem]("com.typesafe.sbt.packager.archetypes.scripts.BatStartScriptKeys.com$typesafe$sbt$packager$archetypes$scripts$BatStartScriptKeys$_setter_$batForwarderTemplateLocation_=")
94+
ProblemFilters.exclude[ReversedMissingMethodProblem]("com.typesafe.sbt.packager.archetypes.scripts.BatStartScriptKeys.batForwarderTemplateLocation")
95+
ProblemFilters.exclude[ReversedMissingMethodProblem]("com.typesafe.sbt.packager.archetypes.scripts.CommonStartScriptGenerator#ScriptConfig.forwarderTemplateLocation")
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/sh
2+
3+
# Absolute path to this script
4+
# macOS doesn't support "readlink -f"
5+
realpath () {
6+
TARGET_FILE="$1"
7+
CHECK_CYGWIN="$2"
8+
9+
cd "$(dirname "$TARGET_FILE")"
10+
TARGET_FILE=$(basename "$TARGET_FILE")
11+
12+
COUNT=0
13+
while [ -L "$TARGET_FILE" -a $COUNT -lt 100 ]
14+
do
15+
TARGET_FILE=$(readlink "$TARGET_FILE")
16+
cd "$(dirname "$TARGET_FILE")"
17+
TARGET_FILE=$(basename "$TARGET_FILE")
18+
COUNT=$(($COUNT + 1))
19+
done
20+
21+
if [ "$TARGET_FILE" == "." -o "$TARGET_FILE" == ".." ]; then
22+
cd "$TARGET_FILE"
23+
TARGET_FILEPATH=
24+
else
25+
TARGET_FILEPATH=/$TARGET_FILE
26+
fi
27+
28+
# make sure we grab the actual windows path, instead of cygwin's path.
29+
if [[ "x$CHECK_CYGWIN" == "x" ]]; then
30+
echo "$(pwd -P)/$TARGET_FILE"
31+
else
32+
echo $(cygwinpath "$(pwd -P)/$TARGET_FILE")
33+
fi
34+
}
35+
36+
# Uses uname to detect if we're in the odd cygwin environment.
37+
is_cygwin() {
38+
local os=$(uname -s)
39+
case "$os" in
40+
CYGWIN*) return 0 ;;
41+
*) return 1 ;;
42+
esac
43+
}
44+
45+
# This can fix cygwin style /cygdrive paths so we get the
46+
# windows style paths.
47+
cygwinpath() {
48+
local file="$1"
49+
if is_cygwin; then
50+
echo $(cygpath -w $file)
51+
else
52+
echo $file
53+
fi
54+
}
55+
56+
# get the absolute path for the current script
57+
SCRIPT=$(realpath "$0")
58+
SCRIPTPATH=$(dirname "$SCRIPT")
59+
60+
# execute the main start script
61+
$SCRIPTPATH/${{startScript}} -main ${{qualifiedClassName}} "$@"

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,12 @@ object AshScriptPlugin extends AutoPlugin {
7575
override def requires = JavaAppPackaging && BashStartScriptPlugin
7676

7777
val ashTemplate = "ash-template"
78+
val ashForwarderTemplate = "ash-forwarder-template"
7879

7980
override def projectSettings =
8081
Seq(
8182
bashScriptTemplateLocation := (sourceDirectory.value / "templates" / ashTemplate),
83+
bashForwarderTemplateLocation := Some(sourceDirectory.value / "templates" / ashForwarderTemplate),
8284
bashScriptDefines := Defines(
8385
(scriptClasspath in bashScriptDefines).value,
8486
bashScriptConfigLocation.value,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,7 @@ trait BashStartScriptKeys {
3131
"bashScriptConfigLocation",
3232
"The location where the bash script will load default argument configuration from."
3333
)
34+
35+
val bashForwarderTemplateLocation =
36+
TaskKey[Option[File]]("bashForwarderTemplateLocation", "The location of the bash forwarder template")
3437
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ object BashStartScriptPlugin extends AutoPlugin with ApplicationIniGenerator wit
4545
override val executableScriptName: String,
4646
override val scriptClasspath: Seq[String],
4747
override val replacements: Seq[(String, String)],
48-
override val templateLocation: File
48+
override val templateLocation: File,
49+
override val forwarderTemplateLocation: Option[File]
4950
) extends ScriptConfig {
5051
override def withScriptName(scriptName: String): BashScriptConfig = copy(executableScriptName = scriptName)
5152
}
@@ -55,6 +56,7 @@ object BashStartScriptPlugin extends AutoPlugin with ApplicationIniGenerator wit
5556
override def projectSettings: Seq[Setting[_]] =
5657
Seq(
5758
bashScriptTemplateLocation := (sourceDirectory.value / "templates" / bashTemplate),
59+
bashForwarderTemplateLocation := Some(sourceDirectory.value / "templates" / forwarderTemplateName),
5860
bashScriptExtraDefines := Nil,
5961
bashScriptDefines := Defines(
6062
(scriptClasspath in bashScriptDefines).value,
@@ -79,7 +81,8 @@ object BashStartScriptPlugin extends AutoPlugin with ApplicationIniGenerator wit
7981
executableScriptName = executableScriptName.value,
8082
scriptClasspath = (scriptClasspath in bashScriptDefines).value,
8183
replacements = bashScriptReplacements.value,
82-
templateLocation = bashScriptTemplateLocation.value
84+
templateLocation = bashScriptTemplateLocation.value,
85+
forwarderTemplateLocation = bashForwarderTemplateLocation.value
8386
),
8487
(mainClass in (Compile, bashScriptDefines)).value,
8588
(discoveredMainClasses in Compile).value,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ trait BatStartScriptKeys {
1212
val makeBatScripts = TaskKey[Seq[(File, String)]]("makeBatScripts", "Creates start scripts for this project.")
1313
val batScriptTemplateLocation =
1414
TaskKey[File]("batScriptTemplateLocation", "The location of the bat script template.")
15+
16+
val batForwarderTemplateLocation =
17+
TaskKey[Option[File]]("batForwarderTemplateLocation", "The location of the bat forwarder script template.")
18+
1519
val batScriptReplacements = TaskKey[Seq[(String, String)]](
1620
"batScriptReplacements",
1721
"""|Replacements of template parameters used in the windows bat script.

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ object BatStartScriptPlugin extends AutoPlugin with ApplicationIniGenerator with
5050
extraDefines: Seq[String],
5151
override val replacements: Seq[(String, String)],
5252
override val templateLocation: File,
53-
bundledJvmLocation: Option[String]
53+
bundledJvmLocation: Option[String],
54+
override val forwarderTemplateLocation: Option[File]
5455
) extends ScriptConfig {
5556

5657
@deprecated("1.3.21", "")
@@ -62,7 +63,16 @@ object BatStartScriptPlugin extends AutoPlugin with ApplicationIniGenerator with
6263
replacements: Seq[(String, String)],
6364
templateLocation: File
6465
) =
65-
this(executableScriptName, scriptClasspath, configLocation, extraDefines, replacements, templateLocation, None)
66+
this(
67+
executableScriptName,
68+
scriptClasspath,
69+
configLocation,
70+
extraDefines,
71+
replacements,
72+
templateLocation,
73+
None,
74+
None
75+
)
6676

6777
@deprecated("1.3.21", "")
6878
def copy(
@@ -80,7 +90,8 @@ object BatStartScriptPlugin extends AutoPlugin with ApplicationIniGenerator with
8090
extraDefines,
8191
replacements,
8292
templateLocation,
83-
bundledJvmLocation
93+
bundledJvmLocation,
94+
forwarderTemplateLocation
8495
)
8596

8697
override def withScriptName(scriptName: String): BatScriptConfig = copy(executableScriptName = scriptName)
@@ -107,6 +118,7 @@ object BatStartScriptPlugin extends AutoPlugin with ApplicationIniGenerator with
107118
extraDefines,
108119
replacements,
109120
templateLocation,
121+
None,
110122
None
111123
)
112124

@@ -117,6 +129,7 @@ object BatStartScriptPlugin extends AutoPlugin with ApplicationIniGenerator with
117129
override def projectSettings: Seq[Setting[_]] =
118130
Seq(
119131
batScriptTemplateLocation := (sourceDirectory.value / "templates" / batTemplate),
132+
batForwarderTemplateLocation := Some(sourceDirectory.value / "templates" / forwarderTemplateName),
120133
batScriptConfigLocation := (batScriptConfigLocation ?? Some(appIniLocation)).value,
121134
batScriptExtraDefines := Nil,
122135
batScriptReplacements := Replacements(executableScriptName.value),
@@ -136,7 +149,8 @@ object BatStartScriptPlugin extends AutoPlugin with ApplicationIniGenerator with
136149
extraDefines = batScriptExtraDefines.value,
137150
replacements = batScriptReplacements.value,
138151
templateLocation = batScriptTemplateLocation.value,
139-
bundledJvmLocation = bundledJvmLocation.value
152+
bundledJvmLocation = bundledJvmLocation.value,
153+
forwarderTemplateLocation = batForwarderTemplateLocation.value
140154
),
141155
(mainClass in (Compile, batScriptReplacements)).value,
142156
(discoveredMainClasses in Compile).value,

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ trait CommonStartScriptGenerator {
5151
val scriptClasspath: Seq[String]
5252
val replacements: Seq[(String, String)]
5353
val templateLocation: File
54+
val forwarderTemplateLocation: Option[File]
5455

5556
def withScriptName(scriptName: String): SpecializedScriptConfig
5657
}
@@ -135,9 +136,9 @@ trait CommonStartScriptGenerator {
135136
script -> s"$scriptTargetFolder/$scriptNameWithSuffix"
136137
}
137138

138-
private[this] def resolveTemplate(defaultTemplateLocation: File): URL =
139-
if (defaultTemplateLocation.exists) defaultTemplateLocation.toURI.toURL
140-
else getClass.getResource(defaultTemplateLocation.getName)
139+
private[this] def resolveTemplate(templateLocation: File): URL =
140+
if (templateLocation.exists) templateLocation.toURI.toURL
141+
else getClass.getResource(templateLocation.getName)
141142

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

0 commit comments

Comments
 (0)