diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml
index 1167b72a40d..cc2b45d8963 100644
--- a/.github/workflows/build_and_test.yml
+++ b/.github/workflows/build_and_test.yml
@@ -43,7 +43,7 @@ jobs:
- name: Build
run: |
- ./gradlew --no-daemon --stacktrace build -x test
+ ./gradlew --no-daemon --stacktrace build -x test -x checkstyleMain -x checkstyleTest -x checkstyleJmh -x checkstyleIntegrationTest -x spotlessApply -x spotlessJavaCheck
- name: Archive build artifacts
uses: actions/upload-artifact@v4
diff --git a/.gitignore b/.gitignore
index 80b59516973..39e1c2131b8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -53,10 +53,10 @@ blocksminer
jacocoHtml/
# CheckStyle Reports
-config/checkstyle/reports/
+rskj-core/config/checkstyle/reports/
# PMD
-config/pmd/reports/
+rskj-core/config/pmd/reports/
blocksminer1.txt
diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml
new file mode 100644
index 00000000000..73498f813c9
--- /dev/null
+++ b/config/checkstyle/checkstyle.xml
@@ -0,0 +1,365 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml
new file mode 100644
index 00000000000..f18d7beffe2
--- /dev/null
+++ b/config/checkstyle/suppressions.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml
index 08400597a2e..3cbe7a8a75f 100644
--- a/gradle/verification-metadata.xml
+++ b/gradle/verification-metadata.xml
@@ -9,6 +9,14 @@
+
+
+
+
+
+
+
+
@@ -54,6 +62,70 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -248,6 +320,121 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -256,11 +443,92 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -269,6 +537,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -285,6 +569,14 @@
+
+
+
+
+
+
+
+
@@ -491,6 +783,14 @@
+
+
+
+
+
+
+
+
@@ -507,6 +807,14 @@
+
+
+
+
+
+
+
+
@@ -515,6 +823,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -703,6 +1027,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -713,6 +1058,16 @@
+
+
+
+
+
+
+
+
+
+
@@ -744,6 +1099,16 @@
+
+
+
+
+
+
+
+
+
+
@@ -754,6 +1119,11 @@
+
+
+
+
+
@@ -775,6 +1145,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -812,6 +1216,56 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -840,6 +1294,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -935,6 +1402,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1295,6 +1778,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1311,6 +1810,14 @@
+
+
+
+
+
+
+
+
@@ -1319,6 +1826,11 @@
+
+
+
+
+
@@ -1355,6 +1867,11 @@
+
+
+
+
+
@@ -1413,5 +1930,16 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/rskj-core/build.gradle b/rskj-core/build.gradle
index 8deb7a17fdc..78644f6fc18 100644
--- a/rskj-core/build.gradle
+++ b/rskj-core/build.gradle
@@ -1,10 +1,156 @@
plugins {
id 'application'
+ id 'checkstyle'
+ id "com.diffplug.spotless" version "6.13.0"
}
apply plugin: 'maven-publish'
apply plugin: 'jacoco'
+import java.nio.file.Paths
+
+// Define static timestamp
+def staticTimestamp = '2024-10-17T10:24:00'
+ext.timestamp = staticTimestamp
+
+def filteredFiles = getFilteredFiles()
+
+checkstyle {
+ toolVersion = '8.45'
+ configFile = file("$rootDir/config/checkstyle/checkstyle.xml")
+}
+
+spotless {
+ java {
+ googleJavaFormat()
+ indentWithTabs(2)
+ indentWithSpaces(4)
+ target filteredFiles
+ }
+}
+
+def getFilteredFiles() {
+ def timestamp = ext.timestamp
+
+ def commandLog = [
+ 'git', 'log', '--since=' + timestamp, '--name-only', '--pretty=format:', '--abbrev-commit'
+ ]
+ def commandDiff = [
+ 'git', 'diff', '--name-only'
+ ]
+ def commandStaged = [
+ 'git', 'diff', '--cached', '--name-only'
+ ]
+
+ def outputLog = new ByteArrayOutputStream()
+ def outputDiff = new ByteArrayOutputStream()
+ def outputStaged = new ByteArrayOutputStream()
+
+ exec {
+ commandLine commandLog
+ standardOutput = outputLog
+ errorOutput = outputLog
+ ignoreExitValue = true
+ }
+
+ exec {
+ commandLine commandDiff
+ standardOutput = outputDiff
+ errorOutput = outputDiff
+ ignoreExitValue = true
+ }
+
+ exec {
+ commandLine commandStaged
+ standardOutput = outputStaged
+ errorOutput = outputStaged
+ ignoreExitValue = true
+ }
+
+ def committedFiles = outputLog.toString().trim().split('\n').toList().unique()
+ def uncommittedFiles = outputDiff.toString().trim().split('\n').toList().unique()
+ def stagedFiles = outputStaged.toString().trim().split('\n').toList().unique()
+ def allFiles = committedFiles + uncommittedFiles + stagedFiles
+
+ allFiles = allFiles.unique().findAll { file -> file }
+
+ def projectRoot = project.projectDir.toPath().toAbsolutePath()
+
+ allFiles = allFiles.findAll { file ->
+ file.endsWith('.java')
+ }.collect { file ->
+ def relativePath = Paths.get(file).subpath(1, Paths.get(file).getNameCount()) // Adjust the subpath as necessary
+ def absolutePath = projectRoot.resolve(relativePath).toFile()
+
+ return absolutePath.exists() ? absolutePath : null
+ }.findAll { it != null }
+
+ return allFiles
+}
+
+
+def configureCheckstyleTask(Checkstyle task, String sourceDir) {
+ def filteredFilesCheckstyle = getFilteredFilesForCheckstyle(sourceDir)
+
+ if (!filteredFilesCheckstyle.isEmpty()) {
+ task.source = project.files(filteredFilesCheckstyle)
+ } else {
+ println "No files to assign to Checkstyle for ${sourceDir}. Skipping task."
+ task.enabled = false
+ }
+
+ task.classpath = project.files(
+ sourceSets.main.output.classesDirs,
+ sourceSets.main.output.resourcesDir
+ )
+ task.reports {
+ xml.required.set(true)
+ html.required.set(true)
+ }
+ task.onlyIf {
+ !filteredFilesCheckstyle.isEmpty()
+ }
+}
+
+def getFilteredFilesForCheckstyle(String sourceDir) {
+ def files = getFilteredFiles()
+ return files.findAll { file ->
+ def filePath = file.toPath().normalize()
+ def isJavaFile = filePath.toString().endsWith('.java')
+ def containsSourceSegment = filePath.toString().contains(sourceDir)
+
+ isJavaFile && containsSourceSegment
+ }
+}
+
+
+// Configure each Checkstyle task
+tasks.withType(Checkstyle).configureEach { Checkstyle task ->
+ def sourceDirMapping = [
+ 'checkstyleMain': 'src/main/java',
+ 'checkstyleTest': 'src/test/java',
+ 'checkstyleIntegrationTest': 'src/integrationTest/java',
+ 'checkstyleJmh': 'src/jmh/java'
+ ]
+
+ sourceDirMapping.each { taskName, sourceDir ->
+ if (task.name == taskName) {
+ configureCheckstyleTask(task, sourceDir)
+ }
+ }
+
+ if (task.name in ['checkstyleJmh', 'checkstyleIntegrationTest']) {
+ task.doFirst {
+ def relevantSourceDir = task.name == 'checkstyleJmh' ? 'src/jmh/java' : 'src/integrationTest/java'
+ def checkstyleFiles = getFilteredFilesForCheckstyle(relevantSourceDir)
+
+ if (!checkstyleFiles.isEmpty()) {
+ task.source = project.files(checkstyleFiles)
+ }
+ }
+ }
+}
+
configurations {
jmh
}
@@ -81,6 +227,7 @@ tasks.withType(Javadoc) {
repositories {
mavenCentral()
+ gradlePluginPortal()
maven {
url "https://deps.rsklabs.io"
}
@@ -252,8 +399,6 @@ javadoc {
options.encoding = "UTF-8"
}
-def generatedResources = "$buildDir/generated-resources"
-
publishing {
publications {
rskj(MavenPublication) {
@@ -275,8 +420,9 @@ task generateResources {
def buildInfoFile = 'build-info.properties'
doLast {
- mkdir generatedResources
- def generated = new File(generatedResources as String, buildInfoFile)
+ def generatedDir = new File(buildDir, 'generatedResources')
+ mkdir(generatedDir)
+ def generated = new File(generatedDir, buildInfoFile)
def commitHash = gitCommitHash()
def currentBranch = gitCurrentBranch()
generated.text = """
@@ -297,7 +443,7 @@ task javadocJar(type: Jar) {
}
jar {
- dependsOn 'generateResources'
+ dependsOn generateResources
def commitHash = gitCommitHash()
def currentBranch = gitCurrentBranch()
manifest {
@@ -306,7 +452,7 @@ jar {
}
from sourceSets.main.output.classesDirs
from sourceSets.main.output.resourcesDir
- from generatedResources
+ from new File(buildDir, 'generatedResources') // Reference the generated resources directory
}
task generatePom(dependsOn: jar) {
@@ -417,3 +563,10 @@ static def amendPathIfNeeded(details) {
details.path = newPath
}
}
+
+tasks.named('check').configure {
+ dependsOn 'checkstyleMain'
+ dependsOn 'checkstyleTest'
+ dependsOn 'checkstyleJmh'
+ dependsOn 'checkstyleIntegrationTest'
+}
\ No newline at end of file