Jar deployment, SBT hacking, and more related to launcher code.

Some refactoring, bugfixing, and self awareness of launcher jar.
This commit is contained in:
meeh
2018-05-01 11:15:11 +00:00
parent 345e7414e6
commit f6c8e44329
7 changed files with 95 additions and 33 deletions

View File

@@ -1,7 +1,13 @@
package net.i2p.launchers
import java.io.{File, IOException}
import java.nio.file.FileAlreadyExistsException
import java.util.zip.ZipFile
import java.nio.file.StandardCopyOption.REPLACE_EXISTING
import java.nio.file.Files.copy
import java.nio.file.Paths.get
import collection.JavaConverters._
/**
@@ -120,14 +126,19 @@ class OSXDeployment extends
*/
def copyDirFromRes(dir: File): Unit = {
// A small hack
val zipFile = new ZipFile(DeployProfile.executingJarFile.getFile)
zipFile.entries().asScala.toList.filter(_.toString.startsWith(dir.getPath)).filter(!_.isDirectory).map { entry =>
new File(DeployProfile.pathJoin(baseDir,entry.getName)).getParentFile.mkdirs()
if (entry.isDirectory) {
createFileOrDirectory(new File(DeployProfile.pathJoin(baseDir,entry.getName)), true)
} else {
copyBaseFileResToDisk(entry.getName, getClass.getResourceAsStream("/".concat(entry.getName)))
try {
val zipFile = new ZipFile(DeployProfile.executingJarFile.getFile)
zipFile.entries().asScala.toList.filter(_.toString.startsWith(dir.getPath)).filter(!_.isDirectory).map { entry =>
new File(DeployProfile.pathJoin(baseDir,entry.getName)).getParentFile.mkdirs()
if (entry.isDirectory) {
createFileOrDirectory(new File(DeployProfile.pathJoin(baseDir,entry.getName)), true)
} else {
copyBaseFileResToDisk(entry.getName, getClass.getResourceAsStream("/".concat(entry.getName)))
}
}
} catch {
case ex:IOException => println(s"Error! Exception ${ex}")
case _:FileAlreadyExistsException => {} // Ignored
}
}
@@ -156,6 +167,7 @@ class OSXDeployment extends
}
} catch {
case ex:IOException => println(s"Error! Exception ${ex}")
case _:FileAlreadyExistsException => {} // Ignored
}
}
}
@@ -164,6 +176,29 @@ class OSXDeployment extends
new File(baseDir).mkdirs()
}
implicit def toPath (filename: String) = get(filename)
val selfFile = new File(DeployProfile.executingJarFile.getFile)
val selfDir = selfFile.getParentFile
val resDir = new File(selfDir.getParent, "Resources")
val i2pBaseBundleDir = new File(resDir, "i2pbase")
val i2pBundleJarDir = new File(i2pBaseBundleDir, "lib")
val i2pBaseDir = OSXDefaults.getOSXBaseDirectory
val i2pDeployJarDir = new File(i2pBaseDir, "lib")
if (!i2pDeployJarDir.exists()) {
i2pDeployJarDir.mkdirs()
i2pBundleJarDir.list().toList.map {
jar => {
copy (
DeployProfile.pathJoin(i2pBundleJarDir.getAbsolutePath, jar),
DeployProfile.pathJoin(i2pDeployJarDir.getAbsolutePath, jar),
REPLACE_EXISTING)
println(s"Copied ${jar} to right place")
}
}
}
/**
* Please note that in Scala, the constructor body is same as class body.
* What's defined outside of methods is considered constructor code and
@@ -184,12 +219,15 @@ class OSXDeployment extends
// Case subject is a file/resource
case Left(is) => {
// Write file
if (!new File(DeployProfile.pathJoin(baseDir, fd.getPath)).exists()) {
val f = DeployProfile.pathJoin(baseDir, fd.getPath)
println(s"f: ${f.toString}")
if (!new File(f).exists()) {
//println(s"copyBaseFileResToDisk(${fd.getPath})")
try {
copyBaseFileResToDisk(fd.getPath, is)
} catch {
case ex:IOException => println(s"Error! Exception ${ex}")
case _:FileAlreadyExistsException => {} // Ignored
}
}
}

View File

@@ -0,0 +1,18 @@
package net.i2p.launchers
import java.net.URL
/**
* A abstract class is kind of like an java interface.
*
* @author Meeh
* @since 0.9.35
*/
abstract class RouterLauncher {
def getClassLoader: ClassLoader
def addJarToClassPath(url: URL): Boolean
def runRouter(args: Array[String]): Unit
}