Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for absolute paths in classpath #882

Merged
merged 6 commits into from
Sep 28, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.typesafe.sbt.packager.archetypes

import java.io.File
import java.net.URL

/**
Expand Down Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.typesafe.sbt.packager.archetypes

import java.io.File
import java.net.URL

/**
Expand Down Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) == ':'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused about the "c:\\".lengthdefinition. It looks like putting documentation into the source code.
If you have to check for a path longer than 4 characters do so explicitly and add a small comment for what reason. At first I thought you were checking if the path starts with `c:\`` ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok will do it in a few minutes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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) = {
Expand Down
21 changes: 21 additions & 0 deletions src/sbt-test/universal/absolute-path/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
enablePlugins(JavaAppPackaging)
Copy link
Contributor

@muuki88 muuki88 Sep 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test looks good. However can you split this into two tests?

The bash one goes into sbt-test/bash and ( I know this is confusing :( ) into sbt-test/windows

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


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")
}
1 change: 1 addition & 0 deletions src/sbt-test/universal/absolute-path/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object MainApp extends App {
println("SUCCESS!")
}
3 changes: 3 additions & 0 deletions src/sbt-test/universal/absolute-path/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Run the staging and check the script.
> stage
> run-check