mirror of
https://github.com/ij-plugins/ijp-imagej-launcher.git
synced 2024-11-13 16:29:01 -08:00
Support Fiji update processing
This commit is contained in:
parent
30d41e3a40
commit
876e62bcd4
5 changed files with 76 additions and 11 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
IJP ImageJ Launcher
|
IJP ImageJ Launcher
|
||||||
===================
|
===================
|
||||||
|
|
||||||
IJP ImageJ Launcher is native launcher that starts [ImageJ 2] or [Fiji].
|
IJP ImageJ Launcher is a native launcher that starts [ImageJ 2] or [Fiji].
|
||||||
It is intended to be a general drop-in replacement for the original [ImageJ Launcher].
|
It is intended to be a general drop-in replacement for the original [ImageJ Launcher].
|
||||||
IJP ImageJ Launcher is a clean implementation on the core function of starting [ImageJ 2] or [Fiji].
|
IJP ImageJ Launcher is a clean implementation on the core function of starting [ImageJ 2] or [Fiji].
|
||||||
|
|
||||||
|
|
@ -25,16 +25,16 @@ Features [work in progress]
|
||||||
- Mac OS X Arm64 (Apple Silicon)
|
- Mac OS X Arm64 (Apple Silicon)
|
||||||
- Mac OS X Intel
|
- Mac OS X Intel
|
||||||
- Linux
|
- Linux
|
||||||
* Selects location of ImageJ directory
|
* Selects location of the ImageJ directory
|
||||||
- Startup directory or
|
- Startup directory or
|
||||||
- Directory specified by `--ij-dir` command line option
|
- Directory specified by `--ij-dir` command line option
|
||||||
* Locates Java Virtual Machine for ImageJ:
|
* Locates Java Virtual Machine for ImageJ:
|
||||||
- Use Java VM requested the by the use (`--java-home`)
|
- Use Java VM requested by the user (`--java-home`)
|
||||||
- Use `JAVA_HOME` environment variable
|
- Use `JAVA_HOME` environment variable
|
||||||
- Search ImageJ directory for available Java executables
|
- Search ImageJ directory for available Java executables
|
||||||
* Determines the amount of memory used by JVM based on total system memory use 75% of the max
|
* Determines the amount of memory used by JVM based on total system memory use 75% of the max
|
||||||
* Determines available `imagej-launcher*.jar`
|
* Determines available `imagej-launcher*.jar`
|
||||||
* Performs updates pending after last time ImageJ was closed
|
* Performs updates pending after the last time ImageJ was closed
|
||||||
|
|
||||||
### Full list of command line options
|
### Full list of command line options
|
||||||
|
|
||||||
|
|
@ -45,7 +45,6 @@ Features [work in progress]
|
||||||
--info informational output
|
--info informational output
|
||||||
--debug verbose output
|
--debug verbose output
|
||||||
--java-home <path> specify JAVA_HOME explicitly
|
--java-home <path> specify JAVA_HOME explicitly
|
||||||
--print-java-home print ImageJ's idea of JAVA_HOME
|
|
||||||
--ij-dir <path> set the ImageJ directory to <path> (used to find jars/, plugins/ and macros/)
|
--ij-dir <path> set the ImageJ directory to <path> (used to find jars/, plugins/ and macros/)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ class Launcher(logger: Logger):
|
||||||
private val jarsDirName = "jars"
|
private val jarsDirName = "jars"
|
||||||
|
|
||||||
def run(config: Config): Unit =
|
def run(config: Config): Unit =
|
||||||
createCommandLine(config) match
|
prepareLaunch(config) match
|
||||||
case Right(commandLine) =>
|
case Right(commandLine) =>
|
||||||
if config.dryRun then
|
if config.dryRun then
|
||||||
logger.debug("dry-run")
|
logger.debug("dry-run")
|
||||||
|
|
@ -27,9 +27,10 @@ class Launcher(logger: Logger):
|
||||||
case Left(errorMessage) =>
|
case Left(errorMessage) =>
|
||||||
logger.error(errorMessage)
|
logger.error(errorMessage)
|
||||||
|
|
||||||
private def createCommandLine(config: Config): Either[String, Seq[String]] =
|
private def prepareLaunch(config: Config): Either[String, Seq[String]] =
|
||||||
for
|
for
|
||||||
ijDir <- locateIJDir(config)
|
ijDir <- locateIJDir(config)
|
||||||
|
_ <- Updater.update(Path(ijDir), config.dryRun, logger)
|
||||||
launcherJar <- findImageJLauncherJar(ijDir)
|
launcherJar <- findImageJLauncherJar(ijDir)
|
||||||
javaExe <- locateJavaExecutable(config, ijDir)
|
javaExe <- locateJavaExecutable(config, ijDir)
|
||||||
systemType <- determineSystemType()
|
systemType <- determineSystemType()
|
||||||
|
|
|
||||||
|
|
@ -58,10 +58,6 @@ object Main:
|
||||||
.action((path, c) => c.copy(javaHome = Option(path)))
|
.action((path, c) => c.copy(javaHome = Option(path)))
|
||||||
.text("specify JAVA_HOME explicitly"),
|
.text("specify JAVA_HOME explicitly"),
|
||||||
//
|
//
|
||||||
opt[Unit]("print-java-home")
|
|
||||||
.action((_, c) => c.copy(dryRun = true))
|
|
||||||
.text("print ImageJ's idea of JAVA_HOME"),
|
|
||||||
//
|
|
||||||
opt[File]("ij-dir")
|
opt[File]("ij-dir")
|
||||||
.valueName("<path>")
|
.valueName("<path>")
|
||||||
.action((path, c) => c.copy(ijDir = Option(path)))
|
.action((path, c) => c.copy(ijDir = Option(path)))
|
||||||
|
|
|
||||||
60
src/main/scala/ij_plugins/imagej_launcher/Updater.scala
Normal file
60
src/main/scala/ij_plugins/imagej_launcher/Updater.scala
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
package ij_plugins.imagej_launcher
|
||||||
|
|
||||||
|
import os.Path
|
||||||
|
|
||||||
|
import scala.util.control.NonFatal
|
||||||
|
|
||||||
|
object Updater:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform update using files in `update` subdirectory, if it exists.
|
||||||
|
* @param ijDir imagej
|
||||||
|
* @param dryRun locate files to process but do not make any changes, but count the files that would be processed
|
||||||
|
* @param logger configured logger
|
||||||
|
* @return Number of files processed or an error message.
|
||||||
|
*/
|
||||||
|
def update(ijDir: Path, dryRun: Boolean, logger: Logger): Either[String, Long] =
|
||||||
|
try
|
||||||
|
val updateDir = ijDir / "update"
|
||||||
|
// Count used only for debug info
|
||||||
|
var count = 0
|
||||||
|
if os.exists(updateDir) then
|
||||||
|
logger.info("Performing update..")
|
||||||
|
os.walk(updateDir)
|
||||||
|
.filter(os.isFile)
|
||||||
|
.foreach { src =>
|
||||||
|
val dst = ijDir / src.relativeTo(updateDir)
|
||||||
|
if os.size(src) == 0 then
|
||||||
|
logger.debug(s"remove: $dst")
|
||||||
|
if !dryRun then os.remove(dst)
|
||||||
|
logger.debug(s"remove: $src")
|
||||||
|
if !dryRun then os.remove(src)
|
||||||
|
else
|
||||||
|
logger.debug(s"move : $src -> $dst")
|
||||||
|
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)
|
||||||
|
Right(count)
|
||||||
|
else
|
||||||
|
logger.info("No update found")
|
||||||
|
Right(count)
|
||||||
|
catch
|
||||||
|
case NonFatal(ex) =>
|
||||||
|
ex.printStackTrace()
|
||||||
|
Left(s"Failed to perform update: ${ex.getMessage} - ${ex.getClass.getSimpleName}")
|
||||||
|
|
||||||
|
private def deleteEmptyDirs(dir: Path, logger: Logger): Unit =
|
||||||
|
logger.debug(s"Cleaning directory: $dir")
|
||||||
|
os.list(dir)
|
||||||
|
.filter(os.isDir)
|
||||||
|
.foreach(p => deleteEmptyDirs(p, logger))
|
||||||
|
|
||||||
|
if os.list(dir).isEmpty then
|
||||||
|
logger.debug(s"Removing empty dir: $dir")
|
||||||
|
os.remove(dir)
|
||||||
|
else
|
||||||
|
logger.debug(s"Cannot delete directory, not empty: $dir")
|
||||||
|
|
||||||
|
end Updater
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package ij_plugins.imagej_launcher
|
||||||
|
|
||||||
|
import os.Path
|
||||||
|
|
||||||
|
@main
|
||||||
|
def updaterDemo(ijDir: String): Unit =
|
||||||
|
Updater.update(Path(ijDir), dryRun = false, new Logger(Logger.Level.Debug)) 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