mirror of
https://github.com/ij-plugins/ijp-imagej-launcher.git
synced 2024-11-13 16:29:01 -08:00
Refactor: using given logger
This commit is contained in:
parent
faf6a879e5
commit
eb8b6a9a17
4 changed files with 9 additions and 8 deletions
|
|
@ -16,7 +16,7 @@ object IJDir:
|
|||
val jarsDirName = "jars"
|
||||
|
||||
/** Locate ImageJ directory */
|
||||
def locate(config: Config, logger: Logger): Either[String, Path] =
|
||||
def locate(config: Config)(using logger: Logger): Either[String, Path] =
|
||||
logger.debug("Looking for ImageJ directory")
|
||||
|
||||
config.ijDir match
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ class Launcher(using logger: Logger):
|
|||
|
||||
private def prepareLaunch(config: Config): Either[String, Seq[String]] =
|
||||
for
|
||||
ijDir <- IJDir.locate(config, logger)
|
||||
_ <- Updater.update(ijDir, config.dryRun, logger)
|
||||
ijDir <- IJDir.locate(config)
|
||||
_ <- Updater.update(ijDir, config.dryRun)
|
||||
ijConfig <- IJConfigFile.readFromDir(ijDir)
|
||||
launcherJar <- findImageJLauncherJar(ijDir.toIO)
|
||||
javaExe <- locateJavaExecutable(config, ijDir.toIO)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ object Updater:
|
|||
* @param logger configured logger
|
||||
* @return Number of files processed or an error message.
|
||||
*/
|
||||
def update(ijDir: Path, dryRun: Boolean, logger: Logger): Either[String, Long] =
|
||||
def update(ijDir: Path, dryRun: Boolean)(using logger: Logger): Either[String, Long] =
|
||||
try
|
||||
val updateDir = ijDir / "update"
|
||||
// Count used only for debug info
|
||||
|
|
@ -39,7 +39,7 @@ object Updater:
|
|||
if !dryRun then os.move(src, dst, replaceExisting = true, createFolders = true)
|
||||
count += 1
|
||||
logger.debug(s"Delete update directory: $updateDir")
|
||||
if !dryRun then deleteEmptyDirs(updateDir, logger)
|
||||
if !dryRun then deleteEmptyDirs(updateDir)
|
||||
Right(count)
|
||||
else
|
||||
logger.info("No update found")
|
||||
|
|
@ -49,11 +49,11 @@ object Updater:
|
|||
ex.printStackTrace()
|
||||
Left(s"Failed to perform update: ${ex.getMessage} - ${ex.getClass.getSimpleName}")
|
||||
|
||||
private def deleteEmptyDirs(dir: Path, logger: Logger): Unit =
|
||||
private def deleteEmptyDirs(dir: Path)(using logger: Logger): Unit =
|
||||
logger.debug(s"Cleaning directory: $dir")
|
||||
os.list(dir)
|
||||
.filter(os.isDir)
|
||||
.foreach(p => deleteEmptyDirs(p, logger))
|
||||
.foreach(p => deleteEmptyDirs(p))
|
||||
|
||||
if os.list(dir).isEmpty then
|
||||
logger.debug(s"Removing empty dir: $dir")
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import os.Path
|
|||
|
||||
@main
|
||||
def updaterDemo(ijDir: String): Unit =
|
||||
Updater.update(Path(ijDir), dryRun = false, new Logger(Logger.Level.Debug)) match
|
||||
given logger: Logger = new Logger(Logger.Level.Debug)
|
||||
Updater.update(Path(ijDir), dryRun = false) match
|
||||
case Right(count) => println(s"Processed $count files")
|
||||
case Left(error) => println(s"Failed with error: $error")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue