Skip to content

Conversation

@chrisrueger
Copy link
Contributor

@chrisrueger chrisrueger commented Jan 3, 2026

Closes #6660

This fixes the problem specifically in the comment #6660 (comment)

and the test github repo:
https://github.com/steinybot/bug-reports/tree/bnd/illegal-argumen

The problem was the the developer wants to reference a maven-repository entry which is NOT a .jar file via the ${repo} macro. But currently bnd assumes a .jar file in a couple of places and fails in new Jar(file) if it is not a .jar.

There were two issues:

  1. MavenBndRepository could not work with the coordinates to .so and .dylib files
# github.mvn
# GitHub mvn-repo-master repository
# https://github.com/nroduit/mvn-repo/tree/master/org/weasis/thirdparty/org/opencv/libopencv_java/4.6.0-dcm
org.weasis.thirdparty.org.opencv:libopencv_java:so:linux-aarch64:4.6.0-dcm
org.weasis.thirdparty.org.opencv:libopencv_java:so:linux-x86-64:4.6.0-dcm
org.weasis.thirdparty.org.opencv:libopencv_java:dylib:macosx-aarch64:4.6.0-dcm
-plugin.30.mvn-repo-master: \
    aQute.bnd.repository.maven.provider.MavenBndRepository; \
        releaseUrl="https://raw.githubusercontent.com/nroduit/mvn-repo/master/"; \
        index=${.}/github.mvn; \
        readOnly=true; \
        name="GitHub mvn-repo-master"
  1. -includeresources with ${repo} macro fails to reference them
-includeresource: \
  linux-aarch64/libopencv_java.so=${repo;org.weasis.thirdparty.org.opencv:libopencv_java:so:linux-aarch64;4.6.0.-dcm},\
  linux-x86-64/libopencv_java.so=${repo;org.weasis.thirdparty.org.opencv:libopencv_java:so:linux-x86-64;4.6.0.-dcm},\
  macos-aarch64/libopencv_java.so=${repo;org.weasis.thirdparty.org.opencv:libopencv_java:dylib:macosx-aarch64;4.6.0.-dcm}

fails to load e.g. /.m2/repository/org/weasis/thirdparty/org/opencv/libopencv_java/4.6.0-dcm/libopencv_java-4.6.0-dcm-linux-x86-64.so

( to my knowledge maven repos can contain various file extensions and not just .jar files)

After the fix

The two issues are resolve:

  1. MavenBndRepository now works with the coordinates to .so and .dylib files
image
  1. -includeresources can reference them

I got the .so and .dylib file included.

image

BTW: also latest would work instead of the awkward version syntax 4.6.0.-dcm (see description of #6660 )

linux-aarch64/libopencv_java.so=${repo;org.weasis.thirdparty.org.opencv:libopencv_java:so:linux-aarch64;latest},\

TODOs

@chrisrueger chrisrueger marked this pull request as draft January 3, 2026 22:28
@chrisrueger chrisrueger force-pushed the 6660-fix-Unable-to-include-dynlib-resources branch from db8dc80 to 89ed4fe Compare January 3, 2026 23:15
@chrisrueger
Copy link
Contributor Author

chrisrueger commented Jan 3, 2026

Update: I am certain that it is ok.
e.g. it adds the SHA here:

image

but with just

ResourceBuilder rb = new ResourceBuilder();
return rb.build();

SHA woud be missing.
image

So I think it is useful to have it.

Original:

I am not sure about my change in ResourceBuilder.parse() in the catch block. https://github.com/bndtools/bnd/pull/7038/changes#diff-32c7fa31300fdfcff9b45a51a4a8cf962650b0a2a2b9d14eea2bcb36aca3a25f

The current code is adopted from before the current code was adopted for Multi-Release JARs in a7a6bee#diff-32c7fa31300fdfcff9b45a51a4a8cf962650b0a2a2b9d14eea2bcb36aca3a25fR782

I wonder if I should just do this for non-Jar files:

ResourceBuilder rb = new ResourceBuilder();
return rb.build();

@chrisrueger chrisrueger force-pushed the 6660-fix-Unable-to-include-dynlib-resources branch 4 times, most recently from 5eb9a2a to 7ef7597 Compare January 4, 2026 16:06
@chrisrueger chrisrueger requested a review from Copilot January 4, 2026 19:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issues preventing the use of non-JAR files (e.g., .so, .dylib dynamic libraries) from Maven repositories via the ${repo} macro and -includeresource directive. The fix addresses two main problems: MavenBndRepository's inability to handle coordinates for non-JAR file extensions, and failures when including these resources via the ${repo} macro.

Key Changes

  • Enhanced ZipException handling to gracefully process non-JAR files instead of failing
  • Fixed file extension check bug (.lib instead of lib)
  • Added filtering to prevent non-JAR files from being added as Eclipse classpath library entries

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
biz.aQute.bndlib/src/aQute/bnd/osgi/resource/ResourceBuilder.java Added ZipException catch block to handle non-JAR files by treating them as octet-stream resources
biz.aQute.bndlib/src/aQute/bnd/build/ProjectBuilder.java Added ZipException handling and null check when processing repo references to skip non-JAR files
biz.aQute.bndlib/src/aQute/bnd/build/Project.java Fixed typo in extension check - changed endsWith("lib") to endsWith(".lib")
bndtools.builder/src/org/bndtools/builder/classpath/BndContainerInitializer.java Added check to skip non-JAR files when adding library entries to Eclipse classpath
biz.aQute.bndlib.tests/test/test/ProjectTest.java Added test case testRepoCollectorNonJar() to verify non-JAR resource inclusion
biz.aQute.bndlib.tests/testresources/ws-repononjar/* Added test workspace with Maven repository cache containing .so and .dylib files

@chrisrueger chrisrueger marked this pull request as ready for review January 4, 2026 21:06
- added testcase for non-jar repo references tp prove the current problems of bndtools#6660

- Fix file extension check for library containers. Changed the file name check from 'lib' to '.lib' to correctly identify library containers based on file extension.
There are other places where ".lib" is checked already.

- Added handling for ZipException in ProjectBuilder and ResourceBuilder to support non-JAR files (e.g., .so, .dylib) referenced in repositories. This prevents errors when such files are encountered (e.g. via ${repo} macro) and ensures dependencies and resources are processed gracefully.

- Also do not add non-jar files as library entries in BndContainerInitializer

Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
@chrisrueger chrisrueger force-pushed the 6660-fix-Unable-to-include-dynlib-resources branch from 7ef7597 to afd45dd Compare January 4, 2026 21:10
@chrisrueger chrisrueger changed the title fix unable to include dynlib resources fix unable to reference non-jar resources in MavenBndRepo and repo macro Jan 4, 2026
@chrisrueger chrisrueger merged commit ebba7d8 into bndtools:master Jan 5, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to include dynlib resources

1 participant