Commit 975a3e52 by Jessica Hawkwell

Lots of work today. 😺

1 parent c6f99429
......@@ -9,6 +9,8 @@ import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Properties;
......@@ -50,13 +52,17 @@ public class Bootstrap {
try { installed = checkProperties(sb.toString()); }
catch (IOException ex) { }
File pomFile = new File(sb.toString().concat("pom.xml"));
MavenArtifact[] deps;
ClassLoader cl = Bootstrap.class.getClassLoader();
if ( !installed ) {
File test = new File(sb.toString().concat("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); }
String[] deps = getDepList(test);
deps = getDepList(pomFile);
StringBuilder command = new StringBuilder();
if ( mvn ) { command.append(mavenFile.getAbsolutePath()); }
......@@ -67,17 +73,32 @@ public class Bootstrap {
catch (InterruptedException ex) { }
command.append("dependency:get -Dartifact=");
for ( String s : deps )
File test;
for ( MavenArtifact ma : deps )
{
try { exec(folder, command.toString().concat(s)); }
catch (InterruptedException ex) { }
test = new File(ma.getFileLocation());
if ( test.exists() ) {
try { exec(folder, command.toString().concat(ma.getLocation())); }
catch (InterruptedException ex) { }
}
}
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) {}
}
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 {
......@@ -184,8 +205,8 @@ public class Bootstrap {
return true;
}
private static String[] getDepList(File pomFile) throws FileNotFoundException, IOException {
ArrayList<String> builder = new ArrayList<>();
private static MavenArtifact[] getDepList(File pomFile) throws FileNotFoundException, IOException {
ArrayList<MavenArtifact> builder = new ArrayList<>();
FileReader fr = new FileReader(pomFile);
BufferedReader br = new BufferedReader(fr);
......@@ -202,7 +223,7 @@ public class Bootstrap {
else if ( pt.startsWith("<artifactId>") ) { ma.setArtifact(lineFix(pt)); }
else if ( pt.startsWith("<version>") ) { ma.setVersion(lineFix(pt)); }
else if ( pt.startsWith("</dependency>") ) {
if ( ma.isReady() ) { builder.add(ma.getLocation()); }
if ( ma.isReady() ) { builder.add(ma); }
inDep = false;
}
}
......@@ -215,7 +236,7 @@ public class Bootstrap {
line = br.readLine();
}
return builder.toArray(new String[builder.size()]);
return builder.toArray(new MavenArtifact[builder.size()]);
}
private static String lineFix(String input) {
......@@ -234,4 +255,47 @@ public class Bootstrap {
Process p = pb.start();
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;
}
}
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 {
public String getLocation()
{
if ( !isReady( ) ) { return ""; }
if ( !isReady() ) { return ""; }
StringBuilder sb = new StringBuilder(g);
sb.append(":");
......@@ -60,4 +60,23 @@ public class MavenArtifact {
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
<modules>
<module>apps/bootstrap</module>
<module>apps/langbuilder</module>
</modules>
<developers>
......@@ -130,8 +131,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
<scope>runtime</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.testng</groupId>
......@@ -144,6 +143,11 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
<artifactId>bootstrap</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>me.felinewith.lang_toolkit.apps</groupId>
<artifactId>langbuilder</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!