1.1 --- a/rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/Bck2BrwsrJars.java Wed Nov 19 19:32:00 2014 +0100
1.2 +++ b/rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/Bck2BrwsrJars.java Thu Nov 20 05:56:47 2014 +0100
1.3 @@ -32,6 +32,7 @@
1.4 import java.util.List;
1.5 import java.util.Map;
1.6 import java.util.Set;
1.7 +import java.util.jar.Attributes;
1.8 import java.util.jar.JarEntry;
1.9 import java.util.jar.JarFile;
1.10 import java.util.logging.Level;
1.11 @@ -171,8 +172,15 @@
1.12 }
1.13 }
1.14 }
1.15 - String exp = j.getManifest().getMainAttributes().getValue("Export-Package");
1.16 - if (exp != null && keep != null) {
1.17 + if (keep != null) {
1.18 + final Attributes mainAttr = j.getManifest().getMainAttributes();
1.19 + exportPublicPackages(mainAttr, keep);
1.20 + }
1.21 + }
1.22 +
1.23 + static void exportPublicPackages(final Attributes mainAttr, Set<String> keep) {
1.24 + String exp = mainAttr.getValue("Export-Package"); // NOI18N
1.25 + if (exp != null) {
1.26 for (String def : exp.split(",")) {
1.27 for (String sep : def.split(";")) {
1.28 keep.add(sep.replace('.', '/') + "/");
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/rt/aot/src/test/java/org/apidesign/bck2brwsr/aot/ExportPublicPackagesTest.java Thu Nov 20 05:56:47 2014 +0100
2.3 @@ -0,0 +1,73 @@
2.4 +/**
2.5 + * Back 2 Browser Bytecode Translator
2.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
2.7 + *
2.8 + * This program is free software: you can redistribute it and/or modify
2.9 + * it under the terms of the GNU General Public License as published by
2.10 + * the Free Software Foundation, version 2 of the License.
2.11 + *
2.12 + * This program is distributed in the hope that it will be useful,
2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.15 + * GNU General Public License for more details.
2.16 + *
2.17 + * You should have received a copy of the GNU General Public License
2.18 + * along with this program. Look for COPYING file in the top folder.
2.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
2.20 + */
2.21 +package org.apidesign.bck2brwsr.aot;
2.22 +
2.23 +import java.io.File;
2.24 +import java.io.InputStream;
2.25 +import java.util.HashSet;
2.26 +import java.util.Set;
2.27 +import java.util.TreeSet;
2.28 +import java.util.jar.Attributes;
2.29 +import org.apidesign.vm4brwsr.Bck2Brwsr;
2.30 +import static org.testng.Assert.*;
2.31 +import org.testng.annotations.AfterClass;
2.32 +import org.testng.annotations.AfterMethod;
2.33 +import org.testng.annotations.BeforeClass;
2.34 +import org.testng.annotations.BeforeMethod;
2.35 +import org.testng.annotations.Test;
2.36 +
2.37 +/**
2.38 + *
2.39 + * @author Jaroslav Tulach
2.40 + */
2.41 +public class ExportPublicPackagesTest {
2.42 +
2.43 + public ExportPublicPackagesTest() {
2.44 + }
2.45 +
2.46 + @Test public void classicOSGIHeaders() throws Exception {
2.47 + Attributes attr = new Attributes();
2.48 + attr.putValue("Export-Package",
2.49 + "net.java.html.json;uses:=\"net.java.html\";version=\"1.0.0\","
2.50 + + "org.netbeans.html.json.spi;uses:=\"net.java.html\";version=\"1.0.0\""
2.51 + );
2.52 + Set<String> keep = new HashSet<>();
2.53 + Bck2BrwsrJars.exportPublicPackages(attr, keep);
2.54 +
2.55 + assertEquals(keep.size(), 2, "Two: " + keep);
2.56 + assertTrue(keep.contains("net/java/html/json/"), "json pkg: " + keep);
2.57 + assertTrue(keep.contains("org/netbeans/html/json/spi/"), "SPI pkg: " + keep);
2.58 + }
2.59 +
2.60 + @Test public void mylynOSGIHeaders() throws Exception {
2.61 + Attributes attr = new Attributes();
2.62 + attr.putValue("Export-Package",
2.63 +"org.eclipse.mylyn.commons.core,org.eclipse.mylyn.commo" +
2.64 +"ns.core.io,org.eclipse.mylyn.commons.core.net,org.eclipse.mylyn.commo" +
2.65 +"ns.core.operations,org.eclipse.mylyn.commons.core.storage;x-internal:" +
2.66 +"=true,org.eclipse.mylyn.internal.commons.core;x-internal:=true,org.ec" +
2.67 +"lipse.mylyn.internal.commons.core.operations;x-internal:=true"
2.68 + );
2.69 + Set<String> keep = new TreeSet<>();
2.70 + Bck2BrwsrJars.exportPublicPackages(attr, keep);
2.71 +
2.72 + assertEquals(keep.size(), 7, "Two: " + keep);
2.73 + 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/]");
2.74 + }
2.75 +
2.76 +}