diff options
author | rockjam <5min4eq.unity@gmail.com> | 2016-06-24 08:06:16 +0300 |
---|---|---|
committer | rockjam <5min4eq.unity@gmail.com> | 2016-06-24 08:06:16 +0300 |
commit | ac502d551d54cecdadc6ac9cc02898d730867139 (patch) | |
tree | cd3c33418b97545d50737335994a270df9d4a966 /plugins/uber-jar/src | |
parent | d56d4fc1beb2b9a7885f87c5056ea9d1ea37d1ad (diff) | |
download | cbt-ac502d551d54cecdadc6ac9cc02898d730867139.tar.gz cbt-ac502d551d54cecdadc6ac9cc02898d730867139.tar.bz2 cbt-ac502d551d54cecdadc6ac9cc02898d730867139.zip |
explicitly specify jar extension, delete file before writing jar in lib
Diffstat (limited to 'plugins/uber-jar/src')
-rw-r--r-- | plugins/uber-jar/src/UberJar.scala | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/plugins/uber-jar/src/UberJar.scala b/plugins/uber-jar/src/UberJar.scala index 51edbf1..1a31dd8 100644 --- a/plugins/uber-jar/src/UberJar.scala +++ b/plugins/uber-jar/src/UberJar.scala @@ -15,7 +15,7 @@ trait UberJar extends BaseBuild { def uberJarMainClass: Option[String] = Some(runClass) - def uberJarName: String = projectName + def uberJarName: String = projectName + ".jar" } @@ -33,6 +33,7 @@ class UberJarLib(logger: Logger) { * @param target build's target directory * @param compileTarget directory where compiled classfiles are * @param classpath build's classpath + * @param mainClass optional main class * @param jarName name of resulting jar file */ def create(target: File, @@ -43,12 +44,9 @@ class UberJarLib(logger: Logger) { log(s"Compiler target directory is: $compileTarget") log(s"Classpath is: $classpath") log(s"Target directory is: $target") + log(s"Jar name is: $jarName") mainClass foreach (c => log(s"Main class is is: $c")) - log("Creating far file...") - val file = createJarFile(target.toPath, jarName) - log("Creating far file - DONE") - val jars = classpath.files filter (f => jarFileMatcher.matches(f.toPath)) log(s"Found ${jars.length} jar dependencies: \n ${jars mkString "\n"}") @@ -57,24 +55,16 @@ class UberJarLib(logger: Logger) { log("Extracting jars - DONE") log("Writing jar file...") - val optOutput = lib.jarFile(file, Seq(compileTarget, extractedJarsRoot), mainClass) + val uberJarPath = target.toPath.resolve(jarName) + val uberJar = + lib.jarFile(uberJarPath.toFile, Seq(compileTarget, extractedJarsRoot), mainClass) getOrElse { + throw new Exception("Jar file wasn't created!") + } log("Writing jar file - DONE") - optOutput foreach { uberJar => - System.err.println(s"Uber jar created. You can grab it at $uberJar") - } - + System.err.println(s"Uber jar created. You can grab it at $uberJar") } - private def createJarFile(parent: Path, name: String): File = { - val path = parent.resolve(validJarName(name)) - Files.deleteIfExists(path) - Files.createFile(path) - path.toFile - } - - private def validJarName(name: String) = if (name.endsWith(".jar")) name else name + ".jar" - /** * Extracts jars, and writes them on disk. Returns root directory of extracted jars * TODO: in future we probably should save extracted jars in target directory, to reuse them on second run |