rt/aot/src/test/java/org/apidesign/bck2brwsr/aot/ExportPublicPackagesTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 20 Nov 2014 05:56:47 +0100
changeset 1724 50ad005d1597
child 1728 1d850aa501bb
permissions -rw-r--r--
Test whether we can parse OSGi export package manifest tag
     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.aot;
    19 
    20 import java.io.File;
    21 import java.io.InputStream;
    22 import java.util.HashSet;
    23 import java.util.Set;
    24 import java.util.TreeSet;
    25 import java.util.jar.Attributes;
    26 import org.apidesign.vm4brwsr.Bck2Brwsr;
    27 import static org.testng.Assert.*;
    28 import org.testng.annotations.AfterClass;
    29 import org.testng.annotations.AfterMethod;
    30 import org.testng.annotations.BeforeClass;
    31 import org.testng.annotations.BeforeMethod;
    32 import org.testng.annotations.Test;
    33 
    34 /**
    35  *
    36  * @author Jaroslav Tulach
    37  */
    38 public class ExportPublicPackagesTest {
    39     
    40     public ExportPublicPackagesTest() {
    41     }
    42 
    43     @Test public void classicOSGIHeaders() throws Exception {
    44         Attributes attr = new Attributes();
    45         attr.putValue("Export-Package", 
    46             "net.java.html.json;uses:=\"net.java.html\";version=\"1.0.0\","
    47           + "org.netbeans.html.json.spi;uses:=\"net.java.html\";version=\"1.0.0\""
    48         );
    49         Set<String> keep = new HashSet<>();
    50         Bck2BrwsrJars.exportPublicPackages(attr, keep);
    51         
    52         assertEquals(keep.size(), 2, "Two: " + keep);
    53         assertTrue(keep.contains("net/java/html/json/"), "json pkg: " + keep);
    54         assertTrue(keep.contains("org/netbeans/html/json/spi/"), "SPI pkg: " + keep);
    55     }
    56     
    57     @Test public void mylynOSGIHeaders() throws Exception {
    58         Attributes attr = new Attributes();
    59         attr.putValue("Export-Package", 
    60 "org.eclipse.mylyn.commons.core,org.eclipse.mylyn.commo" +
    61 "ns.core.io,org.eclipse.mylyn.commons.core.net,org.eclipse.mylyn.commo" +
    62 "ns.core.operations,org.eclipse.mylyn.commons.core.storage;x-internal:" +
    63 "=true,org.eclipse.mylyn.internal.commons.core;x-internal:=true,org.ec" +
    64 "lipse.mylyn.internal.commons.core.operations;x-internal:=true"                
    65         );
    66         Set<String> keep = new TreeSet<>();
    67         Bck2BrwsrJars.exportPublicPackages(attr, keep);
    68         
    69         assertEquals(keep.size(), 7, "Two: " + keep);
    70         assertEquals(keep.toString(), "[org/eclipse/mylyn/commons/core/, org/eclipse/mylyn/commons/core/io/, org/eclipse/mylyn/commons/core/net/, org/eclipse/mylyn/commons/core/operations/, org/eclipse/mylyn/commons/core/storage/, org/eclipse/mylyn/internal/commons/core/, org/eclipse/mylyn/internal/commons/core/operations/]");
    71     }
    72 
    73 }