diff -r 0b9154a59a3b core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoServicesTest.java
--- a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoServicesTest.java Mon Jan 16 17:25:47 2012 +0100
+++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoServicesTest.java Mon Jan 16 18:46:58 2012 +0100
@@ -177,7 +177,7 @@
}
- static Bundle findBundle(String bsn) throws Exception {
+ public static Bundle findBundle(String bsn) throws Exception {
Bundle[] arr = findFramework().getBundleContext().getBundles();
for (Bundle b : arr) {
if (bsn.equals(b.getSymbolicName())) {
diff -r 0b9154a59a3b netbinox/nbproject/project.xml
--- a/netbinox/nbproject/project.xml Mon Jan 16 17:25:47 2012 +0100
+++ b/netbinox/nbproject/project.xml Mon Jan 16 18:46:58 2012 +0100
@@ -45,6 +45,7 @@
org.netbeans.core.netigso
+
org.netbeans.libs.junit4
diff -r 0b9154a59a3b netbinox/src/org/netbeans/modules/netbinox/JarBundleFile.java
--- a/netbinox/src/org/netbeans/modules/netbinox/JarBundleFile.java Mon Jan 16 17:25:47 2012 +0100
+++ b/netbinox/src/org/netbeans/modules/netbinox/JarBundleFile.java Mon Jan 16 18:46:58 2012 +0100
@@ -59,6 +59,8 @@
import org.eclipse.osgi.baseadaptor.bundlefile.ZipBundleFile;
import org.netbeans.core.netigso.spi.BundleContent;
import org.netbeans.core.netigso.spi.NetigsoArchive;
+import org.openide.modules.ModuleInfo;
+import org.openide.util.Lookup;
/** This is fake bundle. It is created by the Netbinox infrastructure to
* use the {@link NetigsoArchive} to get cached data and speed up the start.
@@ -216,7 +218,28 @@
return arr;
}
- private BundleEntry findEntry(String why, String name) {
+ private BundleEntry findEntry(String why, final String name) {
+ if (!name.equals("META-INF/MANIFEST.MF") && // NOI18N
+ data != null &&
+ data.getLocation() != null &&
+ data.getLocation().startsWith("netigso://") // NOI18N
+ ) {
+ String cnb = data.getLocation().substring(10);
+ for (ModuleInfo mi : Lookup.getDefault().lookupAll(ModuleInfo.class)) {
+ if (mi.getCodeNameBase().equals(cnb)) {
+ if (!mi.isEnabled()) {
+ break;
+ }
+ final URL url = mi.getClassLoader().getResource(name);
+ if (url != null) {
+ return new ModuleEntry(url, name);
+ } else {
+ break;
+ }
+ }
+ }
+ }
+
BundleEntry u;
for (;;) {
BundleFile d = delegate(why, name);
diff -r 0b9154a59a3b netbinox/src/org/netbeans/modules/netbinox/ModuleEntry.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/netbinox/src/org/netbeans/modules/netbinox/ModuleEntry.java Mon Jan 16 18:46:58 2012 +0100
@@ -0,0 +1,92 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2012 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]"
+ *
+ * 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.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2012 Sun Microsystems, Inc.
+ */
+package org.netbeans.modules.netbinox;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
+
+/** An entry representing a direct entry inside a NetBeans
+ * module.
+ *
+ * @author Jaroslav Tulach
+ */
+final class ModuleEntry extends BundleEntry {
+ private final URL url;
+ private final String name;
+
+ public ModuleEntry(URL url, String name) {
+ this.url = url;
+ this.name = name;
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return url.openStream();
+ }
+
+ @Override
+ public long getSize() {
+ return -1;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public long getTime() {
+ return 0L;
+ }
+
+ @Override
+ public URL getLocalURL() {
+ return url;
+ }
+
+ @Override
+ public URL getFileURL() {
+ return url;
+ }
+}
diff -r 0b9154a59a3b netbinox/test/unit/src/org/netbeans/modules/netbinox/BundleGetEntryTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/netbinox/test/unit/src/org/netbeans/modules/netbinox/BundleGetEntryTest.java Mon Jan 16 18:46:58 2012 +0100
@@ -0,0 +1,130 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2010 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 Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
+ * Microsystems, Inc. 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.modules.netbinox;
+
+import java.net.URL;
+import org.netbeans.core.startup.*;
+import java.io.File;
+import java.io.IOException;
+import java.util.Locale;
+import java.util.concurrent.Callable;
+import org.netbeans.Module;
+import org.netbeans.ModuleManager;
+import org.netbeans.SetupHid;
+import org.netbeans.core.netigso.NetigsoServicesTest;
+import org.openide.util.Lookup;
+import org.openide.util.Mutex.ExceptionAction;
+import org.osgi.framework.Bundle;
+
+/**
+ * Do we correctly handle META-INF/services in bundles?
+ *
+ * @author Jaroslav Tulach
+ */
+public class BundleGetEntryTest extends SetupHid {
+ private static Module m1;
+ private static ModuleManager mgr;
+ private int cnt;
+ private File jar;
+ private File simpleModule;
+
+ public BundleGetEntryTest(String name) {
+ super(name);
+ }
+
+ protected @Override void setUp() throws Exception {
+ Locale.setDefault(Locale.US);
+ clearWorkDir();
+ File ud = new File(getWorkDir(), "ud");
+ ud.mkdirs();
+ System.setProperty("netbeans.user", ud.getPath());
+
+ data = new File(getDataDir(), "jars");
+ jars = new File(getWorkDir(), "space in path");
+ jars.mkdirs();
+ simpleModule = createTestJAR("activate", null);
+ String mf = "OpenIDE-Module: can.read.metainf\n"
+ + "OpenIDE-Public-Packages: org.activate\n"
+ + "\n"
+ + "\n";
+ jar = NetigsoHid.changeManifest(getWorkDir(), simpleModule, mf);
+ }
+
+ public void testActivation() throws Exception {
+ ModuleSystem ms = Main.getModuleSystem();
+ mgr = ms.getManager();
+ mgr.mutex().writeAccess(new ExceptionAction() {
+ @Override
+ public Void run() throws Exception {
+ Callable> fr = Lookup.getDefault().lookup(Callable.class);
+ assertNull("No registration found yet", fr);
+
+
+ m1 = mgr.create(jar, null, false, false, false);
+ mgr.enable(m1);
+
+ Module m2 = mgr.create(simpleModule, null, false, false, false);
+ mgr.enable(m2);
+
+
+ Bundle bundle = NetigsoServicesTest.findBundle("can.read.metainf");
+ assertNotNull("Bundle found", bundle);
+ URL res = bundle.getEntry("org/activate/entry.txt");
+ assertNotNull("Entry found", res);
+ byte[] arr = new byte[1000];
+ int len = res.openStream().read(arr);
+ String s = new String(arr, 0, len);
+ assertEquals("Ahoj", s.substring(0,4));
+
+ mgr.disable(m1);
+
+ return null;
+ }
+ });
+ }
+ private File createTestJAR(String name, String srcdir, File... classpath) throws IOException {
+ return createTestJAR(data, jars, name, srcdir, classpath);
+ }
+}