Improved code documentation and readableness in form of syntax cleanup.

This commit is contained in:
meeh
2018-05-01 03:15:44 +00:00
parent a3a8ee1329
commit 2d15f8e16e
2 changed files with 40 additions and 17 deletions

View File

@ -3,6 +3,19 @@ package net.i2p.launchers
import java.io.{File, InputStream}
/**
*
* This is a singleton ish style. It's an object - it was never a class.
* However it has a class-"brother/sister"
*
* objects like this should be considered like containers for java's
* public static methods.
*
* Many classes/objects benefits from pathJoin, so therefore it's defined
* as an "public static method".
*
* @since 0.9.35
*/
object DeployProfile {
/**

View File

@ -157,6 +157,12 @@ class OSXDeployment extends
}
/**
* Please note that in Scala, the constructor body is same as class body.
* What's defined outside of methods is considered constructor code and
* executed as it.
*
*
*
* a map function work as a loop with some built in security
* for "null" objects.
* What happens here is "for each staticFilesFromResources" do =>
@ -165,26 +171,30 @@ class OSXDeployment extends
*
* the match case is controlling the flow based upon which type of object it is.
*/
staticFilesFromResources.map { fd => fd.getContent match {
case Left(is) => {
// Write file
if (!new File(DeployProfile.pathJoin(baseDir, fd.getPath)).exists()) {
println(s"copyBaseFileResToDisk(${fd.getPath})")
try {
copyBaseFileResToDisk(fd.getPath, is)
} catch {
case ex:IOException => println(s"Error! Exception ${ex}")
staticFilesFromResources.map {
fd => fd.getContent match {
// Case subject is a file/resource
case Left(is) => {
// Write file
if (!new File(DeployProfile.pathJoin(baseDir, fd.getPath)).exists()) {
println(s"copyBaseFileResToDisk(${fd.getPath})")
try {
copyBaseFileResToDisk(fd.getPath, is)
} catch {
case ex:IOException => println(s"Error! Exception ${ex}")
}
}
}
}
case Right(dir) => {
// Ensure directory
println(s"Directory(${fd.getPath})")
if (!new File(DeployProfile.pathJoin(baseDir,fd.getPath)).exists()) {
new File(DeployProfile.pathJoin(baseDir,fd.getPath)).mkdirs()
// Case subject is a directory
case Right(dir) => {
// Ensure directory
println(s"Directory(${fd.getPath})")
if (!new File(DeployProfile.pathJoin(baseDir,fd.getPath)).exists()) {
new File(DeployProfile.pathJoin(baseDir,fd.getPath)).mkdirs()
}
dir.map { f => createFileOrDirectory(f,fd.filesIsDirectories) }
}
dir.map { f => createFileOrDirectory(f,fd.filesIsDirectories) }
}
} }
}
}