diff --git a/src/main/java/com/gtnexus/appxpress/AppXpressDirResolver.java b/src/main/java/com/gtnexus/appxpress/AppXpressDirResolver.java index 6ae048d..70edcab 100644 --- a/src/main/java/com/gtnexus/appxpress/AppXpressDirResolver.java +++ b/src/main/java/com/gtnexus/appxpress/AppXpressDirResolver.java @@ -26,5 +26,11 @@ public Path resovleCurrentDirectory() { String cwd = System.getProperty(CURRENT_DIR); return Paths.get(cwd).toAbsolutePath(); } + + public static class Helper { + public static Path resolveAppxpressDir() { + return new File(String.format(DIR_TEMPLATE, System.getProperty(USER_HOME))).toPath(); + } + } } diff --git a/src/main/java/com/gtnexus/appxpress/commons/file/filter/FileFilterFactory.java b/src/main/java/com/gtnexus/appxpress/commons/file/filter/FileFilterFactory.java index 8c8e408..86e3982 100644 --- a/src/main/java/com/gtnexus/appxpress/commons/file/filter/FileFilterFactory.java +++ b/src/main/java/com/gtnexus/appxpress/commons/file/filter/FileFilterFactory.java @@ -85,4 +85,8 @@ public boolean accept(File f) { }; } + public static FileFilter isJar() { + return endsWith(".jar"); + } + } diff --git a/src/main/java/com/gtnexus/appxpress/plugin/PluginLoader.java b/src/main/java/com/gtnexus/appxpress/plugin/PluginLoader.java new file mode 100644 index 0000000..485fe0a --- /dev/null +++ b/src/main/java/com/gtnexus/appxpress/plugin/PluginLoader.java @@ -0,0 +1,45 @@ +package com.gtnexus.appxpress.plugin; + +import java.io.File; +import java.net.URL; +import java.net.URLClassLoader; +import java.nio.file.Path; + +import com.gtnexus.appxpress.AppXpressDirResolver; +import com.gtnexus.appxpress.commons.file.filter.FileFilterFactory; + +public class PluginLoader { + + public void findPlugins() { + Path appxDirPath = AppXpressDirResolver.Helper.resolveAppxpressDir(); + File appxDir = appxDirPath.toFile(); + if(appxDir.exists()) { //TODO:we have this somewhere already ... + File[] jars = appxDir.listFiles(FileFilterFactory.isJar()); + + } + } + + protected void asPayload(File jar) { + + } + + protected void load() { + URL[] urls = new URL[]{}; + String canonicalName = null; + ClassLoader loader = URLClassLoader.newInstance(urls); + try { + Class plugin = loader.loadClass(canonicalName); + Object newInstance = plugin.newInstance(); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private class Payload { + private boolean isEligible; + private String canonicalName; + private File jar; + } +} +