Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple input directories #203

Merged
merged 2 commits into from
Oct 2, 2023
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
2 changes: 2 additions & 0 deletions baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
<ManuallySuppressedIssues></ManuallySuppressedIssues>
<CurrentIssues>
<ID>InvalidPackageDeclaration:ValidFile.kt$package `code-samples`.`valid`</ID>
<ID>InvalidPackageDeclaration:ValidFile2.kt$package `code-samples`.valid2</ID>
<ID>InvalidPackageDeclaration:WildcardImportViolated.kt$package `code-samples`.`invalid-package-naming`</ID>
<ID>PackageNaming:ValidFile.kt$package `code-samples`.`valid`</ID>
<ID>PackageNaming:ValidFile2.kt$package `code-samples`.valid2</ID>
<ID>PackageNaming:WildcardImportViolated.kt$package `code-samples`.`invalid-package-naming`</ID>
</CurrentIssues>
</SmellBaseline>
16 changes: 11 additions & 5 deletions src/main/java/com/github/ozsie/CheckMojo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ class CheckMojo : DetektMojo() {
log.debug("Applying $it")
}
val cliArgs = parseArguments(getCliSting().log().toTypedArray())
val foundInputDir = Files.isDirectory(Paths.get(input))
if (!skip && foundInputDir)
val invalidInputDirs = input.split(",").mapNotNull {
if (!Files.isDirectory(Paths.get(it))) it else null
}
if (!skip && invalidInputDirs.isEmpty())
failBuildIfNeeded { Runner(cliArgs, System.out, System.err).execute() }
else
inputSkipLog(skip)
inputSkipLog(skip, invalidInputDirs)
}

private fun failBuildIfNeeded(block: () -> Unit) {
Expand All @@ -38,7 +40,11 @@ class CheckMojo : DetektMojo() {
}
}

private fun inputSkipLog(skip: Boolean) {
if (skip) log.info("Skipping execution") else log.info("Input directory '$input' not found, skipping module")
private fun inputSkipLog(skip: Boolean, invalidInputDirs: List<String>) {
if (skip) {
log.info("Skipping execution")
} else {
log.info("Failed to resolve input directories '${invalidInputDirs.joinToString()}', skipping module")
}
}
}
34 changes: 30 additions & 4 deletions src/test/java/com/github/ozsie/CheckMojoSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import kotlin.test.assertFailsWith
import kotlin.test.expect

class CheckMojoSpec : Spek({
val invalidPackageNamingDirectoryPath by lazy {
CheckMojoSpec::class.java.classLoader.getResource("code-samples/invalid-package-naming")!!
.file
}
val codeSamplesDirectory = CheckMojoSpec::class.java.classLoader.getResource("code-samples")!!.file
val invalidPackageNamingDirectoryPath = "$codeSamplesDirectory/invalid-package-naming"

given("a CheckMojo and 'skip' is true") {
val checkMojo = CheckMojo()
Expand Down Expand Up @@ -64,4 +62,32 @@ class CheckMojoSpec : Spek({
}
}
}

given("multiple valid comma separated input directories are supplied") {
val checkMojo = CheckMojo().apply {
input = "$codeSamplesDirectory/valid,$codeSamplesDirectory/valid2"
failBuildOnMaxIssuesReached = true
}
on("checkMojo.execute()") {
test("detekt analyses the specified directories") {
assertFailsWith(MaxIssuesReached::class, "Build failed with 2 weighted issues.") {
checkMojo.execute()
}
}
}
}

given("a mix of valid and invalid comma separated input directories are supplied") {
val checkMojo = CheckMojo().apply {
input = "$codeSamplesDirectory/valid,invalidDirectory"
failBuildOnMaxIssuesReached = false
}
on("checkMojo.execute()") {
test("detekt analysis is aborted") {
expect(Unit) {
checkMojo.execute()
}
}
}
}
})
1 change: 1 addition & 0 deletions src/test/resources/code-samples/valid2/ValidFile2.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package `code-samples`.valid2
Loading