Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ report-generator/test-coverage-*.xml
**/logTest/**
**/jacoco.exec
**/target/**
.claude/settings.local.json
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ We use [semantic versioning](http://semver.org/):
# Next version
- _maven-plugin_: Added maven properties for `runImpacted` and `runAllTests` configuration parameters
- _maven-plugin_: The warning "Both baselineRevision and baselineCommit are set but only one of them is needed" was displayed incorrectly
- [fix] _maven-plugin_: Coverage upload used "Now" instead of auto-resolved Git revision when no commit/revision was configured

# 36.2.0
- _agent_: improved logging when multiple agents are attached
Expand Down
73 changes: 73 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
## Build Commands

```bash
# Build with tests
./gradlew build

# Build without tests
./gradlew assemble

# Run all tests for a module
./gradlew :agent:test

# Run a single test
./gradlew :agent:test --tests "com.teamscale.jacoco.agent.MyTest.testMethod"

# Publish to local Maven repo (for local plugin testing)
./gradlew publishToMavenLocal

# Build Docker image
docker build -f agent/src/docker/Dockerfile .

# Compile for different JaCoCo version (don't commit unless upgrading)
./gradlew dist
```

## Project Architecture

This is a multi-module Gradle project (Java 21 toolchain, targets Java 8) that provides a JVM profiler for collecting code coverage and uploading it to Teamscale.

### Core Modules

- **agent** - Main Java agent that instruments bytecode via JaCoCo and collects coverage
- **report-generator** - Converts JaCoCo binary execution data to XML/testwise coverage formats
- **teamscale-client** - HTTP client library for Teamscale server communication
- **tia-client** - Test Impact Analysis client for identifying impacted tests

### Build Tool Plugins

- **teamscale-gradle-plugin** - Gradle plugin for coverage collection and test-wise execution
- **teamscale-maven-plugin** - Maven plugin with equivalent functionality
- **impacted-test-engine** - JUnit 5 engine that queries Teamscale for impacted tests

### Agent Internals

Entry point: `PreMain.premain()` in `agent/src/main/java/com/teamscale/jacoco/agent/PreMain.java`

**Initialization flow:**
1. JVM loads agent via `-javaagent` parameter
2. `PreMain.premain()` parses options and initializes logging
3. `JaCoCoPreMain` registers `LenientCoverageTransformer` with the JVM
4. Classes are instrumented at load time with coverage probes

**Coverage modes:**
- **Interval-based** (`Agent` class) - Periodically dumps coverage (default every 10 min)
- **Test-wise** (`TestwiseCoverageAgent` class) - Per-test coverage via HTTP endpoints (`/test/start`, `/test/end`)

**Key classes:**
- `AgentOptions` - Central configuration holder
- `JacocoRuntimeController` - Interface to JaCoCo's execution data
- `LenientCoverageTransformer` - Bytecode instrumentation with error recovery
- `IUploader` - Interface for upload backends (Teamscale, Azure, Artifactory, disk)

### System Tests

The `system-tests/` directory contains integration tests that exercise the packaged agent JAR in various scenarios. Each subdirectory is a separate Gradle subproject.

## Pre-Commit Checklist

Before completing any code change, verify:

- [ ] CHANGELOG.md updated for user-visible changes (bug fixes, new features, breaking changes)
- [ ] Tests added/updated for the change
- [ ] No unintended files modified
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Session(request: Request) {

private val reports = mutableMapOf<EReportFormat, MutableList<ExternalReport>>()

/** Returns the revision for which the session was opened. */
fun getRevision() = revision

/**
* Retrieves the commit information for the session. Combines the revision and commit data into a single string
* representation separated by a comma.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
Loading
Loading