|
| 1 | +/* |
| 2 | + * Copyright 2000-2024 JetBrains s.r.o. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package kotlinx.kover.cli.commands |
| 18 | + |
| 19 | +import kotlinx.kover.features.jvm.KoverLegacyFeatures |
| 20 | +import org.kohsuke.args4j.Argument |
| 21 | +import org.kohsuke.args4j.Option |
| 22 | +import java.io.File |
| 23 | +import java.io.PrintWriter |
| 24 | + |
| 25 | + |
| 26 | +internal class MergeCommand : Command { |
| 27 | + @Argument(usage = "list of binary reports files", metaVar = "<binary-report-path>") |
| 28 | + private var binaryReports: MutableList<File> = ArrayList() |
| 29 | + |
| 30 | + @Option( |
| 31 | + name = "--target", |
| 32 | + usage = "merged binary report file", |
| 33 | + metaVar = "<merged-report-path>", |
| 34 | + required = true |
| 35 | + ) |
| 36 | + private var targetReport: File? = null |
| 37 | + |
| 38 | + override val name: String = "merge" |
| 39 | + |
| 40 | + override val description: String = "Merge binary report files into one" |
| 41 | + |
| 42 | + |
| 43 | + override fun call(output: PrintWriter, errorWriter: PrintWriter): Int { |
| 44 | + try { |
| 45 | + KoverLegacyFeatures.mergeIc(targetReport!!, binaryReports) |
| 46 | + } catch (e: Exception) { |
| 47 | + errorWriter.println("Binary reports merging failed: " + e.message) |
| 48 | + return -1 |
| 49 | + } |
| 50 | + return 0 |
| 51 | + } |
| 52 | +} |
0 commit comments