Skip to content

Commit 7ef7597

Browse files
committed
Handle non-JAR files in dependency and resource builders
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>
1 parent b329bc7 commit 7ef7597

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

biz.aQute.bndlib/src/aQute/bnd/build/ProjectBuilder.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.function.Supplier;
2121
import java.util.jar.Manifest;
2222
import java.util.regex.Pattern;
23+
import java.util.zip.ZipException;
2324

2425
import org.slf4j.Logger;
2526
import org.slf4j.LoggerFactory;
@@ -229,6 +230,10 @@ public void init() {
229230
try (Jar jar = new Jar(file)) {
230231
fillDependencies(dependencies, jar, containerAttributes);
231232
}
233+
catch (ZipException e) {
234+
// not a jar file (can happen if a
235+
// ${repo}-reference a non-jar (.dylib, .so)
236+
}
232237
}
233238
}
234239
}
@@ -284,6 +289,10 @@ private void fillDependencies(Parameters dependencies, Jar jar, Map<String, Stri
284289
dependencies.add(key.toString(), attrs);
285290
} else {
286291
// fall back to pom.properties in jar
292+
if (jar == null) {
293+
return;
294+
}
295+
287296
jar.getResources(pomPropertiesFilter)
288297
.forEachOrdered(r -> {
289298
UTF8Properties pomProperties = new UTF8Properties();

biz.aQute.bndlib/src/aQute/bnd/osgi/resource/ResourceBuilder.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.function.Supplier;
2424
import java.util.jar.Manifest;
2525
import java.util.stream.Stream;
26+
import java.util.zip.ZipException;
2627

2728
import org.osgi.annotation.versioning.ProviderType;
2829
import org.osgi.framework.Constants;
@@ -1034,7 +1035,21 @@ public static SupportingResource parse(File file, URI uri) {
10341035
file.length(), mime);
10351036

10361037
return rb.build();
1037-
} catch (Exception rt) {
1038+
} catch (ZipException rt) {
1039+
// can happen if the file is not a JAR file (e.g. a dynamic libray,
1040+
// .so, .dylib)
1041+
ResourceBuilder rb = new ResourceBuilder();
1042+
// placeholder for "any file"
1043+
String mime = "application/octet-stream";
1044+
rb.addContentCapability(uri,
1045+
new DeferredComparableValue<String>(String.class,
1046+
SupplierWithException.asSupplier(() -> SHA256.digest(file)
1047+
.asHex()),
1048+
file.hashCode()),
1049+
file.length(), mime);
1050+
return rb.build();
1051+
}
1052+
catch (Exception rt) {
10381053
throw new IllegalArgumentException("illegal format " + file.getAbsolutePath(), rt);
10391054
}
10401055
}

bndtools.builder/src/org/bndtools/builder/classpath/BndContainerInitializer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,16 @@ private JarInfo getJarInfo(File file) {
616616

617617
private void addLibraryEntry(IPath path, File file, List<IAccessRule> accessRules,
618618
List<IClasspathAttribute> extraAttrs, IPath sourceAttachmentPath, IPath sourceAttachmentRootPath) {
619+
620+
if (file.isFile() && !file.getName()
621+
.toLowerCase()
622+
.endsWith(".jar")) {
623+
// non .jar files are no library entries (it is possible that
624+
// the ${repo} macro references non jar files which could end up
625+
// here
626+
return;
627+
}
628+
619629
IClasspathEntry libraryEntry = JavaCore.newLibraryEntry(path, sourceAttachmentPath,
620630
sourceAttachmentRootPath, toAccessRulesArray(accessRules), toClasspathAttributesArray(extraAttrs),
621631
false);

0 commit comments

Comments
 (0)