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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ We use [semantic versioning](http://semver.org/):
- PATCH version when you make backwards compatible bug fixes.

# Next version
- [fix] _agent_: Warning about multiple agents being present is misleading

# 34.2.0
- [fix] _agent_: `search-git-properties-recursively` was not considered when jar was given via `artifactory-git-properties-jar`
Expand Down
20 changes: 12 additions & 8 deletions agent/src/main/java/com/teamscale/jacoco/agent/PreMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ public class PreMain {
*/
private static final String LOCKING_SYSTEM_PROPERTY = "TEAMSCALE_JAVA_PROFILER_ATTACHED";

/** Environment variable from which to read the config ID to use.
* This is an ID for a profiler configuration that is stored in Teamscale. */
/**
* Environment variable from which to read the config ID to use. This is an ID for a profiler configuration that is
* stored in Teamscale.
*/
private static final String CONFIG_ID_ENVIRONMENT_VARIABLE = "TEAMSCALE_JAVA_PROFILER_CONFIG_ID";

/** Environment variable from which to read the config file to use. */
Expand Down Expand Up @@ -91,12 +93,13 @@ public static void premain(String options, Instrumentation instrumentation) thro

@NotNull
private static AgentOptions getAndApplyAgentOptions(String options, String environmentConfigId,
String environmentConfigFile) throws AgentOptionParseException, IOException, AgentOptionReceiveException {
String environmentConfigFile) throws AgentOptionParseException, IOException, AgentOptionReceiveException {

DelayedLogger delayedLogger = new DelayedLogger();
List<String> javaAgents = CollectionUtils.filter(ManagementFactory.getRuntimeMXBean().getInputArguments(),
s -> s.contains("-javaagent"));
if (javaAgents.size() > 1) {
// We allow multiple instances of the teamscale-jacoco-agent as we ensure with the #LOCKING_SYSTEM_PROPERTY to only use it once
if (!javaAgents.stream().allMatch(javaAgent -> javaAgent.contains("teamscale-jacoco-agent.jar"))) {
delayedLogger.warn("Using multiple java agents could interfere with coverage recording.");
}
if (!javaAgents.get(0).contains("teamscale-jacoco-agent.jar")) {
Expand All @@ -109,7 +112,8 @@ private static AgentOptions getAndApplyAgentOptions(String options, String envir
}
AgentOptions agentOptions;
try {
agentOptions = AgentOptionsParser.parse(options, environmentConfigId, environmentConfigFile, credentials, delayedLogger);
agentOptions = AgentOptionsParser.parse(options, environmentConfigId, environmentConfigFile, credentials,
delayedLogger);
} catch (AgentOptionParseException e) {
try (LoggingUtils.LoggingResources ignored = initializeFallbackLogging(options, delayedLogger)) {
delayedLogger.errorAndStdErr("Failed to parse agent options: " + e.getMessage(), e);
Expand Down Expand Up @@ -161,7 +165,7 @@ static void closeLoggingResources() {
* the HTTP server is used.
*/
private static AgentBase createAgent(AgentOptions agentOptions,
Instrumentation instrumentation) throws UploaderException, IOException {
Instrumentation instrumentation) throws UploaderException, IOException {
if (agentOptions.useTestwiseCoverageMode()) {
return TestwiseCoverageAgent.create(agentOptions);
} else {
Expand Down Expand Up @@ -189,7 +193,7 @@ private static void initializeDebugLogging(AgentOptions agentOptions, DelayedLog
* this and falls back to the default logger.
*/
private static LoggingUtils.LoggingResources initializeFallbackLogging(String premainOptions,
DelayedLogger delayedLogger) {
DelayedLogger delayedLogger) {
if (premainOptions == null) {
return LoggingUtils.initializeDefaultLogging();
}
Expand Down Expand Up @@ -222,7 +226,7 @@ private static LoggingUtils.LoggingResources initializeFallbackLogging(String pr

/** Creates a fallback logger using the given config file. */
private static LoggingUtils.LoggingResources createFallbackLoggerFromConfig(String configLocation,
DelayedLogger delayedLogger) {
DelayedLogger delayedLogger) {
try {
return LoggingUtils.initializeLogging(
new FilePatternResolver(delayedLogger).parsePath(AgentOptionsParser.LOGGING_CONFIG_OPTION,
Expand Down
Loading