This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Recognise optional osgi.native reqs

  • Loading branch information...
1 parent e3f34f6 commit f223ac2de035fc3598b645a5eef71a23da14d80d @njbartlett njbartlett committed Mar 20, 2013
@@ -50,6 +50,9 @@
public static final String DIRECTIVE_EFFECTIVE = "effective";
public static final String DIRECTIVE_MANDATORY = "mandatory";
public static final String DIRECTIVE_USES = "uses";
+ public static final String DIRECTIVE_RESOLUTION = "resolution";
+
+ public static final String RESOLUTION_OPTIONAL = "optional";
public static final String EFFECTIVE_RESOLVE = "resolve";
public static final String EFFECTIVE_ACTIVE = "active";
@@ -474,10 +474,17 @@ private void doBundleNativeCode(Resource resource, final List<? super Requiremen
if (nativeHeaderStr == null)
return;
+ boolean optional = false;
List<String> options = new LinkedList<String>();
Map<String, Map<String, String>> nativeHeader = OSGiHeader.parseHeader(nativeHeaderStr);
for (Entry<String, Map<String, String>> entry : nativeHeader.entrySet()) {
+ String name = entry.getKey();
+ if ("*".equals(name)) {
+ optional = true;
+ continue;
+ }
+
StringBuilder builder = new StringBuilder().append("(&");
Map<String, String> attribs = entry.getValue();
@@ -519,11 +526,12 @@ private void doBundleNativeCode(Resource resource, final List<? super Requiremen
filter = builder.toString();
}
- Requirement req = new Builder()
+ Builder builder = new Builder()
.setNamespace(Namespaces.NS_NATIVE)
- .addDirective(Namespaces.DIRECTIVE_FILTER, filter)
- .buildRequirement();
- reqs.add(req);
+ .addDirective(Namespaces.DIRECTIVE_FILTER, filter);
+ if (optional)
+ builder.addDirective(Namespaces.DIRECTIVE_RESOLUTION, Namespaces.RESOLUTION_OPTIONAL);
+ reqs.add(builder.buildRequirement());
}
/*
@@ -331,6 +331,10 @@ public void testFragmentBundleNativeCode() throws Exception {
assertFragmentMatch("testdata/fragment-19.txt", "testdata/19-bundlenativecode.jar");
}
+ public void testFragmentBundleNativeCodeOptional() throws Exception {
+ assertFragmentMatch("testdata/fragment-20.txt", "testdata/20-bundlenativecode-optional.jar");
+ }
+
public void testFragmentPlainJar() throws Exception {
LogService mockLog = Mockito.mock(LogService.class);
RepoIndex indexer = new RepoIndex(mockLog);
@@ -0,0 +1,25 @@
+<resource>
+ <capability namespace='osgi.identity'>
+ <attribute name='osgi.identity' value='org.example.nativecode-optional'/>
+ <attribute name='type' value='osgi.bundle'/>
+ <attribute name='version' type='Version' value='0.0.0'/>
+ </capability>
+ <capability namespace='osgi.content'>
+ <attribute name='osgi.content' value='e3561939d42d430debb21aeea9718de8c4df492b3289ff3b6d6c4f0e53d62191'/>
+ <attribute name='url' value='testdata/20-bundlenativecode-optional.jar'/>
+ <attribute name='size' type='Long' value='466'/>
+ <attribute name='mime' value='application/vnd.osgi.bundle'/>
+ </capability>
+ <capability namespace='osgi.wiring.bundle'>
+ <attribute name='osgi.wiring.bundle' value='org.example.nativecode-optional'/>
+ <attribute name='bundle-version' type='Version' value='0.0.0'/>
+ </capability>
+ <capability namespace='osgi.wiring.host'>
+ <attribute name='osgi.wiring.host' value='org.example.nativecode-optional'/>
+ <attribute name='bundle-version' type='Version' value='0.0.0'/>
+ </capability>
+ <requirement namespace='osgi.native'>
+ <directive name='filter' value='(|(&amp;(osgi.native.osname~=win32)(osgi.native.processor~=x86)(|(osgi.native.language~=en)(osgi.native.language~=se))(com.acme.windowing=win32))(&amp;(|(osgi.native.osname~=Windows95)(osgi.native.osname~=Windows98)(osgi.native.osname~=WindowsNT))(osgi.native.osversion&gt;=6.1.0)(!(osgi.native.osversion&gt;=7.0.0))(osgi.native.processor~=x86_64)))'/>
+ <directive name='resolution' value='optional'/>
+ </requirement>
+</resource>

0 comments on commit f223ac2

Please sign in to comment.