-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use the sq 9.8 api to get the binaries (#706)
- JavaResourceLocator.classFilesToAnalyze() is populated as a side effect of the sonar-java plugin analysis. When a cached analysis is done this will not return all .class files and this will cause the SpotBugs analysis to fail - Instead use the new API added in SonarQube 9.8 to get the binary folders (main and test) - In order to remain compatible with pre-9.8 call the new method using reflection - Now that we get the test binaries, updated ByteCodeResourceLocator to also look for sources in the standard maven/java folder so we can report issues in test sources - Added a unit test to a sample project so the intergration test can confirm that we report the issues
- Loading branch information
Showing
11 changed files
with
307 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/org/sonar/plugins/findbugs/classpath/ClasspathLocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* SonarQube Findbugs Plugin | ||
* Copyright (C) 2012 SonarSource | ||
* [email protected] | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | ||
*/ | ||
package org.sonar.plugins.findbugs.classpath; | ||
|
||
import java.io.File; | ||
import java.util.Collection; | ||
|
||
/** | ||
* @author gtoison | ||
* | ||
*/ | ||
public interface ClasspathLocator { | ||
|
||
Collection<File> binaryDirs(); | ||
|
||
Collection<File> classpath(); | ||
|
||
Collection<File> testBinaryDirs(); | ||
|
||
Collection<File> testClasspath(); | ||
} |
81 changes: 81 additions & 0 deletions
81
src/main/java/org/sonar/plugins/findbugs/classpath/DefaultClasspathLocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* SonarQube Findbugs Plugin | ||
* Copyright (C) 2012 SonarSource | ||
* [email protected] | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | ||
*/ | ||
package org.sonar.plugins.findbugs.classpath; | ||
|
||
import java.io.File; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
import org.sonar.api.utils.log.Logger; | ||
import org.sonar.api.utils.log.Loggers; | ||
import org.sonar.plugins.java.api.JavaResourceLocator; | ||
|
||
/** | ||
* @author gtoison | ||
* | ||
*/ | ||
public class DefaultClasspathLocator implements ClasspathLocator { | ||
@SuppressWarnings("rawtypes") | ||
private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; | ||
private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; | ||
|
||
private static final Logger LOG = Loggers.get(DefaultClasspathLocator.class); | ||
|
||
private JavaResourceLocator javaResourceLocator; | ||
|
||
public DefaultClasspathLocator(JavaResourceLocator javaResourceLocator) { | ||
this.javaResourceLocator = javaResourceLocator; | ||
} | ||
|
||
@Override | ||
public Collection<File> binaryDirs() { | ||
return callNoArgMethodReturningFilesCollection("binaryDirs"); | ||
} | ||
|
||
@Override | ||
public Collection<File> classpath() { | ||
return javaResourceLocator.classpath(); | ||
} | ||
|
||
@Override | ||
public Collection<File> testBinaryDirs() { | ||
return callNoArgMethodReturningFilesCollection("testBinaryDirs"); | ||
} | ||
|
||
@Override | ||
public Collection<File> testClasspath() { | ||
return callNoArgMethodReturningFilesCollection("testClasspath"); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private Collection<File> callNoArgMethodReturningFilesCollection(String methodName) { | ||
try { | ||
Method method = JavaResourceLocator.class.getDeclaredMethod(methodName, EMPTY_CLASS_ARRAY); | ||
return (Collection<File>) method.invoke(javaResourceLocator, EMPTY_OBJECT_ARRAY); | ||
} catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { | ||
LOG.info("JavaResourceLocator." + methodName + "() not available before SonarQube 9.8"); | ||
LOG.debug("Error calling JavaResourceLocator." + methodName + "()", e); | ||
|
||
return Collections.emptySet(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.