Skip to content

Commit

Permalink
Handle the case of empty BSN in maven target location
Browse files Browse the repository at this point in the history
It seem for some reasons there are "bundles" in the wild that contain an
OSGi manifest with an empty BSN what currently leads to a NPE if used
inside a target.

This now enhances the check for a valid OSGi manifest in a way that it
is not only required to have a BSN but also that it is not empty.

(cherry picked from commit a55b0e3)
  • Loading branch information
laeubi authored and eclipse-tycho-bot committed Feb 8, 2025
1 parent 5d4e258 commit c4e3e0c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Properties;
import java.util.Set;
import java.util.function.Function;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -169,9 +170,7 @@ private static WrappedBundle getWrappedNode(DependencyNode node,
return wrappedNode;
}
Jar jar = new Jar(originalFile);
Manifest originalManifest = jar.getManifest();
if (originalManifest != null
&& originalManifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME) != null) {
if (isValidOSGi(jar.getManifest())) {
// already a bundle!
visited.put(node,
wrappedNode = new WrappedBundle(node, List.of(), null, originalFile.toPath(), jar, List.of()));
Expand Down Expand Up @@ -251,6 +250,15 @@ private static WrappedBundle getWrappedNode(DependencyNode node,
}
}

private static boolean isValidOSGi(Manifest originalManifest) {
if (originalManifest == null) {
return false;
}
Attributes attributes = originalManifest.getMainAttributes();
String symbolicName = attributes.getValue(Constants.BUNDLE_SYMBOLICNAME);
return symbolicName != null && !symbolicName.isBlank();
}

private static Jar getCachedJar(Path cacheFile, Path sourceFile) {
try {
if (!isOutdated(cacheFile, sourceFile)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ public void testBadDependencyInChain() throws Exception {
assertStatusOk(getTargetStatus(target));
}

@Test
public void testBadSymbolicName() throws Exception {
ITargetLocation target = resolveMavenTarget("""
<location includeDependencyScope="compile" missingManifest="generate" type="Maven">
<dependencies>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
</location>
""");
assertStatusOk(getTargetStatus(target));
}

@Test
public void testBadDependencyDirect() throws Exception {
ITargetLocation target = resolveMavenTarget("""
Expand Down

0 comments on commit c4e3e0c

Please sign in to comment.