javaquery/demo-calculator/src/test/java/org/apidesign/bck2brwsr/demo/calc/staticcompilation/MinifiedTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 24 Feb 2015 11:01:47 +0100
changeset 1785 3085649750a4
child 1787 ea12a3bb4b33
permissions -rw-r--r--
The closure compiler was broken due to presence of old version of sisu-guava. Exclude and test minification works on JavaQuery API.
     1 /**
     2  * Back 2 Browser Bytecode Translator
     3  * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4  *
     5  * This program is free software: you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation, version 2 of the License.
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program. Look for COPYING file in the top folder.
    16  * If not, see http://opensource.org/licenses/GPL-2.0.
    17  */
    18 package org.apidesign.bck2brwsr.demo.calc.staticcompilation;
    19 
    20 import java.io.BufferedReader;
    21 import java.io.InputStreamReader;
    22 import java.net.URL;
    23 import java.util.Enumeration;
    24 import java.util.Map;
    25 import java.util.jar.Attributes;
    26 import java.util.jar.Manifest;
    27 import org.testng.annotations.Test;
    28 import static org.testng.Assert.*;
    29 
    30 public class MinifiedTest {
    31     @Test public void minifiedVersionDoesNotContainFQN() throws Exception {
    32         final ClassLoader l = MinifiedTest.class.getClassLoader();
    33         Enumeration<URL> en = l.getResources("META-INF/MANIFEST.MF");
    34         while (en.hasMoreElements()) {
    35             URL u = en.nextElement();
    36             Manifest mf = new Manifest(u.openStream());
    37             for (Map.Entry<String, Attributes> entrySet : mf.getEntries().entrySet()) {
    38                 String key = entrySet.getKey();
    39                 if (!key.contains("-min.js")) {
    40                     continue;
    41                 }
    42                 if (!key.contains("javaquery.api")) {
    43                     continue;
    44                 }
    45                 try (BufferedReader r = new BufferedReader(new InputStreamReader(l.getResourceAsStream(key)))) {
    46                     for (;;) {
    47                         String line = r.readLine();
    48                         if (line == null) {
    49                             break;
    50                         }
    51                         if (line.contains(" org_apidesign_bck2brwsr_htmlpage_Knockout")) {
    52                             fail("Found FQN of non-public class. Is it minified version?: " + line + " in " + key);
    53                         } 
    54                     }
    55                 }
    56                 // success
    57                 return;
    58             }
    59         }
    60         fail("No minified javaquery found: " + System.getProperty("java.class.path"));
    61     }
    62 
    63     @Test public void debugVersionContainsFQN() throws Exception {
    64         final ClassLoader l = MinifiedTest.class.getClassLoader();
    65         Enumeration<URL> en = l.getResources("META-INF/MANIFEST.MF");
    66         while (en.hasMoreElements()) {
    67             URL u = en.nextElement();
    68             Manifest mf = new Manifest(u.openStream());
    69             for (Map.Entry<String, Attributes> entrySet : mf.getEntries().entrySet()) {
    70                 String key = entrySet.getKey();
    71                 if (!key.contains("-debug.js")) {
    72                     continue;
    73                 }
    74                 if (!key.contains("javaquery.api")) {
    75                     continue;
    76                 }
    77                 try (BufferedReader r = new BufferedReader(new InputStreamReader(l.getResourceAsStream(key)))) {
    78                     for (;;) {
    79                         String line = r.readLine();
    80                         if (line == null) {
    81                             break;
    82                         }
    83                         if (line.contains(" org_apidesign_bck2brwsr_htmlpage_Knockout")) {
    84                             // ok, it should be there
    85                             return;
    86                         } 
    87                     }
    88                 }
    89                 fail("Found no FQN of non-public Knockout class. Is it debug version?:" + key);
    90             }
    91         }
    92         fail("No debug javaquery found: " + System.getProperty("java.class.path"));
    93     }
    94     
    95 }