diff --git a/src/main/mima-filters/1.3.15.backward.excludes b/src/main/mima-filters/1.3.15.backward.excludes index cbd098e27..f80e3c828 100644 --- a/src/main/mima-filters/1.3.15.backward.excludes +++ b/src/main/mima-filters/1.3.15.backward.excludes @@ -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") diff --git a/src/main/resources/com/typesafe/sbt/packager/archetypes/scripts/ash-forwarder-template b/src/main/resources/com/typesafe/sbt/packager/archetypes/scripts/ash-forwarder-template new file mode 100644 index 000000000..3bdde75bd --- /dev/null +++ b/src/main/resources/com/typesafe/sbt/packager/archetypes/scripts/ash-forwarder-template @@ -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}} "$@" \ No newline at end of file diff --git a/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/AshScriptPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/AshScriptPlugin.scala index 209bcfac0..9d0cd0af6 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/AshScriptPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/AshScriptPlugin.scala @@ -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, diff --git a/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BashStartScriptKeys.scala b/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BashStartScriptKeys.scala index 7f80c28f7..71eca3ca7 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BashStartScriptKeys.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BashStartScriptKeys.scala @@ -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") } diff --git a/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BashStartScriptPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BashStartScriptPlugin.scala index 20cb093b9..2b6aaa8d7 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BashStartScriptPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BashStartScriptPlugin.scala @@ -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) } @@ -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, @@ -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, diff --git a/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BatStartScriptKeys.scala b/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BatStartScriptKeys.scala index 267b7cd1f..ab9042eba 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BatStartScriptKeys.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BatStartScriptKeys.scala @@ -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. diff --git a/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BatStartScriptPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BatStartScriptPlugin.scala index a76bc5946..3904a1550 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BatStartScriptPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/BatStartScriptPlugin.scala @@ -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", "") @@ -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( @@ -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) @@ -107,6 +118,7 @@ object BatStartScriptPlugin extends AutoPlugin with ApplicationIniGenerator with extraDefines, replacements, templateLocation, + None, None ) @@ -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), @@ -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, diff --git a/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/CommonStartScriptGenerator.scala b/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/CommonStartScriptGenerator.scala index bb4fb569d..f9de4b3c7 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/CommonStartScriptGenerator.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/scripts/CommonStartScriptGenerator.scala @@ -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 } @@ -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, @@ -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 :+ ("
" -> mainScriptName(config)), log) classAndScriptNames.map { case (qualifiedClassName, scriptNameWithoutSuffix) =>