-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced Offline Runtime API for saving binary report
- implemented API method to get binary report as a byte array - implemented API method to save binary report - bump Intellij Coverage Library to `1.0.740` Co-authored-by: Leonid Startsev <[email protected]> Resolves #503 PR #500
- Loading branch information
Showing
6 changed files
with
181 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
kover-offline-runtime/src/main/java/kotlinx/kover/offline/runtime/KoverInit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package kotlinx.kover.offline.runtime; | ||
|
||
import com.intellij.rt.coverage.offline.api.CoverageRuntime; | ||
import kotlinx.kover.offline.runtime.api.KoverRuntime; | ||
|
||
import java.io.File; | ||
|
||
import static kotlinx.kover.offline.runtime.api.KoverRuntime.LOG_FILE_PROPERTY_NAME; | ||
import static kotlinx.kover.offline.runtime.api.KoverRuntime.REPORT_PROPERTY_NAME; | ||
|
||
/** | ||
* Class for initializing the Kover offline instrumentation runtime. | ||
* <p> | ||
* This class is initialized by the instrumented code by class name when any of the instrumented method is executed for the first time. | ||
* Therefore, all initialization code must be placed in the {@code <clinit>} method. | ||
*/ | ||
class KoverInit { | ||
|
||
static { | ||
String reportNameSavedOnExitProp = System.getProperty(REPORT_PROPERTY_NAME); | ||
String logFileProp = System.getProperty(LOG_FILE_PROPERTY_NAME); | ||
|
||
if (logFileProp != null) { | ||
CoverageRuntime.setLogPath(new File(LOG_FILE_PROPERTY_NAME)); | ||
} else { | ||
CoverageRuntime.setLogPath(new File(KoverRuntime.DEFAULT_LOG_FILE_NAME)); | ||
} | ||
|
||
if (reportNameSavedOnExitProp != null) { | ||
saveOnExit(reportNameSavedOnExitProp); | ||
} | ||
} | ||
|
||
private static void saveOnExit(final String fileName) { | ||
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { | ||
public void run() { | ||
try { | ||
KoverRuntime.saveReport(new File(fileName)); | ||
} catch (Throwable e) { | ||
System.err.println("Kover error: failed to save report file '" + fileName +"': " + e.getMessage()); | ||
} | ||
} | ||
})); | ||
} | ||
|
||
private KoverInit() { | ||
// no instances | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters