-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #397 from nazoking/fix/72-too-long-classpaths
fix too long classpaths in script(bat/bash).
- Loading branch information
Showing
6 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/main/scala/com/typesafe/sbt/packager/jar/ClasspathJarPlugin.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.typesafe.sbt.packager | ||
package archetypes.jar | ||
|
||
import sbt._ | ||
import sbt.Keys.{ mappings, target, name, mainClass, sourceDirectory } | ||
import com.typesafe.sbt.packager.Keys.{ scriptClasspath } | ||
import com.typesafe.sbt.SbtNativePackager.{ Universal } | ||
|
||
object ClasspathJarPlugin extends AutoPlugin { | ||
|
||
object autoImport { | ||
val classspathJarName = TaskKey[String]("classpath-jar-name", "classpath-jar name") | ||
} | ||
import autoImport._ | ||
|
||
override def requires = archetypes.JavaAppPackaging | ||
|
||
override lazy val projectSettings = Seq[Setting[_]]( | ||
classspathJarName <<= (Keys.packageBin in Compile, Keys.projectID, Keys.artifact in Compile in Keys.packageBin) map { (jar, id, art) => | ||
makeJarName(id.organization, id.name, id.revision, art.name, art.classifier) | ||
}, | ||
mappings in Universal += { | ||
((target in Universal).value / "lib" / classspathJarName.value) -> ("lib/" + classspathJarName.value) | ||
}, | ||
scriptClasspath := { | ||
writeJar((target in Universal).value / "lib" / classspathJarName.value, scriptClasspath.value) | ||
Seq(classspathJarName.value) | ||
} | ||
) | ||
|
||
// Constructs a jar name from components...(ModuleID/Artifact) | ||
private def makeJarName(org: String, name: String, revision: String, artifactName: String, artifactClassifier: Option[String]): String = | ||
(org + "." + | ||
name + "-" + | ||
Option(artifactName.replace(name, "")).filterNot(_.isEmpty).map(_ + "-").getOrElse("") + | ||
revision + | ||
artifactClassifier.filterNot(_.isEmpty).map("-" + _).getOrElse("") + | ||
"-classpath.jar") | ||
|
||
/** write jar file */ | ||
private def writeJar(jarFile: File, allClasspath: Seq[String]) = { | ||
val manifest = new java.util.jar.Manifest() | ||
manifest.getMainAttributes().putValue("Class-Path", allClasspath.mkString(" ")) | ||
IO.jar(Seq.empty, jarFile, manifest) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
enablePlugins(ClasspathJarPlugin) | ||
|
||
name := "classpath-jar-test" | ||
|
||
version := "0.1.0" | ||
|
||
// test dependencies sample | ||
libraryDependencies ++= Seq( | ||
"com.typesafe.akka" %% "akka-kernel" % "2.3.4" | ||
) | ||
|
||
TaskKey[Unit]("check-classspath") := { | ||
val dir = (stagingDirectory in Universal).value | ||
val bat = IO.read(dir / "bin" / "classpath-jar-test.bat") | ||
assert(bat contains "set \"APP_CLASSPATH=%APP_LIB_DIR%\\classpath-jar-test.classpath-jar-test-0.1.0-classpath.jar\"") | ||
val jar = new java.util.jar.JarFile(dir / "lib" / "classpath-jar-test.classpath-jar-test-0.1.0-classpath.jar") | ||
assert(jar.getManifest().getMainAttributes().getValue("Class-Path").toString() contains "com.typesafe.akka.akka-actor") | ||
jar close | ||
} | ||
|
||
TaskKey[Unit]("run-check") := { | ||
val dir = (stagingDirectory in Universal).value | ||
val cmd = if(System.getProperty("os.name").contains("Windows")){ | ||
Seq("cmd", "/c", (dir / "bin" / "classpath-jar-test.bat").getAbsolutePath) | ||
}else{ | ||
Seq((dir / "bin" / "classpath-jar-test").getAbsolutePath) | ||
} | ||
assert(Process(cmd).!! contains "SUCCESS!") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version")) |
19 changes: 19 additions & 0 deletions
19
src/sbt-test/jar/classpath-jar/src/main/scala/test/Test.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package test | ||
|
||
// use dependency library | ||
|
||
import akka.actor._ | ||
import akka.routing.RoundRobinRouter | ||
|
||
class PrintActor extends Actor{ | ||
def receive = { | ||
case msg => println(msg) | ||
} | ||
} | ||
|
||
object Test extends App { | ||
val system = ActorSystem("testSystem") | ||
val router = system.actorOf(Props[PrintActor]) | ||
router ! "SUCCESS!!" | ||
system.shutdown | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
@echo off | ||
rem this template is minimal for test independent | ||
|
||
@setlocal enabledelayedexpansion | ||
@echo off | ||
|
||
set "@@APP_ENV_NAME@@_HOME=%~dp0\\.." | ||
|
||
set "APP_LIB_DIR=%@@APP_ENV_NAME@@_HOME%\lib\" | ||
|
||
set _JAVACMD=%JAVACMD% | ||
|
||
if "%_JAVACMD%"=="" ( | ||
if not "%JAVA_HOME%"=="" ( | ||
if exist "%JAVA_HOME%\bin\java.exe" set "_JAVACMD=%JAVA_HOME%\bin\java.exe" | ||
) | ||
) | ||
|
||
@@APP_DEFINES@@ | ||
|
||
"%_JAVACMD%" -cp "%APP_CLASSPATH%" %APP_MAIN_CLASS% %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Run the staging and check the script. | ||
> stage | ||
$ exists target/universal/stage/lib/classpath-jar-test.classpath-jar-test-0.1.0-classpath.jar | ||
> check-classspath | ||
> run-check |