Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for Spring boot jar:nested: urls #434

Merged
merged 7 commits into from Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@ We use [semantic versioning](http://semver.org/):
- PATCH version when you make backwards compatible bug fixes.

# Next Release
- [feature] Add support for git.properties in Spring Boot 3.2
- [feature] Read configuration file path from `TEAMSCALE_JAVA_PROFILER_CONFIG_FILE` environment variable
- [feature] add installer for Windows
- [feature] Docker: agent copies itself to `/transfer` if this is mounted into the container
Expand Down
Expand Up @@ -42,7 +42,7 @@ public class GitPropertiesLocatorUtils {
private static final String GIT_PROPERTIES_TEAMSCALE_PROJECT = "teamscale.project";

/** Matches the path to the jar file in a jar:file: URL in regex group 1. */
private static final Pattern JAR_URL_REGEX = Pattern.compile("jar:file:(.*?)!/.*", Pattern.CASE_INSENSITIVE);
private static final Pattern JAR_URL_REGEX = Pattern.compile("jar:(?:file|nested):(.*?)!.*", Pattern.CASE_INSENSITIVE);

private static final Pattern NESTED_JAR_REGEX = Pattern.compile("[jwea]ar:file:(.*?)\\*(.*)",
Pattern.CASE_INSENSITIVE);
Expand Down
Expand Up @@ -16,7 +16,7 @@ public class GitPropertiesLocatorTest {

private static final List<String> TEST_ARCHIVES = Arrays
.asList("plain-git-properties.jar", "spring-boot-git-properties.jar", "spring-boot-git-properties.war",
"full-git-properties.jar");
"full-git-properties.jar", "spring-boot-3.jar");

@Test
public void testReadingGitPropertiesFromArchive() throws Exception {
Expand All @@ -28,7 +28,8 @@ public void testReadingGitPropertiesFromArchive() throws Exception {
String rev = GitPropertiesLocatorUtils
.getGitCommitPropertyValue(commits.get(0).getSecond(), "test",
new File("test.jar"));
assertThat(rev).isEqualTo("72c7b3f7e6c4802414283cdf7622e6127f3f8976");
assertThat(rev).withFailMessage("Wrong commit found in " + archiveName)
.isEqualTo("72c7b3f7e6c4802414283cdf7622e6127f3f8976");
}
}

Expand Down
@@ -1,23 +1,51 @@
package com.teamscale.jacoco.agent.commit_resolution.git_properties;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;

import static org.assertj.core.api.Assertions.assertThat;

class GitPropertiesLocatorUtilsTest {

/**
* Registers a protocol handler so the test can construct "nested:" URLs that are not supported by plain Java
* but Spring boot.
*/
@BeforeAll
public static void registerCatchAllUrlProtocol() {
URL.setURLStreamHandlerFactory(protocol -> {
if (!"nested".equals(protocol)) {
return null;
}
return new URLStreamHandler() {
/** Returns null, since opening the connection is never done in the test.: */
protected URLConnection openConnection(URL url) {
return null;
}
};
});
}

@Test
public void parseSpringBootCodeLocations() throws Exception {
Assertions.assertThat(GitPropertiesLocatorUtils
assertThat(GitPropertiesLocatorUtils
.extractGitPropertiesSearchRoot(new URL("jar:file:/home/k/demo.jar!/BOOT-INF/classes!/")).getFirst())
.isEqualTo(new File("/home/k/demo.jar"));

URL springBoot3Url = new URL(
"jar:nested:/home/k/proj/spring-boot/demo/build/libs/demo-0.0.1-SNAPSHOT.jar/!BOOT-INF/classes/!/.");
assertThat(GitPropertiesLocatorUtils.extractGitPropertiesSearchRoot(springBoot3Url).getFirst())
.isEqualTo(new File("/home/k/proj/spring-boot/demo/build/libs/demo-0.0.1-SNAPSHOT.jar"));
}

@Test
public void parseFileCodeLocations() throws Exception {
Assertions.assertThat(GitPropertiesLocatorUtils
assertThat(GitPropertiesLocatorUtils
.extractGitPropertiesSearchRoot(new URL("file:/home/k/demo.jar")).getFirst())
.isEqualTo(new File("/home/k/demo.jar"));
}
Expand Down
Expand Up @@ -128,6 +128,7 @@ Call<List<PrioritizableTestCluster>> testRunStarted(
@Query("include-non-impacted") boolean includeNonImpacted,
@Query("baseline") Long baseline
);

}

@Test
Expand Down
Binary file not shown.
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Expand Up @@ -74,6 +74,8 @@ jsonassert = { module = "org.skyscreamer:jsonassert", version = "1.5.1" }
mockito-core = { module = "org.mockito:mockito-core", version.ref = "mockito" }
mockito-junit = { module = "org.mockito:mockito-junit-jupiter", version.ref = "mockito" }

springboot-loader = { module = "org.springframework.boot:spring-boot-loader", version = "3.2.4" }

[plugins]
versions = { id = "com.github.ben-manes.versions", version = "0.51.0" }
markdownToPdf = { id = "de.fntsoftware.gradle.markdown-to-pdf", version = "1.1.0" }
Expand Down