Skip to content

Commit 692335a

Browse files
committed
TS-38628 More tests
1 parent 0a577c5 commit 692335a

File tree

14 files changed

+340
-362
lines changed

14 files changed

+340
-362
lines changed

agent/src/main/kotlin/com/teamscale/jacoco/agent/commit_resolution/git_properties/GitSingleProjectPropertiesLocator.kt

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,20 @@ import java.util.concurrent.Executors
1515
*/
1616
class GitSingleProjectPropertiesLocator<T>(
1717
private val uploader: DelayedUploader<T>,
18-
private val dataExtractor: DataExtractor<T>,
19-
private val executor: Executor,
2018
private val recursiveSearch: Boolean,
21-
private val gitPropertiesCommitTimeFormat: DateTimeFormatter?
19+
private val gitPropertiesCommitTimeFormat: DateTimeFormatter?,
20+
private val executor: Executor = Executors.newSingleThreadExecutor(
21+
DaemonThreadFactory(
22+
GitSingleProjectPropertiesLocator::class.java,
23+
"git.properties Jar scanner thread"
24+
)
25+
),
26+
private val dataExtractor: DataExtractor<T>
2227
) : IGitPropertiesLocator {
2328
private val logger = getLogger(this)
2429
private var foundData: T? = null
2530
private var jarFileWithGitProperties: File? = null
2631

27-
constructor(
28-
uploader: DelayedUploader<T>,
29-
dataExtractor: DataExtractor<T>,
30-
recursiveSearch: Boolean,
31-
gitPropertiesCommitTimeFormat: DateTimeFormatter?
32-
) : this(
33-
uploader, dataExtractor, Executors.newSingleThreadExecutor(
34-
DaemonThreadFactory(
35-
GitSingleProjectPropertiesLocator::class.java,
36-
"git.properties Jar scanner thread"
37-
)
38-
), recursiveSearch, gitPropertiesCommitTimeFormat
39-
)
40-
4132
/**
4233
* Asynchronously searches the given jar file for a git.properties file.
4334
*/
@@ -96,7 +87,8 @@ class GitSingleProjectPropertiesLocator<T>(
9687
/** Extracts data from the JAR. */
9788
@Throws(IOException::class, InvalidGitPropertiesException::class)
9889
fun extractData(
99-
file: File, isJarFile: Boolean,
90+
file: File,
91+
isJarFile: Boolean,
10092
recursiveSearch: Boolean,
10193
gitPropertiesCommitTimeFormat: DateTimeFormatter?
10294
): List<T>

agent/src/main/kotlin/com/teamscale/jacoco/agent/options/AgentOptions.kt

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -525,31 +525,27 @@ open class AgentOptions(private val logger: ILogger) {
525525
uploader: DelayedUploader<ProjectAndCommit>,
526526
gitPropertiesJar: File
527527
) {
528-
val locator = GitSingleProjectPropertiesLocator(
529-
uploader,
530-
{ file, isJarFile, recursiveSearch, timeFormat ->
531-
getProjectRevisionsFromGitProperties(file, isJarFile, recursiveSearch, timeFormat)
532-
}, searchGitPropertiesRecursively,
533-
gitPropertiesCommitTimeFormat
534-
)
535-
locator.searchFileForGitPropertiesAsync(gitPropertiesJar, true)
528+
GitSingleProjectPropertiesLocator(
529+
uploader, searchGitPropertiesRecursively, gitPropertiesCommitTimeFormat
530+
) { file, isJarFile, recursiveSearch, timeFormat ->
531+
getProjectRevisionsFromGitProperties(file, isJarFile, recursiveSearch, timeFormat)
532+
}.searchFileForGitPropertiesAsync(gitPropertiesJar, true)
536533
}
537534

538535
private fun registerSingleGitPropertiesLocator(
539536
uploader: DelayedUploader<ProjectAndCommit>,
540537
instrumentation: Instrumentation?
541538
) {
542-
val locator = GitSingleProjectPropertiesLocator(uploader,
543-
{ file, isJarFile, recursiveSearch, timeFormat ->
544-
getProjectRevisionsFromGitProperties(file, isJarFile, recursiveSearch, timeFormat)
545-
}, searchGitPropertiesRecursively,
546-
gitPropertiesCommitTimeFormat
547-
)
539+
val locator = GitSingleProjectPropertiesLocator(
540+
uploader, searchGitPropertiesRecursively, gitPropertiesCommitTimeFormat
541+
) { file, isJarFile, recursiveSearch, timeFormat ->
542+
getProjectRevisionsFromGitProperties(file, isJarFile, recursiveSearch, timeFormat)
543+
}
548544
instrumentation?.addTransformer(GitPropertiesLocatingTransformer(locator, locationIncludeFilter))
549545
}
550546

551-
private fun createDelayedSingleProjectTeamscaleUploader() = DelayedUploader(
552-
{ projectAndCommit: ProjectAndCommit ->
547+
private fun createDelayedSingleProjectTeamscaleUploader() =
548+
DelayedUploader<ProjectAndCommit>(outputDirectory!!) { projectAndCommit ->
553549
if (!isEmpty(projectAndCommit.project) && (teamscaleServer.project != projectAndCommit.project)) {
554550
logger.warn(
555551
"Teamscale project '" + teamscaleServer.project + "' specified in the agent configuration is not the same as the Teamscale project '" + projectAndCommit.project + "' specified in git.properties file(s). Proceeding to upload to the" +
@@ -564,8 +560,7 @@ open class AgentOptions(private val logger: ILogger) {
564560
teamscaleServer.revision = projectAndCommit.commitInfo.revision
565561
}
566562
TeamscaleUploader(teamscaleServer)
567-
}, outputDirectory!!
568-
)
563+
}
569564

570565
private fun startMultiGitPropertiesFileSearchInJarFile(
571566
uploader: DelayedTeamscaleMultiProjectUploader,
@@ -587,21 +582,17 @@ open class AgentOptions(private val logger: ILogger) {
587582
}
588583

589584
private fun createDelayedArtifactoryUploader(instrumentation: Instrumentation?): IUploader {
590-
val uploader = DelayedUploader<CommitInfo>(
591-
{ commitInfo ->
585+
val uploader = DelayedUploader<CommitInfo>(outputDirectory!!) { commitInfo ->
592586
artifactoryConfig.commitInfo = commitInfo
593587
ArtifactoryUploader(artifactoryConfig, additionalMetaDataFiles, reportFormat)
594-
}, outputDirectory!!
595-
)
588+
}
596589
val locator = GitSingleProjectPropertiesLocator(
597-
uploader,
598-
{ file, isJarFile, recursiveSearch, timeFormat ->
599-
getCommitInfoFromGitProperties(
600-
file, isJarFile, recursiveSearch, timeFormat
601-
)
602-
},
603-
searchGitPropertiesRecursively, gitPropertiesCommitTimeFormat
604-
)
590+
uploader, searchGitPropertiesRecursively, gitPropertiesCommitTimeFormat
591+
) { file, isJarFile, recursiveSearch, timeFormat ->
592+
getCommitInfoFromGitProperties(
593+
file, isJarFile, recursiveSearch, timeFormat
594+
)
595+
}
605596
instrumentation?.addTransformer(GitPropertiesLocatingTransformer(locator, locationIncludeFilter))
606597
return uploader
607598
}

agent/src/main/kotlin/com/teamscale/jacoco/agent/upload/delay/DelayedUploader.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,15 @@ import kotlin.io.path.walk
1818
* information describing a commit is asynchronously made available.
1919
*/
2020
class DelayedUploader<T> internal constructor(
21-
private val wrappedUploaderFactory: Function<T, IUploader>,
2221
private val cacheDir: Path,
23-
private val executor: Executor
22+
private val executor: Executor = Executors.newSingleThreadExecutor(
23+
DaemonThreadFactory(DelayedUploader::class.java, "Delayed cache upload thread")
24+
),
25+
private val wrappedUploaderFactory: (T) -> IUploader,
2426
) : IUploader {
2527
private val logger = getLogger(this)
2628
private var wrappedUploader: IUploader? = null
2729

28-
constructor(wrappedUploaderFactory: Function<T, IUploader>, cacheDir: Path) : this(
29-
wrappedUploaderFactory, cacheDir, Executors.newSingleThreadExecutor(
30-
DaemonThreadFactory(DelayedUploader::class.java, "Delayed cache upload thread")
31-
)
32-
)
33-
3430
/**
3531
* Visible for testing. Allows tests to control the [Executor] to test the
3632
* asynchronous functionality of this class.
@@ -79,7 +75,7 @@ class DelayedUploader<T> internal constructor(
7975
@Synchronized
8076
fun setCommitAndTriggerAsynchronousUpload(information: T) {
8177
if (wrappedUploader == null) {
82-
wrappedUploader = wrappedUploaderFactory.apply(information)
78+
wrappedUploader = wrappedUploaderFactory(information)
8379
logger.info(
8480
"Commit to upload to has been found: {}. Uploading any cached XMLs now to {}", information,
8581
wrappedUploader?.describe()

agent/src/test/java/com/teamscale/jacoco/agent/upload/UploadTestBase.java

Lines changed: 0 additions & 57 deletions
This file was deleted.

agent/src/test/java/com/teamscale/jacoco/agent/upload/artifactory/ArtifactoryUploaderTest.java

Lines changed: 0 additions & 70 deletions
This file was deleted.

agent/src/test/java/com/teamscale/jacoco/agent/upload/delay/DelayedCommitDescriptorRetrievalTest.java

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)