-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update README and move sarif utils into common module (#477)
### What's done: * Update README and move sarif utils into common module
- Loading branch information
1 parent
69b23ee
commit e5ced44
Showing
9 changed files
with
97 additions
and
72 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
61 changes: 61 additions & 0 deletions
61
save-common/src/commonMain/kotlin/com/saveourtool/save/core/utils/SarifFileUtils.kt
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,61 @@ | ||
/** | ||
* Utility methods to work with SARIF files. | ||
*/ | ||
|
||
package com.saveourtool.save.core.utils | ||
|
||
import com.saveourtool.save.core.files.findAncestorDirContainingFile | ||
import com.saveourtool.save.core.files.fs | ||
import com.saveourtool.save.core.files.parents | ||
import com.saveourtool.save.core.plugin.PluginException | ||
|
||
import okio.FileSystem | ||
import okio.Path | ||
|
||
/** | ||
* @return string with trimmed `file://` or `file:///` | ||
*/ | ||
fun String.dropFileProtocol() = substringAfter("file://") | ||
.let { | ||
// It is a valid format for Windows paths to look like `file:///C:/stuff` | ||
if (it[0] == '/' && it[2] == ':') it.drop(1) else it | ||
} | ||
|
||
/** | ||
* Make all paths in [this] collection relative to [root] | ||
* | ||
* @param root a common root for files in [this] | ||
* @return a list of relative paths | ||
*/ | ||
fun List<Path>.adjustToCommonRoot(root: Path) = map { | ||
it.relativeTo(root).normalized() | ||
} | ||
|
||
/** | ||
* Find the last parent directory containing save.toml. | ||
* | ||
* @param path a path to start the search | ||
* @return one of parent directories | ||
*/ | ||
fun FileSystem.topmostTestDirectory(path: Path): Path = path.parents().last { parent -> | ||
list(parent).any { it.name == "save.toml" } | ||
} | ||
|
||
/** | ||
* Calculate the path to sarif file; we expect, that it single for the all tests and located in one of parent directories | ||
* for evaluated test files | ||
* | ||
* @param sarifFileName sarif file name | ||
* @param anchorTestFilePath anchor file for calculating corresponding sarif file; | ||
* since .sarif file expected to be the one for all test files, it could be any of test file | ||
* @return path to sarif | ||
* @throws PluginException in case of absence of sarif file | ||
*/ | ||
fun calculatePathToSarifFile(sarifFileName: String, anchorTestFilePath: Path): Path = fs.findAncestorDirContainingFile( | ||
anchorTestFilePath, sarifFileName | ||
)?.let { | ||
it / sarifFileName | ||
} ?: throw PluginException( | ||
"Could not find SARIF file with expected warnings/fixes for file $anchorTestFilePath. " + | ||
"Please check if correct `FarningsFormat`/`FixFormat` is set (should be SARIF) and if the file is present and called `$sarifFileName`." | ||
) |
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
52 changes: 0 additions & 52 deletions
52
...arn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/sarif/SarifFileUtils.kt
This file was deleted.
Oops, something went wrong.
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