diff options
author | Godin <mandrikov@gmail.com> | 2010-11-02 17:37:11 +0000 |
---|---|---|
committer | Godin <mandrikov@gmail.com> | 2010-11-02 17:37:11 +0000 |
commit | a5c8a5524aa6aceb9b8e80136640b5c465b30761 (patch) | |
tree | 667136b7a7669e8b233b54bf515bc614d7c10faa /plugins/sonar-findbugs-plugin | |
parent | 638bee10bb066255c5dcac560e992de027f15fef (diff) | |
download | sonarqube-a5c8a5524aa6aceb9b8e80136640b5c465b30761.tar.gz sonarqube-a5c8a5524aa6aceb9b8e80136640b5c465b30761.zip |
SONAR-1772: Add annotations.jar and jsr305.jar to auxiliary classpath before launching Findbugs analysis
Diffstat (limited to 'plugins/sonar-findbugs-plugin')
7 files changed, 39 insertions, 152 deletions
diff --git a/plugins/sonar-findbugs-plugin/pom.xml b/plugins/sonar-findbugs-plugin/pom.xml index 509b963193e..a440d794346 100644 --- a/plugins/sonar-findbugs-plugin/pom.xml +++ b/plugins/sonar-findbugs-plugin/pom.xml @@ -116,6 +116,23 @@ <plugins> <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>copy-dependencies</id> + <phase>process-resources</phase> + <goals> + <goal>copy-dependencies</goal> + </goals> + <configuration> + <outputDirectory>${project.build.outputDirectory}</outputDirectory> + <includeArtifactIds>annotations,jsr305</includeArtifactIds> + </configuration> + </execution> + </executions> + </plugin> + <plugin> <groupId>org.codehaus.sonar</groupId> <artifactId>sonar-packaging-maven-plugin</artifactId> <configuration> diff --git a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java index 6a80b3bbb9c..05b220aa092 100644 --- a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java +++ b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java @@ -21,8 +21,12 @@ 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; import org.sonar.api.BatchExtension; import org.sonar.api.CoreProperties; @@ -43,15 +47,12 @@ public class FindbugsConfiguration implements BatchExtension { private RulesProfile profile; private FindbugsProfileExporter exporter; private ProjectClasspath projectClasspath; - private FindbugsDownloader downloader; - public FindbugsConfiguration(Project project, RulesProfile profile, FindbugsProfileExporter exporter, ProjectClasspath classpath, - FindbugsDownloader downloader) { + public FindbugsConfiguration(Project project, RulesProfile profile, FindbugsProfileExporter exporter, ProjectClasspath classpath) { this.project = project; this.profile = profile; this.exporter = exporter; this.projectClasspath = classpath; - this.downloader = downloader; } public File getTargetXMLReport() { @@ -78,9 +79,8 @@ public class FindbugsConfiguration implements BatchExtension { findbugsProject.addAuxClasspathEntry(file.getAbsolutePath()); } } - for (File file : downloader.getLibs()) { - findbugsProject.addAuxClasspathEntry(file.getAbsolutePath()); - } + findbugsProject.addAuxClasspathEntry(copyLib("/annotations-" + FindbugsVersion.getVersion() + ".jar").getAbsolutePath()); + findbugsProject.addAuxClasspathEntry(copyLib("/jsr305-" + FindbugsVersion.getVersion() + ".jar").getAbsolutePath()); findbugsProject.setCurrentWorkingDirectory(project.getFileSystem().getBuildDir()); return findbugsProject; } @@ -110,4 +110,17 @@ public class FindbugsConfiguration implements BatchExtension { public long getTimeout() { return project.getConfiguration().getLong(CoreProperties.FINDBUGS_TIMEOUT_PROPERTY, CoreProperties.FINDBUGS_TIMEOUT_DEFAULT_VALUE); } + + 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; + } catch (IOException e) { + throw new SonarException(e); + } + } } diff --git a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsDownloader.java b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsDownloader.java deleted file mode 100644 index 96f9e9f33b7..00000000000 --- a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsDownloader.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * Sonar 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. - * - * Sonar 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 Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.plugins.findbugs; - -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.io.FileUtils; -import org.sonar.api.BatchExtension; -import org.sonar.api.platform.Server; -import org.sonar.api.utils.HttpDownloader; -import org.sonar.api.utils.SonarException; - -public class FindbugsDownloader implements BatchExtension { - - private static final String FINDBUGS_URL = "/deploy/plugins/findbugs"; - - private static List<File> libs; - - private HttpDownloader downloader; - private String serverUrl; - - public FindbugsDownloader(Server server, HttpDownloader downloader) { - this.downloader = downloader; - this.serverUrl = server.getURL(); - } - - public synchronized List<File> getLibs() { - if (libs == null) { - libs = Arrays.asList(downloadLib(getUrlForAnnotationsJar()), downloadLib(getUrlForJsrJar())); - } - return libs; - } - - /** - * Visibility has been relaxed to make the code testable. - */ - protected String getUrlForAnnotationsJar() { - return serverUrl + FINDBUGS_URL + "/annotations-" + FindbugsVersion.getVersion() + ".jar"; - } - - /** - * Visibility has been relaxed to make the code testable. - */ - protected String getUrlForJsrJar() { - return serverUrl + FINDBUGS_URL + "/jsr305-" + FindbugsVersion.getVersion() + ".jar"; - } - - protected File downloadLib(String url) { - try { - URI uri = new URI(url); - File temp = File.createTempFile("findbugs", ".jar"); - FileUtils.forceDeleteOnExit(temp); - downloader.download(uri, temp); - return temp; - } catch (URISyntaxException e) { - throw new SonarException(e); - } catch (IOException e) { - throw new SonarException(e); - } - } -} diff --git a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsPlugin.java b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsPlugin.java index 912cf15899f..2a369d3ff1a 100644 --- a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsPlugin.java +++ b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsPlugin.java @@ -59,7 +59,6 @@ public class FindbugsPlugin implements Plugin { List<Class<? extends Extension>> list = new ArrayList<Class<? extends Extension>>(); list.add(FindbugsSensor.class); list.add(FindbugsConfiguration.class); - list.add(FindbugsDownloader.class); list.add(FindbugsExecutor.class); list.add(FindbugsRuleRepository.class); list.add(FindbugsProfileExporter.class); diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java index d6f871ea281..e31d0d0a462 100644 --- a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java +++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java @@ -51,7 +51,7 @@ public class FindbugsConfigurationTest { @Test public void shouldSaveConfigFiles() throws Exception { - FindbugsConfiguration conf = new FindbugsConfiguration(project, RulesProfile.create(), new FindbugsProfileExporter(), null, null); + FindbugsConfiguration conf = new FindbugsConfiguration(project, RulesProfile.create(), new FindbugsProfileExporter(), null); conf.saveIncludeConfigXml(); conf.saveExcludeConfigXml(); diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsDownloaderTest.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsDownloaderTest.java deleted file mode 100644 index 25ff6f54b30..00000000000 --- a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsDownloaderTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * Sonar 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. - * - * Sonar 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 Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.plugins.findbugs; - -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.File; - -import org.junit.Before; -import org.junit.Test; -import org.sonar.api.platform.Server; -import org.sonar.api.utils.HttpDownloader; - -public class FindbugsDownloaderTest { - - private FindbugsDownloader downloader; - - @Before - public void setUp() { - Server server = mock(Server.class); - when(server.getURL()).thenReturn("http://sonar"); - - HttpDownloader httpDownloader = mock(HttpDownloader.class); - downloader = new FindbugsDownloader(server, httpDownloader); - } - - @Test - public void testUrls() { - assertThat(downloader.getUrlForAnnotationsJar(), startsWith("http://sonar/deploy/plugins/findbugs/annotations-")); - assertThat(downloader.getUrlForJsrJar(), startsWith("http://sonar/deploy/plugins/findbugs/jsr305-")); - } - - @Test - public void shouldCreateTempFile() { - File file = downloader.downloadLib("http://sonar/test.jar"); - assertThat(file.exists(), is(true)); - } -} diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsExecutorTest.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsExecutorTest.java index fd6fc2045de..8e488266754 100644 --- a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsExecutorTest.java +++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsExecutorTest.java @@ -64,7 +64,7 @@ public class FindbugsExecutorTest { Project project = mock(Project.class); ProjectFileSystem fs = mock(ProjectFileSystem.class); when(project.getFileSystem()).thenReturn(fs); - FindbugsConfiguration conf = new FindbugsConfiguration(project, null, null, null, null); + FindbugsConfiguration conf = new FindbugsConfiguration(project, null, null, null); new FindbugsExecutor(conf).execute(); } |