From e9ba95a3f558a12d562356c274c89983ba21ea36 Mon Sep 17 00:00:00 2001 From: Guillaume Toison <86775455+gtoison@users.noreply.github.com> Date: Thu, 20 Jun 2024 08:24:03 +0200 Subject: [PATCH] fix: report found languages when failing on missing compiled .class (#1026) --- .../findbugs/FindbugsConfiguration.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java b/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java index 9ef9313f..a5653513 100644 --- a/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java +++ b/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java @@ -150,23 +150,29 @@ void initializeFindbugsProject(Project findbugsProject, ClasspathLocator classpa } public IllegalStateException buildMissingCompiledCodeException() { - String message = "One (sub)project contains Java source files that are not compiled (" + fileSystem.baseDir().getPath() + ")."; + StringBuilder message = new StringBuilder("One (sub)project contains Java source files that are not compiled (" + fileSystem.baseDir().getPath() + ")."); + + for (String language : FindbugsPlugin.SUPPORTED_JVM_LANGUAGES) { + if (fileSystem.hasFiles(fileSystem.predicates().hasLanguage(language))) { + message.append("\nProject has " + language + " source file(s), they must be compiled to be analyzed."); + } + } if (!config.hasKey(SONAR_JAVA_BINARIES) || config.getStringArray(SONAR_JAVA_BINARIES).length == 0) { - message += "\nProperty sonar.java.binaries was not set, it is required to locate the compiled .class files. For instance set the property to: sonar.java.binaries=target/classes"; + message.append("\nProperty sonar.java.binaries was not set, it is required to locate the compiled .class files. For instance set the property to: sonar.java.binaries=target/classes"); } else { - message += "\nsonar.java.binaries was set to " + config.get(SONAR_JAVA_BINARIES).orElse(null); + message.append("\nsonar.java.binaries was set to " + config.get(SONAR_JAVA_BINARIES).orElse(null)); } if (javaResourceLocator.classpath().isEmpty()) { - message += "\nSonar JavaResourceLocator.classpath was empty"; + message.append("\nSonar JavaResourceLocator.classpath was empty"); } if (javaResourceLocator.classFilesToAnalyze().isEmpty()) { - message += "\nSonar JavaResourceLocator.classFilesToAnalyze was empty"; + message.append("\nSonar JavaResourceLocator.classFilesToAnalyze was empty"); } - return new IllegalStateException(message); + return new IllegalStateException(message.toString()); } /**