diff --git a/src/ImageJ/install-native/pom.xml b/src/ImageJ/install-native/pom.xml deleted file mode 100644 index d551c5045204cd59d65ca74e4e17503c4c89385f..0000000000000000000000000000000000000000 --- a/src/ImageJ/install-native/pom.xml +++ /dev/null @@ -1,138 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 - http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.leverjs</groupId> - <artifactId>Leversc_Plugin</artifactId> - <version>1.0.0</version> - </parent> - <artifactId>leversc-installer</artifactId> - <version>21.5.21</version> - <packaging>jar</packaging> - <name>Leversc User-Mode Installer</name> - <description>A jar wrapping the leversc executable folder that self-extracts to a user-executable folder</description> - <properties> - <name>${project.name}</name> - <version>${project.version}</version> - </properties> - <dependencies> - <dependency> - <groupId>net.leverjs</groupId> - <artifactId>Leversc_IJ</artifactId> - <version>${project.version}</version> - </dependency> - <!-- <dependency> - <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter-engine</artifactId> - <version>5.3.1</version> - <scope>test</scope> - </dependency> --> - <dependency> - <groupId>net.imagej</groupId> - <artifactId>ij</artifactId> - <version>1.53h</version> - <scope>provided</scope> - </dependency> - </dependencies> - <profiles> - <profile> - <id>win64</id> - <build> - <finalName>${project.artifactId}-natives-win64-${project.version}</finalName> - <resources> - <resource> - <directory>src/main/resources</directory> - <includes> - <include>leversc-win64/**</include> - </includes> - </resource> - </resources> - </build> - </profile> - <profile> - <id>linux64</id> - <build> - <finalName>${project.artifactId}-natives-linux64-${project.version}</finalName> - <resources> - <resource> - <directory>src/main/resources</directory> - <includes> - <include>leversc-linux64/**</include> - </includes> - </resource> - </resources> - </build> - </profile> - <profile> - <id>macos</id> - <build> - <finalName>${project.artifactId}-natives-macosx-${project.version}</finalName> - <resources> - <resource> - <directory>src/main/resources</directory> - <includes> - <include>leversc-macosx/**</include> - </includes> - </resource> - </resources> - </build> - </profile> - </profiles> - <build> - <plugins> - <!-- <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <version>2.22.0</version> - </plugin> --> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>buildnumber-maven-plugin</artifactId> - <version>1.4</version> - <executions> - <execution> - <phase>validate</phase> - <goals> - <goal>create</goal> - </goals> - </execution> - </executions> - <configuration> - <doCheck>false</doCheck> - <doUpdate>false</doUpdate> - </configuration> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>properties-maven-plugin</artifactId> - <version>1.0.0</version> - <executions> - <execution> - <phase>generate-resources</phase> - <goals> - <goal>write-project-properties</goal> - </goals> - <configuration> - <outputFile>${project.build.outputDirectory}/${project.artifactId}-build.properties</outputFile> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-help-plugin</artifactId> - <version>3.2.0</version> - <executions> - <execution> - <id>show-profiles</id> - <phase>compile</phase> - <goals> - <goal>active-profiles</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> -</project> diff --git a/src/ImageJ/install-native/src/main/java/net/leverjs/LeverscJarInstaller.java b/src/ImageJ/install-native/src/main/java/net/leverjs/LeverscJarInstaller.java deleted file mode 100644 index f9c9e8956b9c2a180b4e65adc6bd75aecc48a401..0000000000000000000000000000000000000000 --- a/src/ImageJ/install-native/src/main/java/net/leverjs/LeverscJarInstaller.java +++ /dev/null @@ -1,233 +0,0 @@ -package net.leverjs; - -import net.leverjs.LeverscInstallInterface; -import net.leverjs.PlatformInfo; -import net.leverjs.PluginHelper; - -import java.io.File; -import java.io.InputStream; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.OutputStreamWriter; - -import java.net.URL; - -import java.nio.file.Path; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.nio.charset.StandardCharsets; - -import java.util.List; -import java.util.ArrayList; -import java.util.Properties; -import java.util.Enumeration; -import java.util.zip.ZipFile; - -import java.util.zip.ZipEntry; - -import java.io.IOException; -import java.util.zip.ZipException; -import java.net.URISyntaxException; -import java.io.FileNotFoundException; - -import ij.IJ; - -public class LeverscJarInstaller implements LeverscInstallInterface -{ - public File installLeversc() - { - try - { - String localAppdata = PlatformInfo.getAppDataPath(); - Path installPath = Paths.get(localAppdata, "leversc"); - - Path jarPath = PluginHelper.getJarPath(getClass()); - // IJ.log(String.format("Installer JarPath: %s", jarPath.toString())); - - if ( !Files.exists(installPath) ) - Files.createDirectories(installPath); - - // Check installed (and compare build-numbers) - String build = PluginHelper.getResourceProperty(getClass(), "/leversc-installer-build.properties", "buildNumber"); - if ( build == null ) - { - IJ.log("Malformed installer jar: No buildNumber in build.properties"); - return null; - } - - boolean bNeedsUpdate = true; - Path buildFile = Paths.get(installPath.toString(), "version.txt"); - if ( Files.exists(buildFile) ) - { - IJ.log("Levesc install found, checking build version..."); - String installedBuild = new String(Files.readAllBytes(buildFile), StandardCharsets.UTF_8).trim(); - - bNeedsUpdate = ( !build.equalsIgnoreCase(installedBuild) ); - } - - // Early out if we already have an up-to-date install - boolean bNeedsInstall = !Files.exists(buildFile); - if ( !bNeedsUpdate ) - { - IJ.log("Leversc up-to-date"); - return getLeverscExecutable(installPath); - } - - IJ.showStatus(String.format("%s Leversc Executable...", (bNeedsInstall ? "Installing" : "Updating"))); - IJ.showProgress(0.0); - // TODO: Warn users that install/update might take some time - removeChildren(installPath.toFile()); - - // TODO: Use showProgress to give feedback during install - String prefix = String.format("leversc-%s/", PlatformInfo.getPlatformString()); - extractJar(installPath.toFile(), jarPath.toFile(), prefix); - writeBuild(installPath.toFile(), build); - - IJ.showStatus(""); - IJ.showProgress(1.0); - - IJ.log("Leversc update complete"); - - return getLeverscExecutable(installPath); - } - catch (FileNotFoundException e) - { - IJ.log(String.format("File not found: %s", e.toString())); - } - catch (URISyntaxException e) - { - IJ.log(String.format("URI error: %s", e.toString())); - } - catch (IOException e) - { - IJ.log(String.format("IO error: %s", e.toString())); - } - - return null; - } - - private static void removeChildren(File inPath) - { - File[] contents = inPath.listFiles(); - if ( contents == null ) - return; - - for ( File entry : contents ) - { - if ( entry.isDirectory() ) - removeChildren(entry); - - entry.delete(); - } - } - - private static File getLeverscExecutable(Path installPath) - { - File leverscExec = null; - if ( PlatformInfo.isWindows() ) - leverscExec = new File(installPath.toFile(), "leverjs.exe"); - else if ( PlatformInfo.isLinux() ) - leverscExec = new File(installPath.toFile(), "leverjs"); - else if ( PlatformInfo.isMac() ) - leverscExec = new File(installPath.toFile(), "leverjs.app");; - - if ( leverscExec != null ) - { - if ( PlatformInfo.isMac() ) - { - Path macosExec = Paths.get(leverscExec.toString(), "Contents", "MacOS", "leverjs"); - macosExec.toFile().setExecutable(true); - } - else - leverscExec.setExecutable(true); - } - - return leverscExec; - } - - private void extractJar(File installPath, File jarFile, String matchPrefix) throws ZipException, IOException - { - // IJ.log(String.format("Extracting %s -> %s", jarFile.getPath(), installPath.getPath())); - ZipFile zipFile = new ZipFile(jarFile); - try - { - int outBytes = 0; - List<ZipEntry> matchEntries = new ArrayList<ZipEntry>(50); - Enumeration<? extends ZipEntry> entries = zipFile.entries(); - while ( entries.hasMoreElements() ) - { - ZipEntry entry = entries.nextElement(); - if ( entry.getName().startsWith(matchPrefix) ) - { - matchEntries.add(entry); - if ( !entry.isDirectory() ) - outBytes += entry.getSize(); - } - } - - int extractBytes = 0; - for ( ZipEntry ze : matchEntries ) - { - String outName = ze.getName().substring(matchPrefix.length()); - // Ignore the leversc-* directory entry - if ( outName.length() > 0 ) - { - File target = new File(installPath, outName); - if ( ze.isDirectory() ) - { - if ( !target.mkdirs() ) - throw new IOException(String.format("Unable to create directory: %s", target.getPath())); - } - else - { - extractEntry(target, ze, zipFile); - - extractBytes += ze.getSize(); - IJ.showProgress(((float)extractBytes) / outBytes); - } - } - } - } - finally - { - zipFile.close(); - } - } - - private void extractEntry(File target, ZipEntry entry, ZipFile zipFile) throws FileNotFoundException, IOException - { - byte[] buffer = new byte[100*1024]; - - InputStream zis = zipFile.getInputStream(entry); - FileOutputStream fos = new FileOutputStream(target); - - try - { - int len = zis.read(buffer); - while ( len > 0 ) - { - fos.write(buffer, 0,len); - len = zis.read(buffer); - } - } - finally - { - zis.close(); - fos.close(); - } - } - - private static void writeBuild(File installPath, String build) throws FileNotFoundException, IOException - { - File verFile = new File(installPath, "version.txt"); - OutputStreamWriter outWriter = new OutputStreamWriter(new FileOutputStream(verFile.toString()), StandardCharsets.UTF_8); - try - { - outWriter.write(build); - } - finally - { - outWriter.close(); - } - } -} diff --git a/src/ImageJ/plugin-ij/src/main/java/net/leverjs/LeverscIJ.java b/src/ImageJ/plugin-ij/src/main/java/net/leverjs/LeverscIJ.java index 23a2be9277e5fadb91ddc47a98b29188a0b54a62..e3b1d8441454508cf31402007e7b5774d465112c 100644 --- a/src/ImageJ/plugin-ij/src/main/java/net/leverjs/LeverscIJ.java +++ b/src/ImageJ/plugin-ij/src/main/java/net/leverjs/LeverscIJ.java @@ -60,8 +60,6 @@ public class LeverscIJ implements PlugInFilter protected static int base_port = 3000; protected static byte[] _crlf = {0x0D, 0x0A}; - private static LeverscInstallInterface installer = LeverscInstallLoader.load(); - // Current image protected ImagePlus image; public int imType; @@ -70,13 +68,8 @@ public class LeverscIJ implements PlugInFilter public int setup(String arg, ImagePlus imp) { + // TODO - Try default install folders (e.g. LOCALAPPDADAT/leversc) leverscExec = null; - if ( installer != null ) - { - IJ.log(String.format("Found installer: %s", installer.toString())); - leverscExec = installer.installLeversc(); - } - image = imp; // TODO - Should we try to support any color (drop DOES_8C or add DOES_RGB) stacks? diff --git a/src/ImageJ/plugin-ij/src/main/java/net/leverjs/LeverscInstallInterface.java b/src/ImageJ/plugin-ij/src/main/java/net/leverjs/LeverscInstallInterface.java deleted file mode 100644 index 3b4586866fa8212de006c84d2cdd415dd67c3620..0000000000000000000000000000000000000000 --- a/src/ImageJ/plugin-ij/src/main/java/net/leverjs/LeverscInstallInterface.java +++ /dev/null @@ -1,8 +0,0 @@ -package net.leverjs; - -import java.io.File; - -public interface LeverscInstallInterface -{ - public File installLeversc(); -} diff --git a/src/ImageJ/plugin-ij/src/main/java/net/leverjs/LeverscInstallLoader.java b/src/ImageJ/plugin-ij/src/main/java/net/leverjs/LeverscInstallLoader.java deleted file mode 100644 index 31d542397cf48b52ca7785466a85c44f1d8e770c..0000000000000000000000000000000000000000 --- a/src/ImageJ/plugin-ij/src/main/java/net/leverjs/LeverscInstallLoader.java +++ /dev/null @@ -1,102 +0,0 @@ -package net.leverjs; - -import java.net.URL; -import java.net.URLClassLoader; - -import java.nio.file.Path; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.nio.file.PathMatcher; -import java.nio.file.FileSystems; -import java.nio.file.FileVisitResult; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; - -import java.util.function.Predicate; - -import java.io.IOException; -import java.net.URISyntaxException; - -import ij.IJ; - -public class LeverscInstallLoader -{ - private static class InstallerPredicate implements Predicate<Path> - { - private PathMatcher matcher; - public InstallerPredicate(PathMatcher inMatcher) - { - matcher = inMatcher; - } - - @Override - public boolean test(Path path) - { - return matcher.matches(path); - } - } - - - public static LeverscInstallInterface load() - { - // NOTE: IJ Platforms: { "linux32", "linux64", "macosx", "tiger", "win32", "win64" } - final Class pluginClass = LeverscIJ.class; - String platform = PlatformInfo.getPlatformString(); - String version = PluginHelper.getResourceProperty(pluginClass, "/Leversc_IJ-build.properties", "version"); - try - { - Path jarFolderPath = PluginHelper.getJarPath(pluginClass).getParent(); - - String glob = String.format("glob:**/leversc-installer-natives-%s-%s.jar",platform,version); - PathMatcher matcher = FileSystems.getDefault().getPathMatcher(glob); - InstallerPredicate matchPred = new InstallerPredicate(matcher); - - Path checkDir = Paths.get(jarFolderPath.toString(), platform); - if ( !Files.exists(checkDir) ) - checkDir = Paths.get(jarFolderPath.toString()); - - Path installerJar = Files.walk(checkDir).filter(matchPred).findFirst().orElse(null); - if ( installerJar == null ) - { - IJ.log(String.format("No installer jar found: %s", checkDir)); - return null; - } - - ClassLoader loader = URLClassLoader.newInstance( - new URL[] {installerJar.toUri().toURL()}, - pluginClass.getClassLoader() - ); - - Class<?> installClass = Class.forName("net.leverjs.LeverscJarInstaller", true, loader); - Class<? extends LeverscInstallInterface> subClass = installClass.asSubclass(LeverscInstallInterface.class); - - return subClass.newInstance(); - } - catch (IllegalAccessException e) - { - IJ.log(e.toString()); - } - catch (InstantiationException e) - { - IJ.log(String.format("Unable to instantiate installer class: %s", e.toString())); - } - catch (ClassNotFoundException e) - { - IJ.log(String.format("Unable to find class: %s", e.toString())); - } - catch (ClassCastException e) - { - IJ.log(String.format("Invalid installer class: %s", e.toString())); - } - catch (URISyntaxException e) - { - IJ.log(String.format("Invalid file URL: %s", e.toString())); - } - catch (IOException e) - { - IJ.log(String.format("IO error: %s:%s", e.toString(), e.getStackTrace()[0].getLineNumber())); - } - - return null; - } -} diff --git a/src/ImageJ/pom.xml b/src/ImageJ/pom.xml index 3cf9d3d9494258b6a0e06322526601e231729f24..45c832059cf4fad3ab293f9b6bd222ca3c0a919c 100644 --- a/src/ImageJ/pom.xml +++ b/src/ImageJ/pom.xml @@ -30,7 +30,6 @@ </scm> <modules> <module>plugin-ij</module> - <module>install-native</module> </modules> </project>