From b812f93aec9594a40a61b532db1165fcb49c0197 Mon Sep 17 00:00:00 2001 From: "david.marinho@codacy.com" Date: Fri, 7 Feb 2025 09:56:37 +0000 Subject: [PATCH 1/7] re-add doc-generator step --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index dbae6e6..db38074 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -13,6 +13,7 @@ workflows: - codacy/sbt: name: publish_docker_local cmd: | + sbt "runMain com.codacy.pmd.DocGenerator" sbt "Test / scalafmt / test; set Docker / version := \"latest\"; Docker / publishLocal;" From 036025b42e6b9a64080299d24ddcae0e59dba978 Mon Sep 17 00:00:00 2001 From: "david.marinho@codacy.com" Date: Fri, 7 Feb 2025 12:14:02 +0000 Subject: [PATCH 2/7] tests --- src/main/scala/com/codacy/pmd/PMD.scala | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main/scala/com/codacy/pmd/PMD.scala b/src/main/scala/com/codacy/pmd/PMD.scala index 3e8c57e..63cd437 100644 --- a/src/main/scala/com/codacy/pmd/PMD.scala +++ b/src/main/scala/com/codacy/pmd/PMD.scala @@ -44,7 +44,6 @@ object PMD extends Tool { } // Files could be empty when given explicitly by configuration a set of empty files to run. - // Confirm what happens in this case / what is the else that is missing from this flow (?) if (!filesStr.isEmpty) { pmdConfig.setInputPathList(filesStr) } @@ -52,13 +51,9 @@ object PMD extends Tool { // Side effectful code to make a pmdConfig with rules which at the start is null: configuration match { case Some(config) => - // If given patterns are empty, we generete a xml with some xml headers, - // but rules obviously are none. Don't know if or how it fails, needs testing here. - // Probably we want to protected here since the code inside - // RulesetsFactoryUtils.getRuleSets checks if rules are != 0... configFile(config) match { case Success(ruleset) => - pmdConfig.setRuleSets(Arrays.asList(ruleset.toString)) + pmdConfig.setRuleSets(ruleset.toString) case Failure(_) => } @@ -73,10 +68,10 @@ object PMD extends Tool { .fold { configFile(DefaultPatterns.list.map(patternId => Pattern.Definition(Pattern.Id(patternId)))) .foreach { defaultCodacyRuleSetFile => - pmdConfig.setRuleSets(Arrays.asList(defaultCodacyRuleSetFile.toString)) + pmdConfig.setRuleSets(defaultCodacyRuleSetFile.toString) } } { ruleset => - pmdConfig.setRuleSets(Arrays.asList(ruleset.toString)) + pmdConfig.setRuleSets(ruleset.toString) } } @@ -103,7 +98,6 @@ object PMD extends Tool { pmdAnalysis.performAnalysis() val ruleViolations = codacyRenderer.getRulesViolations.asScala.view.flatMap { violation => - //println(s"Violation: ${violation.getDescription} in ${violation.getFileId.getFileName.toString}") patternIdByRuleNameAndRuleSet( violation.getRule.getLanguage.getId, violation.getRule.getName, From 826fd452288c4b00e4fef3d9c8d07f37d976ee38 Mon Sep 17 00:00:00 2001 From: "david.marinho@codacy.com" Date: Fri, 7 Feb 2025 12:22:40 +0000 Subject: [PATCH 3/7] tests --- src/main/scala/com/codacy/pmd/PMD.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/com/codacy/pmd/PMD.scala b/src/main/scala/com/codacy/pmd/PMD.scala index 63cd437..0a66b7d 100644 --- a/src/main/scala/com/codacy/pmd/PMD.scala +++ b/src/main/scala/com/codacy/pmd/PMD.scala @@ -68,7 +68,7 @@ object PMD extends Tool { .fold { configFile(DefaultPatterns.list.map(patternId => Pattern.Definition(Pattern.Id(patternId)))) .foreach { defaultCodacyRuleSetFile => - pmdConfig.setRuleSets(defaultCodacyRuleSetFile.toString) + pmdConfig.setRuleSets(Arrays.asList(defaultCodacyRuleSetFile)) } } { ruleset => pmdConfig.setRuleSets(ruleset.toString) From 4168f3cf84f0ad6a3bd3bdf8fdafa961287f4602 Mon Sep 17 00:00:00 2001 From: "david.marinho@codacy.com" Date: Fri, 7 Feb 2025 12:26:59 +0000 Subject: [PATCH 4/7] tests --- src/main/scala/com/codacy/pmd/PMD.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/scala/com/codacy/pmd/PMD.scala b/src/main/scala/com/codacy/pmd/PMD.scala index 0a66b7d..7b15d0f 100644 --- a/src/main/scala/com/codacy/pmd/PMD.scala +++ b/src/main/scala/com/codacy/pmd/PMD.scala @@ -53,7 +53,7 @@ object PMD extends Tool { case Some(config) => configFile(config) match { case Success(ruleset) => - pmdConfig.setRuleSets(ruleset.toString) + pmdConfig.setRuleSets(Arrays.asList(ruleset.toString)) case Failure(_) => } @@ -68,7 +68,7 @@ object PMD extends Tool { .fold { configFile(DefaultPatterns.list.map(patternId => Pattern.Definition(Pattern.Id(patternId)))) .foreach { defaultCodacyRuleSetFile => - pmdConfig.setRuleSets(Arrays.asList(defaultCodacyRuleSetFile)) + pmdConfig.setRuleSets(Arrays.asList(defaultCodacyRuleSetFile.toString)) } } { ruleset => pmdConfig.setRuleSets(ruleset.toString) From be44a3d032fa785a1bbd9770ec072e79bc8f17dc Mon Sep 17 00:00:00 2001 From: "david.marinho@codacy.com" Date: Fri, 7 Feb 2025 14:26:40 +0000 Subject: [PATCH 5/7] tests --- src/main/scala/com/codacy/pmd/PMD.scala | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/scala/com/codacy/pmd/PMD.scala b/src/main/scala/com/codacy/pmd/PMD.scala index 7b15d0f..34290a4 100644 --- a/src/main/scala/com/codacy/pmd/PMD.scala +++ b/src/main/scala/com/codacy/pmd/PMD.scala @@ -32,15 +32,14 @@ object PMD extends Tool { val pmdConfig = new PMDConfiguration() pmdConfig.setIgnoreIncrementalAnalysis(true) - val filesStr: java.util.List[java.nio.file.Path] = files match { + val filesStr = files match { case None => - Arrays.asList(Paths.get(source.path)) + source.path case Some(files) => files - .map(file => Paths.get(file.path)) - .filter(path => !Languages.invalidExtensions.exists(path.toString.endsWith)) - .toList - .asJava + .map(_.path) + .filter(filename => !Languages.invalidExtensions.exists(filename.endsWith)) + .mkString(",") } // Files could be empty when given explicitly by configuration a set of empty files to run. @@ -53,7 +52,7 @@ object PMD extends Tool { case Some(config) => configFile(config) match { case Success(ruleset) => - pmdConfig.setRuleSets(Arrays.asList(ruleset.toString)) + pmdConfig.setRuleSets(ruleset.toString) case Failure(_) => } @@ -68,7 +67,7 @@ object PMD extends Tool { .fold { configFile(DefaultPatterns.list.map(patternId => Pattern.Definition(Pattern.Id(patternId)))) .foreach { defaultCodacyRuleSetFile => - pmdConfig.setRuleSets(Arrays.asList(defaultCodacyRuleSetFile.toString)) + pmdConfig.setRuleSets(defaultCodacyRuleSetFile.toString) } } { ruleset => pmdConfig.setRuleSets(ruleset.toString) @@ -77,13 +76,13 @@ object PMD extends Tool { // Check that we defined the rules to run, if not getRuleSets is null, we should terminate since this is an error. // Forcing a RETURN. This should only happen when we failed to generate a temporary configuration file. - if (pmdConfig.getRuleSetPaths == null) { + if (pmdConfig.getRuleSets == null) { return Failure(new Exception("No rulesets were configured to initialize PMD tool")) } // Load the RuleSets val ruleSetLoader = RuleSetLoader.fromPmdConfig(pmdConfig) - val ruleSetsOpt = Option(ruleSetLoader.loadFromResources(pmdConfig.getRuleSetPaths)) + val ruleSetsOpt = Option(ruleSetLoader.loadFromResources(pmdConfig.getRuleSets)) ruleSetsOpt.fold[Try[List[Result]]] { Failure(new Exception("No rulesets found")) From a8db0693c45dc8925b002c66c15ba56ca6a11501 Mon Sep 17 00:00:00 2001 From: "david.marinho@codacy.com" Date: Fri, 7 Feb 2025 16:14:56 +0000 Subject: [PATCH 6/7] revert file --- src/main/scala/com/codacy/pmd/PMD.scala | 27 ++++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/scala/com/codacy/pmd/PMD.scala b/src/main/scala/com/codacy/pmd/PMD.scala index 34290a4..3e8c57e 100644 --- a/src/main/scala/com/codacy/pmd/PMD.scala +++ b/src/main/scala/com/codacy/pmd/PMD.scala @@ -32,17 +32,19 @@ object PMD extends Tool { val pmdConfig = new PMDConfiguration() pmdConfig.setIgnoreIncrementalAnalysis(true) - val filesStr = files match { + val filesStr: java.util.List[java.nio.file.Path] = files match { case None => - source.path + Arrays.asList(Paths.get(source.path)) case Some(files) => files - .map(_.path) - .filter(filename => !Languages.invalidExtensions.exists(filename.endsWith)) - .mkString(",") + .map(file => Paths.get(file.path)) + .filter(path => !Languages.invalidExtensions.exists(path.toString.endsWith)) + .toList + .asJava } // Files could be empty when given explicitly by configuration a set of empty files to run. + // Confirm what happens in this case / what is the else that is missing from this flow (?) if (!filesStr.isEmpty) { pmdConfig.setInputPathList(filesStr) } @@ -50,9 +52,13 @@ object PMD extends Tool { // Side effectful code to make a pmdConfig with rules which at the start is null: configuration match { case Some(config) => + // If given patterns are empty, we generete a xml with some xml headers, + // but rules obviously are none. Don't know if or how it fails, needs testing here. + // Probably we want to protected here since the code inside + // RulesetsFactoryUtils.getRuleSets checks if rules are != 0... configFile(config) match { case Success(ruleset) => - pmdConfig.setRuleSets(ruleset.toString) + pmdConfig.setRuleSets(Arrays.asList(ruleset.toString)) case Failure(_) => } @@ -67,22 +73,22 @@ object PMD extends Tool { .fold { configFile(DefaultPatterns.list.map(patternId => Pattern.Definition(Pattern.Id(patternId)))) .foreach { defaultCodacyRuleSetFile => - pmdConfig.setRuleSets(defaultCodacyRuleSetFile.toString) + pmdConfig.setRuleSets(Arrays.asList(defaultCodacyRuleSetFile.toString)) } } { ruleset => - pmdConfig.setRuleSets(ruleset.toString) + pmdConfig.setRuleSets(Arrays.asList(ruleset.toString)) } } // Check that we defined the rules to run, if not getRuleSets is null, we should terminate since this is an error. // Forcing a RETURN. This should only happen when we failed to generate a temporary configuration file. - if (pmdConfig.getRuleSets == null) { + if (pmdConfig.getRuleSetPaths == null) { return Failure(new Exception("No rulesets were configured to initialize PMD tool")) } // Load the RuleSets val ruleSetLoader = RuleSetLoader.fromPmdConfig(pmdConfig) - val ruleSetsOpt = Option(ruleSetLoader.loadFromResources(pmdConfig.getRuleSets)) + val ruleSetsOpt = Option(ruleSetLoader.loadFromResources(pmdConfig.getRuleSetPaths)) ruleSetsOpt.fold[Try[List[Result]]] { Failure(new Exception("No rulesets found")) @@ -97,6 +103,7 @@ object PMD extends Tool { pmdAnalysis.performAnalysis() val ruleViolations = codacyRenderer.getRulesViolations.asScala.view.flatMap { violation => + //println(s"Violation: ${violation.getDescription} in ${violation.getFileId.getFileName.toString}") patternIdByRuleNameAndRuleSet( violation.getRule.getLanguage.getId, violation.getRule.getName, From 85fa021a1863ee2f06e989c525140f3abcb5207a Mon Sep 17 00:00:00 2001 From: "david.marinho@codacy.com" Date: Fri, 7 Feb 2025 16:39:42 +0000 Subject: [PATCH 7/7] bump engine-scala-seed --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index fecd3d4..00c62e7 100644 --- a/build.sbt +++ b/build.sbt @@ -13,7 +13,7 @@ libraryDependencies ++= { Seq( "com.typesafe.play" %% "play-json" % "2.7.4", - "com.codacy" %% "codacy-engine-scala-seed" % "5.0.1", + "com.codacy" %% "codacy-engine-scala-seed" % "6.1.3", "org.scala-lang.modules" %% "scala-xml" % "1.2.0", "net.sourceforge.pmd" % "pmd-core" % toolVersion, "net.sourceforge.pmd" % "pmd-java" % toolVersion,