# HG changeset patch # User Jaroslav Tulach # Date 1448567991 -3600 # Node ID c918924ad3c58fc227d8348df901c0852ce7f888 # Parent b5d5cbb44ce041eb81f521a903193a7b92b98e68 #256696: Making OSGi headers, enterprise OSGi ready diff -r b5d5cbb44ce0 -r c918924ad3c5 boot-fx/pom.xml --- a/boot-fx/pom.xml Sun Nov 22 21:18:35 2015 +0100 +++ b/boot-fx/pom.xml Thu Nov 26 20:59:51 2015 +0100 @@ -21,6 +21,12 @@ org.apache.felix maven-bundle-plugin + + + osgi.extender;resolution:=optional;filter:="(osgi.extender=osgi.serviceloader.registrar)" + osgi.serviceloader;osgi.serviceloader=org.netbeans.html.boot.spi.Fn$Presenter + + org.netbeans.html diff -r b5d5cbb44ce0 -r c918924ad3c5 boot/pom.xml --- a/boot/pom.xml Sun Nov 22 21:18:35 2015 +0100 +++ b/boot/pom.xml Thu Nov 26 20:59:51 2015 +0100 @@ -26,6 +26,7 @@ org.netbeans.html.boot.impl.JsAgent org.netbeans.html.boot.impl.JsAgent dependent + osgi.extender;resolution:=optional;filter:="(osgi.extender=osgi.serviceloader.processor)",osgi.serviceloader;filter:="(osgi.serviceloader=org.netbeans.html.boot.spi.Fn$Presenter)";cardinality:=multiple;resolution:=optional diff -r b5d5cbb44ce0 -r c918924ad3c5 context/pom.xml --- a/context/pom.xml Sun Nov 22 21:18:35 2015 +0100 +++ b/context/pom.xml Thu Nov 26 20:59:51 2015 +0100 @@ -24,6 +24,7 @@ dependent + osgi.extender;resolution:=optional;filter:="(osgi.extender=osgi.serviceloader.processor)",osgi.serviceloader;filter:="(osgi.serviceloader=org.netbeans.html.context.spi.Contexts$Provider)";cardinality:=multiple;resolution:=optional diff -r b5d5cbb44ce0 -r c918924ad3c5 ko-felix-test/pom.xml --- a/ko-felix-test/pom.xml Sun Nov 22 21:18:35 2015 +0100 +++ b/ko-felix-test/pom.xml Thu Nov 26 20:59:51 2015 +0100 @@ -36,6 +36,7 @@ ${project.build.directory}/${project.build.finalName}.jar + always @@ -125,5 +126,15 @@ org.apache.felix org.apache.felix.framework + + org.apache.aries.spifly + org.apache.aries.spifly.dynamic.bundle + 1.0.4 + + + org.osgi + org.osgi.service.log + 1.3.0 + \ No newline at end of file diff -r b5d5cbb44ce0 -r c918924ad3c5 ko-felix-test/src/main/java/org/netbeans/html/ko/felix/test/KnockoutFelixTCKImpl.java --- a/ko-felix-test/src/main/java/org/netbeans/html/ko/felix/test/KnockoutFelixTCKImpl.java Sun Nov 22 21:18:35 2015 +0100 +++ b/ko-felix-test/src/main/java/org/netbeans/html/ko/felix/test/KnockoutFelixTCKImpl.java Thu Nov 26 20:59:51 2015 +0100 @@ -101,18 +101,20 @@ return testClasses(); } - public static void start(URI server) throws Exception { + public static void start(String callBackClass, URI server, final boolean useAllClassloader) throws Exception { final BrowserBuilder bb = BrowserBuilder.newBrowser().loadClass(KnockoutFelixTCKImpl.class). loadPage(server.toString()). - invoke("initialized"); + invoke("initialized", callBackClass); Executors.newSingleThreadExecutor().submit(new Runnable() { @Override public void run() { try { Bundle[] arr = FrameworkUtil.getBundle(BrowserBuilder.class).getBundleContext().getBundles(); - final ClassLoader osgiClassLoader = new AllBundlesLoader(arr); - bb.classloader(osgiClassLoader); + if (useAllClassloader) { + final ClassLoader osgiClassLoader = new AllBundlesLoader(arr); + bb.classloader(osgiClassLoader); + } bb.showAndWait(); } catch (Throwable t) { t.printStackTrace(); @@ -121,16 +123,14 @@ }); } - public static void initialized() throws Exception { + public static void initialized(String... args) throws Exception { Bundle bundle = FrameworkUtil.getBundle(KnockoutFelixTCKImpl.class); if (bundle == null) { throw new IllegalStateException( "Should be loaded from a bundle. But was: " + KnockoutFelixTCKImpl.class.getClassLoader() ); } - Class classpathClass = ClassLoader.getSystemClassLoader().loadClass( - "org.netbeans.html.ko.felix.test.KnockoutFelixIT" - ); + Class classpathClass = ClassLoader.getSystemClassLoader().loadClass(args[0]); Method m = classpathClass.getMethod("initialized", Class.class, Object.class); browserContext = Fn.activePresenter(); m.invoke(null, KnockoutFelixTCKImpl.class, browserContext); diff -r b5d5cbb44ce0 -r c918924ad3c5 ko-felix-test/src/test/java/org/netbeans/html/ko/felix/test/KOFx.java --- a/ko-felix-test/src/test/java/org/netbeans/html/ko/felix/test/KOFx.java Sun Nov 22 21:18:35 2015 +0100 +++ b/ko-felix-test/src/test/java/org/netbeans/html/ko/felix/test/KOFx.java Thu Nov 26 20:59:51 2015 +0100 @@ -60,8 +60,10 @@ private Object result; private Object inst; private int count; + private final Class itClass; - KOFx(Object p, Method m) { + KOFx(Class itClass, Object p, Method m) { + this.itClass = itClass; this.p = p; this.m = m; } @@ -90,7 +92,7 @@ boolean notify = true; Closeable a = null; try { - a = KnockoutFelixIT.activateInOSGi(p); + a = (Closeable) itClass.getMethod("activateInOSGi", Object.class).invoke(null, p); if (inst == null) { inst = m.getDeclaringClass().newInstance(); } diff -r b5d5cbb44ce0 -r c918924ad3c5 ko-felix-test/src/test/java/org/netbeans/html/ko/felix/test/KnockoutFelixAriesIT.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ko-felix-test/src/test/java/org/netbeans/html/ko/felix/test/KnockoutFelixAriesIT.java Thu Nov 26 20:59:51 2015 +0100 @@ -0,0 +1,258 @@ +/** + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.html.ko.felix.test; + +import java.io.Closeable; +import java.io.File; +import java.io.IOException; +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.ServiceLoader; +import java.util.concurrent.Callable; +import java.util.jar.JarFile; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.netbeans.html.boot.spi.Fn; +import org.netbeans.html.json.tck.KOTest; +import org.netbeans.html.json.tck.KnockoutTCK; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleException; +import org.osgi.framework.Constants; +import org.osgi.framework.launch.Framework; +import org.osgi.framework.launch.FrameworkFactory; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Factory; + +public class KnockoutFelixAriesIT { + private static final Logger LOG = Logger.getLogger(KnockoutFelixAriesIT.class.getName()); + private static Framework framework; + private static File dir; + static Framework framework() throws Exception { + if (framework != null) { + return framework; + } + for (FrameworkFactory ff : ServiceLoader.load(FrameworkFactory.class)) { + + String basedir = System.getProperty("basedir"); + assertNotNull("basedir preperty provided", basedir); + File target = new File(basedir, "target"); + dir = new File(target, "osgi-aries"); + dir.mkdirs(); + + Map config = new HashMap(); + config.put(Constants.FRAMEWORK_STORAGE, dir.getPath()); + config.put(Constants.FRAMEWORK_STORAGE_CLEAN, "true"); + config.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "sun.misc," + + "javafx.application," + + "javafx.beans," + + "javafx.beans.property," + + "javafx.beans.value," + + "javafx.collections," + + "javafx.concurrent," + + "javafx.event," + + "javafx.geometry," + + "javafx.scene," + + "javafx.scene.control," + + "javafx.scene.image," + + "javafx.scene.layout," + + "javafx.scene.text," + + "javafx.scene.web," + + "javafx.stage," + + "javafx.util," + + "netscape.javascript" + ); + framework = ff.newFramework(config); + framework.init(); + loadClassPathBundles(framework); + framework.start(); + boolean ok = false; + for (Bundle b : framework.getBundleContext().getBundles()) { + try { + if (!b.getSymbolicName().equals("org.apache.aries.spifly.dynamic.bundle")) { + continue; + } + b.start(); + ok = true; + LOG.log(Level.INFO, "Started {0}", b.getSymbolicName()); + } catch (BundleException ex) { + LOG.log(Level.WARNING, "Cannot start bundle " + b.getSymbolicName(), ex); + } + } + assertTrue(ok, "Aries installed"); + for (Bundle b : framework.getBundleContext().getBundles()) { + try { + if (b.getSymbolicName().contains("felix.framework")) { + continue; + } + if (b.getSymbolicName().contains("glassfish.grizzly")) { + continue; + } + b.start(); + LOG.log(Level.INFO, "Started {0}", b.getSymbolicName()); + } catch (BundleException ex) { + LOG.log(Level.WARNING, "Cannot start bundle " + b.getSymbolicName(), ex); + } + } + return framework; + } + fail("No OSGi framework in the path"); + return null; + } + + @AfterClass public static void cleanUp() throws Exception { + if (framework != null) framework.stop(); + clearUpDir(dir); + } + private static void clearUpDir(File dir) { + if (dir.isDirectory()) { + for (File f : dir.listFiles()) { + clearUpDir(f); + } + } + dir.delete(); + } + + + + private static void loadClassPathBundles(Framework f) throws IOException, BundleException { + for (String jar : System.getProperty("java.class.path").split(File.pathSeparator)) { + File file = new File(jar); + if (!file.isFile()) { + LOG.info("Not loading " + file); + continue; + } + JarFile jf = new JarFile(file); + final String name = jf.getManifest().getMainAttributes().getValue("Bundle-SymbolicName"); + jf.close(); + if (name != null) { + if (name.contains("org.eclipse.osgi")) { + throw new IllegalStateException("Found " + name + " !"); + } + if (name.contains("felix.framework")) { + continue; + } + if (name.contains("testng")) { + continue; + } + final String path = "reference:" + file.toURI().toString(); + try { + Bundle b = f.getBundleContext().installBundle(path); + } catch (BundleException ex) { + LOG.log(Level.WARNING, "Cannot install " + file, ex); + } + } + } + } + + private static Class loadOSGiClass(Class c) throws Exception { + return KnockoutFelixTCKImpl.loadOSGiClass(c.getName(), KnockoutFelixAriesIT.framework().getBundleContext()); + } + + private static Class browserClass; + private static Object browserContext; + + @Factory public static Object[] compatibilityTests() throws Exception { + Class tck = loadOSGiClass(KnockoutTCK.class); + Class peer = loadOSGiClass(KnockoutFelixTCKImpl.class); + // initialize the TCK + Callable inst = (Callable) peer.newInstance(); + + Class[] arr = inst.call(); + for (int i = 0; i < arr.length; i++) { + if (arr[i].getClassLoader() == ClassLoader.getSystemClassLoader()) { + fail("Should be an OSGi class: " + arr[i]); + } + } + + URI uri = DynamicHTTP.initServer(); + + Method start = peer.getMethod("start", String.class, URI.class, boolean.class); + start.invoke(null, KnockoutFelixAriesIT.class.getName(), uri, false); + + ClassLoader l = getClassLoader(); + List res = new ArrayList(); + for (int i = 0; i < arr.length; i++) { + seekKOTests(arr[i], res); + } + return res.toArray(); + } + + private static void seekKOTests(Class c, List res) throws SecurityException, ClassNotFoundException { + Class koTest = + c.getClassLoader().loadClass(KOTest.class.getName()). + asSubclass(Annotation.class); + for (Method m : c.getMethods()) { + if (m.getAnnotation(koTest) != null) { + res.add(new KOFx(KnockoutFelixAriesIT.class, browserContext, m)); + } + } + } + + static synchronized ClassLoader getClassLoader() throws InterruptedException { + while (browserClass == null) { + KnockoutFelixAriesIT.class.wait(); + } + return browserClass.getClassLoader(); + } + + public static synchronized void initialized(Class browserCls, Object presenter) throws Exception { + browserClass = browserCls; + browserContext = presenter; + KnockoutFelixAriesIT.class.notifyAll(); + } + + public static Closeable activateInOSGi(Object presenter) throws Exception { + Class presenterClass = loadOSGiClass(Fn.Presenter.class); + Class fnClass = loadOSGiClass(Fn.class); + Method m = fnClass.getMethod("activate", presenterClass); + return (Closeable) m.invoke(null, presenter); + } +} diff -r b5d5cbb44ce0 -r c918924ad3c5 ko-felix-test/src/test/java/org/netbeans/html/ko/felix/test/KnockoutFelixIT.java --- a/ko-felix-test/src/test/java/org/netbeans/html/ko/felix/test/KnockoutFelixIT.java Sun Nov 22 21:18:35 2015 +0100 +++ b/ko-felix-test/src/test/java/org/netbeans/html/ko/felix/test/KnockoutFelixIT.java Thu Nov 26 20:59:51 2015 +0100 @@ -42,7 +42,6 @@ */ package org.netbeans.html.ko.felix.test; -import org.netbeans.html.ko.felix.test.KnockoutFelixTCKImpl; import java.io.Closeable; import java.io.File; import java.io.IOException; @@ -172,6 +171,9 @@ if (name.contains("testng")) { continue; } + if (name.equals("org.apache.aries.spifly.dynamic.bundle")) { + continue; + } final String path = "reference:" + file.toURI().toString(); try { Bundle b = f.getBundleContext().installBundle(path); @@ -204,10 +206,10 @@ URI uri = DynamicHTTP.initServer(); - Method start = peer.getMethod("start", URI.class); - start.invoke(null, uri); + Method start = peer.getMethod("start", String.class, URI.class, boolean.class); + start.invoke(null, KnockoutFelixIT.class.getName(), uri, true); - ClassLoader l = getClassLoader(); + ClassLoader l = getClassLoader(null); List res = new ArrayList(); for (int i = 0; i < arr.length; i++) { seekKOTests(arr[i], res); @@ -221,15 +223,18 @@ asSubclass(Annotation.class); for (Method m : c.getMethods()) { if (m.getAnnotation(koTest) != null) { - res.add(new KOFx(browserContext, m)); + res.add(new KOFx(KnockoutFelixIT.class, browserContext, m)); } } } - static synchronized ClassLoader getClassLoader() throws InterruptedException { + static synchronized ClassLoader getClassLoader(Object[] presenter) throws InterruptedException { while (browserClass == null) { KnockoutFelixIT.class.wait(); } + if (presenter != null) { + presenter[0] = browserContext; + } return browserClass.getClassLoader(); } @@ -239,7 +244,7 @@ KnockoutFelixIT.class.notifyAll(); } - static Closeable activateInOSGi(Object presenter) throws Exception { + public static Closeable activateInOSGi(Object presenter) throws Exception { Class presenterClass = loadOSGiClass(Fn.Presenter.class); Class fnClass = loadOSGiClass(Fn.class); Method m = fnClass.getMethod("activate", presenterClass); diff -r b5d5cbb44ce0 -r c918924ad3c5 ko4j/pom.xml --- a/ko4j/pom.xml Sun Nov 22 21:18:35 2015 +0100 +++ b/ko4j/pom.xml Thu Nov 26 20:59:51 2015 +0100 @@ -22,6 +22,12 @@ org.apache.felix maven-bundle-plugin + + + osgi.extender;resolution:=optional;filter:="(osgi.extender=osgi.serviceloader.registrar)" + osgi.serviceloader;osgi.serviceloader=org.netbeans.html.context.spi.Contexts$Provider + + org.netbeans.html diff -r b5d5cbb44ce0 -r c918924ad3c5 src/main/javadoc/overview.html --- a/src/main/javadoc/overview.html Sun Nov 22 21:18:35 2015 +0100 +++ b/src/main/javadoc/overview.html Thu Nov 26 20:59:51 2015 +0100 @@ -115,6 +115,8 @@ </configuration> </plugin> + OSGi headers are now + enterprise OSGi ready.

What's Been Improved in Version 1.2.3?