</testResources>
<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>
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;
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() {
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;
}
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);
+ }
+ }
}
+++ /dev/null
-/*
- * 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);
- }
- }
-}
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);
@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();
+++ /dev/null
-/*
- * 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));
- }
-}
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();
}