rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AOTLibrary.java
changeset 1739 e9b9d9ff0621
parent 1737 82fd3830167d
child 1742 0e949cf1b073
     1.1 --- a/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AOTLibrary.java	Sat Dec 06 06:28:17 2014 +0100
     1.2 +++ b/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AOTLibrary.java	Sat Dec 06 07:11:02 2014 +0100
     1.3 @@ -76,6 +76,9 @@
     1.4      @Parameter
     1.5      private String[] exports;
     1.6      
     1.7 +    @Parameter
     1.8 +    private String[] aotDeps;
     1.9 +    
    1.10      @Override
    1.11      public void execute() throws MojoExecutionException, MojoFailureException {
    1.12          URLClassLoader loader;
    1.13 @@ -104,6 +107,31 @@
    1.14                  m.getEntries().put(debug, attr);
    1.15              }
    1.16              
    1.17 +            if (aotDeps != null) {
    1.18 +                for (Artifact a : prj.getArtifacts()) {
    1.19 +                    if (!matches(aotDeps, a)) {
    1.20 +                        continue;
    1.21 +                    }
    1.22 +                    
    1.23 +                    {
    1.24 +                        Attributes attr = new Attributes();
    1.25 +                        attr.putValue("Bck2BrwsrArtifactId", a.getArtifactId());
    1.26 +                        attr.putValue("Bck2BrwsrGroupId", a.getGroupId());
    1.27 +                        attr.putValue("Bck2BrwsrVersion", a.getVersion());
    1.28 +                        attr.putValue("Bck2BrwsrMinified", "true");
    1.29 +                        m.getEntries().put(artifactName(a, true), attr);
    1.30 +                    }
    1.31 +                    {
    1.32 +                        Attributes attr = new Attributes();
    1.33 +                        attr.putValue("Bck2BrwsrArtifactId", prj.getArtifactId());
    1.34 +                        attr.putValue("Bck2BrwsrGroupId", prj.getGroupId());
    1.35 +                        attr.putValue("Bck2BrwsrVersion", prj.getVersion());
    1.36 +                        attr.putValue("Bck2BrwsrDebug", "true");
    1.37 +                        m.getEntries().put(artifactName(a, false), attr);
    1.38 +                    }
    1.39 +                        }
    1.40 +            }
    1.41 +            
    1.42              FileOutputStream fos = new FileOutputStream(this.aotJar);
    1.43              JarOutputStream os = new JarOutputStream(fos, m);
    1.44  
    1.45 @@ -132,6 +160,33 @@
    1.46                  w.flush();
    1.47                  os.closeEntry();
    1.48              }
    1.49 +            
    1.50 +            if (aotDeps != null) {
    1.51 +                for (Artifact a : prj.getArtifacts()) {
    1.52 +                    if (!matches(aotDeps, a)) {
    1.53 +                        continue;
    1.54 +                    }
    1.55 +                    {
    1.56 +                        os.putNextEntry(new JarEntry(artifactName(a, true)));
    1.57 +                        Writer w = new OutputStreamWriter(os);
    1.58 +                        c.
    1.59 +                            obfuscation(ObfuscationLevel.NONE).
    1.60 +                            generate(w);
    1.61 +                        w.flush();
    1.62 +                        os.closeEntry();
    1.63 +                    }
    1.64 +                    {
    1.65 +                        os.putNextEntry(new JarEntry(artifactName(a, false)));
    1.66 +
    1.67 +                        Writer w = new OutputStreamWriter(os);
    1.68 +                        c.
    1.69 +                            obfuscation(ObfuscationLevel.FULL).
    1.70 +                            generate(w);
    1.71 +                        w.flush();
    1.72 +                        os.closeEntry();
    1.73 +                    }                    
    1.74 +                }
    1.75 +            }
    1.76              os.close();
    1.77              
    1.78              projectHelper.attachArtifact(prj, "jar", "bck2brwsr", aotJar);
    1.79 @@ -140,6 +195,10 @@
    1.80          }
    1.81      }
    1.82  
    1.83 +    private static String artifactName(Artifact a, boolean debug) {
    1.84 +        return a.getGroupId() + "-" + a.getArtifactId() + (debug ? "-debug.js" : "-min.js");
    1.85 +    }
    1.86 +
    1.87      private static URLClassLoader buildClassLoader(File root, Collection<Artifact> deps) throws MalformedURLException {
    1.88          List<URL> arr = new ArrayList<URL>();
    1.89          if (root != null) {
    1.90 @@ -152,4 +211,27 @@
    1.91          }
    1.92          return new URLClassLoader(arr.toArray(new URL[0]), Java2JavaScript.class.getClassLoader());
    1.93      }
    1.94 +
    1.95 +    private static boolean matches(String[] aotDeps, Artifact a) {
    1.96 +        for (String d : aotDeps) {
    1.97 +            String[] parts = d.split(":");
    1.98 +            for (int i = 0; i < parts.length; i++) {
    1.99 +                if ("*".equals(parts[i])) {
   1.100 +                    parts[i] = null;
   1.101 +                }
   1.102 +            }
   1.103 +            
   1.104 +            if (parts[0] != null && !parts[0].equals(a.getGroupId())) {
   1.105 +                continue;
   1.106 +            }
   1.107 +            if (parts[1] != null && !parts[1].equals(a.getArtifactId())) {
   1.108 +                continue;
   1.109 +            }
   1.110 +            if (parts.length > 2 && parts[2] != null && !parts[2].equals(a.getClassifier())) {
   1.111 +                continue;
   1.112 +            }
   1.113 +            return true;
   1.114 +        }
   1.115 +        return false;
   1.116 +    }
   1.117  }