Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test project failure #33 #35

Merged
merged 1 commit into from
Jul 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.sonarsource.sonar-findbugs-plugin</groupId>
<artifactId>sonar-findbugs-plugin</artifactId>
<version>3.4.2</version>
<version>3.4.3</version>
<packaging>sonar-plugin</packaging>

<name>SonarQube Findbugs Plugin</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public Project getFindbugsProject() throws IOException {
LOG.warn("Findbugs needs sources to be compiled."
+ " Please build project before executing sonar or check the location of compiled classes to"
+ " make it possible for Findbugs to analyse your project.");

if(hasSourceFiles()) { //This exclude test source files
throw new IllegalStateException("This project contains Java source files that are not compiled.");
}
}

if(hasJspFiles && !hasPrecompiledJsp) {
Expand All @@ -131,9 +135,9 @@ public Project getFindbugsProject() throws IOException {
return findbugsProject;
}

private Iterable<File> getSourceFiles() {
private boolean hasSourceFiles() {
FilePredicates pred = fileSystem.predicates();
return fileSystem.files(pred.and(pred.hasType(Type.MAIN), pred.hasLanguage(Java.KEY)));
return fileSystem.hasFiles(pred.and(pred.hasType(Type.MAIN), pred.hasLanguage(Java.KEY)));
}

@VisibleForTesting
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/sonar/plugins/findbugs/FindbugsExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public Collection<ReportedBug> execute(boolean useAllPlugin) {
}

public Collection<ReportedBug> execute(boolean useFbContrib, boolean useFindSecBugs) {
TimeProfiler profiler = new TimeProfiler().start("Execute Findbugs " + FindbugsVersion.getVersion());
// We keep a handle on the current security manager because FB plays with it and we need to restore it before shutting down the executor
// service
SecurityManager currentSecurityManager = System.getSecurityManager();
Expand All @@ -118,6 +117,12 @@ public Collection<ReportedBug> execute(boolean useFbContrib, boolean useFindSecB
final FindBugs2 engine = new FindBugs2();

Project project = configuration.getFindbugsProject();

if(project.getFileCount() == 0) {
LOG.info("Findbugs analysis skipped for this project.");
return new ArrayList<>();
}

customPlugins = loadFindbugsPlugins(useFbContrib,useFindSecBugs);

disableUpdateChecksOnEveryPlugin();
Expand Down Expand Up @@ -157,8 +162,6 @@ public Collection<ReportedBug> execute(boolean useFbContrib, boolean useFindSecB

executorService.submit(new FindbugsTask(engine)).get(configuration.getTimeout(), TimeUnit.MILLISECONDS);

profiler.stop();

return toReportedBugs(xmlBugReporter.getBugCollection());
} catch (TimeoutException e) {
throw new IllegalStateException("Can not execute Findbugs with a timeout threshold value of " + configuration.getTimeout() + " milliseconds", e);
Expand Down Expand Up @@ -251,7 +254,7 @@ private Collection<Plugin> loadFindbugsPlugins(boolean useFbContrib,boolean useF
Plugin plugin = Plugin.addCustomPlugin(new File(path).toURI(), contextClassLoader);
if (plugin != null) {
customPluginList.add(plugin);
LOG.info("Found findbugs plugin: " + path);
LOG.info("Loading findbugs plugin: " + path);
}
} catch (PluginException e) {
LOG.warn("Failed to load plugin for custom detector: " + path);
Expand Down