Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions biz.aQute.bndlib.tests/test/test/ProjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,59 @@ public void testRepoCollector() throws Exception {
}
}

@Test
public void testRepoCollectorNonJar() throws Exception {
try (Workspace ws = getWorkspace(IO.getFile("testresources/ws-repononjar"));
Project project = ws.getProject("org.example.impl");
RepoCollector rc = new RepoCollector(project);
) {

List<RepositoryPlugin> repositories = project.getRepositories();
RepositoryPlugin repo = ws.getRepository("Maven Central");
assertNotNull(repo);

Collection<Container> repoRefs = rc.repoRefs();
System.out.println(repoRefs);
assertThat(repoRefs).hasSize(3);
assertThat(IO.normalizePath(repoRefs.toString()))
.contains(
"cnf/cache/org/weasis/thirdparty/org/opencv/libopencv_java/4.6.0-dcm/libopencv_java-4.6.0-dcm-linux-aarch64.so",
"cnf/cache/org/weasis/thirdparty/org/opencv/libopencv_java/4.6.0-dcm/libopencv_java-4.6.0-dcm-linux-x86-64.so",
"cnf/cache/org/weasis/thirdparty/org/opencv/libopencv_java/4.6.0-dcm/libopencv_java-4.6.0-dcm-macosx-aarch64.dylib");

ProjectBuilder builder = project.getBuilder(null);
Jar jar = builder.build();

assertTrue(IO.normalizePath(jar.getDirectory("linux-aarch64")
.get("linux-aarch64/libopencv_java.so")
.toString())
.endsWith(
"cnf/cache/org/weasis/thirdparty/org/opencv/libopencv_java/4.6.0-dcm/libopencv_java-4.6.0-dcm-linux-aarch64.so"));
assertEquals("a", IO.collect(jar.getDirectory("linux-aarch64")
.get("linux-aarch64/libopencv_java.so")
.openInputStream()));

assertTrue(IO.normalizePath(jar.getDirectory("linux-x86-64")
.get("linux-x86-64/libopencv_java.so")
.toString())
.endsWith(
"cnf/cache/org/weasis/thirdparty/org/opencv/libopencv_java/4.6.0-dcm/libopencv_java-4.6.0-dcm-linux-x86-64.so"));
assertEquals("b", IO.collect(jar.getDirectory("linux-x86-64")
.get("linux-x86-64/libopencv_java.so")
.openInputStream()));

assertTrue(IO.normalizePath(jar.getDirectory("macos-aarch64")
.get("macos-aarch64/libopencv_java.so")
.toString())
.endsWith(
"cnf/cache/org/weasis/thirdparty/org/opencv/libopencv_java/4.6.0-dcm/libopencv_java-4.6.0-dcm-macosx-aarch64.dylib"));
assertEquals("c", IO.collect(jar.getDirectory("macos-aarch64")
.get("macos-aarch64/libopencv_java.so")
.openInputStream()));

}
}

@Test
public void testClasspath() throws Exception {
File project = new File("").getAbsoluteFile();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-plugin: \
aQute.bnd.repository.maven.provider.MavenBndRepository;\
releaseUrl="https://repo.maven.apache.org/maven2";\
index=${.}/central.mvn;\
name='Maven Central';\
local=${.}/cache;\
readOnly=true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# 3rd party artifacts
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<classpathentry kind="src" output="generated/classes" path="src/main/java"/>
<classpathentry kind="src" output="generated/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="generated/classes"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bin/
/generated/
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.example.impl</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>bndtools.core.bndbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>bndtools.core.bndnature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# org.example.impl PROVIDER BUNDLE
#

-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}
2 changes: 1 addition & 1 deletion biz.aQute.bndlib/src/aQute/bnd/build/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,7 @@ protected Container toContainer(String bsn, String range, Map<String, String> at
}
Container container;
if (f.getName()
.endsWith("lib"))
.endsWith(".lib"))
container = new Container(this, bsn, range, Container.TYPE.LIBRARY, f, null, attrs, db);
else
container = new Container(this, bsn, range, Container.TYPE.REPO, f, null, attrs, db);
Expand Down
9 changes: 9 additions & 0 deletions biz.aQute.bndlib/src/aQute/bnd/build/ProjectBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.function.Supplier;
import java.util.jar.Manifest;
import java.util.regex.Pattern;
import java.util.zip.ZipException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -229,6 +230,10 @@ public void init() {
try (Jar jar = new Jar(file)) {
fillDependencies(dependencies, jar, containerAttributes);
}
catch (ZipException e) {
// not a jar file (can happen if a
// ${repo}-reference a non-jar (.dylib, .so)
}
}
}
}
Expand Down Expand Up @@ -284,6 +289,10 @@ private void fillDependencies(Parameters dependencies, Jar jar, Map<String, Stri
dependencies.add(key.toString(), attrs);
} else {
// fall back to pom.properties in jar
if (jar == null) {
return;
}

jar.getResources(pomPropertiesFilter)
.forEachOrdered(r -> {
UTF8Properties pomProperties = new UTF8Properties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.function.Supplier;
import java.util.jar.Manifest;
import java.util.stream.Stream;
import java.util.zip.ZipException;

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

return rb.build();
} catch (Exception rt) {
} catch (ZipException rt) {
// can happen if the file is not a JAR file (e.g. a dynamic libray,
// .so, .dylib)
ResourceBuilder rb = new ResourceBuilder();
// placeholder for "any file"
String mime = "application/octet-stream";
rb.addContentCapability(uri,
new DeferredComparableValue<String>(String.class,
SupplierWithException.asSupplier(() -> SHA256.digest(file)
.asHex()),
file.hashCode()),
file.length(), mime);
return rb.build();
}
catch (Exception rt) {
throw new IllegalArgumentException("illegal format " + file.getAbsolutePath(), rt);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,16 @@ private JarInfo getJarInfo(File file) {

private void addLibraryEntry(IPath path, File file, List<IAccessRule> accessRules,
List<IClasspathAttribute> extraAttrs, IPath sourceAttachmentPath, IPath sourceAttachmentRootPath) {

if (file.isFile() && !file.getName()
.toLowerCase()
.endsWith(".jar")) {
// non .jar files are no library entries (it is possible that
// the ${repo} macro references non jar files which could end up
// here
return;
}

IClasspathEntry libraryEntry = JavaCore.newLibraryEntry(path, sourceAttachmentPath,
sourceAttachmentRootPath, toAccessRulesArray(accessRules), toClasspathAttributesArray(extraAttrs),
false);
Expand Down