Skip to content

Commit 3d53b70

Browse files
committed
JBoss may use the "jar:file" format to reference jar files instead of nested jars
1 parent 74ee62c commit 3d53b70

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

telemetry/src/main/java/datadog/telemetry/dependency/DependencyResolver.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ private static JarReader.Extracted resolveNestedJar(final URI uri) throws IOExce
7171
path = path.substring("file:".length());
7272
final int sepIdx = path.indexOf("!/");
7373
if (sepIdx == -1) {
74-
throw new IllegalArgumentException("Invalid nested jar path: " + path);
74+
// JBoss may use the "jar:file" format to reference jar files instead of nested jars.
75+
// These look like: jar:file:/path/to.jar!/
76+
return JarReader.readJarFile(path);
7577
}
7678
final String outerPath = path.substring(0, sepIdx);
7779
final String innerPath = path.substring(sepIdx + 2);

telemetry/src/test/groovy/datadog/telemetry/dependency/DependencyResolverSpecification.groovy

+32-8
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,7 @@ class DependencyResolverSpecification extends DepSpecification {
2121
'Implementation-Title' : implementationTitle,
2222
'Implementation-Version': implementationVersion,
2323
]
24-
File file = new File(testDir, filename)
25-
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file))
26-
ZipEntry e = new ZipEntry("META-INF/MANIFEST.MF")
27-
def manifest = attributes.findAll { it.value != null }.collect { k, v -> "$k: $v" }.join('\n')
28-
out.putNextEntry(e)
29-
out.write(manifest.getBytes(Charset.forName('UTF-8')))
30-
out.closeEntry()
31-
out.close()
24+
File file = prepareJar(filename, attributes)
3225

3326
when:
3427
def dependencies = DependencyResolver.resolve(file.toURI())
@@ -66,6 +59,18 @@ class DependencyResolverSpecification extends DepSpecification {
6659
'com.samskivert.jmustache' | 'jmustache' | '1.14.0' | null | null | 'jmustache-1.14.jar' || 'com.samskivert:jmustache' | '1.14'
6760
}
6861

62+
private File prepareJar(final filename, final attributes) {
63+
File file = new File(testDir, filename)
64+
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file))
65+
ZipEntry e = new ZipEntry("META-INF/MANIFEST.MF")
66+
def manifest = attributes.findAll { it.value != null }.collect { k, v -> "$k: $v" }.join('\n')
67+
out.putNextEntry(e)
68+
out.write(manifest.getBytes(Charset.forName('UTF-8')))
69+
out.closeEntry()
70+
out.close()
71+
file
72+
}
73+
6974
void 'jar without pom.properties get resolved with hash'() {
7075
expect:
7176
knownJarCheck(
@@ -328,4 +333,23 @@ class DependencyResolverSpecification extends DepSpecification {
328333
assert dep.version == opts['version']
329334
assert dep.hash == opts['hash']
330335
}
336+
337+
void 'JBoss may use the "jar:file" format to reference jar files instead of nested jars'(){
338+
setup:
339+
final attributes = [
340+
'Bundle-SymbolicName' : null,
341+
'Bundle-Name' : null,
342+
'Bundle-Version' : null,
343+
'Implementation-Title' : 'JUnit',
344+
'Implementation-Version': '4.12',
345+
]
346+
final file = prepareJar("junit-4.12.jar", attributes)
347+
final uri = new URI("jar:"+file.toURI()+"!/")
348+
349+
when:
350+
final deps = DependencyResolver.resolve(uri)
351+
352+
then:
353+
deps.size() == 1
354+
}
331355
}

0 commit comments

Comments
 (0)