Skip to content

Commit 023df95

Browse files
authored
Merge pull request #7035 from chrisrueger/7028-exclude-bundlenativecode-from-reorderclause
skip reorderClause() for Bundle-NativeCode
2 parents 6028cc0 + 2eda08e commit 023df95

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed

biz.aQute.bndlib.tests/test/test/JarTest.java

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,91 @@ public void testWriteManifestNonOSGiHeadersNotReordered() throws Exception {
645645
assertEquals(customHeader, writtenCustomHeader);
646646
}
647647

648+
/**
649+
* Test Bundle-NativeCode is untouched from Jar.reorderClause() for now,
650+
* because this header is special and needs to be parsed differently than
651+
* normal OSGi headers. In the future we could evaluate how to build a
652+
* special reordering for this header.
653+
*/
654+
@Test
655+
public void testWriteManifestBundleNativeCodeNoReordering() throws Exception {
656+
Manifest manifest = new Manifest();
657+
658+
String customHeader = """
659+
natives/linux-amd64/libgluegen_rt.so;
660+
natives/linux-amd64/libjocl.so;
661+
natives/linux-amd64/libnativewindow_awt.so;
662+
natives/linux-amd64/libnewt_drm.so;
663+
natives/linux-amd64/libnativewindow_x11.so;
664+
natives/linux-amd64/libnativewindow_drm.so;
665+
natives/linux-amd64/libnewt_head.so;
666+
natives/linux-amd64/libjogl_mobile.so;
667+
natives/linux-amd64/libjogl_desktop.so;
668+
processor=x86-64; osname=Linux
669+
""";
670+
manifest.getMainAttributes()
671+
.putValue(Constants.BUNDLE_NATIVECODE, customHeader);
672+
673+
try (ByteArrayOutputStream bout = new ByteArrayOutputStream()) {
674+
Jar.writeManifest(manifest, bout);
675+
676+
Manifest writtenManifest = new Manifest(new ByteArrayInputStream(bout.toByteArray()));
677+
String writtenCustomHeader = writtenManifest.getMainAttributes()
678+
.getValue(Constants.BUNDLE_NATIVECODE);
679+
680+
assertEquals(customHeader.replaceAll("\n", "")
681+
.replace(" ", ""),
682+
writtenCustomHeader.replaceAll("\n", "")
683+
.replace(" ", ""));
684+
}
685+
}
686+
687+
/**
688+
* Test Bundle-NativeCode is untouched from Jar.reorderClause() for now,
689+
* because this header is special and needs to be parsed differently than
690+
* normal OSGi headers. In the future we could evaluate how to build a
691+
* special reordering for this header.
692+
*/
693+
@Test
694+
public void testWriteManifestBundleNativeCodeNoReordering2() throws Exception {
695+
Manifest manifest = new Manifest();
696+
697+
String customHeader = """
698+
f1;\
699+
osname=Windows95;
700+
processor=x86;
701+
selection-filter='(com.acme.windowing=win32)';
702+
language=en;
703+
osname=Windows98;
704+
language=se,
705+
lib/solaris/libhttp.so;
706+
osname=Solaris;
707+
osname = SunOS ;
708+
processor = sparc,
709+
lib/linux/libhttp.so;
710+
osname = Linux ;
711+
osversion = 3.1.4;
712+
processor = mips;
713+
selection-filter = '(com.acme.windowing=gtk)',
714+
*""";
715+
manifest.getMainAttributes()
716+
.putValue(Constants.BUNDLE_NATIVECODE, customHeader);
717+
718+
try (ByteArrayOutputStream bout = new ByteArrayOutputStream()) {
719+
Jar.writeManifest(manifest, bout);
720+
721+
Manifest writtenManifest = new Manifest(new ByteArrayInputStream(bout.toByteArray()));
722+
String writtenCustomHeader = writtenManifest.getMainAttributes()
723+
.getValue(Constants.BUNDLE_NATIVECODE);
724+
725+
assertEquals(customHeader.replaceAll("\n", "")
726+
.replace(" ", ""),
727+
writtenCustomHeader.replaceAll("\n", "")
728+
.replace(" ", ""));
729+
}
730+
}
731+
732+
648733
@Test
649734
public void testWriteManifestComprehensiveAttributeDirectiveOrdering() throws Exception {
650735
Manifest manifest = new Manifest();

biz.aQute.bndlib/src/aQute/bnd/osgi/Jar.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,8 @@ private static Manifest clean(Manifest org) {
786786
.entrySet()) {
787787
String nice = clean((String) entry.getValue());
788788
Object key = entry.getKey();
789-
if (Constants.OSGI_SYNTAX_HEADERS.contains(key.toString())) {
789+
if (Constants.OSGI_SYNTAX_HEADERS.contains(key.toString())
790+
&& !Constants.BUNDLE_NATIVECODE.equals(key.toString())) {
790791
nice = reorderClause(nice, collator);
791792
}
792793
mainAttributes.put(key, nice);

0 commit comments

Comments
 (0)