Skip to content

Commit 673fc5b

Browse files
committed
Handle the case of empty BSN in maven target location
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.
1 parent 11e9141 commit 673fc5b

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

org.eclipse.m2e.pde.feature/feature.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<feature
33
id="org.eclipse.m2e.pde.feature"
44
label="%featureName"
5-
version="2.3.200.qualifier"
5+
version="2.3.300.qualifier"
66
provider-name="%providerName"
77
plugin="org.eclipse.m2e.core"
88
license-feature="org.eclipse.license"

org.eclipse.m2e.pde.target.tests/src/org/eclipse/m2e/pde/target/tests/OSGiMetadataGenerationTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ public void testBadDependencyInChain() throws Exception {
5555
assertStatusOk(getTargetStatus(target));
5656
}
5757

58+
@Test
59+
public void testBadSymbolicName() throws Exception {
60+
ITargetLocation target = resolveMavenTarget("""
61+
<location includeDependencyScope="compile" missingManifest="generate" type="Maven">
62+
<dependencies>
63+
<dependency>
64+
<groupId>javax.xml.ws</groupId>
65+
<artifactId>jaxws-api</artifactId>
66+
<version>2.3.1</version>
67+
</dependency>
68+
</dependencies>
69+
</location>
70+
""");
71+
assertStatusOk(getTargetStatus(target));
72+
}
73+
5874
@Test
5975
public void testBadDependencyDirect() throws Exception {
6076
ITargetLocation target = resolveMavenTarget("""

org.eclipse.m2e.pde.target/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: M2E PDE Integration
44
Bundle-SymbolicName: org.eclipse.m2e.pde.target;singleton:=true
5-
Bundle-Version: 2.1.0.qualifier
5+
Bundle-Version: 2.1.1.qualifier
66
Automatic-Module-Name: org.eclipse.m2e.pde.target
77
Bundle-RequiredExecutionEnvironment: JavaSE-21
88
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.27.0,4.0.0)",

org.eclipse.m2e.pde.target/src/org/eclipse/m2e/pde/target/shared/MavenBundleWrapper.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Properties;
2727
import java.util.Set;
2828
import java.util.function.Function;
29+
import java.util.jar.Attributes;
2930
import java.util.jar.Manifest;
3031
import java.util.regex.Pattern;
3132
import java.util.stream.Collectors;
@@ -164,9 +165,7 @@ private static WrappedBundle getWrappedNode(DependencyNode node,
164165
return wrappedNode;
165166
}
166167
Jar jar = new Jar(originalFile);
167-
Manifest originalManifest = jar.getManifest();
168-
if (originalManifest != null
169-
&& originalManifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME) != null) {
168+
if (isValidOSGi(jar.getManifest())) {
170169
// already a bundle!
171170
visited.put(node,
172171
wrappedNode = new WrappedBundle(node, List.of(), null, originalFile.toPath(), jar, List.of()));
@@ -246,6 +245,15 @@ private static WrappedBundle getWrappedNode(DependencyNode node,
246245
}
247246
}
248247

248+
private static boolean isValidOSGi(Manifest originalManifest) {
249+
if (originalManifest == null) {
250+
return false;
251+
}
252+
Attributes attributes = originalManifest.getMainAttributes();
253+
String symbolicName = attributes.getValue(Constants.BUNDLE_SYMBOLICNAME);
254+
return symbolicName != null && !symbolicName.isBlank();
255+
}
256+
249257
private static Jar getCachedJar(Path cacheFile, Path sourceFile) {
250258
try {
251259
if (!isOutdated(cacheFile, sourceFile)) {

0 commit comments

Comments
 (0)