--- /dev/null
+/*
+ * 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);
+ }
+ }
+}
private static final Logger LOG = LoggerFactory.getLogger(BatchPluginRepository.class);
private JpaPluginDao dao;
- private ExtensionDownloader artifactDownloader;
+ private ArtifactDownloader artifactDownloader;
private Map<String, Plugin> 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());
private URLClassLoader classLoader;
- public BootstrapClassLoader(ExtensionDownloader extensionDownloader) {
+ public BootstrapClassLoader(ArtifactDownloader extensionDownloader) {
this(extensionDownloader.downloadJdbcDriver());
}
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();
+++ /dev/null
-/*
- * 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);
- }
- }
-}
* Module describes group of components - {@link #configure()}.
* Several modules can be grouped together - {@link #install(Module)}, {@link #installChild(Module)}.
* <p/>
- * TODO Move to org.sonar.batch.bootstrap ?
*/
public abstract class Module {
--- /dev/null
+/*
+ * 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);
+ }
+}
@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);
*/
@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);
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<JpaPluginFile>() {
public boolean matches(Object o) {
return o != null && ((JpaPluginFile) o).getPluginKey().equals(pluginKey);
+++ /dev/null
-/*
- * 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);
- }
-}