Commit 975a3e52 by Jessica Hawkwell

Lots of work today. 😺

1 parent c6f99429
...@@ -9,6 +9,8 @@ import java.io.FileReader; ...@@ -9,6 +9,8 @@ import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
...@@ -50,13 +52,17 @@ public class Bootstrap { ...@@ -50,13 +52,17 @@ public class Bootstrap {
try { installed = checkProperties(sb.toString()); } try { installed = checkProperties(sb.toString()); }
catch (IOException ex) { } catch (IOException ex) { }
File pomFile = new File(sb.toString().concat("pom.xml"));
MavenArtifact[] deps;
ClassLoader cl = Bootstrap.class.getClassLoader();
if ( !installed ) { if ( !installed ) {
File test = new File(sb.toString().concat("pom.xml"));
String pt = "DEPS/pom.xml"; String pt = "DEPS/pom.xml";
try { copyContents(Bootstrap.class.getClassLoader().getResourceAsStream(pt), new FileOutputStream(test)); } try { copyContents(cl.getResourceAsStream(pt), new FileOutputStream(pomFile)); }
catch (FileNotFoundException ex) { Logger.getLogger(Bootstrap.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(Bootstrap.class.getName()).log(Level.SEVERE, null, ex); }
String[] deps = getDepList(test); deps = getDepList(pomFile);
StringBuilder command = new StringBuilder(); StringBuilder command = new StringBuilder();
if ( mvn ) { command.append(mavenFile.getAbsolutePath()); } if ( mvn ) { command.append(mavenFile.getAbsolutePath()); }
...@@ -67,17 +73,32 @@ public class Bootstrap { ...@@ -67,17 +73,32 @@ public class Bootstrap {
catch (InterruptedException ex) { } catch (InterruptedException ex) { }
command.append("dependency:get -Dartifact="); command.append("dependency:get -Dartifact=");
for ( String s : deps ) File test;
for ( MavenArtifact ma : deps )
{ {
try { exec(folder, command.toString().concat(s)); } test = new File(ma.getFileLocation());
catch (InterruptedException ex) { } if ( test.exists() ) {
try { exec(folder, command.toString().concat(ma.getLocation())); }
catch (InterruptedException ex) { }
}
} }
test = new File(sb.toString().concat("pom.properties")); test = new File(sb.toString().concat("pom.properties"));
try { copyContents(Bootstrap.class.getClassLoader().getResourceAsStream(PROPERTIES), new FileOutputStream(test)); } try { copyContents(cl.getResourceAsStream(PROPERTIES), new FileOutputStream(test)); }
catch(FileNotFoundException ex) {} catch(FileNotFoundException ex) {}
} }
BootstrapClassLoader bcl = new BootstrapClassLoader(cl);
bcl.init();
deps = getDepList(pomFile);
File jar;
for ( MavenArtifact ma : deps ) {
jar = new File(ma.getFileLocation());
if ( jar.exists() ) { bcl.addJar(jar); }
}
startUp(bcl, args);
} }
private static boolean check_maven() throws IOException, InterruptedException { private static boolean check_maven() throws IOException, InterruptedException {
...@@ -184,8 +205,8 @@ public class Bootstrap { ...@@ -184,8 +205,8 @@ public class Bootstrap {
return true; return true;
} }
private static String[] getDepList(File pomFile) throws FileNotFoundException, IOException { private static MavenArtifact[] getDepList(File pomFile) throws FileNotFoundException, IOException {
ArrayList<String> builder = new ArrayList<>(); ArrayList<MavenArtifact> builder = new ArrayList<>();
FileReader fr = new FileReader(pomFile); FileReader fr = new FileReader(pomFile);
BufferedReader br = new BufferedReader(fr); BufferedReader br = new BufferedReader(fr);
...@@ -202,7 +223,7 @@ public class Bootstrap { ...@@ -202,7 +223,7 @@ public class Bootstrap {
else if ( pt.startsWith("<artifactId>") ) { ma.setArtifact(lineFix(pt)); } else if ( pt.startsWith("<artifactId>") ) { ma.setArtifact(lineFix(pt)); }
else if ( pt.startsWith("<version>") ) { ma.setVersion(lineFix(pt)); } else if ( pt.startsWith("<version>") ) { ma.setVersion(lineFix(pt)); }
else if ( pt.startsWith("</dependency>") ) { else if ( pt.startsWith("</dependency>") ) {
if ( ma.isReady() ) { builder.add(ma.getLocation()); } if ( ma.isReady() ) { builder.add(ma); }
inDep = false; inDep = false;
} }
} }
...@@ -215,7 +236,7 @@ public class Bootstrap { ...@@ -215,7 +236,7 @@ public class Bootstrap {
line = br.readLine(); line = br.readLine();
} }
return builder.toArray(new String[builder.size()]); return builder.toArray(new MavenArtifact[builder.size()]);
} }
private static String lineFix(String input) { private static String lineFix(String input) {
...@@ -234,4 +255,47 @@ public class Bootstrap { ...@@ -234,4 +255,47 @@ public class Bootstrap {
Process p = pb.start(); Process p = pb.start();
p.waitFor(); p.waitFor();
} }
private static void startUp(BootstrapClassLoader bcl, String[] args) {
Thread t = new Thread() {
@Override@SuppressWarnings("unchecked")
public void run() {
System.out.println("Booting...");
Class<?> cls = null;
try { cls = bcl.loadClass("me.felinewith.lang_toolkit.apps.bootstrap.BootstrapApp"); }
catch (ClassNotFoundException ex) {
Logger.getLogger(Bootstrap.class.getName()).log(Level.SEVERE, null, ex);
return;
}
Method m = null;
try { m = cls.getMethod("init", String[].class); }
catch (NoSuchMethodException | SecurityException ex) {
Logger.getLogger(Bootstrap.class.getName()).log(Level.SEVERE, null, ex);
return;
}
Object o = null;
try { o = cls.newInstance(); }
catch (InstantiationException | IllegalAccessException ex) {
Logger.getLogger(Bootstrap.class.getName()).log(Level.SEVERE, null, ex);
}
if ( (m != null) && (o != null) ) {
try { m.invoke(o, (Object) args); }
catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
if ( (ex instanceof InvocationTargetException) && (ex.getCause() != null) ) {
Logger.getLogger(Bootstrap.class.getName()).log(Level.SEVERE, null, ex.getCause());
}
else { Logger.getLogger(Bootstrap.class.getName()).log(Level.SEVERE, null, ex); }
}
}
}
};
t.setName("Bootstrap-Main");
t.setContextClassLoader(bcl);
t.setDaemon(false);
t.start();
}
} }
package me.felinewith.lang_toolkit.apps.bootstrap;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author jlhawkwell
*/
public class BootstrapApp {
private ClassLoader cl;
String[] args;
public static void init(String[] args) {
ClassLoader cl = BootstrapApp.class.getClassLoader();
Enumeration<URL> urls = null;
try { urls = cl.getResources("bootstrap/bootstrap.properties"); }
catch (IOException ex) { Logger.getLogger(BootstrapApp.class.getName()).log(Level.SEVERE, null, ex); }
Properties props = new Properties();
URL u;
if ( urls != null ) {
while ( urls.hasMoreElements() ) {
u = urls.nextElement();
try { props.load(u.openStream()); }
catch (IOException ex) {
Logger.getLogger(BootstrapApp.class.getName()).log(Level.WARNING, null, ex);
}
}
// TODO: initialize app then iterate plugins
}
}
public BootstrapApp(ClassLoader classloader, String[] arguments) {
cl = classloader;
args = arguments;
}
}
...@@ -2,10 +2,21 @@ package me.felinewith.lang_toolkit.apps.bootstrap; ...@@ -2,10 +2,21 @@ package me.felinewith.lang_toolkit.apps.bootstrap;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.jar.Attributes;
import java.util.jar.Attributes.Name;
import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.jar.Manifest; import java.util.jar.Manifest;
import java.util.logging.Level; import java.util.logging.Level;
...@@ -14,19 +25,36 @@ import java.util.zip.ZipEntry; ...@@ -14,19 +25,36 @@ import java.util.zip.ZipEntry;
/** /**
* *
* @author jlhawkwel * @author Jessica Hawkwell
*/ */
public class BootstrapClassLoader extends ClassLoader public class BootstrapClassLoader extends ClassLoader
{ {
/** /**
* HashMap for jars. * JarName - File mapping.
* Also used to determine if a jar has already been loaded.
*/ */
private static HashMap<String, File> jars; private static HashMap<String, File> jars;
/** /**
* ClassPath - File mapping.
* Also used to determine if a ClassPath has already been loaded.
*/
private static HashMap<String, File> flds;
/**
* Set buffer length to 4096. * Set buffer length to 4096.
*/ */
public static final int BUFFER_LEN = 4096; public static final int BUFFER_LEN = 4096;
/**
* Package lists.
*/
private static HashMap<String, Package> pkgs;
/**
* Package - Jar/CP mapping.
*/
private static HashMap<String, String> maps;
/**
* Loaded classes.
*/
private static HashMap<String, Class<?>> clss;
/** /**
* Parent class loader. * Parent class loader.
*/ */
...@@ -34,87 +62,122 @@ public class BootstrapClassLoader extends ClassLoader ...@@ -34,87 +62,122 @@ public class BootstrapClassLoader extends ClassLoader
/** /**
* Constructor. * Constructor.
*/
public BootstrapClassLoader()
{
parent = getClass().getClassLoader();
jars = new HashMap<>();
flds = new HashMap<>();
pkgs = new HashMap<>();
clss = new HashMap<>();
maps = new HashMap<>();
}
/**
* Constructor.
* @param cl ClassLoader to be considered the parent * @param cl ClassLoader to be considered the parent
*/ */
public BootstrapClassLoader(ClassLoader cl) public BootstrapClassLoader(ClassLoader cl)
{ {
parent = cl; parent = cl;
jars = new HashMap<>();
flds = new HashMap<>();
pkgs = new HashMap<>();
clss = new HashMap<>();
maps = new HashMap<>();
} }
/** Initialize this ClassLoader. /** Initialize this ClassLoader.
*/ */
public void init() public void init()
{ {
jars = new HashMap<>(); Iterator<String> paths;
paths = cpDirs(System.getProperty("java.class.path"));
StringBuilder sb = new StringBuilder(System.getProperty("user.dir"));
sb.append(File.separator);
sb.append(System.getProperty("java.class.path"));
String st;
addJar(new File(sb.toString()));
Manifest mf = new Manifest();
try
{
JarFile jf = new JarFile(sb.toString());
ZipEntry ze = jf.getEntry("META-INF/MANIFEST.MF");
mf.read(jf.getInputStream(ze));
}
catch ( IOException x ) { System.out.println("Whoops!"); return; }
if ( mf.getMainAttributes().isEmpty() ) { System.out.println("No manifest?"); return; }
st = mf.getMainAttributes().getValue("Class-Path");
String[] pt = st.split(" ");
sb = new StringBuilder(System.getProperty("user.home"));
sb.append("/.m2/repository/");
File f; File f;
for ( String s : pt ) String s;
while ( paths.hasNext() )
{ {
f = new File(sb.toString().concat(s)); s = paths.next();
if ( f.exists() ) { addJar(f); } f = new File(s);
if ( f.isDirectory() ) { addDir(f); }
else if ( s.toLowerCase().endsWith(".jar") ) { addJar(f); }
} }
} }
@Override public URL getResource(final String path) @Override public Class<?> findClass(String name) throws ClassNotFoundException
{ return getResource(true, path); } {
if ( clss.containsKey(name) ) { return clss.get(name); }
else { throw new ClassNotFoundException(name); }
}
@Override public URL getResource(final String path) { return getResource(true, path); }
private URL getResource(boolean goup, final String path) private URL getResource(boolean goup, final String path)
{ {
String pth; String pth;
URL u = null; URL u = null;
if ( path.startsWith("/") ) { pth = path.substring(1); } if ( path.startsWith("/") ) { pth = path.substring(1); } else { pth = path; }
else { pth = path; } try { u = this.getResourceLocator(pth); } catch ( Throwable t ) { }
try { u = this.getResourceLocator(pth); }
catch ( Throwable t ) { }
if ( (u == null) && goup ) { u = parent.getResource(path); } if ( (u == null) && goup ) { u = parent.getResource(path); }
return u; return u;
} }
@Override public Package getPackage(String name) { return pkgs.get(name); }
@Override public Package[] getPackages() { return pkgs.values().toArray(new Package[]{}); }
private URL getResourceLocator(final String path) throws Throwable private URL getResourceLocator(final String path) throws Throwable
{ {
JarFile jf; JarFile jf;
ZipEntry ze; ZipEntry ze;
Iterator<File> it;
File f;
// FAST search
if ( !maps.isEmpty() )
{
String pack = path.replace("/", ".").substring(0, path.lastIndexOf("/"));
if ( maps.containsKey(pack) )
{
f = new File(maps.get(pack));
if ( f.isDirectory() )
{ return new URL("file:".concat(maps.get(pack)).concat(File.separator).concat(path)); }
else { return new URL("jar:file:".concat(maps.get(pack)).concat("!/").concat(path)); }
}
}
// slow search
if ( !jars.isEmpty() ) if ( !jars.isEmpty() )
{ {
for ( File f : jars.values().toArray(new File[jars.size()]) ) System.err.println("Warning: Slow search: ".concat(path));
it = jars.values().iterator();
while ( it.hasNext() )
{ {
f = it.next();
jf = new JarFile(f); jf = new JarFile(f);
ze = jf.getJarEntry(path); ze = jf.getEntry(path);
jf.close();
if ( ze != null ) if ( ze != null )
{ return new URL("jar:file:".concat(f.getCanonicalPath()).concat("!/").concat(path)); }
}
}
File t;
if ( !flds.isEmpty() )
{
System.err.println("Warning: Slow search: ".concat(path));
it = flds.values().iterator();
while ( it.hasNext() )
{
f = it.next();
try
{ {
URL u = new URL("jar:file:".concat(f.getCanonicalPath()).concat("!/").concat(path)); t = new File("file:".concat(f.getCanonicalPath()).concat(File.separator).concat(path));
return u; if ( t.exists() ) { return new URL(t.getCanonicalPath()); }
} }
catch ( IOException x ) {}
} }
} }
return null; return null;
} }
...@@ -122,24 +185,46 @@ public class BootstrapClassLoader extends ClassLoader ...@@ -122,24 +185,46 @@ public class BootstrapClassLoader extends ClassLoader
{ return getResourceAsStream(true, path); } { return getResourceAsStream(true, path); }
private InputStream getResourceAsStream(boolean goup, final String path) private InputStream getResourceAsStream(boolean goup, final String path)
{ {
final URL u = this.getResource(goup, path); final URL u = getResource(goup, path);
if ( u == null ) { return null; } if ( u == null ) { return null; }
try { return u.openStream(); } catch ( IOException e ) { e.printStackTrace(System.out); }
return null;
}
try { return u.openStream(); } @Override public Enumeration<URL> getResources(String name) throws IOException
catch ( IOException e ) { e.printStackTrace(System.out); } {
if ( jars.isEmpty() ) { return null; }
ArrayList<URL> ar = new ArrayList<>();
Iterator<File> it = jars.values().iterator();
File f;
JarFile jf;
ZipEntry ze;
return null; while ( it.hasNext() )
{
f = it.next();
jf = new JarFile(f);
ze = jf.getEntry(name);
jf.close();
if ( ze != null ) { ar.add(new URL("jar:file:".concat(f.getCanonicalPath()).concat("!/").concat(name))); }
}
return new Iterator2Enum<>(ar.iterator());
} }
@Override public Class<?> loadClass(final String name) throws ClassNotFoundException @Override public Class<?> loadClass(final String name) throws ClassNotFoundException
{ return this.loadClass(name, true); } { return loadClass(name, true); }
@Override protected Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException @Override protected Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException
{ {
Class<?> cls; // fast exit
/*Class<?> cls = findLoadedClass(name); String pack = name.substring(0, name.lastIndexOf('.'));
if ( !maps.containsKey(pack) ) { return parent.loadClass(name); }
//Class<?> cls;
Class<?> cls = findLoadedClass(name);
if ( cls != null ) { return cls; } // */ if ( cls != null ) { return cls; } // */
final InputStream is = this.getResourceAsStream(false, name.replaceAll("\\.", "/").concat(".class")); final InputStream is = getResourceAsStream(false, name.replaceAll("\\.", "/").concat(".class"));
if ( is == null ) { cls = parent.loadClass(name); } if ( is == null ) { cls = parent.loadClass(name); }
else else
{ {
...@@ -153,6 +238,7 @@ public class BootstrapClassLoader extends ClassLoader ...@@ -153,6 +238,7 @@ public class BootstrapClassLoader extends ClassLoader
private Class<?> loadClassWorker(final String name, final boolean resolve, final InputStream is) private Class<?> loadClassWorker(final String name, final boolean resolve, final InputStream is)
throws ClassNotFoundException, IOException throws ClassNotFoundException, IOException
{ {
getClassLoadingLock(name);
Class<?> cls; Class<?> cls;
final byte[] buffer = new byte[BUFFER_LEN]; final byte[] buffer = new byte[BUFFER_LEN];
...@@ -160,10 +246,7 @@ public class BootstrapClassLoader extends ClassLoader ...@@ -160,10 +246,7 @@ public class BootstrapClassLoader extends ClassLoader
byte[] bytecode; byte[] bytecode;
int i; int i;
while ( (i = is.read(buffer, 0, BUFFER_LEN)) > 0 ) { baos.write(buffer, 0, i); }
while ( (i = is.read(buffer, 0, BUFFER_LEN)) > 0 )
{ baos.write(buffer, 0, i); }
is.close(); is.close();
bytecode = baos.toByteArray(); bytecode = baos.toByteArray();
...@@ -179,18 +262,231 @@ public class BootstrapClassLoader extends ClassLoader ...@@ -179,18 +262,231 @@ public class BootstrapClassLoader extends ClassLoader
return cls; return cls;
} }
public void addJar(File jar) private String addDefHelper(Attributes manifest, Attributes file, me key)
{
if ( (file != null) && !file.isEmpty() )
{ if ( file.containsKey(key.getPrimary()) ) { return file.getValue(key.getPrimary()); } }
if ( (manifest != null) && !manifest.isEmpty() )
{
if ( manifest.containsKey(key.getPrimary()) ) { return manifest.getValue(key.getPrimary()); }
else { return key.getDefault(); }
}
return "null";
}
private void defPkg(String pack, String file, Attributes master, Attributes pkg)
throws MalformedURLException
{
Package p;
if ( !pkgs.containsKey(pack) )
{
p = definePackage(pack,
addDefHelper(master, pkg, me.SPECTITLE), addDefHelper(master, pkg, me.SPECVERSION),
addDefHelper(master, pkg, me.SPECVENDOR),
addDefHelper(master, pkg, me.IMPLTITLE), addDefHelper(master, pkg, me.IMPLVERSION),
addDefHelper(master, pkg, me.IMPLVENDOR),
new URL("file:".concat(file))
);
pkgs.put(pack, p);
maps.put(pack, file);
}
}
public void addDir(File dir)
{ {
String pt = null; String pt = null;
try { pt = jar.getCanonicalPath(); } try { pt = dir.getCanonicalPath(); }
catch (IOException ex) { Logger.getLogger(BootstrapClassLoader.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(BootstrapClassLoader.class.getName()).log(Level.SEVERE, null, ex); }
if ( pt != null ) if ( pt != null )
{ {
if ( !jars.containsKey(pt) ) if ( !flds.containsKey(pt) )
{ {
jars.put(pt, new File(pt)); flds.put(pt, new File(pt));
System.out.println("Added ".concat(pt));
// easy part done, now scan and add packages
StringBuilder sb = new StringBuilder(pt);
sb.append(File.separator);
sb.append("META-INF");
sb.append(File.separator);
sb.append("MANIFEST.MF");
File f = new File(sb.toString());
try
{
Manifest mf;
if ( f.exists() )
{
FileInputStream fis = new FileInputStream(f);
mf = new Manifest(fis);
}
else { mf = new Manifest(); }
if ( mf.getMainAttributes().containsKey(Name.CLASS_PATH) )
{ addClassPath(mf.getMainAttributes().getValue(Name.CLASS_PATH)); }
addDirHelper(dir, null, "", mf);
System.out.println("Added Dir ".concat(pt));
}
catch (IOException x) {}
} }
} }
} }
private void addDirHelper(File root, File dir, String name, Manifest mf) throws IOException
{
File[] files;
if ( dir != null ) { files = dir.listFiles(); } else { files = root.listFiles(); }
String n;
for ( File f : files )
{
if ( f.isDirectory() )
{
if ( name.isEmpty() ) { addDirHelper(root, f, f.getName(), mf); }
else
{
n = name.concat(".").concat(f.getName());
if ( n.startsWith(".") ) { n = n.substring(1); }
if ( !flds.containsKey(n) )
{ defPkg(n, root.getCanonicalPath(), mf.getMainAttributes(), mf.getAttributes(n)); }
addDirHelper(root, f, n, mf);
}
}
else if ( f.isFile() && f.getName().endsWith(".jar") ) { addJar(f); }
}
}
public void addJar(File jar)
{
String pt = null;
pt = jar.getName();
if ( pt != null )
{
if ( !jars.containsKey(pt) )
{
jars.put(pt, jar);
String tp;
// easy part done, now scan and add packages
try
{
JarFile jf = new JarFile(jars.get(pt));
Enumeration<JarEntry> en = jf.entries();
Manifest mf = jf.getManifest();
Attributes msf = mf.getMainAttributes();
JarEntry je;
if ( msf.containsKey(Name.CLASS_PATH) ) { addClassPath(msf.getValue(Name.CLASS_PATH)); }
while ( en.hasMoreElements() )
{
je = en.nextElement();
tp = je.getName();
if ( tp.endsWith("/") ) { tp = tp.substring(0, tp.lastIndexOf("/")); }
if ( je.isDirectory() && !tp.startsWith("META-INF") && tp.contains("/") )
{
tp = je.getName().replace('/', '.');
tp = tp.substring(0, tp.lastIndexOf("."));
defPkg(tp, jf.getName(), msf, je.getAttributes());
}
}
System.out.println("Added Jar ".concat(pt));
}
catch ( IOException x ) {}
}
}
}
private Iterator<String> cpDirs(String cp)
{
String[] pt;
ArrayList<String> al = new ArrayList<>();
if ( cp.contains(File.pathSeparator) || cp.contains(" ") )
{ pt = cp.split("[ ".concat(File.pathSeparator).concat("]")); }
else { pt = new String[]{cp}; }
al.addAll(Arrays.asList(pt));
return al.iterator();
}
private void addClassPath(String list) { addClassPath(cpDirs(list)); }
private void addClassPath(Iterator<String> it)
{
String st;
File finale;
String[] lists = new String[]
{
System.getProperty("user.home").concat("/.m2/repository/"),
"./libs/",
"./"
};
File f;
File t;
while ( it.hasNext() )
{
finale = null;
st = it.next();
f = new File(st);
if ( f.exists() ) { finale = f; }
for ( String s : lists )
{
if ( finale == null )
{
t = new File(s.concat(f.getPath()));
if ( t.exists() ) { finale = t; }
}
}
if ( finale != null )
{
if ( finale.isDirectory() ) { addDir(finale); }
else if ( finale.getName().endsWith(".jar") ) { addJar(finale); }
}
}
}
private enum me
{
NAME(new Name("Package"), "App"),
SPECTITLE(Name.SPECIFICATION_TITLE, "Default"),
SPECVERSION(Name.SPECIFICATION_VERSION, "1.0"),
SPECVENDOR(Name.SPECIFICATION_VENDOR, "Developer"),
IMPLTITLE(Name.IMPLEMENTATION_TITLE, "Default"),
IMPLVERSION(Name.IMPLEMENTATION_VERSION, "1.0"),
IMPLVENDOR(Name.IMPLEMENTATION_VENDOR, "Developer"),
SEALED(Name.SEALED, "false");
private final Name p;
private final String d;
me(Name pri, String def)
{
p = pri;
d = def;
}
public Name getPrimary() { return p; }
public String getDefault() { return d; }
}
public class Enum2Iterator<E> implements Iterator<E>
{
Enumeration<E> en;
public Enum2Iterator(Enumeration<E> enumer) { en = enumer; }
@Override public void forEachRemaining(Consumer<? super E> action)
{
Objects.requireNonNull(action);
while ( en.hasMoreElements() ) { action.accept(en.nextElement()); }
}
@Override public boolean hasNext() { return en.hasMoreElements(); }
@Override public E next() { return en.nextElement(); }
}
public class Iterator2Enum<E> implements Enumeration<E>
{
Iterator<E> it;
public Iterator2Enum(Iterator<E> iter) { it = iter; }
@Override public boolean hasMoreElements() { return it.hasNext(); }
@Override public E nextElement() { return it.next(); }
}
} }
package me.felinewith.lang_toolkit.apps.bootstrap;
/**
*
* @author jlhawkwell
*/
public interface IStrappedApp {
public void preStart();
public void registerPlugin(IStrappedPlugin plugin);
public void start();
}
package me.felinewith.lang_toolkit.apps.bootstrap;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JToolBar;
/**
*
* @author jlhawkwell
*/
public interface IStrappedPlugin {
public String getName();
public boolean hasButton();
public boolean hasToolBar();
public boolean hasWindow();
public JButton getButton();
public JToolBar getToolBar();
public JFrame getFrame();
}
...@@ -50,7 +50,7 @@ public class MavenArtifact { ...@@ -50,7 +50,7 @@ public class MavenArtifact {
public String getLocation() public String getLocation()
{ {
if ( !isReady( ) ) { return ""; } if ( !isReady() ) { return ""; }
StringBuilder sb = new StringBuilder(g); StringBuilder sb = new StringBuilder(g);
sb.append(":"); sb.append(":");
...@@ -60,4 +60,23 @@ public class MavenArtifact { ...@@ -60,4 +60,23 @@ public class MavenArtifact {
return sb.toString(); return sb.toString();
} }
public String getFileLocation() {
if ( !isReady() ) { return ""; }
StringBuilder sb = new StringBuilder(System.getProperty("user.home"));
sb.append("/.m2/repository/");
sb.append(g.replaceAll(".", "/"));
sb.append("/");
sb.append(a);
sb.append("/");
sb.append(v);
sb.append("/");
sb.append(a);
sb.append("-");
sb.append(v);
sb.append(".jar");
return sb.toString();
}
} }
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.felinewith.lang_toolkit.apps</groupId>
<artifactId>langbuilder</artifactId>
<packaging>jar</packaging>
<name>LangBuilder</name>
<version>1.0-SNAPSHOT</version>
<inceptionYear>2017</inceptionYear>
<description>Language builder desktop app.</description>
<parent>
<groupId>me.felinewith</groupId>
<artifactId>lang-toolkit</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>me.felinewith.lang_toolkit.apps</groupId>
<artifactId>bootstrap</artifactId>
</dependency>
</dependencies>
</project>
package me.felinewith.lang_toolkit.apps.langbuilder;
import java.util.HashMap;
import javax.swing.JFrame;
import me.felinewith.lang_toolkit.apps.bootstrap.IStrappedApp;
import me.felinewith.lang_toolkit.apps.bootstrap.IStrappedPlugin;
/**
*
* @author jlhawkwell
*/
public class LangBuilder implements IStrappedApp {
private HashMap<String, IStrappedPlugin> plugins;
private JFrame window;
@Override public void preStart() {
plugins = new HashMap<>();
window = new JFrame("LangBuilder");
// TODO: app settings, main window, toolbar menu
}
@Override public void registerPlugin(IStrappedPlugin plugin) {
}
@Override public void start() {
}
}
app=me.felinewith.lang_toolkit.apps.langbuilder.LangBuilder
...@@ -74,6 +74,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma ...@@ -74,6 +74,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
<modules> <modules>
<module>apps/bootstrap</module> <module>apps/bootstrap</module>
<module>apps/langbuilder</module>
</modules> </modules>
<developers> <developers>
...@@ -130,8 +131,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma ...@@ -130,8 +131,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
<groupId>org.apache.velocity</groupId> <groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId> <artifactId>velocity</artifactId>
<version>1.7</version> <version>1.7</version>
<scope>runtime</scope>
<type>jar</type>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.testng</groupId> <groupId>org.testng</groupId>
...@@ -144,6 +143,11 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma ...@@ -144,6 +143,11 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
<artifactId>bootstrap</artifactId> <artifactId>bootstrap</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>me.felinewith.lang_toolkit.apps</groupId>
<artifactId>langbuilder</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!