# HG changeset patch # User Jaroslav Tulach # Date 1417994569 -3600 # Node ID 001275142bf76b4310cdc592aaa800468eb457f9 # Parent 40d676c86a87ab9104cfe86988206bca41b06923 Can use precompiled versions even when running tests diff -r 40d676c86a87 -r 001275142bf7 launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java --- a/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java Sat Dec 06 11:11:45 2014 +0100 +++ b/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java Mon Dec 08 00:22:49 2014 +0100 @@ -32,19 +32,24 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.net.URLConnection; import java.util.ArrayList; import java.util.Arrays; import java.util.Enumeration; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; +import java.util.Properties; import java.util.Set; import java.util.concurrent.BlockingQueue; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; +import java.util.jar.Attributes; import java.util.jar.JarFile; +import java.util.jar.Manifest; import java.util.logging.Level; import java.util.logging.Logger; import org.apidesign.bck2brwsr.launcher.InvocationContext.Resource; @@ -567,7 +572,7 @@ abstract void generateBck2BrwsrJS(StringBuilder sb, Res loader) throws IOException; abstract String harnessResource(); - String compileJar(URL jar) throws IOException { + Object compileJar(URL jar, URL precompiled) throws IOException { return null; } String compileFromClassPath(URL f, Res loader) throws IOException { @@ -587,8 +592,53 @@ final class Res { private final Set ignore = new HashSet(); - String compileJar(URL jarURL) throws IOException { - String ret = BaseHTTPLauncher.this.compileJar(jarURL); + Object compileJar(URL jarURL) throws IOException { + List libraries = new ArrayList(); + for (ClassLoader loader : loaders) { + Enumeration en = loader.getResources("META-INF/MANIFEST.MF"); + while (en.hasMoreElements()) { + URL e = en.nextElement(); + Manifest mf = new Manifest(e.openStream()); + for (Map.Entry entrySet : mf.getEntries().entrySet()) { + String key = entrySet.getKey(); + Attributes attr = entrySet.getValue(); + + final String a = attr.getValue("Bck2BrwsrArtifactId"); + final String g = attr.getValue("Bck2BrwsrGroupId"); + final String v = attr.getValue("Bck2BrwsrVersion"); + final String d = attr.getValue("Bck2BrwsrDebug"); + + if (g != null && a != null && v != null && "true".equals(d)) { + libraries.add(new String[] { + a, g, v, key + }); + } + } + } + } + URL precompiled = null; + for (ClassLoader loader : loaders) { + for (String[] lib : libraries) { + final String res = "META-INF/maven/" + lib[1] + "/" + lib[0] + "/pom.properties"; + URL props = loader.getResource(res); + if (props != null) { + URLConnection c = props.openConnection(); + Properties load = new Properties(); + final InputStream is = c.getInputStream(); + load.load(is); + is.close(); + if (lib[2].equals(load.getProperty("version"))) { + if (c instanceof JarURLConnection) { + final URL definedInURL = ((JarURLConnection)c).getJarFileURL(); + if (definedInURL.equals(jarURL)) { + precompiled = loader.getResource(lib[3]); + } + } + } + } + } + } + Object ret = BaseHTTPLauncher.this.compileJar(jarURL, precompiled); ignore.add(jarURL); return ret; } @@ -750,18 +800,22 @@ response.setCharacterEncoding("UTF-8"); if (url.getProtocol().equals("jar")) { JarURLConnection juc = (JarURLConnection) url.openConnection(); - String s = null; + Object s = null; try { s = loader.compileJar(juc.getJarFileURL()); } catch (IOException iOException) { throw new IOException("Can't compile " + url.toExternalForm(), iOException); } - if (s != null) { + if (s instanceof String) { Writer w = response.getWriter(); - w.append(s); + w.append((String)s); w.close(); return; } + if (s instanceof InputStream) { + copyStream((InputStream) s, response.getOutputStream(), null); + return; + } } if (url.getProtocol().equals("file")) { final String filePart = url.getFile(); diff -r 40d676c86a87 -r 001275142bf7 launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java --- a/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Sat Dec 06 11:11:45 2014 +0100 +++ b/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Mon Dec 08 00:22:49 2014 +0100 @@ -24,7 +24,9 @@ import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; +import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.Set; import java.util.logging.Level; @@ -46,13 +48,18 @@ } @Override - String compileJar(URL jar) throws IOException { + Object compileJar(URL jar, URL precompiled) throws IOException { + if (precompiled != null) { + LOG.log(Level.INFO, "Found precompiled JAR version of {0} at {1}. Using.", new Object[]{jar, precompiled}); + return precompiled.openStream(); + } File f; try { f = new File(jar.toURI()); } catch (URISyntaxException ex) { throw new IOException(ex); } + LOG.log(Level.INFO, "No precompiled version for {0} found. Compiling.", jar); return CompileCP.compileJAR(f, testClasses); }