JavaTargetParameter (String agentPath, String sessionDataFilePath, String @Nullable [] patterns, String[] excludePatterns, String[] excludeAnnotations, boolean testTracking, boolean branchCoverage, String sourceMapPath) { try { final File tempFile = createTempFile(); tempFile.deleteOnExit(); Ref<Boolean> writeOnceRef = new Ref<>(false); String tempFilePath = tempFile.getAbsolutePath(); TargetPaths targetPaths = TargetPaths.ordered(builder -> { builder .download(sessionDataFilePath, __ -> { createFileOrClearExisting(sessionDataFilePath); return Unit.INSTANCE; }, targetSessionDataPath -> { if (!writeOnceRef.get()) { try { writeOptionsToFile(tempFile, targetSessionDataPath, patterns, excludePatterns, excludeAnnotations, testTracking, branchCoverage, sourceMapPath); } catch (IOException e) { throw new RuntimeException(e); } finally { writeOnceRef.set(true); } } return Unit.INSTANCE; }) .upload(agentPath, __ -> Unit.INSTANCE, __ -> Unit.INSTANCE) .upload(tempFilePath, __ -> Unit.INSTANCE, __ -> Unit.INSTANCE); return Unit.INSTANCE; }); return new JavaTargetParameter.Builder(targetPaths) .fixed("-javaagent:") .resolved(agentPath) .fixed("=") .resolved(tempFilePath) .build(); } catch (IOException e) { LOG.info("Coverage was not enabled", e); return null; } }