From 04b28015d86818152f4c4687dd2d2bd9bc9071d3 Mon Sep 17 00:00:00 2001 From: hayssams Date: Thu, 22 Sep 2016 14:59:43 +0200 Subject: [PATCH 1/6] Support for absolute paths when adding to classpath Do not prefix with $lib_dir when an absolute path is added to the classpath --- .../typesafe/sbt/packager/archetypes/JavaAppAshScript.scala | 3 ++- .../typesafe/sbt/packager/archetypes/JavaAppBashScript.scala | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppAshScript.scala b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppAshScript.scala index f6c99f09e..5a1180342 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppAshScript.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppAshScript.scala @@ -1,5 +1,6 @@ package com.typesafe.sbt.packager.archetypes +import java.io.File import java.net.URL /** @@ -34,7 +35,7 @@ object JavaAppAshScript { extras private def makeClasspathDefine(cp: Seq[String]): String = { - val fullString = cp map (n => "$lib_dir/" + n) mkString ":" + val fullString = cp map (n => if (n.startsWith(File.separator)) n else "$lib_dir/" + n) mkString ":" "app_classpath=\"" + fullString + "\"\n" } def generateScript(defines: Seq[String], template: URL = bashTemplateSource): String = { diff --git a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppBashScript.scala b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppBashScript.scala index 48007b293..a7cc3f366 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppBashScript.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppBashScript.scala @@ -1,5 +1,6 @@ package com.typesafe.sbt.packager.archetypes +import java.io.File import java.net.URL /** @@ -34,7 +35,7 @@ object JavaAppBashScript { extras private def makeClasspathDefine(cp: Seq[String]): String = { - val fullString = cp map (n => "$lib_dir/" + n) mkString ":" + val fullString = cp map (n => if (n.startsWith(File.separator)) n else "$lib_dir/" + n) mkString ":" "declare -r app_classpath=\"" + fullString + "\"\n" } def generateScript(defines: Seq[String], template: URL = bashTemplateSource): String = { From 5a50c26c64896c52fd38de53f8f4620476ddc2ca Mon Sep 17 00:00:00 2001 From: hayssams Date: Fri, 23 Sep 2016 23:43:14 +0200 Subject: [PATCH 2/6] Add absolute path support in Windows --- .../typesafe/sbt/packager/archetypes/JavaAppBatScript.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppBatScript.scala b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppBatScript.scala index d89e001d9..2eca7ec7a 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppBatScript.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppBatScript.scala @@ -11,9 +11,10 @@ object JavaAppBatScript { def makeWindowsRelativeClasspathDefine(cp: Seq[String]): String = { def cleanPath(path: String): String = path.replaceAll("/", "\\\\") + def isAbsolute(path: String): Boolean = path.length > "c:\\".length && Character.isLetter(path(0)) && path(1) == ':' def makeRelativePath(path: String): String = "%APP_LIB_DIR%\\" + cleanPath(path) - "set \"APP_CLASSPATH=" + (cp map makeRelativePath mkString ";") + "\"" + "set \"APP_CLASSPATH=" + (cp map { path => if (isAbsolute(path)) path else makeRelativePath(path) } mkString ";") + "\"" } def makeMainClassDefine(mainClass: String) = { From 8f38b0a62f5036091822d10abe5f4fe78d9724a1 Mon Sep 17 00:00:00 2001 From: hayssams Date: Fri, 23 Sep 2016 23:43:42 +0200 Subject: [PATCH 3/6] Test case for absolute path support --- .../universal/absolute-path/build.sbt | 21 +++++++++++++++++++ .../absolute-path/project/plugins.sbt | 1 + .../src/main/scala/MainApp.scala | 3 +++ src/sbt-test/universal/absolute-path/test | 3 +++ 4 files changed, 28 insertions(+) create mode 100644 src/sbt-test/universal/absolute-path/build.sbt create mode 100644 src/sbt-test/universal/absolute-path/project/plugins.sbt create mode 100644 src/sbt-test/universal/absolute-path/src/main/scala/MainApp.scala create mode 100644 src/sbt-test/universal/absolute-path/test diff --git a/src/sbt-test/universal/absolute-path/build.sbt b/src/sbt-test/universal/absolute-path/build.sbt new file mode 100644 index 000000000..990a80bc6 --- /dev/null +++ b/src/sbt-test/universal/absolute-path/build.sbt @@ -0,0 +1,21 @@ +enablePlugins(JavaAppPackaging) + +name := "absolute-path" + +version := "0.1.0" + +scriptClasspath in bashScriptDefines ++= Seq("/dummy/absolute/path", "relative/path") + +scriptClasspath in batScriptReplacements ++= Seq("x:\\dummy\\absolute\\path", "relative\\path") + +TaskKey[Unit]("run-check") := { + val dir = (stagingDirectory in Universal).value + + val bash = IO.read(dir / "bin" / "absolute-path") + assert(bash contains ":/dummy/absolute/path") + assert(bash contains ":$lib_dir/relative/path") + + val bat = IO.read(dir / "bin" / "absolute-path.bat") + assert(bat contains ";x:\\dummy\\absolute\\path") + assert(bat contains "%APP_LIB_DIR%\\relative\\path") +} diff --git a/src/sbt-test/universal/absolute-path/project/plugins.sbt b/src/sbt-test/universal/absolute-path/project/plugins.sbt new file mode 100644 index 000000000..b53de154c --- /dev/null +++ b/src/sbt-test/universal/absolute-path/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version")) diff --git a/src/sbt-test/universal/absolute-path/src/main/scala/MainApp.scala b/src/sbt-test/universal/absolute-path/src/main/scala/MainApp.scala new file mode 100644 index 000000000..0325f9cb5 --- /dev/null +++ b/src/sbt-test/universal/absolute-path/src/main/scala/MainApp.scala @@ -0,0 +1,3 @@ +object MainApp extends App { + println("SUCCESS!") +} diff --git a/src/sbt-test/universal/absolute-path/test b/src/sbt-test/universal/absolute-path/test new file mode 100644 index 000000000..877989c06 --- /dev/null +++ b/src/sbt-test/universal/absolute-path/test @@ -0,0 +1,3 @@ +# Run the staging and check the script. +> stage +> run-check \ No newline at end of file From 7a5e65bfb41897ff7676b1819c1dd3ae80af08d0 Mon Sep 17 00:00:00 2001 From: hayssams Date: Sun, 25 Sep 2016 20:57:46 +0200 Subject: [PATCH 4/6] add comment --- .../packager/archetypes/JavaAppBatScript.scala | 6 +++++- src/sbt-test/bash/absolute-path-in-bash/build.sbt | 15 +++++++++++++++ .../absolute-path-in-bash/project/plugins.sbt | 1 + .../src/main/scala/MainApp.scala | 3 +++ src/sbt-test/bash/absolute-path-in-bash/test | 3 +++ .../windows/absolute-path-in-bat/build.sbt | 15 +++++++++++++++ .../absolute-path-in-bat/project/plugins.sbt | 1 + .../src/main/scala/MainApp.scala | 3 +++ src/sbt-test/windows/absolute-path-in-bat/test | 3 +++ 9 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/sbt-test/bash/absolute-path-in-bash/build.sbt create mode 100644 src/sbt-test/bash/absolute-path-in-bash/project/plugins.sbt create mode 100644 src/sbt-test/bash/absolute-path-in-bash/src/main/scala/MainApp.scala create mode 100644 src/sbt-test/bash/absolute-path-in-bash/test create mode 100644 src/sbt-test/windows/absolute-path-in-bat/build.sbt create mode 100644 src/sbt-test/windows/absolute-path-in-bat/project/plugins.sbt create mode 100644 src/sbt-test/windows/absolute-path-in-bat/src/main/scala/MainApp.scala create mode 100644 src/sbt-test/windows/absolute-path-in-bat/test diff --git a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppBatScript.scala b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppBatScript.scala index 2eca7ec7a..04e79d91a 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppBatScript.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppBatScript.scala @@ -11,7 +11,11 @@ object JavaAppBatScript { def makeWindowsRelativeClasspathDefine(cp: Seq[String]): String = { def cleanPath(path: String): String = path.replaceAll("/", "\\\\") - def isAbsolute(path: String): Boolean = path.length > "c:\\".length && Character.isLetter(path(0)) && path(1) == ':' + def isAbsolute(path: String): Boolean = + path.length > "c:\\".length && // check path len is long enough to hold a windows absolute path + Character.isLetter(path(0)) && + path(1) == ':' + def makeRelativePath(path: String): String = "%APP_LIB_DIR%\\" + cleanPath(path) "set \"APP_CLASSPATH=" + (cp map { path => if (isAbsolute(path)) path else makeRelativePath(path) } mkString ";") + "\"" diff --git a/src/sbt-test/bash/absolute-path-in-bash/build.sbt b/src/sbt-test/bash/absolute-path-in-bash/build.sbt new file mode 100644 index 000000000..e18051fb8 --- /dev/null +++ b/src/sbt-test/bash/absolute-path-in-bash/build.sbt @@ -0,0 +1,15 @@ +enablePlugins(JavaAppPackaging) + +name := "absolute-path-in-bash" + +version := "0.1.0" + +scriptClasspath in bashScriptDefines ++= Seq("/dummy/absolute/path", "relative/path") + +TaskKey[Unit]("run-check") := { + val dir = (stagingDirectory in Universal).value + + val bash = IO.read(dir / "bin" / "absolute-path-in-bash") + assert(bash contains ":/dummy/absolute/path") + assert(bash contains ":$lib_dir/relative/path") +} diff --git a/src/sbt-test/bash/absolute-path-in-bash/project/plugins.sbt b/src/sbt-test/bash/absolute-path-in-bash/project/plugins.sbt new file mode 100644 index 000000000..b53de154c --- /dev/null +++ b/src/sbt-test/bash/absolute-path-in-bash/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version")) diff --git a/src/sbt-test/bash/absolute-path-in-bash/src/main/scala/MainApp.scala b/src/sbt-test/bash/absolute-path-in-bash/src/main/scala/MainApp.scala new file mode 100644 index 000000000..0325f9cb5 --- /dev/null +++ b/src/sbt-test/bash/absolute-path-in-bash/src/main/scala/MainApp.scala @@ -0,0 +1,3 @@ +object MainApp extends App { + println("SUCCESS!") +} diff --git a/src/sbt-test/bash/absolute-path-in-bash/test b/src/sbt-test/bash/absolute-path-in-bash/test new file mode 100644 index 000000000..877989c06 --- /dev/null +++ b/src/sbt-test/bash/absolute-path-in-bash/test @@ -0,0 +1,3 @@ +# Run the staging and check the script. +> stage +> run-check \ No newline at end of file diff --git a/src/sbt-test/windows/absolute-path-in-bat/build.sbt b/src/sbt-test/windows/absolute-path-in-bat/build.sbt new file mode 100644 index 000000000..3591a30df --- /dev/null +++ b/src/sbt-test/windows/absolute-path-in-bat/build.sbt @@ -0,0 +1,15 @@ +enablePlugins(JavaAppPackaging) + +name := "absolute-path-in-bat" + +version := "0.1.0" + +scriptClasspath in batScriptReplacements ++= Seq("x:\\dummy\\absolute\\path", "relative\\path") + +TaskKey[Unit]("run-check") := { + val dir = (stagingDirectory in Universal).value + + val bat = IO.read(dir / "bin" / "absolute-path.bat") + assert(bat contains ";x:\\dummy\\absolute\\path") + assert(bat contains "%APP_LIB_DIR%\\relative\\path") +} diff --git a/src/sbt-test/windows/absolute-path-in-bat/project/plugins.sbt b/src/sbt-test/windows/absolute-path-in-bat/project/plugins.sbt new file mode 100644 index 000000000..b53de154c --- /dev/null +++ b/src/sbt-test/windows/absolute-path-in-bat/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version")) diff --git a/src/sbt-test/windows/absolute-path-in-bat/src/main/scala/MainApp.scala b/src/sbt-test/windows/absolute-path-in-bat/src/main/scala/MainApp.scala new file mode 100644 index 000000000..0325f9cb5 --- /dev/null +++ b/src/sbt-test/windows/absolute-path-in-bat/src/main/scala/MainApp.scala @@ -0,0 +1,3 @@ +object MainApp extends App { + println("SUCCESS!") +} diff --git a/src/sbt-test/windows/absolute-path-in-bat/test b/src/sbt-test/windows/absolute-path-in-bat/test new file mode 100644 index 000000000..877989c06 --- /dev/null +++ b/src/sbt-test/windows/absolute-path-in-bat/test @@ -0,0 +1,3 @@ +# Run the staging and check the script. +> stage +> run-check \ No newline at end of file From 276168a48e8472c0c135b2101a9edac88ec5d580 Mon Sep 17 00:00:00 2001 From: hayssams Date: Sun, 25 Sep 2016 21:29:49 +0200 Subject: [PATCH 5/6] bat filename should match project name --- src/sbt-test/windows/absolute-path-in-bat/build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sbt-test/windows/absolute-path-in-bat/build.sbt b/src/sbt-test/windows/absolute-path-in-bat/build.sbt index 3591a30df..12d06b2f1 100644 --- a/src/sbt-test/windows/absolute-path-in-bat/build.sbt +++ b/src/sbt-test/windows/absolute-path-in-bat/build.sbt @@ -9,7 +9,7 @@ scriptClasspath in batScriptReplacements ++= Seq("x:\\dummy\\absolute\\path", "r TaskKey[Unit]("run-check") := { val dir = (stagingDirectory in Universal).value - val bat = IO.read(dir / "bin" / "absolute-path.bat") + val bat = IO.read(dir / "bin" / "absolute-path-in-bat.bat") assert(bat contains ";x:\\dummy\\absolute\\path") assert(bat contains "%APP_LIB_DIR%\\relative\\path") } From 4cd42b73d05207fbb49ab3a93dc1a9f269786af4 Mon Sep 17 00:00:00 2001 From: hayssams Date: Tue, 27 Sep 2016 11:15:21 +0200 Subject: [PATCH 6/6] Explicit check for path len --- .../com/typesafe/sbt/packager/archetypes/JavaAppBatScript.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppBatScript.scala b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppBatScript.scala index 04e79d91a..493ae9a50 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppBatScript.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppBatScript.scala @@ -12,7 +12,7 @@ object JavaAppBatScript { def makeWindowsRelativeClasspathDefine(cp: Seq[String]): String = { def cleanPath(path: String): String = path.replaceAll("/", "\\\\") def isAbsolute(path: String): Boolean = - path.length > "c:\\".length && // check path len is long enough to hold a windows absolute path + path.length > 3 && // check path len is long enough to hold a windows absolute path ("c:\ ...") Character.isLetter(path(0)) && path(1) == ':'