Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2016-08-30 15:25:50 +0000
committerThomas Watson2016-08-30 15:25:50 +0000
commitfef33690b9c5b85c608f5466aeede64a8c18b9b7 (patch)
tree02fca9afec587e2c797231c4fad93f7300e016a6
parenteddd793e2f23907996725b67ed03025ea72a5821 (diff)
downloadrt.equinox.framework-fef33690b9c5b85c608f5466aeede64a8c18b9b7.tar.gz
rt.equinox.framework-fef33690b9c5b85c608f5466aeede64a8c18b9b7.tar.xz
rt.equinox.framework-fef33690b9c5b85c608f5466aeede64a8c18b9b7.zip
Bug 492890 - Must escape values in a Bundle-NativeCode header when theyY20160901-1000I20160906-0800
have special filter characters Change-Id: Ia10e30ac0090f92297196d1ace0ba19c5b454ee5 Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
-rw-r--r--bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/compatibility/state/StateConverter.java36
-rw-r--r--bundles/org.eclipse.osgi.tests/.classpath1
-rw-r--r--bundles/org.eclipse.osgi.tests/build.properties6
-rw-r--r--bundles/org.eclipse.osgi.tests/bundles_src/nativetest.f/META-INF/MANIFEST.MF8
-rw-r--r--bundles/org.eclipse.osgi.tests/bundles_src/nativetest.f/libs/test1/nativecode.txt1
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PlatformAdminBundleTests.java34
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java2
7 files changed, 83 insertions, 5 deletions
diff --git a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/compatibility/state/StateConverter.java b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/compatibility/state/StateConverter.java
index 7ef9beaab..56b59211c 100644
--- a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/compatibility/state/StateConverter.java
+++ b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/compatibility/state/StateConverter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013, 2014 IBM Corporation and others. All rights reserved.
+ * Copyright (c) 2013, 2016 IBM Corporation and others. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
@@ -144,7 +144,12 @@ class StateConverter {
}
private List<GenericSpecification> createRequireCapability(Requirement requirement) {
- String declaration = requirement.getNamespace() + toString(requirement.getAttributes(), "=", false) + toString(requirement.getDirectives(), ":=", true); //$NON-NLS-1$ //$NON-NLS-2$
+ Map<String, String> directives = new HashMap<String, String>(requirement.getDirectives());
+ String filter = directives.get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
+ if (filter != null) {
+ directives.put(Namespace.REQUIREMENT_FILTER_DIRECTIVE, escapeFilterInput(filter));
+ }
+ String declaration = requirement.getNamespace() + toString(requirement.getAttributes(), "=", false) + toString(directives, ":=", true); //$NON-NLS-1$ //$NON-NLS-2$
List<GenericSpecification> result = state.getFactory().createGenericSpecifications(declaration);
for (GenericSpecification genericSpecification : result) {
genericSpecification.setUserObject(requirement);
@@ -152,6 +157,33 @@ class StateConverter {
return result;
}
+ // We have to re-escape the escape characters in the filter string
+ private static String escapeFilterInput(final String filter) {
+ boolean escaped = false;
+ int inlen = filter.length();
+ int outlen = inlen << 1; /* inlen * 2 */
+
+ char[] output = new char[outlen];
+ filter.getChars(0, inlen, output, inlen);
+
+ int cursor = 0;
+ for (int i = inlen; i < outlen; i++) {
+ char c = output[i];
+ switch (c) {
+ case '\\' :
+ output[cursor] = '\\';
+ cursor++;
+ escaped = true;
+ break;
+ }
+
+ output[cursor] = c;
+ cursor++;
+ }
+
+ return escaped ? new String(output, 0, cursor) : filter;
+ }
+
private String createOSGiRequirement(Requirement requirement, String namespace, String... versions) {
Map<String, String> directives = new HashMap<String, String>(requirement.getDirectives());
String filter = directives.remove(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
diff --git a/bundles/org.eclipse.osgi.tests/.classpath b/bundles/org.eclipse.osgi.tests/.classpath
index 41bd4f9ad..47d870ee3 100644
--- a/bundles/org.eclipse.osgi.tests/.classpath
+++ b/bundles/org.eclipse.osgi.tests/.classpath
@@ -42,6 +42,7 @@
<classpathentry kind="src" output="bundle_tests/nativetest.c" path="bundles_src/nativetest.c"/>
<classpathentry kind="src" output="bundle_tests/nativetest.d" path="bundles_src/nativetest.d"/>
<classpathentry kind="src" output="bundle_tests/nativetest.e" path="bundles_src/nativetest.e"/>
+ <classpathentry kind="src" output="bundle_tests/nativetest.f" path="bundles_src/nativetest.f"/>
<classpathentry kind="src" output="bundle_tests/host.multiple.exports" path="bundles_src/host.multiple.exports"/>
<classpathentry kind="src" output="bundle_tests/frag.multiple.exports" path="bundles_src/frag.multiple.exports"/>
<classpathentry kind="src" output="bundle_tests/client1.multiple.exports" path="bundles_src/client1.multiple.exports"/>
diff --git a/bundles/org.eclipse.osgi.tests/build.properties b/bundles/org.eclipse.osgi.tests/build.properties
index 8676259ad..219cffe7a 100644
--- a/bundles/org.eclipse.osgi.tests/build.properties
+++ b/bundles/org.eclipse.osgi.tests/build.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2000, 2011 IBM Corporation and others.
+# Copyright (c) 2000, 2016 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -95,6 +95,8 @@ source.bundle_tests/nativetest.d.jar = bundles_src/nativetest.d/
manifest.bundle_tests/nativetest.d.jar = META-INF/MANIFEST.MF
source.bundle_tests/nativetest.e.jar = bundles_src/nativetest.e/
manifest.bundle_tests/nativetest.e.jar = META-INF/MANIFEST.MF
+source.bundle_tests/nativetest.f.jar = bundles_src/nativetest.f/
+manifest.bundle_tests/nativetest.f.jar = META-INF/MANIFEST.MF
source.bundle_tests/host.multiple.exports.jar = bundles_src/host.multiple.exports/
manifest.bundle_tests/host.multiple.exports.jar = META-INF/MANIFEST.MF
source.bundle_tests/frag.multiple.exports.jar = bundles_src/frag.multiple.exports/
@@ -315,6 +317,8 @@ jars.compile.order = bundle_tests/ext.framework.b.jar,\
bundle_tests/nativetest.b2.jar,\
bundle_tests/nativetest.c.jar,\
bundle_tests/nativetest.d.jar,\
+ bundle_tests/nativetest.e.jar,\
+ bundle_tests/nativetest.f.jar,\
bundle_tests/host.multiple.exports.jar,\
bundle_tests/frag.multiple.exports.jar,\
bundle_tests/client1.multiple.exports.jar,\
diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.f/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.f/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..16a108930
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.f/META-INF/MANIFEST.MF
@@ -0,0 +1,8 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: NativeBundle Plug-in
+Bundle-SymbolicName: nativetest.f
+Bundle-Version: 1.0.0
+Bundle-Localization: plugin
+Bundle-NativeCode:
+ libs/test1/nativecode.txt; osname="Windows NT (unknown)", *
diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.f/libs/test1/nativecode.txt b/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.f/libs/test1/nativecode.txt
new file mode 100644
index 000000000..8c4e7bb10
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.f/libs/test1/nativecode.txt
@@ -0,0 +1 @@
+libs.test1
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PlatformAdminBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PlatformAdminBundleTests.java
index c4860a2ca..c7f4dde32 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PlatformAdminBundleTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PlatformAdminBundleTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2014 IBM Corporation and others.
+ * Copyright (c) 2007, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,6 +11,9 @@
package org.eclipse.osgi.tests.bundles;
import java.util.Arrays;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.osgi.service.resolver.*;
@@ -131,4 +134,33 @@ public class PlatformAdminBundleTests extends AbstractBundleTests {
r3Installer.shutdown();
}
}
+
+ public void testNativeCodeFilterWithSpecialChars() throws BundleException, InterruptedException {
+ final AtomicReference<FrameworkEvent> error = new AtomicReference<FrameworkEvent>();
+ final CountDownLatch errorCnt = new CountDownLatch(1);
+ FrameworkListener errorListener = new FrameworkListener() {
+
+ @Override
+ public void frameworkEvent(FrameworkEvent event) {
+ if (event.getType() == FrameworkEvent.ERROR) {
+ error.set(event);
+ errorCnt.countDown();
+ }
+ }
+ };
+ getContext().addFrameworkListener(errorListener);
+ try {
+ PlatformAdmin pa = installer.getPlatformAdmin();
+ State systemState = pa.getState(false);
+ // just making sure the system state is fully created first
+ assertNotNull(systemState.getBundle(0));
+ Bundle nativeTestF = installer.installBundle("nativetest.f");
+ nativeTestF.start();
+ // expecting no errors
+ errorCnt.await(5, TimeUnit.SECONDS);
+ assertNull("Found an error: " + error.get(), error.get());
+ } finally {
+ getContext().removeFrameworkListener(errorListener);
+ }
+ }
}
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java
index 1fb980cd1..fe24f2384 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java
@@ -2101,7 +2101,7 @@ public class TestModuleContainer extends AbstractTest {
}
@Test
- public void testNativeWithFitlerChars() throws BundleException, IOException {
+ public void testNativeWithFilterChars() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();

Back to the top