mirror of
https://github.com/SonarSource/sonarqube.git
synced 2024-08-03 08:18:00 +02:00
SONAR-2332 Findbugs plugin must remove temporary files created during execution
This commit is contained in:
parent
18ad773901
commit
fbbb9f83cc
@ -19,12 +19,6 @@
|
||||
*/
|
||||
package org.sonar.plugins.findbugs;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@ -38,6 +32,8 @@ import org.sonar.plugins.findbugs.xml.ClassFilter;
|
||||
import org.sonar.plugins.findbugs.xml.FindBugsFilter;
|
||||
import org.sonar.plugins.findbugs.xml.Match;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* @since 2.4
|
||||
*/
|
||||
@ -75,12 +71,12 @@ public class FindbugsConfiguration implements BatchExtension {
|
||||
}
|
||||
findbugsProject.addFile(classesDir.getAbsolutePath());
|
||||
for (File file : projectClasspath.getElements()) {
|
||||
if ( !file.equals(classesDir)) {
|
||||
if (!file.equals(classesDir)) {
|
||||
findbugsProject.addAuxClasspathEntry(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
findbugsProject.addAuxClasspathEntry(copyLib("/annotations-" + FindbugsVersion.getVersion() + ".jar").getAbsolutePath());
|
||||
findbugsProject.addAuxClasspathEntry(copyLib("/jsr305-" + FindbugsVersion.getVersion() + ".jar").getAbsolutePath());
|
||||
findbugsProject.addAuxClasspathEntry(annotationsLib.getAbsolutePath());
|
||||
findbugsProject.addAuxClasspathEntry(jsr305Lib.getAbsolutePath());
|
||||
findbugsProject.setCurrentWorkingDirectory(project.getFileSystem().getBuildDir());
|
||||
return findbugsProject;
|
||||
}
|
||||
@ -111,11 +107,29 @@ public class FindbugsConfiguration implements BatchExtension {
|
||||
return project.getConfiguration().getLong(CoreProperties.FINDBUGS_TIMEOUT_PROPERTY, CoreProperties.FINDBUGS_TIMEOUT_DEFAULT_VALUE);
|
||||
}
|
||||
|
||||
private File jsr305Lib;
|
||||
private File annotationsLib;
|
||||
|
||||
/**
|
||||
* Invoked by PicoContainer to extract additional FindBugs libraries into temporary files.
|
||||
*/
|
||||
public void start() {
|
||||
jsr305Lib = copyLib("/jsr305-" + FindbugsVersion.getVersion() + ".jar");
|
||||
annotationsLib = copyLib("/annotations-" + FindbugsVersion.getVersion() + ".jar");
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked by PicoContainer to remove temporary files.
|
||||
*/
|
||||
public void stop() {
|
||||
jsr305Lib.delete();
|
||||
annotationsLib.delete();
|
||||
}
|
||||
|
||||
private File copyLib(String name) {
|
||||
try {
|
||||
InputStream is = getClass().getResourceAsStream(name);
|
||||
File temp = File.createTempFile("findbugs", ".jar");
|
||||
FileUtils.forceDeleteOnExit(temp);
|
||||
OutputStream os = FileUtils.openOutputStream(temp);
|
||||
IOUtils.copy(is, os);
|
||||
return temp;
|
||||
|
Loading…
Reference in New Issue
Block a user