javaquery demo now uses only extracted dependencies because javaquery.api generates additional bck2brwsr js files for core annotations library
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 06 Dec 2014 07:11:02 +0100
changeset 1739e9b9d9ff0621
parent 1738 83151e1e0cac
child 1740 3afec2d34319
javaquery demo now uses only extracted dependencies because javaquery.api generates additional bck2brwsr js files for core annotations library
javaquery/api/pom.xml
rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AOTLibrary.java
     1.1 --- a/javaquery/api/pom.xml	Sat Dec 06 06:49:24 2014 +0100
     1.2 +++ b/javaquery/api/pom.xml	Sat Dec 06 07:11:02 2014 +0100
     1.3 @@ -41,6 +41,11 @@
     1.4                          </goals>
     1.5                      </execution>
     1.6                  </executions>
     1.7 +                <configuration>
     1.8 +                    <aotDeps>
     1.9 +                        <aotDep>org.apidesign.bck2brwsr:core</aotDep>
    1.10 +                    </aotDeps>
    1.11 +                </configuration>
    1.12              </plugin>
    1.13          </plugins>
    1.14      </build>
     2.1 --- a/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AOTLibrary.java	Sat Dec 06 06:49:24 2014 +0100
     2.2 +++ b/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AOTLibrary.java	Sat Dec 06 07:11:02 2014 +0100
     2.3 @@ -76,6 +76,9 @@
     2.4      @Parameter
     2.5      private String[] exports;
     2.6      
     2.7 +    @Parameter
     2.8 +    private String[] aotDeps;
     2.9 +    
    2.10      @Override
    2.11      public void execute() throws MojoExecutionException, MojoFailureException {
    2.12          URLClassLoader loader;
    2.13 @@ -104,6 +107,31 @@
    2.14                  m.getEntries().put(debug, attr);
    2.15              }
    2.16              
    2.17 +            if (aotDeps != null) {
    2.18 +                for (Artifact a : prj.getArtifacts()) {
    2.19 +                    if (!matches(aotDeps, a)) {
    2.20 +                        continue;
    2.21 +                    }
    2.22 +                    
    2.23 +                    {
    2.24 +                        Attributes attr = new Attributes();
    2.25 +                        attr.putValue("Bck2BrwsrArtifactId", a.getArtifactId());
    2.26 +                        attr.putValue("Bck2BrwsrGroupId", a.getGroupId());
    2.27 +                        attr.putValue("Bck2BrwsrVersion", a.getVersion());
    2.28 +                        attr.putValue("Bck2BrwsrMinified", "true");
    2.29 +                        m.getEntries().put(artifactName(a, true), attr);
    2.30 +                    }
    2.31 +                    {
    2.32 +                        Attributes attr = new Attributes();
    2.33 +                        attr.putValue("Bck2BrwsrArtifactId", prj.getArtifactId());
    2.34 +                        attr.putValue("Bck2BrwsrGroupId", prj.getGroupId());
    2.35 +                        attr.putValue("Bck2BrwsrVersion", prj.getVersion());
    2.36 +                        attr.putValue("Bck2BrwsrDebug", "true");
    2.37 +                        m.getEntries().put(artifactName(a, false), attr);
    2.38 +                    }
    2.39 +                        }
    2.40 +            }
    2.41 +            
    2.42              FileOutputStream fos = new FileOutputStream(this.aotJar);
    2.43              JarOutputStream os = new JarOutputStream(fos, m);
    2.44  
    2.45 @@ -132,6 +160,33 @@
    2.46                  w.flush();
    2.47                  os.closeEntry();
    2.48              }
    2.49 +            
    2.50 +            if (aotDeps != null) {
    2.51 +                for (Artifact a : prj.getArtifacts()) {
    2.52 +                    if (!matches(aotDeps, a)) {
    2.53 +                        continue;
    2.54 +                    }
    2.55 +                    {
    2.56 +                        os.putNextEntry(new JarEntry(artifactName(a, true)));
    2.57 +                        Writer w = new OutputStreamWriter(os);
    2.58 +                        c.
    2.59 +                            obfuscation(ObfuscationLevel.NONE).
    2.60 +                            generate(w);
    2.61 +                        w.flush();
    2.62 +                        os.closeEntry();
    2.63 +                    }
    2.64 +                    {
    2.65 +                        os.putNextEntry(new JarEntry(artifactName(a, false)));
    2.66 +
    2.67 +                        Writer w = new OutputStreamWriter(os);
    2.68 +                        c.
    2.69 +                            obfuscation(ObfuscationLevel.FULL).
    2.70 +                            generate(w);
    2.71 +                        w.flush();
    2.72 +                        os.closeEntry();
    2.73 +                    }                    
    2.74 +                }
    2.75 +            }
    2.76              os.close();
    2.77              
    2.78              projectHelper.attachArtifact(prj, "jar", "bck2brwsr", aotJar);
    2.79 @@ -140,6 +195,10 @@
    2.80          }
    2.81      }
    2.82  
    2.83 +    private static String artifactName(Artifact a, boolean debug) {
    2.84 +        return a.getGroupId() + "-" + a.getArtifactId() + (debug ? "-debug.js" : "-min.js");
    2.85 +    }
    2.86 +
    2.87      private static URLClassLoader buildClassLoader(File root, Collection<Artifact> deps) throws MalformedURLException {
    2.88          List<URL> arr = new ArrayList<URL>();
    2.89          if (root != null) {
    2.90 @@ -152,4 +211,27 @@
    2.91          }
    2.92          return new URLClassLoader(arr.toArray(new URL[0]), Java2JavaScript.class.getClassLoader());
    2.93      }
    2.94 +
    2.95 +    private static boolean matches(String[] aotDeps, Artifact a) {
    2.96 +        for (String d : aotDeps) {
    2.97 +            String[] parts = d.split(":");
    2.98 +            for (int i = 0; i < parts.length; i++) {
    2.99 +                if ("*".equals(parts[i])) {
   2.100 +                    parts[i] = null;
   2.101 +                }
   2.102 +            }
   2.103 +            
   2.104 +            if (parts[0] != null && !parts[0].equals(a.getGroupId())) {
   2.105 +                continue;
   2.106 +            }
   2.107 +            if (parts[1] != null && !parts[1].equals(a.getArtifactId())) {
   2.108 +                continue;
   2.109 +            }
   2.110 +            if (parts.length > 2 && parts[2] != null && !parts[2].equals(a.getClassifier())) {
   2.111 +                continue;
   2.112 +            }
   2.113 +            return true;
   2.114 +        }
   2.115 +        return false;
   2.116 +    }
   2.117  }