Skip to content
Browse files

Merge pull request #24 from jonnyzzz/jars

More changes on packing and debugging
  • Loading branch information...
2 parents e22cb98 + 21d3a5a commit 64dc543bc5be3a26ebad4d1969d348f357831cc2 @ajselvig ajselvig committed Mar 13, 2013
View
3 .idea/artifacts/kara_dist.xml
@@ -16,6 +16,9 @@
</element>
<element id="directory" name="samples">
<element id="dir-copy" path="$PROJECT_DIR$/samples/KaraDemo" />
+ <element id="directory" name="bin">
+ <element id="module-output" name="KaraDemo" />
+ </element>
</element>
<element id="directory" name="licenses">
<element id="dir-copy" path="$PROJECT_DIR$/license" />
View
23 .idea/runConfigurations/Samples_Server.xml
@@ -0,0 +1,23 @@
+<component name="ProjectRunConfigurationManager">
+ <configuration default="false" name="Samples Server" type="JetRunConfigurationType" factoryName="Kotlin" singleton="true">
+ <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
+ <option name="MAIN_CLASS_NAME" value="kara.setup.SetupPackage" />
+ <option name="VM_PARAMETERS" value="-Dkara.development.dist=$PROJECT_DIR$/out/artifacts/kara_dist" />
+ <option name="PROGRAM_PARAMETERS" value="s" />
+ <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/out/artifacts/kara_dist/samples" />
+ <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
+ <option name="ALTERNATIVE_JRE_PATH" />
+ <option name="PASS_PARENT_ENVS" value="true" />
+ <module name="KaraExec" />
+ <envs>
+ <env name="KARA_HOME" value="$PROJECT_DIR$/out/artifacts/kara_dist/samples" />
+ </envs>
+ <RunnerSettings RunnerId="Run" />
+ <ConfigurationWrapper RunnerId="Run" />
+ <method>
+ <option name="BuildArtifacts" enabled="true">
+ <artifact name="kara-dist" />
+ </option>
+ </method>
+ </configuration>
+</component>
View
18 bin/kara
@@ -5,20 +5,4 @@
# determine where Kara is installed
export KARA_HOME="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-# get the jars needed for the classpath
-JARS="$KARA_HOME/lib/*.jar"
-CP_JARS="$KARA_HOME/modules/core/kara-core.jar:$KARA_HOME/modules/exec/kara-exec.jar"
-for JAR in $JARS
-do
- case $JAR in
- *-sources.jar)
- ;;
- *-javadoc.jar)
- ;;
- *)
- CP_JARS="$JAR:$CP_JARS"
- ;;
- esac
-done
-
-java -DKARA_HOME="$KARA_HOME" -classpath "$CP_JARS" kara.KaraPackage "$@"
+java -DKARA_HOME="$KARA_HOME" -classpath "$KARA_HOME/lib/kotlin-runtime.jar:$KARA_HOME/modules/exec/kara-exec.jar" kara.setup.SetupPackage "$@"
View
12 bin/kara.bat
@@ -1,14 +1,6 @@
@echo off
-setLocal EnableDelayedExpansion
-set kara_home=%~dp0
+set KARA_HOME=%~dp0%
-set jars=%kara_home%lib\*.jar
+java -DKARA_HOME=%KARA_HOME% -cp "%KARA_HOME%\lib\kotlin-runtime.jar;%KARA_HOME%\modules\exec\kara-exec.jar" kara.setup.SetupPackage %*
-for %%j in (%jars%) do (
- set cp_jars=%%j;!cp_jars!
-)
-
-set cp_jars=!cp_jars!;%kara_home%\modules\core\kara-core.jar;%kara_home%\modules\exec\kara-exec.jar
-
-java -DKARA_HOME=%kara_home% -classpath %cp_jars% kara.KaraPackage %*
View
93 src/KaraExec/src/CLMain.kt
@@ -0,0 +1,93 @@
+package kara.setup
+
+import java.io.File
+import java.io.FileFilter
+import java.net.URL
+import java.net.URLClassLoader
+import java.net.URLDecoder
+
+fun main(args: Array<String>) {
+ val cl = URLClassLoader(HomePathResolver.collectJars(), null)
+ Thread.currentThread().setContextClassLoader(cl)
+ val clazz = cl.loadClass("kara.KaraPackage")!!
+ clazz.getMethod("main2", javaClass<Array<String>>()).invoke(null, args)
+}
+
+object HomePathResolver {
+ fun resolveHome(): File {
+ val IDEA_DEBUG = System.getProperty("kara.development.dist")
+ if (IDEA_DEBUG != null && File(IDEA_DEBUG).isDirectory()) {
+ return File(IDEA_DEBUG)
+ }
+ //jar location is <home>/modules/exec
+ return File(File(ClassPathHelper.getClasspathEntry()).getParentFile(), "../..").getCanonicalFile()
+ }
+
+ fun collectJars(): Array<URL> {
+ val home = resolveHome()
+ println("Kara home: ${home}")
+ val libs = File(home, "lib").listJars()
+ val modules = File(home, "modules").listDirs().flatMap { it.listJars().toList() }
+ return (libs + modules).map { it.toURI().toURL() }.toArray(array<URL>())
+ }
+
+ val jarFilter = object : FileFilter {
+ public override fun accept(pathname: File): Boolean
+ = pathname.isFile() && pathname.getName().endsWith(".jar") && !pathname.getName().endsWith("-sources.jar")
+ }
+
+ val dirFilter = object : FileFilter {
+ public override fun accept(pathname: File): Boolean = pathname.isDirectory()
+ }
+
+ fun File.listJars(): Array<out File> = this.listFiles(jarFilter)?:array<File>()
+ fun File.listDirs(): Array<out File> = this.listFiles(dirFilter)?:array<File>()
+
+ object ClassPathHelper {
+ fun classNameToResourcePath(className: String) = "/" + className.replace('.', '/') + ".class";
+ fun encodePlusCharacter(orig: String) = orig.replace("+", "%2B");
+
+ fun resourceUrlToClasspathEntry(className: String, resUrl: URL): String {
+ val path = classNameToResourcePath(className);
+ // we have to encode '+' character manually because otherwise URLDecoder.decode will
+ // transform it into the space character
+ var urlStr = URLDecoder.decode(encodePlusCharacter(resUrl.toExternalForm()), "UTF-8");
+ if (resUrl.getProtocol() != null) {
+ // drop path within jar file only if protocol in the URL is 'jar:'
+ if ("jar".equals(resUrl.getProtocol())) {
+ val jarSeparatorIndex = urlStr.indexOf("!");
+ if (jarSeparatorIndex >= 0) {
+ urlStr = urlStr.substring(0, jarSeparatorIndex);
+ }
+ }
+
+ var startIndex = urlStr.indexOf(':');
+ while (startIndex >= 0 && urlStr.charAt(startIndex + 1) != '/') {
+ startIndex = urlStr.indexOf(':', startIndex + 1);
+ }
+ if (startIndex >= 0) {
+ urlStr = urlStr.substring(startIndex + 1);
+ }
+ }
+
+ if (urlStr.endsWith(path)) {
+ urlStr = urlStr.substring(0, urlStr.length() - path.length());
+ }
+
+ // !Workaround for /D:/some/path/a.jar, which doesn't work if D is subst disk
+ if (urlStr.startsWith("/") && urlStr.indexOf(":") == 2) {
+ urlStr = urlStr.substring(1);
+ }
+
+ // URL may contain spaces, that is why we need to decode it
+ return File(urlStr).getPath();
+ }
+
+ private fun getClasspathEntry<T>(aClass: Class<T>): String {
+ val path = classNameToResourcePath(aClass.getName());
+ return resourceUrlToClasspathEntry(aClass.getName(), aClass.getResource(path));
+ }
+
+ public fun getClasspathEntry(): String = getClasspathEntry(javaClass);
+ }
+}
View
2 src/KaraExec/src/Main.kt
@@ -70,7 +70,7 @@ Generators:
println(s)
}
-fun main(args: Array<String>) {
+fun main2(args: Array<String>) {
BasicConfigurator.configure()
val logger = Logger.getLogger("Kara.Main")!!
View
4 src/KaraExec/src/server/AppLoader.kt
@@ -64,7 +64,9 @@ class AppLoader(val appConfig : AppConfig) : FileWatchListener {
synchronized(appLock) {
// load the application class
- classLoader = URLClassLoader(buildClasspath())
+ val cp = buildClasspath()
+ logger.debug("Application classpath: " + cp)
+ classLoader = URLClassLoader(cp, javaClass.getClassLoader())
val appClassObject = classLoader?.loadClass("${appConfig.appPackage}.Application")
if (appClassObject == null)
throw RuntimeException("Expected class ${appConfig.appPackage}.Application to be defined")

0 comments on commit 64dc543

Please sign in to comment.
Something went wrong with that request. Please try again.