From: simonbrandhof Date: Fri, 27 May 2011 13:15:17 +0000 (+0200) Subject: Rename org.sonar.batch.ExtensionDownloader to ArtifactDownloader X-Git-Tag: 2.9~129 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=78f121539257fda264f929a4d596e3919eaafdcc;p=sonarqube.git Rename org.sonar.batch.ExtensionDownloader to ArtifactDownloader --- diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ArtifactDownloader.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ArtifactDownloader.java new file mode 100644 index 00000000000..6aa16b1c1e1 --- /dev/null +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ArtifactDownloader.java @@ -0,0 +1,67 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * 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.batch.bootstrap; + +import org.sonar.api.BatchComponent; +import org.sonar.api.utils.HttpDownloader; +import org.sonar.api.utils.SonarException; +import org.sonar.batch.ServerMetadata; +import org.sonar.core.plugin.JpaPluginFile; + +import java.io.File; +import java.net.URI; +import java.net.URISyntaxException; + +public class ArtifactDownloader implements BatchComponent { + + private HttpDownloader httpDownloader; + private TempDirectories workingDirectories; + private String baseUrl; + + public ArtifactDownloader(HttpDownloader httpDownloader, TempDirectories workingDirectories, ServerMetadata server) { + this.httpDownloader = httpDownloader; + this.workingDirectories = workingDirectories; + this.baseUrl = server.getURL(); + } + + public File downloadJdbcDriver() { + String url = baseUrl + "/deploy/jdbc-driver.jar"; + try { + File jdbcDriver = new File(workingDirectories.getRoot(), "jdbc-driver.jar"); + httpDownloader.download(new URI(url), jdbcDriver); + return jdbcDriver; + + } catch (URISyntaxException e) { + throw new SonarException("Fail to download the JDBC driver from : " + url, e); + } + } + + public File downloadExtension(JpaPluginFile extension) { + File targetFile = new File(workingDirectories.getDir(extension.getPluginKey()), extension.getFilename()); + String url = baseUrl + "/deploy/plugins/" + extension.getPluginKey() + "/" + extension.getFilename(); + try { + httpDownloader.download(new URI(url), targetFile); + return targetFile; + + } catch (URISyntaxException e) { + throw new SonarException("Fail to download extension: " + url, e); + } + } +} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java index b647df8bc7a..47270c198ab 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java @@ -47,10 +47,10 @@ public class BatchPluginRepository implements PluginRepository { private static final Logger LOG = LoggerFactory.getLogger(BatchPluginRepository.class); private JpaPluginDao dao; - private ExtensionDownloader artifactDownloader; + private ArtifactDownloader artifactDownloader; private Map pluginsByKey; - public BatchPluginRepository(JpaPluginDao dao, ExtensionDownloader artifactDownloader) { + public BatchPluginRepository(JpaPluginDao dao, ArtifactDownloader artifactDownloader) { this.dao = dao; this.artifactDownloader = artifactDownloader; // TODO reactivate somewhere else: LOG.info("Execution environment: {} {}", environment.getKey(), environment.getVersion()); diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapClassLoader.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapClassLoader.java index e9ec1e8cf7c..ca00f9a0691 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapClassLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapClassLoader.java @@ -33,7 +33,7 @@ public class BootstrapClassLoader { private URLClassLoader classLoader; - public BootstrapClassLoader(ExtensionDownloader extensionDownloader) { + public BootstrapClassLoader(ArtifactDownloader extensionDownloader) { this(extensionDownloader.downloadJdbcDriver()); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java index 10546623f32..fda540156a8 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java @@ -55,7 +55,7 @@ public class BootstrapModule extends Module { addComponent(ServerMetadata.class);// registered here because used by BootstrapClassLoader addComponent(TempDirectories.class);// registered here because used by BootstrapClassLoader addComponent(HttpDownloader.class);// registered here because used by BootstrapClassLoader - addComponent(ExtensionDownloader.class);// registered here because used by BootstrapClassLoader + addComponent(ArtifactDownloader.class);// registered here because used by BootstrapClassLoader addComponent(BootstrapClassLoader.class); URLClassLoader bootstrapClassLoader = getComponent(BootstrapClassLoader.class).getClassLoader(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionDownloader.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionDownloader.java deleted file mode 100644 index 397838986f7..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionDownloader.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource - * 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.batch.bootstrap; - -import org.sonar.api.BatchComponent; -import org.sonar.api.utils.HttpDownloader; -import org.sonar.api.utils.SonarException; -import org.sonar.batch.ServerMetadata; -import org.sonar.core.plugin.JpaPluginFile; - -import java.io.File; -import java.net.URI; -import java.net.URISyntaxException; - -/** - * TODO this class should be renamed ArtifactDownloader, because it does not relate only to plugin extensions. - */ -public class ExtensionDownloader implements BatchComponent { - - private HttpDownloader httpDownloader; - private TempDirectories workingDirectories; - private String baseUrl; - - public ExtensionDownloader(HttpDownloader httpDownloader, TempDirectories workingDirectories, ServerMetadata server) { - this.httpDownloader = httpDownloader; - this.workingDirectories = workingDirectories; - this.baseUrl = server.getURL(); - } - - public File downloadJdbcDriver() { - String url = baseUrl + "/deploy/jdbc-driver.jar"; - try { - File jdbcDriver = new File(workingDirectories.getRoot(), "jdbc-driver.jar"); - httpDownloader.download(new URI(url), jdbcDriver); - return jdbcDriver; - - } catch (URISyntaxException e) { - throw new SonarException("Fail to download the JDBC driver from : " + url, e); - } - } - - public File downloadExtension(JpaPluginFile extension) { - File targetFile = new File(workingDirectories.getDir(extension.getPluginKey()), extension.getFilename()); - String url = baseUrl + "/deploy/plugins/" + extension.getPluginKey() + "/" + extension.getFilename(); - try { - httpDownloader.download(new URI(url), targetFile); - return targetFile; - - } catch (URISyntaxException e) { - throw new SonarException("Fail to download extension: " + url, e); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/Module.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/Module.java index 2c0d289b548..0fab9682c7b 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/Module.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/Module.java @@ -30,7 +30,6 @@ import java.util.List; * Module describes group of components - {@link #configure()}. * Several modules can be grouped together - {@link #install(Module)}, {@link #installChild(Module)}. *

- * TODO Move to org.sonar.batch.bootstrap ? */ public abstract class Module { diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ArtifactDownloaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ArtifactDownloaderTest.java new file mode 100644 index 00000000000..e318ca69249 --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ArtifactDownloaderTest.java @@ -0,0 +1,68 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * 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.batch.bootstrap; + +import org.junit.Test; +import org.sonar.api.utils.HttpDownloader; +import org.sonar.batch.ServerMetadata; +import org.sonar.core.plugin.JpaPlugin; +import org.sonar.core.plugin.JpaPluginFile; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; + +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.*; + +public class ArtifactDownloaderTest { + + @Test + public void shouldDownloadJdbcDriver() throws IOException, URISyntaxException { + ServerMetadata server = mock(ServerMetadata.class); + when(server.getURL()).thenReturn("http://sonar:8000"); + + HttpDownloader httpDownloader = mock(HttpDownloader.class); + TempDirectories workingDirectories = new TempDirectories(); + + ArtifactDownloader downloader = new ArtifactDownloader(httpDownloader, workingDirectories, server); + File jdbcDriver = downloader.downloadJdbcDriver(); + + assertNotNull(jdbcDriver); + verify(httpDownloader).download(new URI("http://sonar:8000/deploy/jdbc-driver.jar"), jdbcDriver); + } + + @Test + public void shouldDownloadExtension() throws IOException, URISyntaxException { + ServerMetadata server = mock(ServerMetadata.class); + when(server.getURL()).thenReturn("http://sonar:8000"); + + HttpDownloader httpDownloader = mock(HttpDownloader.class); + TempDirectories workingDirectories = new TempDirectories(); + + ArtifactDownloader downloader = new ArtifactDownloader(httpDownloader, workingDirectories, server); + JpaPluginFile extension = new JpaPluginFile(new JpaPlugin("findbugs"), "bcel.jar"); + File bcel = downloader.downloadExtension(extension); + + assertNotNull(bcel); + verify(httpDownloader).download(new URI("http://sonar:8000/deploy/plugins/findbugs/bcel.jar"), bcel); + } +} diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java index 6e848f4278d..0c617bf4271 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java @@ -43,7 +43,7 @@ public class BatchPluginRepositoryTest { @Test public void shouldLoadPlugin() { - ExtensionDownloader extensionDownloader = mock(ExtensionDownloader.class); + ArtifactDownloader extensionDownloader = mock(ArtifactDownloader.class); when(extensionDownloader.downloadExtension(any(JpaPluginFile.class))).thenReturn( FileUtils.toFile(getClass().getResource("/org/sonar/batch/bootstrap/BatchPluginRepositoryTest/sonar-artifact-size-plugin-0.2.jar"))); BatchPluginRepository repository = new BatchPluginRepository(null, extensionDownloader); @@ -64,7 +64,7 @@ public class BatchPluginRepositoryTest { */ @Test public void shouldPluginExtensionInTheSameClassloader() { - ExtensionDownloader extensionDownloader = mock(ExtensionDownloader.class); + ArtifactDownloader extensionDownloader = mock(ArtifactDownloader.class); prepareDownloader(extensionDownloader, "artifactsize", "/org/sonar/batch/bootstrap/BatchPluginRepositoryTest/sonar-artifact-size-plugin-0.2.jar"); prepareDownloader(extensionDownloader, "clirr", "/org/sonar/batch/bootstrap/BatchPluginRepositoryTest/sonar-clirr-plugin-1.1.jar"); BatchPluginRepository repository = new BatchPluginRepository(null, extensionDownloader); @@ -85,7 +85,7 @@ public class BatchPluginRepositoryTest { assertThat(entryPointBase.getClass().getClassLoader(), is(entryPointExtension.getClass().getClassLoader())); } - private void prepareDownloader(ExtensionDownloader extensionDownloader, final String pluginKey, final String filename) { + private void prepareDownloader(ArtifactDownloader extensionDownloader, final String pluginKey, final String filename) { when(extensionDownloader.downloadExtension(argThat(new BaseMatcher() { public boolean matches(Object o) { return o != null && ((JpaPluginFile) o).getPluginKey().equals(pluginKey); diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionDownloaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionDownloaderTest.java deleted file mode 100644 index ab9a0aad137..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionDownloaderTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource - * 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.batch.bootstrap; - -import org.junit.Test; -import org.sonar.api.utils.HttpDownloader; -import org.sonar.batch.ServerMetadata; -import org.sonar.core.plugin.JpaPlugin; -import org.sonar.core.plugin.JpaPluginFile; - -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; - -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.*; - -public class ExtensionDownloaderTest { - - @Test - public void shouldDownloadJdbcDriver() throws IOException, URISyntaxException { - ServerMetadata server = mock(ServerMetadata.class); - when(server.getURL()).thenReturn("http://sonar:8000"); - - HttpDownloader httpDownloader = mock(HttpDownloader.class); - TempDirectories workingDirectories = new TempDirectories(); - - ExtensionDownloader downloader = new ExtensionDownloader(httpDownloader, workingDirectories, server); - File jdbcDriver = downloader.downloadJdbcDriver(); - - assertNotNull(jdbcDriver); - verify(httpDownloader).download(new URI("http://sonar:8000/deploy/jdbc-driver.jar"), jdbcDriver); - } - - @Test - public void shouldDownloadExtension() throws IOException, URISyntaxException { - ServerMetadata server = mock(ServerMetadata.class); - when(server.getURL()).thenReturn("http://sonar:8000"); - - HttpDownloader httpDownloader = mock(HttpDownloader.class); - TempDirectories workingDirectories = new TempDirectories(); - - ExtensionDownloader downloader = new ExtensionDownloader(httpDownloader, workingDirectories, server); - JpaPluginFile extension = new JpaPluginFile(new JpaPlugin("findbugs"), "bcel.jar"); - File bcel = downloader.downloadExtension(extension); - - assertNotNull(bcel); - verify(httpDownloader).download(new URI("http://sonar:8000/deploy/plugins/findbugs/bcel.jar"), bcel); - } -}