# HG changeset patch # User Jaroslav Tulach # Date 1459143191 -7200 # Node ID 17d09f3e5f08ec72740b639ff29e6a416c757b7e # Parent 37194f101d351cff2a8e5b408c4ec1122fda0268# Parent 66c99d4b35323a21983a3013e712c0fdbb6d4ab5 Merging in improvements with respect to stability and precompiled bck2brwsr libraries behavior diff -r 37194f101d35 -r 17d09f3e5f08 benchmarks/jbox2d-osgi/pom.xml --- a/benchmarks/jbox2d-osgi/pom.xml Fri Mar 25 21:47:32 2016 +0100 +++ b/benchmarks/jbox2d-osgi/pom.xml Mon Mar 28 07:33:11 2016 +0200 @@ -6,6 +6,7 @@ benchmarks 1.0-SNAPSHOT + JBox2d OSGI Wrapper bundle jbox2d-osgi @@ -41,6 +42,15 @@ true + maven-jar-plugin + 2.6 + + + false + + + + org.apidesign.bck2brwsr bck2brwsr-maven-plugin ${project.version} diff -r 37194f101d35 -r 17d09f3e5f08 benchmarks/jbox2d/pom.xml --- a/benchmarks/jbox2d/pom.xml Fri Mar 25 21:47:32 2016 +0100 +++ b/benchmarks/jbox2d/pom.xml Mon Mar 28 07:33:11 2016 +0200 @@ -43,28 +43,10 @@ brwsr + .* - - org.apidesign.bck2brwsr - bck2brwsr-maven-plugin - ${project.version} - - - - library - - - - - - org.jbox2d:* - - false - false - - @@ -106,6 +88,13 @@ org.apidesign.bck2brwsr + launcher.http + ${project.version} + bck2brwsr + test + + + org.apidesign.bck2brwsr jbox2d-osgi ${project.version} @@ -115,5 +104,11 @@ + + org.apidesign.bck2brwsr + jbox2d-osgi + ${project.version} + bck2brwsr + diff -r 37194f101d35 -r 17d09f3e5f08 launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java --- a/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java Fri Mar 25 21:47:32 2016 +0100 +++ b/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java Mon Mar 28 07:33:11 2016 +0200 @@ -37,6 +37,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Enumeration; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; @@ -649,6 +650,7 @@ Object compileJar(URL jarURL) throws IOException { List libraries = new ArrayList(); + Map osgiJars = new HashMap(); for (ClassLoader loader : loaders) { Enumeration en = loader.getResources("META-INF/MANIFEST.MF"); while (en.hasMoreElements()) { @@ -662,13 +664,26 @@ final String g = attr.getValue("Bck2BrwsrGroupId"); final String v = attr.getValue("Bck2BrwsrVersion"); final String d = attr.getValue("Bck2BrwsrDebug"); + final String n = attr.getValue("Bck2BrwsrName"); if (g != null && a != null && v != null && "true".equals(d)) { libraries.add(new String[] { - a, g, v, key + a, g, v, key, n }); } } + final Attributes main = mf.getMainAttributes(); + String symbol = main.getValue("Bundle-SymbolicName"); + String version; + if (symbol == null) { + symbol = main.getValue("OpenIDE-Module-Name"); + version = main.getValue("OpenIDE-Module-SpecificationVersion"); + } else { + version = main.getValue("Bundle-Version"); + } + if (symbol != null) { + osgiJars.put(symbol, new Object[] { e, version }); + } } } URL precompiled = null; @@ -693,6 +708,16 @@ } } } + if (precompiled == null) { + for (ClassLoader loader : loaders) { + for (String[] lib : libraries) { + Object[] urlVersion = osgiJars.get(lib[4]); + if (urlVersion != null && urlVersion[1].toString().startsWith(lib[2])) { + precompiled = loader.getResource(lib[3]); + } + } + } + } Object ret = BaseHTTPLauncher.this.compileJar(jarURL, precompiled); ignore.add(jarURL); return ret; diff -r 37194f101d35 -r 17d09f3e5f08 launcher/http/pom.xml --- a/launcher/http/pom.xml Fri Mar 25 21:47:32 2016 +0100 +++ b/launcher/http/pom.xml Mon Mar 28 07:33:11 2016 +0200 @@ -30,6 +30,29 @@ false + + org.apidesign.bck2brwsr + bck2brwsr-maven-plugin + 0.17 + + + + library + + + + + false + + + + org.apidesign.bck2brwsr + aot + ${project.version} + jar + + + @@ -70,7 +93,7 @@ org.apidesign.bck2brwsr aot - 1.0-SNAPSHOT + ${project.version} jar diff -r 37194f101d35 -r 17d09f3e5f08 launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java --- a/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Fri Mar 25 21:47:32 2016 +0100 +++ b/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Mon Mar 28 07:33:11 2016 +0200 @@ -24,11 +24,10 @@ 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; +import java.util.regex.Pattern; /** * Lightweight server to launch Bck2Brwsr applications and tests. @@ -59,6 +58,10 @@ } catch (URISyntaxException ex) { throw new IOException(ex); } + final String precompile = System.getProperty("vmtest.precompiled"); + if (precompile != null && Pattern.compile(precompile).matcher(jar.toString()).find()) { + throw new IOException("Compilation of " + jar + " forbidden"); + } LOG.log(Level.INFO, "No precompiled version for {0} found. Compiling.", jar); return CompileCP.compileJAR(f, testClasses); } diff -r 37194f101d35 -r 17d09f3e5f08 rt/emul/compact/src/main/assembly/rt.xml --- a/rt/emul/compact/src/main/assembly/rt.xml Fri Mar 25 21:47:32 2016 +0100 +++ b/rt/emul/compact/src/main/assembly/rt.xml Mon Mar 28 07:33:11 2016 +0200 @@ -12,7 +12,7 @@ provided - META-INF/maven/** + META-INF/maven/**/*mini*/** diff -r 37194f101d35 -r 17d09f3e5f08 rt/emul/compacttest/pom.xml --- a/rt/emul/compacttest/pom.xml Fri Mar 25 21:47:32 2016 +0100 +++ b/rt/emul/compacttest/pom.xml Mon Mar 28 07:33:11 2016 +0200 @@ -29,12 +29,26 @@ ${project.groupId} + launcher.http + ${project.version} + bck2brwsr + test + + + ${project.groupId} emul rt ${project.version} test + ${project.groupId} + emul + bck2brwsr + ${project.version} + test + + org.netbeans.api org-openide-util-lookup test @@ -76,7 +90,12 @@ - + + + .* + + + diff -r 37194f101d35 -r 17d09f3e5f08 rt/mojo/pom.xml --- a/rt/mojo/pom.xml Fri Mar 25 21:47:32 2016 +0100 +++ b/rt/mojo/pom.xml Mon Mar 28 07:33:11 2016 +0200 @@ -39,8 +39,8 @@ maven-compiler-plugin 2.3.2 - 1.6 - 1.6 + 1.7 + 1.7 diff -r 37194f101d35 -r 17d09f3e5f08 rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AOTLibrary.java --- a/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AOTLibrary.java Fri Mar 25 21:47:32 2016 +0100 +++ b/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AOTLibrary.java Mon Mar 28 07:33:11 2016 +0200 @@ -18,6 +18,7 @@ package org.apidesign.bck2brwsr.mojo; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; @@ -30,6 +31,7 @@ import java.util.List; import java.util.jar.Attributes; import java.util.jar.JarEntry; +import java.util.jar.JarFile; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; import org.apache.maven.artifact.Artifact; @@ -105,6 +107,7 @@ attr.putValue("Bck2BrwsrGroupId", prj.getGroupId()); attr.putValue("Bck2BrwsrVersion", prj.getVersion()); attr.putValue("Bck2BrwsrMinified", "true"); + bundleName(attr, mainJar); m.getEntries().put(minified, attr); } if (!"false".equals(debug)) { @@ -113,6 +116,7 @@ attr.putValue("Bck2BrwsrGroupId", prj.getGroupId()); attr.putValue("Bck2BrwsrVersion", prj.getVersion()); attr.putValue("Bck2BrwsrDebug", "true"); + bundleName(attr, mainJar); m.getEntries().put(debug, attr); } @@ -128,6 +132,8 @@ attr.putValue("Bck2BrwsrGroupId", a.getGroupId()); attr.putValue("Bck2BrwsrVersion", a.getVersion()); attr.putValue("Bck2BrwsrDebug", "true"); + bundleName(attr, a.getFile()); + m.getEntries().put(artifactName(a, true), attr); } { @@ -136,15 +142,18 @@ attr.putValue("Bck2BrwsrGroupId", a.getGroupId()); attr.putValue("Bck2BrwsrVersion", a.getVersion()); attr.putValue("Bck2BrwsrMinified", "true"); + bundleName(attr, a.getFile()); m.getEntries().put(artifactName(a, false), attr); } } } - FileOutputStream fos = new FileOutputStream(this.aotJar); - JarOutputStream os = new JarOutputStream(fos, m); + JarOutputStream os = null; if (!"false".equals(debug)) { + if (os == null) { + os = aotJar(m); + } os.putNextEntry(new JarEntry(debug)); Writer w = new OutputStreamWriter(os, "UTF-8"); configureMain(loader). @@ -154,6 +163,9 @@ os.closeEntry(); } if (!"false".equals(minified)) { + if (os == null) { + os = aotJar(m); + } os.putNextEntry(new JarEntry(minified)); Writer w = new OutputStreamWriter(os, "UTF-8"); @@ -177,6 +189,9 @@ } } { + if (os == null) { + os = aotJar(m); + } os.putNextEntry(new JarEntry(artifactName(a, true))); Writer w = new OutputStreamWriter(os, "UTF-8"); c. @@ -197,7 +212,9 @@ } } } - os.close(); + if (os != null) { + os.close(); + } projectHelper.attachArtifact(prj, "jar", "bck2brwsr", aotJar); } catch (IOException ex) { @@ -205,6 +222,13 @@ } } + private JarOutputStream aotJar(Manifest m) throws IOException, FileNotFoundException { + this.aotJar.getParentFile().mkdirs(); + FileOutputStream fos = new FileOutputStream(this.aotJar); + JarOutputStream os = new JarOutputStream(fos, m); + return os; + } + private Bck2Brwsr configureMain(URLClassLoader loader) throws IOException { Bck2Brwsr c = Bck2BrwsrJars.configureFrom(null, mainJar, loader, ignoreBootClassPath); if (exports != null) { @@ -219,6 +243,19 @@ return a.getGroupId() + "-" + a.getArtifactId() + (debug ? "-debug.js" : "-min.js"); } + private static void bundleName(Attributes attr, File file) throws IOException { + try (JarFile jf = new JarFile(file)) { + Attributes main = jf.getManifest().getMainAttributes(); + String version = main.getValue("Bundle-SymbolicName"); + if (version == null) { + version = main.getValue("OpenIDE-Module-Name"); + } + if (version != null) { + attr.putValue("Bck2BrwsrName", version); + } + } + } + private static URLClassLoader buildClassLoader(File root, Collection deps) throws MalformedURLException { List arr = new ArrayList(); if (root != null) { diff -r 37194f101d35 -r 17d09f3e5f08 rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Fri Mar 25 21:47:32 2016 +0100 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Mon Mar 28 07:33:11 2016 +0200 @@ -107,7 +107,11 @@ append("\n ").append(getExportsObject()).append("['registerResource']('"); append(r).append("', '"); InputStream is = this.resources.get(r); - byte[] arr = new byte[is.available()]; + int avail = is.available(); + if (avail <= 0) { + avail = 4096; + } + byte[] arr = new byte[avail]; int offset = 0; for (;;) { if (offset == arr.length) {