diff --git a/.idea/misc.xml b/.idea/misc.xml index 86c1552fc..c163eb201 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,3 +1,4 @@ + @@ -28,7 +29,7 @@ - + diff --git a/CHANGELOG.md b/CHANGELOG.md index 99dabf524..7309c1c94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/agent/src/main/java/com/teamscale/jacoco/agent/commit_resolution/git_properties/GitPropertiesLocatorUtils.java b/agent/src/main/java/com/teamscale/jacoco/agent/commit_resolution/git_properties/GitPropertiesLocatorUtils.java index e3a7e4eb1..0b6487014 100644 --- a/agent/src/main/java/com/teamscale/jacoco/agent/commit_resolution/git_properties/GitPropertiesLocatorUtils.java +++ b/agent/src/main/java/com/teamscale/jacoco/agent/commit_resolution/git_properties/GitPropertiesLocatorUtils.java @@ -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); diff --git a/agent/src/test/java/com/teamscale/jacoco/agent/commit_resolution/git_properties/GitPropertiesLocatorTest.java b/agent/src/test/java/com/teamscale/jacoco/agent/commit_resolution/git_properties/GitPropertiesLocatorTest.java index cd59224d7..0f88d8800 100644 --- a/agent/src/test/java/com/teamscale/jacoco/agent/commit_resolution/git_properties/GitPropertiesLocatorTest.java +++ b/agent/src/test/java/com/teamscale/jacoco/agent/commit_resolution/git_properties/GitPropertiesLocatorTest.java @@ -16,7 +16,7 @@ public class GitPropertiesLocatorTest { private static final List 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 { @@ -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"); } } diff --git a/agent/src/test/java/com/teamscale/jacoco/agent/commit_resolution/git_properties/GitPropertiesLocatorUtilsTest.java b/agent/src/test/java/com/teamscale/jacoco/agent/commit_resolution/git_properties/GitPropertiesLocatorUtilsTest.java index 456f79e21..76098c76d 100644 --- a/agent/src/test/java/com/teamscale/jacoco/agent/commit_resolution/git_properties/GitPropertiesLocatorUtilsTest.java +++ b/agent/src/test/java/com/teamscale/jacoco/agent/commit_resolution/git_properties/GitPropertiesLocatorUtilsTest.java @@ -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")); } diff --git a/agent/src/test/java/com/teamscale/jacoco/agent/testimpact/TestwiseCoverageAgentTest.java b/agent/src/test/java/com/teamscale/jacoco/agent/testimpact/TestwiseCoverageAgentTest.java index a6ff4b3d3..90a1d4fac 100644 --- a/agent/src/test/java/com/teamscale/jacoco/agent/testimpact/TestwiseCoverageAgentTest.java +++ b/agent/src/test/java/com/teamscale/jacoco/agent/testimpact/TestwiseCoverageAgentTest.java @@ -128,6 +128,7 @@ Call> testRunStarted( @Query("include-non-impacted") boolean includeNonImpacted, @Query("baseline") Long baseline ); + } @Test diff --git a/agent/src/test/resources/com/teamscale/jacoco/agent/commit_resolution/git_properties/spring-boot-3.jar b/agent/src/test/resources/com/teamscale/jacoco/agent/commit_resolution/git_properties/spring-boot-3.jar new file mode 100644 index 000000000..e33fa53d3 Binary files /dev/null and b/agent/src/test/resources/com/teamscale/jacoco/agent/commit_resolution/git_properties/spring-boot-3.jar differ diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 78f0caf2f..98f8f6e93 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" }