Skip to content

Commit

Permalink
Merge branch 'master' into ts/38049_config_file_env_variable
Browse files Browse the repository at this point in the history
  • Loading branch information
karottenreibe committed Apr 4, 2024
2 parents 9831adc + d6cca42 commit 6557f46
Show file tree
Hide file tree
Showing 49 changed files with 1,515 additions and 672 deletions.
37 changes: 29 additions & 8 deletions .github/workflows/actions.yml
Expand Up @@ -9,17 +9,14 @@ on:

jobs:
build:
name: Build & Deploy
name: Build on Linux & Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up GraalVM
uses: graalvm/setup-graalvm@v1
- uses: actions/setup-java@v4
with:
java-version: '17.0.8'
distribution: 'graalvm-community'
github-token: ${{ secrets.GITHUB_TOKEN }}
set-java-home: true
distribution: 'temurin'
java-version: '17'
- name: Build with Gradle
run: ./gradlew build
- name: Upload Release Assets
Expand Down Expand Up @@ -71,7 +68,31 @@ jobs:
accesskey: ${{ secrets.CQSE_TEAMSCALE_IO_ACCESSKEY }}
partition: 'Coverage'
format: 'JACOCO'
message: 'Coverage'
message: 'Linux Coverage'
files: '**/jacocoTestReport.xml'

test-windows:
name: Test on Windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Build with Gradle
run: ./gradlew build
- name: Upload coverage to Teamscale
if: always() && github.event_name == 'push'
uses: cqse/teamscale-upload-action@v9.2.1
with:
server: 'https://cqse.teamscale.io'
project: 'teamscale-jacoco-agent'
user: ${{ secrets.CQSE_TEAMSCALE_IO_USER }}
accesskey: ${{ secrets.CQSE_TEAMSCALE_IO_ACCESSKEY }}
partition: 'Coverage Windows'
format: 'JACOCO'
message: 'Coverage Windows'
files: '**/jacocoTestReport.xml'

docker:
Expand Down
5 changes: 5 additions & 0 deletions .idea/codeStyles/Project.xml

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

2 changes: 1 addition & 1 deletion .idea/misc.xml

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

