Skip to content

Commit 695f4a1

Browse files
committed
Fix dependency collection for new Spring Boot nested jars
1 parent 40f3b5d commit 695f4a1

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,14 @@ static List<Dependency> internalResolve(final URI uri) throws IOException {
3535
}
3636
path = f.getAbsolutePath();
3737
metadata = JarReader.readJarFile(path);
38-
} else if ("jar".equals(scheme) && uri.getSchemeSpecificPart().startsWith("file:")) {
39-
path = uri.getSchemeSpecificPart().substring("file:".length());
38+
} else if ("jar".equals(scheme)) {
39+
final String schemeSpecificPart = uri.getSchemeSpecificPart();
40+
if (!schemeSpecificPart.startsWith("file:") && !schemeSpecificPart.startsWith("nested:")) {
41+
log.debug("unsupported dependency type: {}", uri);
42+
return Collections.emptyList();
43+
}
44+
final int idx = schemeSpecificPart.indexOf(":");
45+
path = schemeSpecificPart.substring(idx + 1);
4046
metadata = JarReader.readNestedJarFile(path);
4147
} else {
4248
log.debug("unsupported dependency type: {}", uri);

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,48 @@ class DependencyResolverSpecification extends DepSpecification {
159159
dep.source == 'opentracing-util-0.33.0.jar'
160160
}
161161

162+
void 'spring boot dependency new style'() throws IOException {
163+
when:
164+
String zipPath = Classloader.classLoader.getResource('datadog/telemetry/dependencies/spring-boot-app.jar').path
165+
URI uri = new URI("jar:nested:$zipPath!/BOOT-INF/lib/opentracing-util-0.33.0.jar!/")
166+
167+
Dependency dep = DependencyResolver.resolve(uri).get(0)
168+
169+
then:
170+
dep != null
171+
dep.name == 'io.opentracing:opentracing-util'
172+
dep.version == '0.33.0'
173+
dep.hash == null
174+
dep.source == 'opentracing-util-0.33.0.jar'
175+
}
176+
177+
void 'spring boot dependency new style empty path'() throws IOException {
178+
when:
179+
URI uri = new URI("jar:nested:")
180+
List<Dependency> deps = DependencyResolver.resolve(uri)
181+
182+
then:
183+
deps.isEmpty()
184+
}
185+
186+
void 'spring boot dependency old style empty path'() throws IOException {
187+
when:
188+
URI uri = new URI("jar:file:")
189+
List<Dependency> deps = DependencyResolver.resolve(uri)
190+
191+
then:
192+
deps.isEmpty()
193+
}
194+
195+
void 'jar unknown'() throws IOException {
196+
when:
197+
URI uri = new URI("jar:unknown")
198+
List<Dependency> deps = DependencyResolver.resolve(uri)
199+
200+
then:
201+
deps.isEmpty()
202+
}
203+
162204
void 'spring boot dependency without maven metadata'() throws IOException {
163205
given:
164206
def innerJarData = new ByteArrayOutputStream()

0 commit comments

Comments
 (0)