From bf3dbbbdd6379904fe7e18a20ce78a62fe5bf927 Mon Sep 17 00:00:00 2001 From: Reynold Morel Date: Mon, 19 Aug 2024 09:34:39 -0400 Subject: [PATCH 01/14] Adding Checkstyle linter --- .gitignore | 4 +- config/checkstyle/checkstyle.xml | 365 ++++++++++++++++++ config/checkstyle/suppressions.xml | 5 + gradle/verification-metadata.xml | 242 ++++++++++++ rskj-core/build.gradle | 79 +++- .../main/java/co/rsk/core/ExampleObject.java | 50 +++ 6 files changed, 737 insertions(+), 8 deletions(-) create mode 100644 config/checkstyle/checkstyle.xml create mode 100644 config/checkstyle/suppressions.xml create mode 100644 rskj-core/src/main/java/co/rsk/core/ExampleObject.java 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 510e633ddef..4f6ea37e38f 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -1113,6 +1113,248 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/rskj-core/build.gradle b/rskj-core/build.gradle index 0078115a127..5d42bbc995f 100644 --- a/rskj-core/build.gradle +++ b/rskj-core/build.gradle @@ -1,10 +1,73 @@ plugins { id 'application' + id 'checkstyle' } apply plugin: 'maven-publish' apply plugin: 'jacoco' +checkstyle { + toolVersion = '8.45' + configFile = file("$rootDir/config/checkstyle/checkstyle.xml") +} + + +// Start time for Checkstyle checks +def checkstyleStartTime = '2024-08-19 09:52:59 EST' + +def getModifiedFiles(File baseDir, String timestampString) { + def dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss z") + Date timestamp = dateFormat.parse(timestampString) + + def modifiedFiles = [] + fileTree(baseDir).matching { + include '**/*.java' + }.each { File file -> + if (file.lastModified() > timestamp.time) { + modifiedFiles.add(file) + } + } + + return modifiedFiles +} + +def configureCheckstyleTask(Checkstyle task, File sourceDir, String timestampString) { + def newFiles = getModifiedFiles(sourceDir, timestampString) + task.source = files(newFiles) + task.classpath = files( + sourceSets.main.output.classesDirs, + sourceSets.main.output.resourcesDir + ) + task.reports { + xml.required.set(true) + html.required.set(true) + } +} + +tasks.withType(Checkstyle).configureEach { Checkstyle task -> + switch (task.name) { + case 'checkstyleMain': + configureCheckstyleTask(task, file('src/main/java'), checkstyleStartTime) + break + case 'checkstyleTest': + configureCheckstyleTask(task, file('src/test/java'), checkstyleStartTime) + break + case 'checkstyleIntegrationTest': + configureCheckstyleTask(task, file('src/integrationTest/java'), checkstyleStartTime) + break + case 'checkstyleJmh': + configureCheckstyleTask(task, file('src/jmh/java'), checkstyleStartTime) + break + } +} + +checkstyleMain.mustRunAfter clean +checkstyleTest.mustRunAfter clean + +checkstyleMain.dependsOn 'classes' +checkstyleTest.dependsOn 'testClasses' + + configurations { jmh } @@ -252,8 +315,6 @@ javadoc { options.encoding = "UTF-8" } -def generatedResources = "$buildDir/generated-resources" - publishing { publications { rskj(MavenPublication) { @@ -275,8 +336,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 +359,7 @@ task javadocJar(type: Jar) { } jar { - dependsOn 'generateResources' + dependsOn generateResources def commitHash = gitCommitHash() def currentBranch = gitCurrentBranch() manifest { @@ -306,7 +368,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 +479,8 @@ static def amendPathIfNeeded(details) { details.path = newPath } } + +tasks.named('check').configure { + dependsOn 'checkstyleMain' + dependsOn 'checkstyleTest' +} diff --git a/rskj-core/src/main/java/co/rsk/core/ExampleObject.java b/rskj-core/src/main/java/co/rsk/core/ExampleObject.java new file mode 100644 index 00000000000..ccb4fd8be47 --- /dev/null +++ b/rskj-core/src/main/java/co/rsk/core/ExampleObject.java @@ -0,0 +1,50 @@ +package co.rsk.core; + +/** + * Testing + * This comment demonstrates the use of Javadoc comment. + */ +public class ExampleObject { + private int number; + private String text; + + public ExampleObject(int number, String text) { + this.number = number; + this.text = text; + } + + public int getNumber() { + return number; + } + + public void setNumber(int number) { + this.number = number; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + @Override + public String toString() { + return "DummyClass{" + + "number=" + number + + ", text='" + text + '\'' + + '}'; + } + + /** + * Example method def comment. + */ + public int testDummyProcess(int a, int b) { + int x = a + b; + int help = x * 2; + int test = help + 10; + + return test; + } +} From 36f8b142b009a8bf1763cf94a8fe336241e777ee Mon Sep 17 00:00:00 2001 From: Reynold Morel Date: Tue, 20 Aug 2024 22:18:52 -0400 Subject: [PATCH 02/14] Adding formatter and fixing checkstyle --- gradle/verification-metadata.xml | 189 ++++++++++++++++++ rskj-core/build.gradle | 73 +++++-- .../main/java/co/rsk/core/ExampleObject.java | 50 ----- 3 files changed, 242 insertions(+), 70 deletions(-) delete mode 100644 rskj-core/src/main/java/co/rsk/core/ExampleObject.java diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 4f6ea37e38f..c79250bafe8 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -1244,6 +1244,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1342,6 +1471,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/rskj-core/build.gradle b/rskj-core/build.gradle index 5d42bbc995f..025d324e65f 100644 --- a/rskj-core/build.gradle +++ b/rskj-core/build.gradle @@ -1,39 +1,52 @@ plugins { id 'application' id 'checkstyle' + id 'com.github.sherter.google-java-format' version '0.9' } apply plugin: 'maven-publish' apply plugin: 'jacoco' +import java.time.LocalDateTime +import java.time.ZoneOffset +import java.time.format.DateTimeFormatter +import com.github.sherter.googlejavaformatgradleplugin.GoogleJavaFormat +import com.github.sherter.googlejavaformatgradleplugin.VerifyGoogleJavaFormat + checkstyle { toolVersion = '8.45' configFile = file("$rootDir/config/checkstyle/checkstyle.xml") } +googleJavaFormat { + toolVersion = '1.7' +} + +// Use a static timestamp for filtering +def staticTimestamp = '2024-08-21T02:17:00' -// Start time for Checkstyle checks -def checkstyleStartTime = '2024-08-19 09:52:59 EST' +ext.timestamp = staticTimestamp +ext.timestampMillis = LocalDateTime.parse(staticTimestamp, DateTimeFormatter.ISO_LOCAL_DATE_TIME) + .toInstant(ZoneOffset.UTC) + .toEpochMilli() -def getModifiedFiles(File baseDir, String timestampString) { - def dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss z") - Date timestamp = dateFormat.parse(timestampString) - def modifiedFiles = [] - fileTree(baseDir).matching { +// Method to filter Java files based on the timestamp +def getFilteredFiles() { + return fileTree('src/main/java').matching { include '**/*.java' - }.each { File file -> - if (file.lastModified() > timestamp.time) { - modifiedFiles.add(file) - } + }.files.findAll { file -> + file.lastModified() > ext.timestampMillis } - - return modifiedFiles } -def configureCheckstyleTask(Checkstyle task, File sourceDir, String timestampString) { - def newFiles = getModifiedFiles(sourceDir, timestampString) - task.source = files(newFiles) +def configureCheckstyleTask(Checkstyle task, File sourceDir) { + def filteredFiles = fileTree(sourceDir).matching { + include '**/*.java' + }.files.findAll { file -> + file.lastModified() > ext.timestampMillis + } + task.source = files(filteredFiles) task.classpath = files( sourceSets.main.output.classesDirs, sourceSets.main.output.resourcesDir @@ -47,16 +60,16 @@ def configureCheckstyleTask(Checkstyle task, File sourceDir, String timestampStr tasks.withType(Checkstyle).configureEach { Checkstyle task -> switch (task.name) { case 'checkstyleMain': - configureCheckstyleTask(task, file('src/main/java'), checkstyleStartTime) + configureCheckstyleTask(task, file('src/main/java')) break case 'checkstyleTest': - configureCheckstyleTask(task, file('src/test/java'), checkstyleStartTime) + configureCheckstyleTask(task, file('src/test/java')) break case 'checkstyleIntegrationTest': - configureCheckstyleTask(task, file('src/integrationTest/java'), checkstyleStartTime) + configureCheckstyleTask(task, file('src/integrationTest/java')) break case 'checkstyleJmh': - configureCheckstyleTask(task, file('src/jmh/java'), checkstyleStartTime) + configureCheckstyleTask(task, file('src/jmh/java')) break } } @@ -67,6 +80,26 @@ checkstyleTest.mustRunAfter clean checkstyleMain.dependsOn 'classes' checkstyleTest.dependsOn 'testClasses' +task formatCode(type: GoogleJavaFormat) { + def filteredFiles = getFilteredFiles() + + source = files(filteredFiles) + include '**/*.java' + exclude '**/*Template.java' + + inputs.files filteredFiles + outputs.files filteredFiles +} + +task verifyFormatting(type: VerifyGoogleJavaFormat) { + def filteredFiles = getFilteredFiles() + + source = files(filteredFiles) + ignoreFailures = true + + inputs.files filteredFiles + outputs.files filteredFiles +} configurations { jmh diff --git a/rskj-core/src/main/java/co/rsk/core/ExampleObject.java b/rskj-core/src/main/java/co/rsk/core/ExampleObject.java deleted file mode 100644 index ccb4fd8be47..00000000000 --- a/rskj-core/src/main/java/co/rsk/core/ExampleObject.java +++ /dev/null @@ -1,50 +0,0 @@ -package co.rsk.core; - -/** - * Testing - * This comment demonstrates the use of Javadoc comment. - */ -public class ExampleObject { - private int number; - private String text; - - public ExampleObject(int number, String text) { - this.number = number; - this.text = text; - } - - public int getNumber() { - return number; - } - - public void setNumber(int number) { - this.number = number; - } - - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } - - @Override - public String toString() { - return "DummyClass{" - + "number=" + number - + ", text='" + text + '\'' - + '}'; - } - - /** - * Example method def comment. - */ - public int testDummyProcess(int a, int b) { - int x = a + b; - int help = x * 2; - int test = help + 10; - - return test; - } -} From 310ecaceaec66236086443bd239c1f2b520d71e2 Mon Sep 17 00:00:00 2001 From: Reynold Morel Date: Wed, 4 Sep 2024 11:36:57 -0400 Subject: [PATCH 03/14] Refactor file filtering to use Git commands for modified files --- rskj-core/build.gradle | 89 +++++++++++++++++++++++++++++------------- 1 file changed, 62 insertions(+), 27 deletions(-) diff --git a/rskj-core/build.gradle b/rskj-core/build.gradle index 025d324e65f..97f4a73e8c0 100644 --- a/rskj-core/build.gradle +++ b/rskj-core/build.gradle @@ -7,11 +7,9 @@ plugins { apply plugin: 'maven-publish' apply plugin: 'jacoco' -import java.time.LocalDateTime -import java.time.ZoneOffset -import java.time.format.DateTimeFormatter import com.github.sherter.googlejavaformatgradleplugin.GoogleJavaFormat import com.github.sherter.googlejavaformatgradleplugin.VerifyGoogleJavaFormat +import java.nio.file.Paths checkstyle { toolVersion = '8.45' @@ -22,32 +20,74 @@ googleJavaFormat { toolVersion = '1.7' } -// Use a static timestamp for filtering -def staticTimestamp = '2024-08-21T02:17:00' - +// Define static timestamp +def staticTimestamp = '2024-09-03T02:17:00' ext.timestamp = staticTimestamp -ext.timestampMillis = LocalDateTime.parse(staticTimestamp, DateTimeFormatter.ISO_LOCAL_DATE_TIME) - .toInstant(ZoneOffset.UTC) - .toEpochMilli() - -// Method to filter Java files based on the timestamp def getFilteredFiles() { - return fileTree('src/main/java').matching { - include '**/*.java' - }.files.findAll { file -> - file.lastModified() > ext.timestampMillis + 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 } + + allFiles = allFiles.findAll { file -> + file.endsWith('.java') + } + + return allFiles.collect { file -> Paths.get(file).toAbsolutePath().toFile() } } +// Method to configure Checkstyle tasks def configureCheckstyleTask(Checkstyle task, File sourceDir) { - def filteredFiles = fileTree(sourceDir).matching { - include '**/*.java' - }.files.findAll { file -> - file.lastModified() > ext.timestampMillis + def sourceDirPath = sourceDir.toPath().normalize() + def files = getFilteredFiles() + def filteredFiles = files.findAll { file -> + def filePath = file.toPath().normalize() + def isUnderSourceDir = filePath.startsWith(sourceDirPath) && !filePath.equals(sourceDirPath) + isUnderSourceDir } - task.source = files(filteredFiles) - task.classpath = files( + + task.source = project.files(filteredFiles) + task.classpath = project.files( sourceSets.main.output.classesDirs, sourceSets.main.output.resourcesDir ) @@ -57,6 +97,7 @@ def configureCheckstyleTask(Checkstyle task, File sourceDir) { } } +// Configure each Checkstyle task explicitly tasks.withType(Checkstyle).configureEach { Checkstyle task -> switch (task.name) { case 'checkstyleMain': @@ -74,12 +115,6 @@ tasks.withType(Checkstyle).configureEach { Checkstyle task -> } } -checkstyleMain.mustRunAfter clean -checkstyleTest.mustRunAfter clean - -checkstyleMain.dependsOn 'classes' -checkstyleTest.dependsOn 'testClasses' - task formatCode(type: GoogleJavaFormat) { def filteredFiles = getFilteredFiles() From 817f1170872fc17bf77d1198cf9c74e604a2a569 Mon Sep 17 00:00:00 2001 From: Reynold Morel Date: Wed, 4 Sep 2024 13:07:25 -0400 Subject: [PATCH 04/14] Replace unofficial google-java-format plugin with Spotless for official Google format --- gradle/verification-metadata.xml | 545 +++++++++++++++++++++++++++++++ rskj-core/build.gradle | 49 +-- 2 files changed, 563 insertions(+), 31 deletions(-) diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index c79250bafe8..3b01aa24ae4 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -9,6 +9,14 @@ + + + + + + + + @@ -46,6 +54,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -227,6 +303,11 @@ + + + + + @@ -240,6 +321,121 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -248,11 +444,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -261,6 +538,22 @@ + + + + + + + + + + + + + + + + @@ -277,6 +570,14 @@ + + + + + + + + @@ -483,6 +784,14 @@ + + + + + + + + @@ -499,6 +808,14 @@ + + + + + + + + @@ -507,6 +824,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -695,6 +1036,27 @@ + + + + + + + + + + + + + + + + + + + + + @@ -705,6 +1067,16 @@ + + + + + + + + + + @@ -736,6 +1108,16 @@ + + + + + + + + + + @@ -746,6 +1128,11 @@ + + + + + @@ -767,6 +1154,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -804,6 +1225,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -832,6 +1303,19 @@ + + + + + + + + + + + + + @@ -927,6 +1411,22 @@ + + + + + + + + + + + + + + + + @@ -1718,6 +2218,22 @@ + + + + + + + + + + + + + + + + @@ -1734,6 +2250,14 @@ + + + + + + + + @@ -1742,6 +2266,11 @@ + + + + + @@ -1778,6 +2307,11 @@ + + + + + @@ -1836,5 +2370,16 @@ + + + + + + + + + + + diff --git a/rskj-core/build.gradle b/rskj-core/build.gradle index 97f4a73e8c0..1d9494f130f 100644 --- a/rskj-core/build.gradle +++ b/rskj-core/build.gradle @@ -1,28 +1,35 @@ plugins { id 'application' id 'checkstyle' - id 'com.github.sherter.google-java-format' version '0.9' + id "com.diffplug.spotless" version "6.13.0" } apply plugin: 'maven-publish' apply plugin: 'jacoco' -import com.github.sherter.googlejavaformatgradleplugin.GoogleJavaFormat -import com.github.sherter.googlejavaformatgradleplugin.VerifyGoogleJavaFormat import java.nio.file.Paths +// Define static timestamp +def staticTimestamp = '2024-09-03T02:17:00' +ext.timestamp = staticTimestamp + +def filteredFiles = getFilteredFiles() + checkstyle { toolVersion = '8.45' configFile = file("$rootDir/config/checkstyle/checkstyle.xml") } -googleJavaFormat { - toolVersion = '1.7' +spotless { + java { + googleJavaFormat() + indentWithTabs(2) + indentWithSpaces(4) + target filteredFiles + + } } -// Define static timestamp -def staticTimestamp = '2024-09-03T02:17:00' -ext.timestamp = staticTimestamp def getFilteredFiles() { def timestamp = ext.timestamp @@ -80,13 +87,13 @@ def getFilteredFiles() { def configureCheckstyleTask(Checkstyle task, File sourceDir) { def sourceDirPath = sourceDir.toPath().normalize() def files = getFilteredFiles() - def filteredFiles = files.findAll { file -> + def filteredFilesCheckstyle = files.findAll { file -> def filePath = file.toPath().normalize() def isUnderSourceDir = filePath.startsWith(sourceDirPath) && !filePath.equals(sourceDirPath) isUnderSourceDir } - task.source = project.files(filteredFiles) + task.source = project.files(filteredFilesCheckstyle) task.classpath = project.files( sourceSets.main.output.classesDirs, sourceSets.main.output.resourcesDir @@ -115,27 +122,6 @@ tasks.withType(Checkstyle).configureEach { Checkstyle task -> } } -task formatCode(type: GoogleJavaFormat) { - def filteredFiles = getFilteredFiles() - - source = files(filteredFiles) - include '**/*.java' - exclude '**/*Template.java' - - inputs.files filteredFiles - outputs.files filteredFiles -} - -task verifyFormatting(type: VerifyGoogleJavaFormat) { - def filteredFiles = getFilteredFiles() - - source = files(filteredFiles) - ignoreFailures = true - - inputs.files filteredFiles - outputs.files filteredFiles -} - configurations { jmh } @@ -212,6 +198,7 @@ tasks.withType(Javadoc) { repositories { mavenCentral() + gradlePluginPortal() maven { url "https://deps.rsklabs.io" } From 09515737842f00a2de8d7bba22f9f57bdae9b374 Mon Sep 17 00:00:00 2001 From: Reynold Morel Date: Thu, 5 Sep 2024 13:46:23 -0400 Subject: [PATCH 05/14] Skipping checkstyle and spotless tasks in the build --- .github/workflows/build_and_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index a40d4e4690a..2601e4e3d7d 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -46,7 +46,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@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 #v4.4.3 From 5ac84be99be2c1a9766028b2797324aef3ea0ff5 Mon Sep 17 00:00:00 2001 From: Reynold Morel Date: Fri, 6 Sep 2024 16:05:32 -0400 Subject: [PATCH 06/14] Addressing comments --- rskj-core/build.gradle | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/rskj-core/build.gradle b/rskj-core/build.gradle index 1d9494f130f..bca56271db0 100644 --- a/rskj-core/build.gradle +++ b/rskj-core/build.gradle @@ -26,11 +26,9 @@ spotless { indentWithTabs(2) indentWithSpaces(4) target filteredFiles - } } - def getFilteredFiles() { def timestamp = ext.timestamp @@ -72,7 +70,6 @@ def getFilteredFiles() { 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 } @@ -83,7 +80,6 @@ def getFilteredFiles() { return allFiles.collect { file -> Paths.get(file).toAbsolutePath().toFile() } } -// Method to configure Checkstyle tasks def configureCheckstyleTask(Checkstyle task, File sourceDir) { def sourceDirPath = sourceDir.toPath().normalize() def files = getFilteredFiles() @@ -92,7 +88,6 @@ def configureCheckstyleTask(Checkstyle task, File sourceDir) { def isUnderSourceDir = filePath.startsWith(sourceDirPath) && !filePath.equals(sourceDirPath) isUnderSourceDir } - task.source = project.files(filteredFilesCheckstyle) task.classpath = project.files( sourceSets.main.output.classesDirs, @@ -102,9 +97,12 @@ def configureCheckstyleTask(Checkstyle task, File sourceDir) { xml.required.set(true) html.required.set(true) } + task.onlyIf { + !filteredFilesCheckstyle.isEmpty() + } } -// Configure each Checkstyle task explicitly +// Configure each Checkstyle task tasks.withType(Checkstyle).configureEach { Checkstyle task -> switch (task.name) { case 'checkstyleMain': @@ -120,6 +118,13 @@ tasks.withType(Checkstyle).configureEach { Checkstyle task -> configureCheckstyleTask(task, file('src/jmh/java')) break } + if (task.name == 'checkstyleJmh' || task.name == 'checkstyleIntegrationTest') { + task.doFirst { + if(!getFilteredFiles().isEmpty()) { + task.source = project.files(getFilteredFiles()) + } + } + } } configurations { @@ -538,4 +543,6 @@ static def amendPathIfNeeded(details) { tasks.named('check').configure { dependsOn 'checkstyleMain' dependsOn 'checkstyleTest' + dependsOn 'checkstyleJmh' + dependsOn 'checkstyleIntegrationTest' } From 6d5fe7567a236ab8c079d008692455786939b742 Mon Sep 17 00:00:00 2001 From: Reynold Morel Date: Fri, 27 Sep 2024 11:23:46 -0400 Subject: [PATCH 07/14] Updating timestamp and fixing code --- rskj-core/build.gradle | 80 +++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 28 deletions(-) diff --git a/rskj-core/build.gradle b/rskj-core/build.gradle index bca56271db0..ed2804154ae 100644 --- a/rskj-core/build.gradle +++ b/rskj-core/build.gradle @@ -10,7 +10,7 @@ apply plugin: 'jacoco' import java.nio.file.Paths // Define static timestamp -def staticTimestamp = '2024-09-03T02:17:00' +def staticTimestamp = '2024-09-27T02:17:00' ext.timestamp = staticTimestamp def filteredFiles = getFilteredFiles() @@ -71,24 +71,34 @@ def getFilteredFiles() { 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 allFiles.collect { file -> Paths.get(file).toAbsolutePath().toFile() } + return absolutePath.exists() ? absolutePath : null + }.findAll { it != null } + + return allFiles } -def configureCheckstyleTask(Checkstyle task, File sourceDir) { - def sourceDirPath = sourceDir.toPath().normalize() - def files = getFilteredFiles() - def filteredFilesCheckstyle = files.findAll { file -> - def filePath = file.toPath().normalize() - def isUnderSourceDir = filePath.startsWith(sourceDirPath) && !filePath.equals(sourceDirPath) - isUnderSourceDir + +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.source = project.files(filteredFilesCheckstyle) + task.classpath = project.files( sourceSets.main.output.classesDirs, sourceSets.main.output.resourcesDir @@ -102,26 +112,40 @@ def configureCheckstyleTask(Checkstyle task, File sourceDir) { } } +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 -> - switch (task.name) { - case 'checkstyleMain': - configureCheckstyleTask(task, file('src/main/java')) - break - case 'checkstyleTest': - configureCheckstyleTask(task, file('src/test/java')) - break - case 'checkstyleIntegrationTest': - configureCheckstyleTask(task, file('src/integrationTest/java')) - break - case 'checkstyleJmh': - configureCheckstyleTask(task, file('src/jmh/java')) - break + 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 == 'checkstyleJmh' || task.name == 'checkstyleIntegrationTest') { + + if (task.name in ['checkstyleJmh', 'checkstyleIntegrationTest']) { task.doFirst { - if(!getFilteredFiles().isEmpty()) { - task.source = project.files(getFilteredFiles()) + def relevantSourceDir = task.name == 'checkstyleJmh' ? 'src/jmh/java' : 'src/integrationTest/java' + def checkstyleFiles = getFilteredFilesForCheckstyle(relevantSourceDir) + + if (!checkstyleFiles.isEmpty()) { + task.source = project.files(checkstyleFiles) } } } @@ -545,4 +569,4 @@ tasks.named('check').configure { dependsOn 'checkstyleTest' dependsOn 'checkstyleJmh' dependsOn 'checkstyleIntegrationTest' -} +} \ No newline at end of file From d91e4e5ced3fa0134cb425954f83de526e51c16b Mon Sep 17 00:00:00 2001 From: Reynold Morel Date: Tue, 8 Oct 2024 10:27:50 -0400 Subject: [PATCH 08/14] Updating timestamp and removing sherter from verification-metadata --- gradle/verification-metadata.xml | 13 ------------- rskj-core/build.gradle | 2 +- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 3b01aa24ae4..7c4eb859579 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -303,11 +303,6 @@ - - - - - @@ -824,14 +819,6 @@ - - - - - - - - diff --git a/rskj-core/build.gradle b/rskj-core/build.gradle index ed2804154ae..084e517c02b 100644 --- a/rskj-core/build.gradle +++ b/rskj-core/build.gradle @@ -10,7 +10,7 @@ apply plugin: 'jacoco' import java.nio.file.Paths // Define static timestamp -def staticTimestamp = '2024-09-27T02:17:00' +def staticTimestamp = '2024-10-11T10:24:00' ext.timestamp = staticTimestamp def filteredFiles = getFilteredFiles() From 3db4484f190cdcd066301babaea43c835a84e999 Mon Sep 17 00:00:00 2001 From: Reynold Morel Date: Fri, 11 Oct 2024 12:44:53 -0400 Subject: [PATCH 09/14] Fixing spotless pom.xml checksum --- gradle/verification-metadata.xml | 26 +++++++++++++++----------- rskj-core/build.gradle | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 7c4eb859579..dbc6c92e67c 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -93,6 +93,7 @@ + @@ -121,6 +122,9 @@ + + + @@ -350,10 +354,10 @@ - + - + @@ -373,7 +377,7 @@ - + @@ -394,10 +398,10 @@ - + - + @@ -415,7 +419,7 @@ - + @@ -465,10 +469,10 @@ - + - + @@ -498,7 +502,7 @@ - + @@ -1222,10 +1226,10 @@ - + - + diff --git a/rskj-core/build.gradle b/rskj-core/build.gradle index 084e517c02b..e080699a4ed 100644 --- a/rskj-core/build.gradle +++ b/rskj-core/build.gradle @@ -10,7 +10,7 @@ apply plugin: 'jacoco' import java.nio.file.Paths // Define static timestamp -def staticTimestamp = '2024-10-11T10:24:00' +def staticTimestamp = '2024-10-17T10:24:00' ext.timestamp = staticTimestamp def filteredFiles = getFilteredFiles() From 26da1921828f7306146bb636318f43751df6e7dd Mon Sep 17 00:00:00 2001 From: Reynold Morel Date: Thu, 31 Oct 2024 08:23:18 -0400 Subject: [PATCH 10/14] addressing comments --- rskj-core/build.gradle | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rskj-core/build.gradle b/rskj-core/build.gradle index e080699a4ed..f7a8fb332ad 100644 --- a/rskj-core/build.gradle +++ b/rskj-core/build.gradle @@ -10,7 +10,7 @@ apply plugin: 'jacoco' import java.nio.file.Paths // Define static timestamp -def staticTimestamp = '2024-10-17T10:24:00' +def staticTimestamp = '2024-10-31T10:24:00' ext.timestamp = staticTimestamp def filteredFiles = getFilteredFiles() @@ -24,7 +24,8 @@ spotless { java { googleJavaFormat() indentWithTabs(2) - indentWithSpaces(4) + trimTrailingWhitespace() + endWithNewline() target filteredFiles } } From 941944f46433482fd5d29360a9de37b336eccd3f Mon Sep 17 00:00:00 2001 From: Reynold Morel Date: Fri, 1 Nov 2024 08:37:54 -0400 Subject: [PATCH 11/14] updating dependencies --- gradle/verification-metadata.xml | 444 +------------------------------ 1 file changed, 13 insertions(+), 431 deletions(-) diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index dbc6c92e67c..adc09c6f6ab 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -307,6 +307,11 @@ + + + + + @@ -823,6 +828,14 @@ + + + + + + + + @@ -1604,437 +1617,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 427e4d5cb8b07caae5bb90ff8f7fe441882aa2bc Mon Sep 17 00:00:00 2001 From: frederico leal Date: Tue, 29 Oct 2024 16:02:24 +0100 Subject: [PATCH 12/14] Fixing typos in branch config --- .github/workflows/rit.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rit.yml b/.github/workflows/rit.yml index 98e6c8dfb77..24f673ba46e 100644 --- a/.github/workflows/rit.yml +++ b/.github/workflows/rit.yml @@ -33,8 +33,8 @@ jobs: id: set-branch-variables env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - github_event_input_powpeg_branch: ${{ github.event.inputs.powpeg-branch }} - github_event_input_rit_branch: ${{ github.event.inputs.rit-branch }} + github_event_inputs_powpeg_branch: ${{ github.event.inputs.powpeg-branch }} + github_event_inputs_rit_branch: ${{ github.event.inputs.rit-branch }} github_event_name: ${{ github.event_name }} github_event_pull_request_number: ${{ github.event.pull_request.number }} github_head_ref: ${{ github.head_ref }} From c24940d351b1d173f0ed3cfefa61d29b82f78150 Mon Sep 17 00:00:00 2001 From: Nazaret Garcia Date: Tue, 29 Oct 2024 19:06:29 -0300 Subject: [PATCH 13/14] Updating smell test --- .github/workflows/build_and_test.yml | 36 ++++------------------------ build.gradle | 8 +++++++ 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 2601e4e3d7d..8eb14e3d014 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -101,40 +101,14 @@ jobs: - name: Run SonarQube analysis env: - GH_EVENT: ${{ github.event_name }} - GH_PR_NUMBER: ${{ github.event.pull_request.number }} - GH_PR_BASE_REF: ${{ github.base_ref }} - GH_PR_HEAD_REF: ${{ github.head_ref }} GH_REF: ${{ github.ref }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - IS_FORK: ${{ github.event.pull_request.head.repo.fork }} run: | - if [ "$GH_EVENT" = "pull_request" ]; then - if [ "$IS_FORK" != "true" ]; then - ./gradlew -Dorg.gradle.jvmargs=-Xmx5g sonarqube --no-daemon -x build -x test \ - -Dsonar.pullrequest.base="$GH_PR_BASE_REF" \ - -Dsonar.pullrequest.branch="$GH_PR_HEAD_REF" \ - -Dsonar.pullrequest.key="$GH_PR_NUMBER" \ - -Dsonar.organization=rsksmart \ - -Dsonar.projectKey=rskj \ - -Dsonar.host.url="https://sonarcloud.io" \ - -Dsonar.junit.reportPaths=rskj-core/build/test-results/ \ - -Dsonar.coverage.jacoco.xmlReportPaths=rskj-core/build/reports/jacoco/test/jacocoTestReport.xml \ - -Dsonar.token="$SONAR_TOKEN" - else - echo "Skipping SonarQube analysis for pull request from a forked repo." - fi - else - ./gradlew -Dorg.gradle.jvmargs=-Xmx5g sonarqube --no-daemon -x build -x test \ - -Dsonar.branch.name="$GH_REF" \ - -Dsonar.organization=rsksmart \ - -Dsonar.projectKey=rskj \ - -Dsonar.host.url="https://sonarcloud.io" \ - -Dsonar.junit.reportPaths=rskj-core/build/test-results/ \ - -Dsonar.coverage.jacoco.xmlReportPaths=rskj-core/build/reports/jacoco/test/jacocoTestReport.xml \ - -Dsonar.token="$SONAR_TOKEN" - fi - + ./gradlew -Dorg.gradle.jvmargs=-Xmx5g sonar --no-daemon -x build -x test \ + -Dsonar.branch.name="$GH_REF" \ + -Dsonar.junit.reportPaths=rskj-core/build/test-results/ \ + -Dsonar.coverage.jacoco.xmlReportPaths=rskj-core/build/reports/jacoco/test/jacocoTestReport.xml \ + -Dsonar.token="$SONAR_TOKEN" mining-tests: needs: build diff --git a/build.gradle b/build.gradle index 9a423cc072c..7047a1e84cd 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,14 @@ plugins { id "org.sonarqube" version "5.1.0.4882" } +sonar { + properties { + property "sonar.projectKey", "rskj" + property "sonar.organization", "rsksmart" + property "sonar.host.url", "https://sonarcloud.io" + } +} + subprojects { def config = new ConfigSlurper().parse(file("$projectDir/src/main/resources/version.properties").toURI().toURL()) group = 'co.rsk' From ecb810d9cb76817b5cdb03eb38856dd00769a507 Mon Sep 17 00:00:00 2001 From: Nazaret Garcia Date: Tue, 29 Oct 2024 19:30:02 -0300 Subject: [PATCH 14/14] Adding tmp code --- .../java/co/rsk/rpc/modules/debug/DebugModuleImpl.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rskj-core/src/main/java/co/rsk/rpc/modules/debug/DebugModuleImpl.java b/rskj-core/src/main/java/co/rsk/rpc/modules/debug/DebugModuleImpl.java index 62be8e6e55c..ffaa5a3278d 100644 --- a/rskj-core/src/main/java/co/rsk/rpc/modules/debug/DebugModuleImpl.java +++ b/rskj-core/src/main/java/co/rsk/rpc/modules/debug/DebugModuleImpl.java @@ -143,6 +143,16 @@ private JsonNode traceBlock(Block block, TraceOptions options) { return programTraceProcessor.getProgramTracesAsJsonNode(txHashes); } + private boolean testFunctionNotCovered() { + boolean var1 = false; + boolean var2 = true; + boolean var3 = false; + if (!var1 && var2 || !var3) { + return true; + } + return false; + } + private TraceOptions toTraceOptions(Map traceOptions) { TraceOptions options = new TraceOptions(traceOptions);