Skip to content

Commit

Permalink
Add support of spring boot nested jar for SymDB (#7678)
Browse files Browse the repository at this point in the history
Spring boot use a special jar organisation for nested ones. It uses a
new jar protocol for URL: jar:nested:
  • Loading branch information
jpbempel authored Sep 24, 2024
1 parent 010e6f7 commit 4f03507
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
public class JarScanner {
private static final Logger LOGGER = LoggerFactory.getLogger(JarScanner.class);
private static final String JAR_FILE_PREFIX = "jar:file:";
private static final String JAR_NESTED_PREFIX = "jar:nested:";
private static final String FILE_PREFIX = "file:";
// Spring prefixes:
// https://docs.spring.io/spring-boot/docs/current/reference/html/executable-jar.html
Expand Down Expand Up @@ -41,6 +42,11 @@ public static Path extractJarPath(ProtectionDomain protectionDomain) throws URIS
if (idx != -1) {
return getPathFromPrefixedFileName(locationStr, JAR_FILE_PREFIX, idx);
}
} else if (locationStr.startsWith(JAR_NESTED_PREFIX)) {
int idx = locationStr.indexOf("/!BOOT-INF/");
if (idx != -1) {
return getPathFromPrefixedFileName(locationStr, JAR_NESTED_PREFIX, idx);
}
} else if (locationStr.startsWith(FILE_PREFIX)) {
return getPathFromPrefixedFileName(locationStr, FILE_PREFIX, locationStr.length());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.datadog.debugger.symbol;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.security.cert.Certificate;
import org.junit.jupiter.api.Test;

class JarScannerTest {
Expand All @@ -31,4 +36,15 @@ public void extractJarPathFromFile() throws ClassNotFoundException, URISyntaxExc
Class<?> testClass = urlClassLoader.loadClass(CLASS_NAME);
assertEquals(jarFileUrl.getFile(), JarScanner.extractJarPath(testClass).toString());
}

@Test
public void extractJarPathFromNestedJar() throws URISyntaxException {
URL jarFileUrl = getClass().getResource("/debugger-symbol.jar");
URL mockLocation = mock(URL.class);
when(mockLocation.toString())
.thenReturn("jar:nested:" + jarFileUrl.getFile() + "/!BOOT-INF/classes/!");
CodeSource codeSource = new CodeSource(mockLocation, (Certificate[]) null);
ProtectionDomain protectionDomain = new ProtectionDomain(codeSource, null);
assertEquals(jarFileUrl.getFile(), JarScanner.extractJarPath(protectionDomain).toString());
}
}

0 comments on commit 4f03507

Please sign in to comment.