3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,8 +6,11 @@ We use [semantic versioning](http://semver.org/):

# Next Release
- [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
- [fix] Disable warning about proxy port not being correct when no proxy port was set at all
- [fix] _agent_: `GET /commit` and `GET /revision` endpoints did return 500 error
- [feature] _agent_: Added stable support for Java 22 and experimental support for Java 23

# 33.1.2
- [fix] _teamscale-maven-plugin_: Revision and end commit could not be set via command line (user property)
Expand Down
4 changes: 2 additions & 2 deletions agent/build.gradle.kts
Expand Up @@ -84,8 +84,8 @@ distributions {
named("shadow") {
distributionBaseName.set("teamscale-jacoco-agent")
contents {
from(project(":installer").tasks["nativeCompile"]) {
include("installer")
from(project(":installer").tasks["jlink"]) {
into("installer")
}

from(tasks.readmeToPdf) {
Expand Down
9 changes: 9 additions & 0 deletions agent/src/dist/installer.bat
@@ -0,0 +1,9 @@
@echo off
set DIR="%~dp0"
set BAT_EXEC="%DIR:"=%\installer\installer-windows-x86_64\bin\installer.bat"

rem ensure that we don't accidentally profile the uninstaller
set JAVA_TOOL_OPTIONS=
set _JAVA_OPTIONS=

pushd %DIR% & %BAT_EXEC% %* & popd
8 changes: 8 additions & 0 deletions agent/src/dist/installer.sh
@@ -0,0 +1,8 @@
#!/bin/sh
DIR="${0%/*}"

# ensure that we don't accidentally profile the uninstaller
unset JAVA_TOOL_OPTIONS
unset _JAVA_OPTIONS

exec "$DIR/installer/installer-linux-x86_64/bin/installer" "$@"
4 changes: 3 additions & 1 deletion agent/src/docker/Dockerfile
@@ -1,6 +1,8 @@
# --- build image ---

FROM openjdk:8 as build
FROM openjdk:17 as build
# install xargs which is needed during the build
RUN microdnf install findutils
ADD . /src
WORKDIR /src
RUN ./gradlew :agent:shadowJar
Expand Down
Expand Up @@ -13,14 +13,15 @@

package com.teamscale.jacoco.agent;

import org.jacoco.agent.rt.internal_4742761.Agent;
import org.jacoco.agent.rt.internal_4742761.AgentModule;
import org.jacoco.agent.rt.internal_4742761.CoverageTransformer;
import org.jacoco.agent.rt.internal_4742761.IExceptionLogger;
import org.jacoco.agent.rt.internal_4742761.core.runtime.AgentOptions;
import org.jacoco.agent.rt.internal_4742761.core.runtime.IRuntime;
import org.jacoco.agent.rt.internal_4742761.core.runtime.InjectedClassRuntime;
import org.jacoco.agent.rt.internal_4742761.core.runtime.ModifiedSystemClassRuntime;
import org.jacoco.agent.rt.internal_aeaf9ab.Agent;
import org.jacoco.agent.rt.internal_aeaf9ab.AgentModule;
import org.jacoco.agent.rt.internal_aeaf9ab.CoverageTransformer;
import org.jacoco.agent.rt.internal_aeaf9ab.IExceptionLogger;
import org.jacoco.agent.rt.internal_aeaf9ab.PreMain;
import org.jacoco.agent.rt.internal_aeaf9ab.core.runtime.AgentOptions;
import org.jacoco.agent.rt.internal_aeaf9ab.core.runtime.IRuntime;
import org.jacoco.agent.rt.internal_aeaf9ab.core.runtime.InjectedClassRuntime;
import org.jacoco.agent.rt.internal_aeaf9ab.core.runtime.ModifiedSystemClassRuntime;
import org.slf4j.Logger;

import java.lang.instrument.Instrumentation;
Expand Down
@@ -1,8 +1,8 @@
package com.teamscale.jacoco.agent;

import org.jacoco.agent.rt.internal_4742761.CoverageTransformer;
import org.jacoco.agent.rt.internal_4742761.core.runtime.AgentOptions;
import org.jacoco.agent.rt.internal_4742761.core.runtime.IRuntime;
import org.jacoco.agent.rt.internal_aeaf9ab.CoverageTransformer;
import org.jacoco.agent.rt.internal_aeaf9ab.core.runtime.AgentOptions;
import org.jacoco.agent.rt.internal_aeaf9ab.core.runtime.IRuntime;
import org.slf4j.Logger;

import java.lang.instrument.IllegalClassFormatException;
Expand Down
Expand Up @@ -12,6 +12,8 @@
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Optional;

Expand Down Expand Up @@ -48,13 +50,15 @@ public String getMessage() {
/** Returns revision information for the Teamscale upload. */
@GET
@Path("/revision")
@Produces(MediaType.APPLICATION_JSON)
public RevisionInfo getRevision() {
return this.getRevisionInfo();
}

/** Returns revision information for the Teamscale upload. */
@GET
@Path("/commit")
@Produces(MediaType.APPLICATION_JSON)
public RevisionInfo getCommit() {
return this.getRevisionInfo();
}
Expand Down
Expand Up @@ -86,6 +86,23 @@ public void testGettingPartition() throws Exception {
assertThat(receivedPartition).isEqualTo(defaultPartition);
}

/** Test reading the commit to which the agent will upload. */
@Test
public void testGettingCommit() throws Exception {
String receivedCommit = getText("/commit");
assertThat(receivedCommit).isEqualTo("{\"type\":\"REVISION\",\"value\":null}");
receivedCommit = getJson("/commit");
assertThat(receivedCommit).isEqualTo("{\"type\":\"REVISION\",\"value\":null}");
}

/** Test reading the revision to which the agent will upload. */
@Test
public void testGettingRevision() throws Exception {
String receivedRevision = getText("/revision");
assertThat(receivedRevision).isEqualTo("{\"type\":\"REVISION\",\"value\":null}");
receivedRevision = getJson("/revision");
assertThat(receivedRevision).isEqualTo("{\"type\":\"REVISION\",\"value\":null}");
}

private void putText(String endpointPath, String newValue) throws Exception {
OkHttpClient client = new OkHttpClient();
Expand All @@ -107,4 +124,14 @@ private String getText(String endpointPath) throws Exception {
Response response = client.newCall(request).execute();
return response.body() != null ? response.body().string() : "";
}
}

private String getJson(String endpointPath) throws Exception {
OkHttpClient client = new OkHttpClient();
HttpUrl endpointUrl = HttpUrl.get(baseUri.resolve(endpointPath));
Request request = new Request.Builder()
.url(endpointUrl).header("Accept", javax.ws.rs.core.MediaType.APPLICATION_JSON)
.build();
Response response = client.newCall(request).execute();
return response.body() != null ? response.body().string() : "";
}
}
Expand Up @@ -3,6 +3,8 @@
import okhttp3.HttpUrl;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.io.TempDir;

import java.io.IOException;
Expand Down Expand Up @@ -45,36 +47,44 @@ void successfulParsing() throws AgentOptionParseException, IOException {
void missingUsername() throws IOException {
Files.write(teamscalePropertiesPath, "url=http://test\naccesskey=key".getBytes(StandardCharsets.UTF_8));
assertThatThrownBy(
() -> TeamscalePropertiesUtils.parseCredentials(teamscalePropertiesPath)).hasMessageContaining("missing the username");
() -> TeamscalePropertiesUtils.parseCredentials(teamscalePropertiesPath)).hasMessageContaining(
"missing the username");
}

@Test
void missingAccessKey() throws IOException {
Files.write(teamscalePropertiesPath, "url=http://test\nusername=user".getBytes(StandardCharsets.UTF_8));
assertThatThrownBy(
() -> TeamscalePropertiesUtils.parseCredentials(teamscalePropertiesPath)).hasMessageContaining("missing the accesskey");
() -> TeamscalePropertiesUtils.parseCredentials(teamscalePropertiesPath)).hasMessageContaining(
"missing the accesskey");
}

@Test
void missingUrl() throws IOException {
Files.write(teamscalePropertiesPath, "username=user\nusername=user".getBytes(StandardCharsets.UTF_8));
assertThatThrownBy(
() -> TeamscalePropertiesUtils.parseCredentials(teamscalePropertiesPath)).hasMessageContaining("missing the url");
() -> TeamscalePropertiesUtils.parseCredentials(teamscalePropertiesPath)).hasMessageContaining(
"missing the url");
}

@Test
void malformedUrl() throws IOException {
Files.write(teamscalePropertiesPath, "url=$$**\nusername=user\nusername=user".getBytes(StandardCharsets.UTF_8));
assertThatThrownBy(
() -> TeamscalePropertiesUtils.parseCredentials(teamscalePropertiesPath)).hasMessageContaining("malformed URL");
() -> TeamscalePropertiesUtils.parseCredentials(teamscalePropertiesPath)).hasMessageContaining(
"malformed URL");
}

/** This test doesn't work on Windows since {@link java.io.File#setReadable(boolean)} does not work there. */
@DisabledOnOs(OS.WINDOWS)
@Test
void fileNotReadable() throws IOException {
Files.write(teamscalePropertiesPath, "url=http://test\nusername=user\nusername=user".getBytes(StandardCharsets.UTF_8));
Files.write(teamscalePropertiesPath,
"url=http://test\nusername=user\nusername=user".getBytes(StandardCharsets.UTF_8));
assertThat(teamscalePropertiesPath.toFile().setReadable(false)).isTrue();
assertThatThrownBy(
() -> TeamscalePropertiesUtils.parseCredentials(teamscalePropertiesPath)).hasMessageContaining("Failed to read");
() -> TeamscalePropertiesUtils.parseCredentials(teamscalePropertiesPath)).hasMessageContaining(
"Failed to read");
}

}
Expand Up @@ -3,6 +3,9 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Stream;

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

/**
* Test Utilities
Expand All @@ -11,12 +14,15 @@ public class TestUtils {
/**
* Deletes all contents inside the coverage folder inside the agent directory
*/
@SuppressWarnings("ResultOfMethodCallIgnored")
public static void cleanAgentCoverageDirectory() throws IOException {
Path coverageDir = AgentUtils.getAgentDirectory().resolve("coverage");
if (Files.exists(coverageDir)) {
Files.list(coverageDir).forEach(path -> path.toFile().delete());
try (Stream<Path> stream = Files.list(coverageDir)) {
stream.forEach(path ->
assertThat(path.toFile().delete()).withFailMessage("Failed to delete " + path).isTrue());
}
Files.delete(coverageDir);
}
}

}

0 comments on commit 6557f46

Please sign in to comment.