import java.io.File;
import java.text.MessageFormat;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Sets.newHashSet;
}
static class PluginFilter {
+ private static final String BUILDBREAKER_PLUGIN_KEY = "buildbreaker";
private static final String PROPERTY_IS_DEPRECATED_MSG = "Property {0} is deprecated. Please use {1} instead.";
Set<String> whites = newHashSet(), blacks = newHashSet();
private DefaultAnalysisMode mode;
return !mode.isMediumTest();
}
+ if (BUILDBREAKER_PLUGIN_KEY.equals(pluginKey) && mode.isPreview()) {
+ LOG.info("Build Breaker plugin is no more supported in preview/incremental mode");
+ return false;
+ }
+
List<String> mergeList = newArrayList(blacks);
mergeList.removeAll(whites);
return mergeList.isEmpty() || !mergeList.contains(pluginKey);
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.batch.bootstrap;
-
-import com.google.common.collect.Lists;
-import org.apache.commons.lang.CharUtils;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.SonarPlugin;
-import org.sonar.api.platform.PluginMetadata;
-import org.sonar.core.plugins.RemotePlugin;
-import org.sonar.core.plugins.RemotePluginFile;
-import org.sonar.home.cache.FileCache;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-/**
- * A {@link PluginsRepository} implementation that put downloaded plugins in a FS cache.
- */
-public class DefaultPluginsReferential implements PluginsRepository {
-
- private static final Logger LOG = LoggerFactory.getLogger(DefaultPluginsReferential.class);
-
- private ServerClient server;
- private FileCache fileCache;
-
- public DefaultPluginsReferential(FileCache fileCache, ServerClient server) {
- this.server = server;
- this.fileCache = fileCache;
- }
-
- @Override
- public File pluginFile(final RemotePlugin remote) {
- try {
- final RemotePluginFile file = remote.file();
- return fileCache.get(file.getFilename(), file.getHash(), new FileCache.Downloader() {
- @Override
- public void download(String filename, File toFile) throws IOException {
- String url = "/deploy/plugins/" + remote.getKey() + "/" + file.getFilename();
- if (LOG.isDebugEnabled()) {
- LOG.debug("Download {} to {}", url, toFile.getAbsolutePath());
- } else {
- LOG.info("Download {}", file.getFilename());
- }
- server.download(url, toFile);
- }
- });
-
- } catch (Exception e) {
- throw new IllegalStateException("Fail to download plugin: " + remote.getKey(), e);
- }
- }
-
- @Override
- public List<RemotePlugin> pluginList() {
- String url = "/deploy/plugins/index.txt";
- try {
- LOG.debug("Download index of plugins");
- String indexContent = server.request(url);
- String[] rows = StringUtils.split(indexContent, CharUtils.LF);
- List<RemotePlugin> remoteLocations = Lists.newArrayList();
- for (String row : rows) {
- remoteLocations.add(RemotePlugin.unmarshal(row));
- }
- return remoteLocations;
-
- } catch (Exception e) {
- throw new IllegalStateException("Fail to download plugins index: " + url, e);
- }
- }
-
- @Override
- public Map<PluginMetadata, SonarPlugin> localPlugins() {
- return Collections.emptyMap();
- }
-
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.batch.bootstrap;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.lang.CharUtils;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.SonarPlugin;
+import org.sonar.api.platform.PluginMetadata;
+import org.sonar.core.plugins.RemotePlugin;
+import org.sonar.core.plugins.RemotePluginFile;
+import org.sonar.home.cache.FileCache;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A {@link PluginsRepository} implementation that put downloaded plugins in a FS cache.
+ */
+public class DefaultPluginsRepository implements PluginsRepository {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DefaultPluginsRepository.class);
+
+ private ServerClient server;
+ private FileCache fileCache;
+
+ public DefaultPluginsRepository(FileCache fileCache, ServerClient server) {
+ this.server = server;
+ this.fileCache = fileCache;
+ }
+
+ @Override
+ public File pluginFile(final RemotePlugin remote) {
+ try {
+ final RemotePluginFile file = remote.file();
+ return fileCache.get(file.getFilename(), file.getHash(), new FileCache.Downloader() {
+ @Override
+ public void download(String filename, File toFile) throws IOException {
+ String url = "/deploy/plugins/" + remote.getKey() + "/" + file.getFilename();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Download {} to {}", url, toFile.getAbsolutePath());
+ } else {
+ LOG.info("Download {}", file.getFilename());
+ }
+ server.download(url, toFile);
+ }
+ });
+
+ } catch (Exception e) {
+ throw new IllegalStateException("Fail to download plugin: " + remote.getKey(), e);
+ }
+ }
+
+ @Override
+ public List<RemotePlugin> pluginList() {
+ String url = "/deploy/plugins/index.txt";
+ try {
+ LOG.debug("Download index of plugins");
+ String indexContent = server.request(url);
+ String[] rows = StringUtils.split(indexContent, CharUtils.LF);
+ List<RemotePlugin> remoteLocations = Lists.newArrayList();
+ for (String row : rows) {
+ remoteLocations.add(RemotePlugin.unmarshal(row));
+ }
+ return remoteLocations;
+
+ } catch (Exception e) {
+ throw new IllegalStateException("Fail to download plugins index: " + url, e);
+ }
+ }
+
+ @Override
+ public Map<PluginMetadata, SonarPlugin> localPlugins() {
+ return Collections.emptyMap();
+ }
+
+}
new GlobalRepositoriesProvider(),
UserRepository.class);
if (getComponentByType(PluginsRepository.class) == null) {
- add(DefaultPluginsReferential.class);
+ add(DefaultPluginsRepository.class);
}
if (getComponentByType(GlobalRepositoriesLoader.class) == null) {
add(DefaultGlobalRepositoriesLoader.class);
@Before
public void before() throws IOException {
mode = mock(DefaultAnalysisMode.class);
+ when(mode.isPreview()).thenReturn(false);
userHome = temp.newFolder();
cache = new FileCacheBuilder().setUserHome(userHome).build();
}
public void shouldLoadPlugin() throws Exception {
RemotePlugin checkstyle = new RemotePlugin("checkstyle", true);
- DefaultPluginsReferential downloader = mock(DefaultPluginsReferential.class);
+ DefaultPluginsRepository downloader = mock(DefaultPluginsRepository.class);
when(downloader.pluginFile(checkstyle)).thenReturn(fileFromCache("sonar-checkstyle-plugin-2.8.jar"));
repository = new BatchPluginRepository(downloader, new Settings(), mode, new BatchPluginJarInstaller(cache));
RemotePlugin checkstyle = new RemotePlugin("checkstyle", true);
RemotePlugin checkstyleExt = new RemotePlugin("checkstyleextensions", false);
- DefaultPluginsReferential downloader = mock(DefaultPluginsReferential.class);
+ DefaultPluginsRepository downloader = mock(DefaultPluginsRepository.class);
when(downloader.pluginFile(checkstyle)).thenReturn(fileFromCache("sonar-checkstyle-plugin-2.8.jar"));
when(downloader.pluginFile(checkstyleExt)).thenReturn(fileFromCache("sonar-checkstyle-extensions-plugin-0.1-SNAPSHOT.jar"));
RemotePlugin checkstyle = new RemotePlugin("checkstyle", true);
RemotePlugin checkstyleExt = new RemotePlugin("checkstyleextensions", false);
- DefaultPluginsReferential downloader = mock(DefaultPluginsReferential.class);
+ DefaultPluginsRepository downloader = mock(DefaultPluginsRepository.class);
when(downloader.pluginFile(checkstyle)).thenReturn(fileFromCache("sonar-checkstyle-plugin-2.8.jar"));
when(downloader.pluginFile(checkstyleExt)).thenReturn(fileFromCache("sonar-checkstyle-extensions-plugin-0.1-SNAPSHOT.jar"));
public void shouldAlwaysAcceptIfNoWhiteListAndBlackList() {
BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(new Settings(), mode);
assertThat(filter.accepts("pmd")).isTrue();
+ assertThat(filter.accepts("buildbreaker")).isTrue();
+ }
+
+ @Test
+ public void shouldBlackListBuildBreakerInPreviewMode() {
+ when(mode.isPreview()).thenReturn(true);
+ BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(new Settings(), mode);
+ assertThat(filter.accepts("buildbreaker")).isFalse();
}
@Test
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.batch.bootstrap;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.core.plugins.RemotePlugin;
-import org.sonar.home.cache.FileCache;
-
-import java.io.File;
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class DefaultPluginsReferentialTest {
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Test
- public void should_request_list_of_plugins() {
- FileCache cache = mock(FileCache.class);
- ServerClient server = mock(ServerClient.class);
- when(server.request("/deploy/plugins/index.txt")).thenReturn("checkstyle,true\nsqale,false");
- DefaultPluginsReferential downloader = new DefaultPluginsReferential(cache, server);
-
- List<RemotePlugin> plugins = downloader.pluginList();
- assertThat(plugins).hasSize(2);
- assertThat(plugins.get(0).getKey()).isEqualTo("checkstyle");
- assertThat(plugins.get(0).isCore()).isTrue();
- assertThat(plugins.get(1).getKey()).isEqualTo("sqale");
- assertThat(plugins.get(1).isCore()).isFalse();
- }
-
- @Test
- public void should_download_plugin() throws Exception {
- FileCache cache = mock(FileCache.class);
-
- File pluginJar = temp.newFile();
- when(cache.get(eq("checkstyle-plugin.jar"), eq("fakemd5_1"), any(FileCache.Downloader.class))).thenReturn(pluginJar);
-
- ServerClient server = mock(ServerClient.class);
- DefaultPluginsReferential downloader = new DefaultPluginsReferential(cache, server);
-
- RemotePlugin plugin = new RemotePlugin("checkstyle", true)
- .setFile("checkstyle-plugin.jar", "fakemd5_1");
- File file = downloader.pluginFile(plugin);
-
- assertThat(file).isEqualTo(pluginJar);
- }
-
- @Test
- public void should_fail_to_get_plugin_index() throws Exception {
- thrown.expect(IllegalStateException.class);
-
- ServerClient server = mock(ServerClient.class);
- doThrow(new IllegalStateException()).when(server).request("/deploy/plugins/index.txt");
-
- new DefaultPluginsReferential(mock(FileCache.class), server).pluginList();
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.batch.bootstrap;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.core.plugins.RemotePlugin;
+import org.sonar.home.cache.FileCache;
+
+import java.io.File;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class DefaultPluginsRepositoryTest {
+
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void should_request_list_of_plugins() {
+ FileCache cache = mock(FileCache.class);
+ ServerClient server = mock(ServerClient.class);
+ when(server.request("/deploy/plugins/index.txt")).thenReturn("checkstyle,true\nsqale,false");
+ DefaultPluginsRepository downloader = new DefaultPluginsRepository(cache, server);
+
+ List<RemotePlugin> plugins = downloader.pluginList();
+ assertThat(plugins).hasSize(2);
+ assertThat(plugins.get(0).getKey()).isEqualTo("checkstyle");
+ assertThat(plugins.get(0).isCore()).isTrue();
+ assertThat(plugins.get(1).getKey()).isEqualTo("sqale");
+ assertThat(plugins.get(1).isCore()).isFalse();
+ }
+
+ @Test
+ public void should_download_plugin() throws Exception {
+ FileCache cache = mock(FileCache.class);
+
+ File pluginJar = temp.newFile();
+ when(cache.get(eq("checkstyle-plugin.jar"), eq("fakemd5_1"), any(FileCache.Downloader.class))).thenReturn(pluginJar);
+
+ ServerClient server = mock(ServerClient.class);
+ DefaultPluginsRepository downloader = new DefaultPluginsRepository(cache, server);
+
+ RemotePlugin plugin = new RemotePlugin("checkstyle", true)
+ .setFile("checkstyle-plugin.jar", "fakemd5_1");
+ File file = downloader.pluginFile(plugin);
+
+ assertThat(file).isEqualTo(pluginJar);
+ }
+
+ @Test
+ public void should_fail_to_get_plugin_index() throws Exception {
+ thrown.expect(IllegalStateException.class);
+
+ ServerClient server = mock(ServerClient.class);
+ doThrow(new IllegalStateException()).when(server).request("/deploy/plugins/index.txt");
+
+ new DefaultPluginsRepository(mock(FileCache.class), server).pluginList();
+ }
+}