Skip to content
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
19 changes: 16 additions & 3 deletions build-logic/src/main/kotlin/polaris-java.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,31 @@ plugins {
`java-library`
`java-test-fixtures`
`jvm-test-suite`
checkstyle
id("polaris-spotless")
id("jacoco-report-aggregation")
id("net.ltgt.errorprone")
}

apply<PublishingHelperPlugin>()

if (project.extra.has("duplicated-project-sources")) {
// skip the style check for duplicated projects
tasks.withType<Checkstyle>().configureEach { enabled = false }
checkstyle {
val checkstyleVersion =
versionCatalogs
.named("libs")
.findVersion("checkstyle")
.orElseThrow { GradleException("checkstyle version not found in libs.versions.toml") }
.requiredVersion
toolVersion = checkstyleVersion
configFile = rootProject.file("codestyle/checkstyle.xml")
isIgnoreFailures = false
maxErrors = 0
maxWarnings = 0
}

// Ensure Checkstyle runs after jandex to avoid task dependency issues
tasks.withType<Checkstyle>().configureEach { tasks.findByName("jandex")?.let { mustRunAfter(it) } }

tasks.withType(JavaCompile::class.java).configureEach {
options.compilerArgs.addAll(listOf("-Xlint:unchecked", "-Xlint:deprecation"))
options.errorprone.disableAllWarnings = true
Expand Down
2 changes: 0 additions & 2 deletions build-logic/src/main/kotlin/polaris-spotless.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/

import com.diffplug.spotless.FormatterFunc
import gradle.kotlin.dsl.accessors._fa00c0b20184971a79f32516372275b9.java
import gradle.kotlin.dsl.accessors._fa00c0b20184971a79f32516372275b9.spotless
import java.io.Serializable
import org.gradle.api.GradleException

Expand Down
51 changes: 51 additions & 0 deletions codestyle/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
<property name="charset" value="UTF-8"/>
<property name="severity" value="warning"/>
<property name="fileExtensions" value="java, properties, xml"/>

<!-- Excludes all 'module-info.java' files -->
<!-- See https://checkstyle.org/config_filefilters.html -->
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>

<!-- https://checkstyle.org/config_filters.html#SuppressionFilter -->
<module name="SuppressionFilter">
<property name="file" value="${org.checkstyle.google.suppressionfilter.config}"
default="checkstyle-suppressions.xml" />
<property name="optional" value="true"/>
</module>

<module name="TreeWalker">
<!-- Checks for imports -->
<!-- See http://checkstyle.org/config_imports.html -->
<module name="IllegalImport">
<property name="illegalPkgs" value=".*\.shaded\..*, .*\.relocated\..*"/>
<property name="regexp" value="true"/>
</module>

</module>
</module>
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#

[versions]
checkstyle = "10.25.0"
hadoop = "3.4.1"
iceberg = "1.9.0" # Ensure to update the iceberg version in regtests to keep regtests up-to-date
quarkus = "3.21.4"
Expand Down
38 changes: 0 additions & 38 deletions plugins/spark/v3.5/spark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -112,44 +112,6 @@ dependencies {
}
}

// TODO: replace the check using gradlew checkstyle plugin
tasks.register("checkNoDisallowedImports") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for help getting rid of that

doLast {
// List of disallowed imports. Right now, we disallow usage of shaded or
// relocated libraries in the iceberg spark runtime jar.
val disallowedImports =
listOf("import org.apache.iceberg.shaded.", "org.apache.iceberg.relocated.")

// Directory to scan for Java files
val sourceDirs = listOf(file("src/main/java"), file("src/test/java"))

val violations = mutableListOf<String>()
// Scan Java files in each directory
sourceDirs.forEach { sourceDir ->
fileTree(sourceDir)
.matching {
include("**/*.java") // Only include Java files
}
.forEach { file ->
val content = file.readText()
disallowedImports.forEach { importStatement ->
if (content.contains(importStatement)) {
violations.add(
"Disallowed import found in ${file.relativeTo(projectDir)}: $importStatement"
)
}
}
}
}

if (violations.isNotEmpty()) {
throw GradleException("Disallowed imports found! $violations")
}
}
}

tasks.named("check") { dependsOn("checkNoDisallowedImports") }

tasks.register<ShadowJar>("createPolarisSparkJar") {
archiveClassifier = "bundle"
isZip64 = true
Expand Down
8 changes: 5 additions & 3 deletions quarkus/test-commons/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ plugins {
}

configurations.all {
exclude(group = "org.antlr", module = "antlr4-runtime")
exclude(group = "org.scala-lang", module = "scala-library")
exclude(group = "org.scala-lang", module = "scala-reflect")
if (name != "checkstyle") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checkstyle depends on antlr4-runtime.

exclude(group = "org.antlr", module = "antlr4-runtime")
exclude(group = "org.scala-lang", module = "scala-library")
exclude(group = "org.scala-lang", module = "scala-reflect")
}
}

dependencies {
Expand Down
Loading