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

Fixed maven plugin #1816

Merged
merged 10 commits into from
Nov 23, 2023
1 change: 0 additions & 1 deletion diktat-maven-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ plugins {
}

dependencies {
implementation(libs.maven.plugin.api)
compileOnly(libs.maven.plugin.annotations)
compileOnly(libs.maven.core)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.saveourtool.diktat.api.DiktatReporterCreationArguments
import com.saveourtool.diktat.api.DiktatReporterType
import com.saveourtool.diktat.diktatRunnerFactory
import com.saveourtool.diktat.util.isKotlinCodeOrScript

import org.apache.maven.plugin.AbstractMojo
import org.apache.maven.plugin.Mojo
Expand All @@ -18,7 +19,6 @@
import java.io.OutputStream
import java.nio.file.Path
import java.nio.file.Paths
import kotlin.io.path.Path
import kotlin.io.path.inputStream
import kotlin.io.path.isRegularFile

Expand Down Expand Up @@ -96,7 +96,7 @@
*/
override fun execute() {
val configFile = resolveConfig()
if (configFile.isRegularFile()) {
if (!configFile.isRegularFile()) {
nulls marked this conversation as resolved.
Show resolved Hide resolved
throw MojoExecutionException("Configuration file $diktatConfigFile doesn't exist")
}
log.info("Running diKTat plugin with configuration file $configFile and inputs $inputs" +
Expand All @@ -113,7 +113,7 @@
val args = DiktatRunnerArguments(
configInputStream = configFile.inputStream(),
sourceRootDir = sourceRootDir,
files = inputs.map(::Path),
files = files(),

Check warning on line 116 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt

View check run for this annotation

Codecov / codecov/patch

diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt#L116

Added line #L116 was not covered by tests
baselineFile = baseline?.toPath(),
reporterArgsList = listOf(reporterArgs),
)
Expand Down Expand Up @@ -160,7 +160,30 @@
return generateSequence(mavenProject) { it.parent }
.map { it.basedir.toPath().resolve(diktatConfigFile) }
.run {
firstOrNull { it.isRegularFile() } ?: first()
firstOrNull { it.isRegularFile() } ?: file
kgevorkyan marked this conversation as resolved.
Show resolved Hide resolved
}
}

private fun files(): List<Path> {
val (excludedDirs, excludedFiles) = excludes.map(::File).partition { it.isDirectory }
return inputs
.asSequence()
.map(::File)
.flatMap {
it.files(excludedDirs, excludedFiles)

Check warning on line 173 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt

View check run for this annotation

Codecov / codecov/patch

diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt#L168-L173

Added lines #L168 - L173 were not covered by tests
}
.map { it.toPath() }
.toList()

Check warning on line 176 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt

View check run for this annotation

Codecov / codecov/patch

diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt#L175-L176

Added lines #L175 - L176 were not covered by tests
}

@Suppress("TYPE_ALIAS")
private fun File.files(
excludedDirs: List<File>,
excludedFiles: List<File>,
): Sequence<File> = walk()
.filter { file ->

Check warning on line 184 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt

View check run for this annotation

Codecov / codecov/patch

diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt#L183-L184

Added lines #L183 - L184 were not covered by tests
file.isDirectory || file.toPath().isKotlinCodeOrScript()
kgevorkyan marked this conversation as resolved.
Show resolved Hide resolved
}
.filter { it.isFile }

Check warning on line 187 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt

View check run for this annotation

Codecov / codecov/patch

diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt#L187

Added line #L187 was not covered by tests
.filterNot { file -> file in excludedFiles || excludedDirs.any { file.startsWith(it) } }
}
2 changes: 0 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ junit-platform-suite = { module = "org.junit.platform:junit-platform-suite-engin

# maven
maven-core = { module = "org.apache.maven:maven-core", version.ref = "maven-api" }
maven-embedder = { module = "org.apache.maven:maven-embedder", version.ref = "maven-api" }
maven-compat = { module = "org.apache.maven:maven-compat", version.ref = "maven-api" }
maven-plugin-api = { module = "org.apache.maven:maven-plugin-api", version.ref = "maven-api" }
maven-plugin-annotations = { module = "org.apache.maven.plugin-tools:maven-plugin-annotations", version.ref = "maven-plugin-tools" }
maven-plugin-testing-harness = { module = "org.apache.maven.plugin-testing:maven-plugin-testing-harness", version.ref = "maven-plugin-testing-harness" }
plexus-cipher = { module = "org.codehaus.plexus:plexus-cipher", version.ref = "plexus" }
Expand Down
Loading