33 * See COPYING.txt for license details.
44 */
55
6+ import groovy.json.JsonSlurper
67import org.jetbrains.changelog.Changelog
78import org.jetbrains.changelog.markdownToHTML
89import org.jetbrains.intellij.platform.gradle.TestFrameworkType
910
1011plugins {
1112 id(" java" )
13+ id(" checkstyle" )
14+ id(" pmd" )
1215 alias(libs.plugins.kotlin)
1316 alias(libs.plugins.intelliJPlatform)
1417 alias(libs.plugins.changelog)
@@ -109,10 +112,6 @@ intellijPlatform {
109112 }
110113}
111114
112- apply {
113- from(" ${project.rootDir} /gradle-tasks/staticChecks.gradle" )
114- }
115-
116115changelog {
117116 groups.empty()
118117 repositoryUrl = providers.gradleProperty(" pluginRepositoryUrl" )
@@ -141,6 +140,20 @@ tasks {
141140 exclude(" com/magento/idea/magento2plugin/actions/**" ) // https://github.com/magento/magento2-phpstorm-plugin/issues/2474
142141 useJUnitPlatform()
143142 }
143+
144+ checkstyle {
145+ toolVersion = " 8.31"
146+ isIgnoreFailures = false
147+ maxWarnings = 0
148+ configFile = rootProject.file(" ${rootDir} /gradle-tasks/checkstyle/checkstyle.xml" )
149+ }
150+
151+ pmd {
152+ toolVersion = " 6.21.0"
153+ isConsoleOutput = true
154+ ruleSetFiles = files(" ${rootDir} /gradle-tasks/pmd/ruleset.xml" )
155+ ruleSets = listOf ()
156+ }
144157}
145158
146159intellijPlatformTesting {
@@ -163,3 +176,66 @@ intellijPlatformTesting {
163176 }
164177 }
165178}
179+
180+ // Configure Checkstyle tasks
181+ tasks.withType(Checkstyle ::class ).configureEach {
182+ // Specify all files that should be checked
183+ classpath = files()
184+ setSource(" ${project.rootDir} " )
185+ }
186+
187+ // Execute Checkstyle on all files
188+ tasks.register<Checkstyle >(" checkstyle" ) {
189+ // Task-specific configuration can go here if necessary
190+ }
191+
192+ // Execute Checkstyle on all modified files
193+ tasks.register<Checkstyle >(" checkstyleCI" ) {
194+ val changedFiles = getChangedFiles()
195+ include(changedFiles)
196+ }
197+
198+ // Configure PMD tasks
199+ tasks.withType(Pmd ::class ).configureEach {
200+ // Specify all files that should be checked
201+ classpath = files()
202+ setSource(" ${project.rootDir} " )
203+ }
204+
205+ // Execute PMD on all files
206+ tasks.register<Pmd >(" pmd" ) {
207+ // Task-specific configuration can go here if necessary
208+ }
209+
210+ // Execute PMD on all modified files
211+ tasks.register<Pmd >(" pmdCI" ) {
212+ val changedFiles = getChangedFiles()
213+ include(changedFiles)
214+ }
215+
216+ /* *
217+ * Get all files that are changed but not deleted nor renamed.
218+ * Compares to master or the specified target branch.
219+ *
220+ * @return list of all changed files
221+ */
222+ fun getChangedFiles (): List <String > {
223+ val modifiedFilesJson = System .getenv(" MODIFIED_FILES" )
224+ val files = mutableListOf<String >()
225+
226+ if (modifiedFilesJson == null ) {
227+ return files
228+ }
229+
230+ println (" Modified Files: $modifiedFilesJson " )
231+
232+ // Parse the JSON string into a list of files
233+ val modifiedFiles = JsonSlurper ().parseText(modifiedFilesJson) as List <* >
234+
235+ modifiedFiles.forEach {
236+ files.add(it.toString())
237+ }
238+
239+ // Return the list of touched files
240+ return files
241+ }
0 commit comments