Skip to content

Commit 20a3eda

Browse files
committed
Fix case where a non jar dependency is in the chain for wrapping
Currently when there is a non jar in the dependency chain it fails to resolve the target because it can not read as a jar
1 parent 89fa13f commit 20a3eda

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,24 @@
4444

4545
public class OSGiMetadataGenerationTest extends AbstractMavenTargetTest {
4646

47+
@Test
48+
public void testNonJarArtifactInDependencies() throws Exception {
49+
ITargetLocation target = resolveMavenTarget(
50+
"""
51+
<location includeDependencyDepth="infinite" includeDependencyScopes="compile,provided,runtime" includeSource="true" label="Azure OpenAI" missingManifest="generate" type="Maven">
52+
<dependencies>
53+
<dependency>
54+
<groupId>com.azure</groupId>
55+
<artifactId>azure-ai-openai</artifactId>
56+
<version>1.0.0-beta.13</version>
57+
<type>jar</type>
58+
</dependency>
59+
</dependencies>
60+
</location>
61+
""");
62+
assertStatusOk(getTargetStatus(target));
63+
}
64+
4765
@Test
4866
public void testVersionRanges() throws Exception {
4967
ITargetLocation target = resolveMavenTarget(

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ private static WrappedBundle getWrappedNode(DependencyNode node,
164164
return wrappedNode;
165165
}
166166
Artifact artifact = node.getArtifact();
167+
if (!"jar".equals(artifact.getExtension())) {
168+
visited.put(node, wrappedNode = new WrappedBundle(node, List.of(), null, null, null, List.of(
169+
new ProcessingMessage(artifact, Type.INFO, "Skip " + node.getArtifact() + " it is not a jar"))));
170+
return wrappedNode;
171+
}
167172
File originalFile = artifact.getFile();
168173
if (originalFile == null) {
169174
if (node.getDependency().isOptional()) {
@@ -177,7 +182,16 @@ private static WrappedBundle getWrappedNode(DependencyNode node,
177182
}
178183
return wrappedNode;
179184
}
180-
Jar jar = new Jar(originalFile);
185+
Jar jar;
186+
try {
187+
jar = new Jar(originalFile);
188+
} catch (IOException e) {
189+
visited.put(node,
190+
wrappedNode = new WrappedBundle(node, List.of(), null, null, null,
191+
List.of(new ProcessingMessage(artifact, Type.ERROR,
192+
"Artifact " + node.getArtifact() + " can not be read as a jar file"))));
193+
return wrappedNode;
194+
}
181195
if (isValidOSGi(jar.getManifest())) {
182196
// already a bundle!
183197
visited.put(node,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
public record ProcessingMessage(Artifact artifact, Type type, String message) {
2121

2222
public enum Type {
23-
ERROR, WARN
23+
ERROR, WARN, INFO;
2424
}
2525

2626
}

0 commit comments

Comments
 (0)