]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1772: Add annotations.jar and jsr305.jar to auxiliary classpath before launchin...
authorGodin <mandrikov@gmail.com>
Tue, 2 Nov 2010 17:37:11 +0000 (17:37 +0000)
committerGodin <mandrikov@gmail.com>
Tue, 2 Nov 2010 17:37:11 +0000 (17:37 +0000)
plugins/sonar-findbugs-plugin/pom.xml
plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java
plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsDownloader.java [deleted file]
plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsPlugin.java
plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsConfigurationTest.java
plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsDownloaderTest.java [deleted file]
plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsExecutorTest.java

index 509b963193e4d7fd78d629dd6c508bcab7be96e3..a440d794346a77e0594730101360f02583e09fd5 100644 (file)
     </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>
index 6a80b3bbb9c62351f52057982f98f9916aece576..05b220aa092a28a288be6d97c68993c61f0674a7 100644 (file)
@@ -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 (file)
index 96f9e9f..0000000
+++ /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);
-    }
-  }
-}
index 912cf15899f86972e378ac9156849d2c6d299779..2a369d3ff1ac4a0768c6ccc1f186c8ff64f5cdfa 100644 (file)
@@ -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);
index d6f871ea281fa9becac72555d65e3dfc5487ac5c..e31d0d0a46255a0758af3d0e1bccbff97383331a 100644 (file)
@@ -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 (file)
index 25ff6f5..0000000
+++ /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));
-  }
-}
index fd6fc2045decb5c0b25885ccb6aca330d3d1f4a4..8e488266754390692b5914269c249780133cfb11 100644 (file)
@@ -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();
   }