Repository navigation
TS-46354 Support nested chars #992
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
Open
Stef2k16
wants to merge
4
commits into
master
Choose a base branch
from
ts/46354_nested_jars
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...generator/src/test/kotlin/com/teamscale/report/testwise/jacoco/cache/AnalyzerCacheTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package com.teamscale.report.testwise.jacoco.cache | ||
|
|
||
| import com.teamscale.report.EDuplicateClassFileBehavior | ||
| import com.teamscale.report.util.ClasspathWildcardIncludeFilter | ||
| import com.teamscale.report.util.ILogger | ||
| import org.assertj.core.api.Assertions.assertThat | ||
| import org.assertj.core.api.Assertions.assertThatThrownBy | ||
| import org.jacoco.core.internal.data.CRC64 | ||
| import org.junit.jupiter.api.Test | ||
| import org.junit.jupiter.api.io.TempDir | ||
| import org.junit.jupiter.params.ParameterizedTest | ||
| import org.junit.jupiter.params.provider.CsvSource | ||
| import org.mockito.Mockito | ||
| import java.io.ByteArrayOutputStream | ||
| import java.io.File | ||
| import java.io.IOException | ||
| import java.util.zip.ZipEntry | ||
| import java.util.zip.ZipOutputStream | ||
|
|
||
| /** Tests for the [AnalyzerCache] class. */ | ||
| class AnalyzerCacheTest { | ||
|
|
||
| @TempDir | ||
| private lateinit var tempDir: File | ||
|
|
||
| private val classBytes = javaClass.getResourceAsStream("AnalyzerCacheTest.class")!!.use { it.readBytes() } | ||
| private val innerJar = zip("com/teamscale/report/testwise/jacoco/cache/AnalyzerCacheTest.class" to classBytes) | ||
|
|
||
| private val logger = Mockito.mock<ILogger>() | ||
| private val probesCache = ProbesCache(logger, EDuplicateClassFileBehavior.IGNORE) | ||
| private val analyzer = AnalyzerCache(probesCache, ClasspathWildcardIncludeFilter(null, null), logger) | ||
|
|
||
| /** | ||
| * An archive may contain JARs, e.g. a WAR contains its libraries and some JARs contain other JARs (e.g. SVNKit). | ||
| * The analyzer addresses such a JAR as `app.war@WEB-INF/lib/inner.jar`, which is not a file on disk, so the cache | ||
| * must not try to read it from there. | ||
| */ | ||
| @ParameterizedTest | ||
| @CsvSource("outer.jar, lib/inner.jar", "app.war, WEB-INF/lib/inner.jar") | ||
| fun analyzesClassesInJarsInsideArchives(archiveName: String, jarPath: String) { | ||
| tempDir.resolve(archiveName).writeBytes(zip(jarPath to innerJar)) | ||
|
|
||
| assertThat(analyzer.analyzeAll(tempDir)).isEqualTo(1) | ||
| assertThat(probesCache.containsClassId(CRC64.classId(classBytes))).isTrue() | ||
| } | ||
|
|
||
| /** A nested JAR that cannot be read must be reported with its location, so that users can find it. */ | ||
| @Test | ||
| fun reportsLocationOfUnreadableNestedJar() { | ||
| val outerJar = zip("lib/inner.jar" to innerJar) | ||
| // Cuts the outer JAR in the middle of the nested JAR's data | ||
| tempDir.resolve("outer.jar").writeBytes(outerJar.copyOf(outerJar.size / 2)) | ||
|
|
||
| assertThatThrownBy { analyzer.analyzeAll(tempDir) } | ||
| .isInstanceOf(IOException::class.java) | ||
| .hasMessageContaining("outer.jar@lib/inner.jar") | ||
| } | ||
|
|
||
| private fun zip(vararg entries: Pair<String, ByteArray>): ByteArray { | ||
| val output = ByteArrayOutputStream() | ||
| ZipOutputStream(output).use { zip -> | ||
| entries.forEach { (name, content) -> | ||
| zip.putNextEntry(ZipEntry(name)) | ||
| zip.write(content) | ||
| zip.closeEntry() | ||
| } | ||
| } | ||
| return output.toByteArray() | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect the special case to be documented inline. Maybe have a separate method for that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claude: Agreed. Right now the reason is only in the method's KDoc (lines 59–61). Someone reading lines 65–74 sees
file.isFilewith no hint why a.jarlocation might not be a file. A separate method would let its name and doc say it, for example:Two things the author should keep:
CHANGELOG.md).isFileas the check. It may be tempting to switch to'@' in location, but@shows up in real paths. Jenkins, for example, names the workspaces of concurrent buildsworkspace@2. With that check, every jar on disk in such a workspace would take the in-memory path and stay buffered in full while it is analyzed, instead of being streamed. That is the extra memory use that commit 7bb9cc5 removed. A comment on the check could say this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claude: Done. The reply above is now the single merged reply, with the corrected point about the
@check. I removed my correction, your request and my note about the blocked edit. Say so if this comment and yours should go too.