Merging in improvements with respect to stability and precompiled bck2brwsr libraries behavior
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 28 Mar 2016 07:33:11 +0200
changeset 191817d09f3e5f08
parent 1913 37194f101d35
parent 1917 66c99d4b3532
child 1919 a064702472ec
Merging in improvements with respect to stability and precompiled bck2brwsr libraries behavior
benchmarks/jbox2d-osgi/pom.xml
benchmarks/jbox2d/pom.xml
launcher/http/pom.xml
rt/emul/compacttest/pom.xml
rt/mojo/pom.xml
     1.1 --- a/benchmarks/jbox2d-osgi/pom.xml	Fri Mar 25 21:47:32 2016 +0100
     1.2 +++ b/benchmarks/jbox2d-osgi/pom.xml	Mon Mar 28 07:33:11 2016 +0200
     1.3 @@ -6,6 +6,7 @@
     1.4          <artifactId>benchmarks</artifactId>
     1.5          <version>1.0-SNAPSHOT</version>
     1.6      </parent>
     1.7 +    <name>JBox2d OSGI Wrapper</name>
     1.8      <packaging>bundle</packaging>
     1.9      <artifactId>jbox2d-osgi</artifactId>
    1.10      <properties>
    1.11 @@ -41,6 +42,15 @@
    1.12                  <extensions>true</extensions>
    1.13              </plugin>
    1.14              <plugin>
    1.15 +                <artifactId>maven-jar-plugin</artifactId>
    1.16 +                <version>2.6</version>
    1.17 +                <configuration>
    1.18 +                    <archive>
    1.19 +                        <addMavenDescriptor>false</addMavenDescriptor>
    1.20 +                    </archive>
    1.21 +                </configuration>
    1.22 +            </plugin>
    1.23 +            <plugin>
    1.24                  <groupId>org.apidesign.bck2brwsr</groupId>
    1.25                  <artifactId>bck2brwsr-maven-plugin</artifactId>
    1.26                  <version>${project.version}</version>
     2.1 --- a/benchmarks/jbox2d/pom.xml	Fri Mar 25 21:47:32 2016 +0100
     2.2 +++ b/benchmarks/jbox2d/pom.xml	Mon Mar 28 07:33:11 2016 +0200
     2.3 @@ -43,28 +43,10 @@
     2.4                <configuration>
     2.5                    <systemPropertyVariables>
     2.6                        <vmtest.js>brwsr</vmtest.js>
     2.7 +                      <vmtest.precompiled>.*</vmtest.precompiled>
     2.8                    </systemPropertyVariables>
     2.9                </configuration>
    2.10            </plugin>
    2.11 -          <plugin>
    2.12 -              <groupId>org.apidesign.bck2brwsr</groupId>
    2.13 -              <artifactId>bck2brwsr-maven-plugin</artifactId>
    2.14 -              <version>${project.version}</version>
    2.15 -              <executions>
    2.16 -                  <execution>
    2.17 -                      <goals>
    2.18 -                          <goal>library</goal>
    2.19 -                      </goals>
    2.20 -                  </execution>
    2.21 -              </executions>
    2.22 -              <configuration>
    2.23 -                  <aotDeps>
    2.24 -                      <aotDep>org.jbox2d:*</aotDep>
    2.25 -                  </aotDeps>
    2.26 -                  <minified>false</minified>
    2.27 -                  <debug>false</debug>
    2.28 -              </configuration>
    2.29 -          </plugin>
    2.30        </plugins>
    2.31    </build>
    2.32    
    2.33 @@ -106,6 +88,13 @@
    2.34      </dependency>
    2.35      <dependency>
    2.36        <groupId>org.apidesign.bck2brwsr</groupId>
    2.37 +      <artifactId>launcher.http</artifactId>
    2.38 +      <version>${project.version}</version>
    2.39 +      <classifier>bck2brwsr</classifier>
    2.40 +      <scope>test</scope>
    2.41 +    </dependency>
    2.42 +    <dependency>
    2.43 +      <groupId>org.apidesign.bck2brwsr</groupId>
    2.44        <artifactId>jbox2d-osgi</artifactId>
    2.45        <version>${project.version}</version>
    2.46        <exclusions>
    2.47 @@ -115,5 +104,11 @@
    2.48          </exclusion>
    2.49        </exclusions>
    2.50      </dependency>
    2.51 +    <dependency>
    2.52 +      <groupId>org.apidesign.bck2brwsr</groupId>
    2.53 +      <artifactId>jbox2d-osgi</artifactId>
    2.54 +      <version>${project.version}</version>
    2.55 +      <classifier>bck2brwsr</classifier>
    2.56 +    </dependency>
    2.57    </dependencies>
    2.58  </project>
     3.1 --- a/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java	Fri Mar 25 21:47:32 2016 +0100
     3.2 +++ b/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java	Mon Mar 28 07:33:11 2016 +0200
     3.3 @@ -37,6 +37,7 @@
     3.4  import java.util.ArrayList;
     3.5  import java.util.Arrays;
     3.6  import java.util.Enumeration;
     3.7 +import java.util.HashMap;
     3.8  import java.util.HashSet;
     3.9  import java.util.LinkedHashSet;
    3.10  import java.util.List;
    3.11 @@ -649,6 +650,7 @@
    3.12  
    3.13          Object compileJar(URL jarURL) throws IOException {
    3.14              List<String[]> libraries = new ArrayList<String[]>();
    3.15 +            Map<String,Object[]> osgiJars = new HashMap<String, Object[]>();
    3.16              for (ClassLoader loader : loaders) {
    3.17                  Enumeration<URL> en = loader.getResources("META-INF/MANIFEST.MF");
    3.18                  while (en.hasMoreElements()) {
    3.19 @@ -662,13 +664,26 @@
    3.20                          final String g = attr.getValue("Bck2BrwsrGroupId");
    3.21                          final String v = attr.getValue("Bck2BrwsrVersion");
    3.22                          final String d = attr.getValue("Bck2BrwsrDebug");
    3.23 +                        final String n = attr.getValue("Bck2BrwsrName");
    3.24  
    3.25                          if (g != null && a != null && v != null && "true".equals(d)) {
    3.26                              libraries.add(new String[] {
    3.27 -                                a, g, v, key
    3.28 +                                a, g, v, key, n
    3.29                              });
    3.30                          }
    3.31                      }
    3.32 +                    final Attributes main = mf.getMainAttributes();
    3.33 +                    String symbol = main.getValue("Bundle-SymbolicName");
    3.34 +                    String version;
    3.35 +                    if (symbol == null) {
    3.36 +                        symbol = main.getValue("OpenIDE-Module-Name");
    3.37 +                        version = main.getValue("OpenIDE-Module-SpecificationVersion");
    3.38 +                    } else {
    3.39 +                        version = main.getValue("Bundle-Version");
    3.40 +                    }
    3.41 +                    if (symbol != null) {
    3.42 +                        osgiJars.put(symbol, new Object[] { e, version });
    3.43 +                    }
    3.44                  }
    3.45              }
    3.46              URL precompiled = null;
    3.47 @@ -693,6 +708,16 @@
    3.48                      }
    3.49                  }
    3.50              }
    3.51 +            if (precompiled == null) {
    3.52 +                for (ClassLoader loader : loaders) {
    3.53 +                    for (String[] lib : libraries) {
    3.54 +                        Object[] urlVersion = osgiJars.get(lib[4]);
    3.55 +                        if (urlVersion != null && urlVersion[1].toString().startsWith(lib[2])) {
    3.56 +                            precompiled = loader.getResource(lib[3]);
    3.57 +                        }
    3.58 +                    }
    3.59 +                }
    3.60 +            }
    3.61              Object ret = BaseHTTPLauncher.this.compileJar(jarURL, precompiled);
    3.62              ignore.add(jarURL);
    3.63              return ret;
     4.1 --- a/launcher/http/pom.xml	Fri Mar 25 21:47:32 2016 +0100
     4.2 +++ b/launcher/http/pom.xml	Mon Mar 28 07:33:11 2016 +0200
     4.3 @@ -30,6 +30,29 @@
     4.4                      <skip>false</skip>
     4.5                  </configuration>
     4.6              </plugin>
     4.7 +            <plugin>
     4.8 +                <groupId>org.apidesign.bck2brwsr</groupId>
     4.9 +                <artifactId>bck2brwsr-maven-plugin</artifactId>
    4.10 +                <version>0.17</version>
    4.11 +                <executions>
    4.12 +                    <execution>
    4.13 +                        <goals>
    4.14 +                            <goal>library</goal>
    4.15 +                        </goals>
    4.16 +                    </execution>
    4.17 +                </executions>
    4.18 +                <configuration>
    4.19 +                    <ignoreBootClassPath>false</ignoreBootClassPath>
    4.20 +                </configuration>
    4.21 +                <dependencies>
    4.22 +                    <dependency>
    4.23 +                        <groupId>org.apidesign.bck2brwsr</groupId>
    4.24 +                        <artifactId>aot</artifactId>
    4.25 +                        <version>${project.version}</version>
    4.26 +                        <type>jar</type>
    4.27 +                    </dependency>
    4.28 +                </dependencies>
    4.29 +            </plugin>
    4.30          </plugins>
    4.31      </build>
    4.32      <properties>
    4.33 @@ -70,7 +93,7 @@
    4.34      <dependency>
    4.35        <groupId>org.apidesign.bck2brwsr</groupId>
    4.36        <artifactId>aot</artifactId>
    4.37 -      <version>1.0-SNAPSHOT</version>
    4.38 +      <version>${project.version}</version>
    4.39        <type>jar</type>
    4.40      </dependency>
    4.41    </dependencies>
     5.1 --- a/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Fri Mar 25 21:47:32 2016 +0100
     5.2 +++ b/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Mon Mar 28 07:33:11 2016 +0200
     5.3 @@ -24,11 +24,10 @@
     5.4  import java.net.MalformedURLException;
     5.5  import java.net.URISyntaxException;
     5.6  import java.net.URL;
     5.7 -import java.util.Arrays;
     5.8  import java.util.HashSet;
     5.9 -import java.util.List;
    5.10  import java.util.Set;
    5.11  import java.util.logging.Level;
    5.12 +import java.util.regex.Pattern;
    5.13  
    5.14  /**
    5.15   * Lightweight server to launch Bck2Brwsr applications and tests.
    5.16 @@ -59,6 +58,10 @@
    5.17          } catch (URISyntaxException ex) {
    5.18              throw new IOException(ex);
    5.19          }
    5.20 +        final String precompile = System.getProperty("vmtest.precompiled");
    5.21 +        if (precompile != null && Pattern.compile(precompile).matcher(jar.toString()).find()) {
    5.22 +            throw new IOException("Compilation of " + jar + " forbidden");
    5.23 +        }
    5.24          LOG.log(Level.INFO, "No precompiled version for {0} found. Compiling.", jar);
    5.25          return CompileCP.compileJAR(f, testClasses);
    5.26      }
     6.1 --- a/rt/emul/compact/src/main/assembly/rt.xml	Fri Mar 25 21:47:32 2016 +0100
     6.2 +++ b/rt/emul/compact/src/main/assembly/rt.xml	Mon Mar 28 07:33:11 2016 +0200
     6.3 @@ -12,7 +12,7 @@
     6.4        <scope>provided</scope>
     6.5        <unpackOptions>
     6.6          <excludes>
     6.7 -          <exclude>META-INF/maven/**</exclude>
     6.8 +          <exclude>META-INF/maven/**/*mini*/**</exclude>
     6.9          </excludes>
    6.10        </unpackOptions>
    6.11        <excludes>
     7.1 --- a/rt/emul/compacttest/pom.xml	Fri Mar 25 21:47:32 2016 +0100
     7.2 +++ b/rt/emul/compacttest/pom.xml	Mon Mar 28 07:33:11 2016 +0200
     7.3 @@ -29,12 +29,26 @@
     7.4          </dependency>
     7.5          <dependency>
     7.6              <groupId>${project.groupId}</groupId>
     7.7 +            <artifactId>launcher.http</artifactId>
     7.8 +            <version>${project.version}</version>
     7.9 +            <classifier>bck2brwsr</classifier>
    7.10 +            <scope>test</scope>
    7.11 +        </dependency>
    7.12 +        <dependency>
    7.13 +            <groupId>${project.groupId}</groupId>
    7.14              <artifactId>emul</artifactId>
    7.15              <classifier>rt</classifier>
    7.16              <version>${project.version}</version>
    7.17              <scope>test</scope>
    7.18          </dependency>
    7.19          <dependency>
    7.20 +            <groupId>${project.groupId}</groupId>
    7.21 +            <artifactId>emul</artifactId>
    7.22 +            <classifier>bck2brwsr</classifier>
    7.23 +            <version>${project.version}</version>
    7.24 +            <scope>test</scope>
    7.25 +        </dependency>
    7.26 +        <dependency>
    7.27              <groupId>org.netbeans.api</groupId>
    7.28              <artifactId>org-openide-util-lookup</artifactId>
    7.29              <scope>test</scope>
    7.30 @@ -76,7 +90,12 @@
    7.31                          </configuration>
    7.32                      </execution>
    7.33                  </executions>
    7.34 -            </plugin>     
    7.35 +                <configuration>
    7.36 +                    <systemProperties>
    7.37 +                        <vmtest.precompiled>.*</vmtest.precompiled>
    7.38 +                    </systemProperties>
    7.39 +                </configuration>
    7.40 +            </plugin>
    7.41          </plugins>
    7.42      </build>
    7.43  </project>
     8.1 --- a/rt/mojo/pom.xml	Fri Mar 25 21:47:32 2016 +0100
     8.2 +++ b/rt/mojo/pom.xml	Mon Mar 28 07:33:11 2016 +0200
     8.3 @@ -39,8 +39,8 @@
     8.4                  <artifactId>maven-compiler-plugin</artifactId>
     8.5                  <version>2.3.2</version>
     8.6                  <configuration>
     8.7 -                    <source>1.6</source>
     8.8 -                    <target>1.6</target>
     8.9 +                    <source>1.7</source>
    8.10 +                    <target>1.7</target>
    8.11                  </configuration>
    8.12              </plugin>
    8.13          </plugins>
     9.1 --- a/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AOTLibrary.java	Fri Mar 25 21:47:32 2016 +0100
     9.2 +++ b/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AOTLibrary.java	Mon Mar 28 07:33:11 2016 +0200
     9.3 @@ -18,6 +18,7 @@
     9.4  package org.apidesign.bck2brwsr.mojo;
     9.5  
     9.6  import java.io.File;
     9.7 +import java.io.FileNotFoundException;
     9.8  import java.io.FileOutputStream;
     9.9  import java.io.IOException;
    9.10  import java.io.OutputStreamWriter;
    9.11 @@ -30,6 +31,7 @@
    9.12  import java.util.List;
    9.13  import java.util.jar.Attributes;
    9.14  import java.util.jar.JarEntry;
    9.15 +import java.util.jar.JarFile;
    9.16  import java.util.jar.JarOutputStream;
    9.17  import java.util.jar.Manifest;
    9.18  import org.apache.maven.artifact.Artifact;
    9.19 @@ -105,6 +107,7 @@
    9.20                  attr.putValue("Bck2BrwsrGroupId", prj.getGroupId());
    9.21                  attr.putValue("Bck2BrwsrVersion", prj.getVersion());
    9.22                  attr.putValue("Bck2BrwsrMinified", "true");
    9.23 +                bundleName(attr, mainJar);
    9.24                  m.getEntries().put(minified, attr);
    9.25              }
    9.26              if (!"false".equals(debug)) {
    9.27 @@ -113,6 +116,7 @@
    9.28                  attr.putValue("Bck2BrwsrGroupId", prj.getGroupId());
    9.29                  attr.putValue("Bck2BrwsrVersion", prj.getVersion());
    9.30                  attr.putValue("Bck2BrwsrDebug", "true");
    9.31 +                bundleName(attr, mainJar);
    9.32                  m.getEntries().put(debug, attr);
    9.33              }
    9.34              
    9.35 @@ -128,6 +132,8 @@
    9.36                          attr.putValue("Bck2BrwsrGroupId", a.getGroupId());
    9.37                          attr.putValue("Bck2BrwsrVersion", a.getVersion());
    9.38                          attr.putValue("Bck2BrwsrDebug", "true");
    9.39 +                        bundleName(attr, a.getFile());
    9.40 +
    9.41                          m.getEntries().put(artifactName(a, true), attr);
    9.42                      }
    9.43                      {
    9.44 @@ -136,15 +142,18 @@
    9.45                          attr.putValue("Bck2BrwsrGroupId", a.getGroupId());
    9.46                          attr.putValue("Bck2BrwsrVersion", a.getVersion());
    9.47                          attr.putValue("Bck2BrwsrMinified", "true");
    9.48 +                        bundleName(attr, a.getFile());
    9.49                          m.getEntries().put(artifactName(a, false), attr);
    9.50                      }
    9.51                  }
    9.52              }
    9.53              
    9.54 -            FileOutputStream fos = new FileOutputStream(this.aotJar);
    9.55 -            JarOutputStream os = new JarOutputStream(fos, m);
    9.56  
    9.57 +            JarOutputStream os = null;
    9.58              if (!"false".equals(debug)) {
    9.59 +                if (os == null) {
    9.60 +                    os = aotJar(m);
    9.61 +                }
    9.62                  os.putNextEntry(new JarEntry(debug));
    9.63                  Writer w = new OutputStreamWriter(os, "UTF-8");
    9.64                  configureMain(loader).
    9.65 @@ -154,6 +163,9 @@
    9.66                  os.closeEntry();
    9.67              }
    9.68              if (!"false".equals(minified)) {
    9.69 +                if (os == null) {
    9.70 +                    os = aotJar(m);
    9.71 +                }
    9.72                  os.putNextEntry(new JarEntry(minified));
    9.73              
    9.74                  Writer w = new OutputStreamWriter(os, "UTF-8");
    9.75 @@ -177,6 +189,9 @@
    9.76                          }
    9.77                      }
    9.78                      {
    9.79 +                        if (os == null) {
    9.80 +                            os = aotJar(m);
    9.81 +                        }
    9.82                          os.putNextEntry(new JarEntry(artifactName(a, true)));
    9.83                          Writer w = new OutputStreamWriter(os, "UTF-8");
    9.84                          c.
    9.85 @@ -197,7 +212,9 @@
    9.86                      }                    
    9.87                  }
    9.88              }
    9.89 -            os.close();
    9.90 +            if (os != null) {
    9.91 +                os.close();
    9.92 +            }
    9.93              
    9.94              projectHelper.attachArtifact(prj, "jar", "bck2brwsr", aotJar);
    9.95          } catch (IOException ex) {
    9.96 @@ -205,6 +222,13 @@
    9.97          }
    9.98      }
    9.99  
   9.100 +    private JarOutputStream aotJar(Manifest m) throws IOException, FileNotFoundException {
   9.101 +        this.aotJar.getParentFile().mkdirs();
   9.102 +        FileOutputStream fos = new FileOutputStream(this.aotJar);
   9.103 +        JarOutputStream os = new JarOutputStream(fos, m);
   9.104 +        return os;
   9.105 +    }
   9.106 +
   9.107      private Bck2Brwsr configureMain(URLClassLoader loader) throws IOException {
   9.108          Bck2Brwsr c = Bck2BrwsrJars.configureFrom(null, mainJar, loader, ignoreBootClassPath);
   9.109          if (exports != null) {
   9.110 @@ -219,6 +243,19 @@
   9.111          return a.getGroupId() + "-" + a.getArtifactId() + (debug ? "-debug.js" : "-min.js");
   9.112      }
   9.113  
   9.114 +    private static void bundleName(Attributes attr, File file) throws IOException {
   9.115 +        try (JarFile jf = new JarFile(file)) {
   9.116 +            Attributes main = jf.getManifest().getMainAttributes();
   9.117 +            String version = main.getValue("Bundle-SymbolicName");
   9.118 +            if (version == null) {
   9.119 +                version = main.getValue("OpenIDE-Module-Name");
   9.120 +            }
   9.121 +            if (version != null) {
   9.122 +                attr.putValue("Bck2BrwsrName", version);
   9.123 +            }
   9.124 +        }
   9.125 +    }
   9.126 +
   9.127      private static URLClassLoader buildClassLoader(File root, Collection<Artifact> deps) throws MalformedURLException {
   9.128          List<URL> arr = new ArrayList<URL>();
   9.129          if (root != null) {
    10.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Fri Mar 25 21:47:32 2016 +0100
    10.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Mon Mar 28 07:33:11 2016 +0200
    10.3 @@ -107,7 +107,11 @@
    10.4              append("\n  ").append(getExportsObject()).append("['registerResource']('");
    10.5              append(r).append("', '");
    10.6              InputStream is = this.resources.get(r);
    10.7 -            byte[] arr = new byte[is.available()];
    10.8 +            int avail = is.available();
    10.9 +            if (avail <= 0) {
   10.10 +                avail = 4096;
   10.11 +            }
   10.12 +            byte[] arr = new byte[avail];
   10.13              int offset = 0;
   10.14              for (;;) {
   10.15                  if (offset == arr.length) {