@@ -90,6 +90,13 @@ | |||
</dependencies> | |||
<build> | |||
<resources> | |||
<resource> | |||
<directory>src/main/resources</directory> | |||
<filtering>true</filtering> | |||
</resource> | |||
</resources> | |||
<testResources> | |||
<testResource> | |||
<directory>${basedir}/src/main/resources</directory> | |||
@@ -98,6 +105,7 @@ | |||
<directory>${basedir}/src/test/resources</directory> | |||
</testResource> | |||
</testResources> | |||
<plugins> | |||
<plugin> | |||
<groupId>org.codehaus.sonar</groupId> |
@@ -1,6 +1,8 @@ | |||
package org.sonar.plugins.findbugs; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.sonar.api.BatchExtension; | |||
import org.sonar.api.CoreProperties; | |||
import org.sonar.api.profiles.RulesProfile; | |||
import org.sonar.api.resources.Project; | |||
import org.sonar.api.utils.SonarException; | |||
@@ -35,17 +37,19 @@ public class FindbugsConfiguration implements BatchExtension { | |||
} | |||
public edu.umd.cs.findbugs.Project getFindbugsProject() { | |||
try { | |||
edu.umd.cs.findbugs.Project findbugsProject = new edu.umd.cs.findbugs.Project(); | |||
for (File dir : project.getFileSystem().getSourceDirs()) { | |||
findbugsProject.addSourceDir(dir.getAbsolutePath()); | |||
} | |||
findbugsProject.addFile(project.getFileSystem().getBuildOutputDir().getAbsolutePath()); | |||
findbugsProject.setCurrentWorkingDirectory(project.getFileSystem().getBuildDir()); | |||
return findbugsProject; | |||
} catch (Exception e) { | |||
throw new SonarException(e); | |||
File classesDir = project.getFileSystem().getBuildOutputDir(); | |||
if (classesDir == null || !classesDir.exists()) { | |||
throw new SonarException("Findbugs needs sources to be compiled. " | |||
+ "Please build project or edit pom.xml to set the <outputDirectory> property before executing sonar."); | |||
} | |||
edu.umd.cs.findbugs.Project findbugsProject = new edu.umd.cs.findbugs.Project(); | |||
for (File dir : project.getFileSystem().getSourceDirs()) { | |||
findbugsProject.addSourceDir(dir.getAbsolutePath()); | |||
} | |||
findbugsProject.addFile(classesDir.getAbsolutePath()); | |||
findbugsProject.setCurrentWorkingDirectory(project.getFileSystem().getBuildDir()); | |||
return findbugsProject; | |||
} | |||
public File saveIncludeConfigXml() throws IOException { | |||
@@ -64,4 +68,8 @@ public class FindbugsConfiguration implements BatchExtension { | |||
} | |||
return project.getFileSystem().writeToWorkingDirectory(findBugsFilter.toXml(), "findbugs-exclude.xml"); | |||
} | |||
public String getEffort() { | |||
return StringUtils.lowerCase(project.getConfiguration().getString(CoreProperties.FINDBUGS_EFFORT_PROPERTY, CoreProperties.FINDBUGS_EFFORT_DEFAULT_VALUE)); | |||
} | |||
} |
@@ -30,7 +30,7 @@ public class FindbugsExecutor implements BatchExtension { | |||
} | |||
public File execute() { | |||
TimeProfiler profiler = new TimeProfiler().start("Execute Findbugs"); | |||
TimeProfiler profiler = new TimeProfiler().start("Execute Findbugs " + FindbugsVersion.getVersion()); | |||
ClassLoader initialClassLoader = Thread.currentThread().getContextClassLoader(); | |||
Thread.currentThread().setContextClassLoader(FindBugs2.class.getClassLoader()); | |||
@@ -60,7 +60,7 @@ public class FindbugsExecutor implements BatchExtension { | |||
engine.setDetectorFactoryCollection(DetectorFactoryCollection.instance()); | |||
UserPreferences userPreferences = UserPreferences.createDefaultUserPreferences(); | |||
userPreferences.setEffort(UserPreferences.EFFORT_DEFAULT); | |||
userPreferences.setEffort(configuration.getEffort()); | |||
engine.addFilter(configuration.saveIncludeConfigXml().getAbsolutePath(), true); | |||
engine.addFilter(configuration.saveExcludeConfigXml().getAbsolutePath(), false); |
@@ -0,0 +1,35 @@ | |||
package org.sonar.plugins.findbugs; | |||
import org.apache.commons.io.IOUtils; | |||
import org.slf4j.LoggerFactory; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.util.Properties; | |||
public enum FindbugsVersion { | |||
INSTANCE; | |||
private static final String PROPERTIES_PATH = "/org/sonar/plugins/findbugs/findbugs-plugin.properties"; | |||
private String version; | |||
public static String getVersion() { | |||
return INSTANCE.version; | |||
} | |||
private FindbugsVersion() { | |||
InputStream input = getClass().getResourceAsStream(PROPERTIES_PATH); | |||
try { | |||
Properties properties = new Properties(); | |||
properties.load(input); | |||
this.version = properties.getProperty("findbugs.version"); | |||
} catch (IOException e) { | |||
LoggerFactory.getLogger(getClass()).warn("Can not load the Findbugs version from the file " + PROPERTIES_PATH); | |||
this.version = ""; | |||
} finally { | |||
IOUtils.closeQuietly(input); | |||
} | |||
} | |||
} |
@@ -0,0 +1 @@ | |||
findbugs.version=${findbugs.version} |
@@ -36,6 +36,7 @@ public class FindbugsExecutorTest { | |||
when(conf.getFindbugsProject()).thenReturn(project); | |||
when(conf.saveExcludeConfigXml()).thenReturn(new File("test-resources/findbugs-exclude.xml")); | |||
when(conf.saveIncludeConfigXml()).thenReturn(new File("test-resources/findbugs-include.xml")); | |||
when(conf.getEffort()).thenReturn("default"); | |||
return conf; | |||
} | |||